From 14b0604bc0a14a110c92457f43b3828fc22e7fc7 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Mon, 29 Sep 2014 09:44:29 +0200 Subject: oscar template: implement autocompleter --- searx/static/oscar/js/scripts.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'searx/static/oscar/js/scripts.js') diff --git a/searx/static/oscar/js/scripts.js b/searx/static/oscar/js/scripts.js index 296cddd94..6c3a10a74 100644 --- a/searx/static/oscar/js/scripts.js +++ b/searx/static/oscar/js/scripts.js @@ -7,6 +7,15 @@ */ +if(searx.autocompleter) { + searx.searchResults = new Bloodhound({ + datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), + queryTokenizer: Bloodhound.tokenizers.whitespace, + remote: '/autocompleter?q=%QUERY' + }); + searx.searchResults.initialize(); +} + $(document).ready(function(){ $('.btn-toggle .btn').click(function() { var btnClass = 'btn-' + $(this).data('btn-class'); @@ -42,4 +51,14 @@ $(document).ready(function(){ $(".select-all-on-click").click(function () { $(this).select(); }); -}); + + if(searx.autocompleter) { + $('#q').typeahead(null, { + name: 'search-results', + displayKey: function(result) { + return result; + }, + source: searx.searchResults.ttAdapter() + }); + } +}); -- cgit v1.2.3