diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-06-05 23:56:49 +0200 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-06-05 23:56:49 +0200 |
commit | 07967bf0ac578a2d25dddf86af55050ecca984f4 (patch) | |
tree | 64bc740b9569e5382c248310333dd6a23647be1f /roles/webserver/files/www/memzero/pub/.gen.sh | |
parent | e931314b97a698d0bb24cbf7c1d9de01f5dbb899 (diff) | |
download | ansible-memzero-07967bf0ac578a2d25dddf86af55050ecca984f4.tar.gz ansible-memzero-07967bf0ac578a2d25dddf86af55050ecca984f4.zip |
nginx: allow selecting multiple filter in pub/reference
Diffstat (limited to 'roles/webserver/files/www/memzero/pub/.gen.sh')
-rw-r--r-- | roles/webserver/files/www/memzero/pub/.gen.sh | 81 |
1 files changed, 48 insertions, 33 deletions
diff --git a/roles/webserver/files/www/memzero/pub/.gen.sh b/roles/webserver/files/www/memzero/pub/.gen.sh index 95e4216..36016f3 100644 --- a/roles/webserver/files/www/memzero/pub/.gen.sh +++ b/roles/webserver/files/www/memzero/pub/.gen.sh @@ -22,51 +22,66 @@ cat <<EOF > $OUT <script> /// Map HTML elements to display kinds. const elementToDisplay = (E) => { - switch (E.nodeName) { - case "LI": - return "list-item"; - default: - return "block"; - } + switch (E.nodeName) { + case "LI": + return "list-item"; + default: + return "block"; + } } - /// Display only elements with tag T. - const showTag = (T) => { - Array.from(document.getElementsByClassName("content")).forEach(E => { - E.style.display = "none"; - }); - - Array.from(document.getElementsByClassName(T)).forEach(E => { - E.style.display = elementToDisplay(E); - }); + /// Display only elements which have all TAGS. + const showTag = (TAGS) => { + Array.from(document.getElementsByClassName("content")).forEach(E => { + // Display the element, iff the element contains every tag T in TAGS. + if (TAGS.every(T => Array.from(E.classList).includes(T))) { + E.style.display = elementToDisplay(E); + } else { + E.style.display = "none"; + } + }); }; /// Initialize buttons and callbacks. window.onload = () => { - // Handle to the filter placeholder. - const filter = document.getElementById("filter"); + // Handle to the filter placeholder. + const filter_node = document.getElementById("filter"); + // Active filter tags. + const filter = Array(); + + // Create buttons for each tag T. + ["arm", "x86", "riscv", "sysv", "clear"].forEach(T => { + const btn = document.createElement("button"); + btn.innerHTML = T; + btn.onclick = T === "clear" + ? (E) => { + // Clear active filter. + while (filter.length) { filter.pop(); } + + showTag(["content"]); + filter_node.innerHTML = "filter:"; + } + : (E) => { + // Toggle tag T in Active filter. + if ((idx = filter.indexOf(T)) > -1) { + filter.splice(idx, 1); + } else { + filter.push(T); + } + + showTag(filter); + out = filter.map(T => \`<mark>\${T}</mark>\`).join(" + "); + filter_node.innerHTML = \`filter: \${out}\`; + }; - // Create buttons for each tag T. - ["clear", "sysv", "arm", "x86", "riscv"].forEach(T => { - const btn = document.createElement("button"); - btn.innerHTML = T; - btn.onclick = T === "clear" - ? (E) => { - showTag("content"); - filter.innerHTML = "filter:"; - } - : (E) => { - showTag(T); - filter.innerHTML = \`filter: <mark>\${T}</mark>\`; - }; - filter.before(btn); - }); + filter_node.insertAdjacentElement("beforebegin", btn); + }); } </script> </head> <body> <p>Self-hosted collection of frequently referenced documents and specifications. This page provides links to the original sources.</p> - <p id="filter">filter:</p> + <p id = "filter">filter:</p> <ul> EOF |