Advertisement
Guest User

Typeahead 0.10.2 Default Results

a guest
May 8th, 2014
1,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     _typeaheadElem.typeahead({ minLength: 0, hint: false },
  3.         $.extend(true, {}, _defaultDataSetConfig,
  4.             {
  5.                 name: 'find-people',
  6.                 source: function (query, cb) {
  7.                     if (query.length >= 3) {
  8.                         var altSource = _bloodhound_peopleSearch.ttAdapter();
  9.                         altSource(query, cb);
  10.                     }
  11.                     return;
  12.                 },
  13.                 templates: {
  14.                     header: '<h4 class="search-header">Search Results</h4>',
  15.                     empty: "Sorry. No results found."
  16.                 }
  17.             }),
  18.         $.extend(true, {}, _defaultDataSetConfig,
  19.             {
  20.                 name: 'recent-people',
  21.                 //Show all RPs all the time
  22.                 source: function (query, cb) { return cb(RECENT_PEOPLE_ARRAY); },
  23.                 templates: {
  24.                     header: '<h4 class="search-header">Recent People</h4>'
  25.                 }
  26.             })
  27.     );
  28.  
  29.     /* @type {Typeahead} A reference to the actual Typeahead object */
  30.     var _typeahead = _typeaheadElem.data('ttTypeahead');
  31.  
  32.     /*
  33.      This is to make Recent People open when the field gets focus and there is no input.
  34.      This relies on the typeahead minLength == 0 and hint == false.
  35.      This is a fix for ttTA v 0.10.2 which doesn't support a feature like this. Newer versions might.
  36.      */
  37.     _typeaheadElem.focus(function() {
  38.         /* WARNING: This is hackery abusing non-public Typeahead APIs */
  39.         if (_typeaheadElem.val() === "") {
  40.             //Set the component's current query to something that won't match the input.
  41.             var input = _typeahead.input; //Reference to the TA Input class
  42.             input.query = "Recent People";
  43.  
  44.             input._onInput("");
  45.             //If you turn on hints, you will need this.
  46.             //input.clearHint(); //Clear out any previous hints
  47.         }
  48.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement