From d7726fe9d86267f50fe4129e53399d014aa7b4c0 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Tue, 7 Dec 2010 19:50:02 +0100 Subject: [PATCH] browser: cumulative search prefixes Queries can be prepended by [-+?] to hide/show/toggle matches without touching other rows. --- searchlocal.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/searchlocal.js b/searchlocal.js index 1a5037f..e6f16ff 100644 --- a/searchlocal.js +++ b/searchlocal.js @@ -6,6 +6,15 @@ function filtercell(el, set, action) { case 'target': if (set) el.classList.toggle(action); break; + case 'remove': + if (set) el.style.display = 'none'; + break; + case 'add': + if (set) el.style.display = ''; + break; + case 'toggle': + if (set) el.style.display = el.style.display == 'none' ? '' : 'none'; + break; case 'filter': el.style.display = set ? '' : 'none'; if (!Element.prototype.hasOwnProperty('classList')) return; @@ -26,6 +35,17 @@ function filterrows(table, match, action) { function filtertable(query, action) { var table = document.getElementsByTagName('TABLE')[0]; + if (!action) { + var match = /^([-+?=]?)(.*)/.exec(query); + switch (match[1]) { + case '+': action = 'add'; break; + case '-': action = 'remove'; break; + case '?': action = 'toggle'; break; + case '=': action = 'filter'; break; + } + query = match[2]; + } + if (/^[A-Z0-9 ]{2,}$/.test(query)) { // category title if all uppercase var match = function(row) { -- 2.30.0