diff --git a/themes/bootstrap/js/common.js b/themes/bootstrap/js/common.js index 064b69ba3f3725e01ed99d205fd0a247feed114c..04edff696952b90caa1f60aae4972dc13a514414 100644 --- a/themes/bootstrap/js/common.js +++ b/themes/bootstrap/js/common.js @@ -100,23 +100,29 @@ $(document).ready(function() { }); // Search autocomplete - var autoCompleteRequest; + var autoCompleteRequest, autoCompleteTimer; $('.autocomplete').typeahead({ + minLength:3, source:function(query, process) { - if(autoCompleteRequest) autoCompleteRequest.abort(); + clearTimeout(autoCompleteTimer); + if(autoCompleteRequest) { + autoCompleteRequest.abort(); + } var searcher = extractClassParams('.autocomplete'); - autoCompleteRequest = $.ajax({ - url: path + '/AJAX/JSON', - data: {method:'getACSuggestions',type:$('#searchForm_type').val(),searcher:searcher['searcher'],q:query}, - dataType:'json', - success: function(json) { - if (json.status == 'OK' && json.data.length > 0) { - process(json.data); - } else { - process([]); + autoCompleteTimer = setTimeout(function() { + autoCompleteRequest = $.ajax({ + url: path + '/AJAX/JSON', + data: {method:'getACSuggestions',type:$('#searchForm_type').val(),searcher:searcher['searcher'],q:query}, + dataType:'json', + success: function(json) { + if (json.status == 'OK' && json.data.length > 0) { + process(json.data); + } else { + process([]); + } } - } - }); + }); + }, 600); // Delay request submission } });