Skip to content

Instantly share code, notes, and snippets.

@bcoe
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save bcoe/8748123afc75129a9191 to your computer and use it in GitHub Desktop.

Select an option

Save bcoe/8748123afc75129a9191 to your computer and use it in GitHub Desktop.
main.js
var $ = window.jQuery = require('jquery');
var typeahead = require('typeahead.js'),
npmUrl = 'https://www.npmjs.org';
$(document).ready(function() {
// Create the engine, used to interact
// with our search backend.
var engine = new Bloodhound({
name: 'packages',
local: [],
remote: '/search?q=%QUERY',
datumTokenizer: function(d) {
return Bloodhound.tokenizers.whitespace(d.val);
},
queryTokenizer: Bloodhound.tokenizers.whitespace
});
engine.initialize();
// attach the typeahead extension to
// our search box using jQuery.
var typeahead = $('typeahead').typeahead({},
{
name: 'states',
displayKey: 'value',
source: engine.ttAdapter()
}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment