browser: only reset focus after filter
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 7 Dec 2010 19:48:50 +0000 (20:48 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 15 Dec 2010 21:40:44 +0000 (22:40 +0100)
Keep target states.

searchlocal.js

index e6f16ff92c672c28ffa519b32864fac2ce0d366a..8741044c4afce0b92cf9f876bcfc520e6ff8cfb4 100644 (file)
@@ -18,7 +18,8 @@ function filtercell(el, set, action) {
                case 'filter':
                        el.style.display = set ? '' : 'none';
                        if (!Element.prototype.hasOwnProperty('classList')) return;
-                       // continue
+                       el.classList.remove('focus');
+                       break;
                default: // reset
                        el.classList.remove('focus');
                        el.classList.remove('target');
@@ -28,7 +29,7 @@ function filtercell(el, set, action) {
 function filterrows(table, match, action) {
        var rows = table.tBodies[0].rows;
        for (var i = 0; i < rows.length; i++) {
-               filtercell(rows[i], match(rows[i]), action);
+               filtercell(rows[i], match && match(rows[i]), action);
        }
 }
 
@@ -52,6 +53,10 @@ function filtertable(query, action) {
                        return row.cells[0].title.match(query, 'i');
                };
        }
+       else if (action == 'focus' && query.length <= 1) {
+               // prevent superfluous highlighting
+               var match = false;
+       }
        else {
                // title text (case-insensitive unless caps in input)
                var match = function(row) {
@@ -82,7 +87,7 @@ function prependsearch(target) {
                        newelement('input', {
                                type: 'search',
                                name: 'q',
-                               onkeyup: "filtertable(this.value, this.value.length > 1 ? 'focus' : 'reset')",
+                               onkeyup: "filtertable(this.value, 'focus')",
                        }),
                        newelement('input', {
                                type: 'button',