From 38ec9dcffcddf2389c27df5ad6e73c71347baf39 Mon Sep 17 00:00:00 2001
From: Chris Hallberg <crhallberg@gmail.com>
Date: Fri, 1 Nov 2013 15:43:02 -0400
Subject: [PATCH] Lessen load of autocomplete in bootstrap.

---
 themes/bootstrap/js/common.js | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/themes/bootstrap/js/common.js b/themes/bootstrap/js/common.js
index 064b69ba3f3..04edff69695 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
     }
   });
 
-- 
GitLab