src/jquery-tokeninput/jquery-tokeninput.js
function populate_dropdown (query, results) {
          // exclude current tokens if configured
          results = excludeCurrent(results);

          if(results && results.length) {
              dropdown.empty();
              var dropdown_ul = $("<ul/>")
                  .appendTo(dropdown)
                  .mouseover(function (event) {
                      select_dropdown_item($(event.target).closest("li"));
                  })
                  .mousedown(function (event) {
                      add_token($(event.target).closest("li").data("tokeninput"));
                      hidden_input.change();
                      return false;
                  })
                  .hide();

              if ($(input).data("settings").resultsLimit && results.length > $(input).data("settings").resultsLimit) {
                  results = results.slice(0, $(input).data("settings").resultsLimit);
              }

              $.each(results, function(index, value) {
                  var this_li = $(input).data("settings").resultsFormatter(value);

                  this_li = find_value_and_highlight_term(this_li ,value[$(input).data("settings").propertyToSearch], query);
                  this_li = $(this_li).appendTo(dropdown_ul);

                  if(index % 2) {
                      this_li.addClass($(input).data("settings").classes.dropdownItem);
                  } else {
                      this_li.addClass($(input).data("settings").classes.dropdownItem2);
                  }

                  if(index === 0 && $(input).data("settings").autoSelectFirstResult) {
                      select_dropdown_item(this_li);
                  }

                  $.data(this_li.get(0), "tokeninput", value);
              });

              show_dropdown();

              if($(input).data("settings").animateDropdown) {
                  dropdown_ul.slideDown("fast");
              } else {
                  dropdown_ul.show();
              }
          } else {
              if($(input).data("settings").noResultsText) {
                  dropdown.html("<p>" + escapeHTML($(input).data("settings").noResultsText) + "</p>");
                  show_dropdown();
              }
          }
      }
function populate_dropdown (query, results) {
          // exclude current tokens if configured
          results = excludeCurrent(results);

          if(results && results.length) {
              dropdown.empty();
              var dropdown_ul = $("<ul/>")
                  .appendTo(dropdown)
                  .mouseover(function (event) {
                      select_dropdown_item($(event.target).closest("li"));
                  })
                  .mousedown(function (event) {
                      add_token($(event.target).closest("li").data("tokeninput"));
                      hidden_input.change();
                      return false;
                  })
                  .hide();

              if ($(input).data("settings").resultsLimit && results.length > $(input).data("settings").resultsLimit) {
                  results = results.slice(0, $(input).data("settings").resultsLimit);
              }

              $.each(results, function(index, value) {
                  var this_li = $(input).data("settings").resultsFormatter(value);

                  this_li = find_value_and_highlight_term(this_li ,value[$(input).data("settings").propertyToSearch], query);
                  this_li = $(this_li).appendTo(dropdown_ul);

                  if(index % 2) {
                      this_li.addClass($(input).data("settings").classes.dropdownItem);
                  } else {
                      this_li.addClass($(input).data("settings").classes.dropdownItem2);
                  }

                  if(index === 0 && $(input).data("settings").autoSelectFirstResult) {
                      select_dropdown_item(this_li);
                  }

                  $.data(this_li.get(0), "tokeninput", value);
              });

              show_dropdown();

              if($(input).data("settings").animateDropdown) {
                  dropdown_ul.slideDown("fast");
              } else {
                  dropdown_ul.show();
              }
          } else {
              if($(input).data("settings").noResultsText) {
                  dropdown.html("<p>" + escapeHTML($(input).data("settings").noResultsText) + "</p>");
                  show_dropdown();
              }
          }
      }
function populate_dropdown ( query , results ) { // exclude current tokens if configured results = excludeCurrent ( results ) ; if ( results && results . length ) { dropdown . empty ( ) ; var dropdown_ul = $ ( "<ul/>" ) . appendTo ( dropdown ) . mouseover ( function ( event ) { select_dropdown_item ( $ ( event . target ) . closest ( "li" ) ) ; } ) . mousedown ( function ( event ) { add_token ( $ ( event . target ) . closest ( "li" ) . data ( "tokeninput" ) ) ; hidden_input . change ( ) ; return false ; } ) . hide ( ) ; if ( $ ( input ) . data ( "settings" ) . resultsLimit && results . length > $ ( input ) . data ( "settings" ) . resultsLimit ) { results = results . slice ( 0 , $ ( input ) . data ( "settings" ) . resultsLimit ) ; } $ . each ( results , function ( index , value ) { var this_li = $ ( input ) . data ( "settings" ) . resultsFormatter ( value ) ; this_li = find_value_and_highlight_term ( this_li , value [ $ ( input ) . data ( "settings" ) . propertyToSearch ] , query ) ; this_li = $ ( this_li ) . appendTo ( dropdown_ul ) ; if ( index % 2 ) { this_li . addClass ( $ ( input ) . data ( "settings" ) . classes . dropdownItem ) ; } else { this_li . addClass ( $ ( input ) . data ( "settings" ) . classes . dropdownItem2 ) ; } if ( index === 0 && $ ( input ) . data ( "settings" ) . autoSelectFirstResult ) { select_dropdown_item ( this_li ) ; } $ . data ( this_li . get ( 0 ) , "tokeninput" , value ) ; } ) ; show_dropdown ( ) ; if ( $ ( input ) . data ( "settings" ) . animateDropdown ) { dropdown_ul . slideDown ( "fast" ) ; } else { dropdown_ul . show ( ) ; } } else { if ( $ ( input ) . data ( "settings" ) . noResultsText ) { dropdown . html ( "<p>" + escapeHTML ( $ ( input ) . data ( "settings" ) . noResultsText ) + "</p>" ) ; show_dropdown ( ) ; } } }
Populate the results dropdown with some results
Populate the results dropdown with some results