From 97d0b2d66c7be628fd6791fa65484bc45bf4dde0 Mon Sep 17 00:00:00 2001 From: Andrea Cardaci Date: Sat, 15 Sep 2018 18:20:39 +0200 Subject: [PATCH] Mark functions matching the filter --- _includes/bin_table.html | 40 ++++++++++++++++++++++++++++++---------- assets/style.scss | 5 +++++ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/_includes/bin_table.html b/_includes/bin_table.html index cc327ec..2c20d15 100644 --- a/_includes/bin_table.html +++ b/_includes/bin_table.html @@ -34,17 +34,37 @@ // filter rows var noResults = true; document.querySelectorAll('#bin-table tbody tr').forEach(function (row) { - var binName = row.children[0].firstElementChild.innerText.toLowerCase(); - var functions = Array.from(row.children[1].firstElementChild.children) - .map(function (x) { return x.innerText }) - .join('\x00').toLowerCase(); // separator + var show = true; - var show = ( - binName.indexOf(binPattern) !== -1 && - functionPatterns.every(function (pattern) { - return functions.indexOf(pattern) !== -1; - }) - ); + var binName = row.children[0].firstElementChild.innerText.toLowerCase(); + if (binName.indexOf(binPattern) === -1) { + show = false; + } + + if (show) { + var functionElems = Array.from(row.children[1].firstElementChild.children); + functionElems.forEach((item) => { + item.className = ''; + }); + functionPatterns.forEach((pattern) => { + // skip empty filters + if (!pattern) { + return; + } + // check against the pattern + var noMatches = true; + functionElems.forEach((item) => { + if (item.innerText.toLowerCase().indexOf(pattern) !== -1) { + item.className = 'match'; + noMatches = false; + } + }); + // no function satisfies the pattern + if (noMatches) { + show = false; + } + }); + } if (show) { row.style.display = ''; diff --git a/assets/style.scss b/assets/style.scss index f8734bc..25e8019 100644 --- a/assets/style.scss +++ b/assets/style.scss @@ -3,6 +3,7 @@ $accent: #bf0707; $lighter: #fff4f4; +$marked: #ffcccc; $hover: #ff0000; // layout @@ -143,6 +144,10 @@ h2, h3, h4, h5, h5 { color: $hover; border-color: $hover; } + + &.match a { + background: $marked; + } } }