var repoExpr = /.+\/.+/; var remoteRepos = new Bloodhound({ queryTokenizer: Bloodhound.tokenizers.whitespace, datumTokenizer: Bloodhound.tokenizers.obj.whitespace("full_name"), identify: function(obj) { return obj.full_name; }, prefetch: '/api/user/repos/remote' }); function reposWithDefaults(q, sync) { if (q === "") { sync(remoteRepos.all()) } else { remoteRepos.search(q, sync); } } $('.typeahead').typeahead({ hint: true, highlight: true, minLength: 0 }, { name: "repos", display: "full_name", source: reposWithDefaults, templates: { empty: function(obj) { if (obj.query.match(repoExpr) !== null) { return [ "
", "
", "

", "No matches found for", "", obj.query, "", "

", "

", "This repository may not be indexed yet.", "", "Click here", "", "to visit this repository page directly.", "

", "
", "
" ].join("\n"); } return [ "
", "
", "No matches found", "
", "
" ].join("\n"); }, suggestion: function(obj) { return "
"+ obj.full_name +"
"; } } }).bind('typeahead:select', function(ev, suggestion) { window.location.href="/"+suggestion.full_name; });