Details
-
Improvement
-
Resolution: Fixed
-
Major
-
None
-
None
-
None
Description
Our installation is getting quite large and the ajax search bar is close to unusable. I've patched our installation to wait for the user to stop typing before firing off a new ajax_search.php request which has helped nicely.
I am by no means a programmer so please excuse the dodgy code. But this gets the idea across:
[root@observium html]# svn -r HEAD diff ./includes/navbar.inc.php
Index: includes/navbar.inc.php
===================================================================
— includes/navbar.inc.php (revision 5757)
+++ includes/navbar.inc.php (working copy)
@@ -465,7 +465,7 @@
<ul class="nav pull-right">
<li class="dropdown hidden-xs">
<form id="searchform" class="navbar-search" action="#" style="margin-left: 5px; margin-right: 10px; margin-top: 5px; margin-bottom: -5px;">
- <input style="width: 100px;" onkeyup="lookup(this.value);" onblur="$('#suggestions').fadeOut()" type="text" value="" class="dropdown-toggle" placeholder="Search" />
+ <input style="width: 100px;" onkeyup="lookupwait(this.value);" onblur="$('#suggestions').fadeOut()" type="text" value="" class="dropdown-toggle" placeholder="Search" />
</form>
<div id="suggestions" class="typeahead dropdown-menu"></div>
</li>
@@ -580,7 +580,24 @@
</header>
<script type="text/javascript">
-
+key_count_global = 0;
+function lookupwait(inputString){
+ if (inputString.length == 0)
else
{ + key_count_global++; + setTimeout("searchwait("+key_count_global+",\""+inputString+"\")", 400); + }+}
+function searchwait(key_count,inputString){
+ if(key_count == key_count_global) {
+ $.post("ajax_search.php",
, function(data)
{ // Do an AJAX call + $('#suggestions').fadeIn(); // Show the suggestions box + $('#suggestions').html(data); // Fill the suggestions box + });
+
+ }
+}
function lookup(inputString) {
if (inputString.length == 0) {
$('#suggestions').fadeOut(); // Hide the suggestions box
Fixed in r6115.