browser: delay automatic search preview
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 7 Dec 2010 21:43:00 +0000 (22:43 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 15 Dec 2010 21:40:44 +0000 (22:40 +0100)
Continuous application of query focus prevents rapid entry due to update on
each key press.  Ensure at most 1 request every 300ms after first keyup.

searchlocal.js

index 5d7493b100616134bddd693d6cdef245010b2974..6c37fc901362c7f2fbb5b9a4c3d2138e8cb729a6 100644 (file)
@@ -1,3 +1,5 @@
+var filterupdate;
+
 function filtercell(el, set, action) {
        switch (action) {
                case 'focus':
@@ -54,6 +56,8 @@ function filterrows(table, match, action) {
 }
 
 function filtertable(query, action) {
+       filterupdate = undefined;
+       if (query === undefined) query = document.getElementById('search').q.value;
        var table = document.getElementsByTagName('TABLE')[0];
 
        if (!action) {
@@ -128,7 +132,8 @@ function prependsearch(target) {
                        newelement('input', {
                                type: 'search',
                                name: 'q',
-                               onkeyup: "filtertable(this.value, 'focus')",
+                               onkeyup: "if (!filterupdate) filterupdate = "
+                                       + "window.setTimeout(filtertable, 300, undefined, 'focus')",
                        }),
                        newelement('input', {
                                type: 'button',