From: Mischa POSLAWSKY Date: Tue, 7 Dec 2010 19:48:50 +0000 (+0100) Subject: browser: only reset focus after filter X-Git-Tag: v1.4~47 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/217c6fda0be7b212d58da7c9edaba58dbe6d788c browser: only reset focus after filter Keep target states. --- diff --git a/searchlocal.js b/searchlocal.js index e6f16ff..8741044 100644 --- a/searchlocal.js +++ b/searchlocal.js @@ -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',