Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- jQuery(function(){
- /* Auto Complete */
- var availableTags = [
- <?php
- $terms_array = array();
- $terms = get_terms( 'majors', 'hide_empty=0' );
- if ($terms) foreach ($terms as $term) {
- $terms_array[] = '"'.$term->name.'"';
- }
- echo implode(',', $terms_array);
- ?>
- ];
- function split( val ) {
- return val.split( /,\s*/ );
- }
- function extractLast( term ) {
- return split( term ).pop();
- }
- jQuery(".majors_wrap input").live( "keydown", function( event ) {
- if ( (event.keyCode === jQuery.ui.keyCode.TAB || event.keyCode === jQuery.ui.keyCode.COMMA) &&
- jQuery( this ).data( "autocomplete" ).menu.active ) {
- event.preventDefault();
- }
- }).autocomplete({
- minLength: 0,
- source: function( request, response ) {
- // delegate back to autocomplete, but extract the last term
- response( jQuery.ui.autocomplete.filter(
- availableTags, extractLast( request.term ) ) );
- },
- focus: function() {
- jQuery('input.ui-autocomplete-input').val('');
- // prevent value inserted on focus
- return false;
- },
- select: function( event, ui ) {
- var terms = split( this.value );
- // remove the current input
- terms.pop();
- // add the selected item
- terms.push( ui.item.value );
- // add placeholder to get the comma-and-space at the end
- terms.push( "" );
- //this.value = terms.join( ", " );
- this.value = terms.join( "" );
- jQuery(this).blur();
- jQuery(this).focus();
- return false;
- }
- });
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement