Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2011
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <script type="text/javascript">
  2.  
  3. jQuery(function(){
  4.  
  5. /* Auto Complete */
  6. var availableTags = [
  7. <?php
  8. $terms_array = array();
  9. $terms = get_terms( 'majors', 'hide_empty=0' );
  10.  
  11. if ($terms) foreach ($terms as $term) {
  12. $terms_array[] = '"'.$term->name.'"';
  13. }
  14. echo implode(',', $terms_array);
  15. ?>
  16. ];
  17. function split( val ) {
  18. return val.split( /,\s*/ );
  19. }
  20. function extractLast( term ) {
  21. return split( term ).pop();
  22.  
  23. }
  24.  
  25.  
  26. jQuery(".majors_wrap input").live( "keydown", function( event ) {
  27. if ( (event.keyCode === jQuery.ui.keyCode.TAB || event.keyCode === jQuery.ui.keyCode.COMMA) &&
  28. jQuery( this ).data( "autocomplete" ).menu.active ) {
  29. event.preventDefault();
  30. }
  31. }).autocomplete({
  32. minLength: 0,
  33. source: function( request, response ) {
  34. // delegate back to autocomplete, but extract the last term
  35. response( jQuery.ui.autocomplete.filter(
  36. availableTags, extractLast( request.term ) ) );
  37. },
  38. focus: function() {
  39. jQuery('input.ui-autocomplete-input').val('');
  40. // prevent value inserted on focus
  41. return false;
  42. },
  43. select: function( event, ui ) {
  44.  
  45. var terms = split( this.value );
  46. // remove the current input
  47. terms.pop();
  48. // add the selected item
  49. terms.push( ui.item.value );
  50. // add placeholder to get the comma-and-space at the end
  51. terms.push( "" );
  52.  
  53. //this.value = terms.join( ", " );
  54. this.value = terms.join( "" );
  55.  
  56. jQuery(this).blur();
  57. jQuery(this).focus();
  58.  
  59. return false;
  60. }
  61. });
  62.  
  63. });
  64. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement