diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/html.html | 63 | ||||
-rw-r--r-- | web/src/tags.html | 60 |
2 files changed, 123 insertions, 0 deletions
diff --git a/web/html.html b/web/html.html index 0bc7cb4..17d96d1 100644 --- a/web/html.html +++ b/web/html.html @@ -306,6 +306,69 @@ window.onload = () => { <p>... and there.</p> </div> </code></pre> +<h1 id="minimal-tags-filter"><a class="header" href="#minimal-tags-filter">Minimal tags filter</a></h1> +<p><a href="src/tags.html">Rendered html</a></p> +<pre><code class="language-html"><script> +/// Map HTML elements to display kinds. +const elementToDisplay = (E) => { + 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); + }); +}; + +/// Initialize buttons and callbacks. +window.onload = () => { + // Handle to the filter placeholder. + const filter = document.getElementById("filter"); + + // Create buttons for each tag T. + ['arm', 'x86', 'clear'].forEach(T => { + const btn = document.createElement("button"); + btn.innerHTML = T; + btn.onclick = T === "clear" + ? (E) => { + showTag("content"); + filter.innerHTML = ""; + } + : (E) => { + showTag(T); + filter.innerHTML = `<p>filter: <mark>${T}</mark></p>`; + }; + + document.body.prepend(btn); + }); +} +</script> + +<div id = "filter"></div> + +<ul> + <li class = "content arm">arm 1</li> + <li class = "content arm">arm 2</li> + <li class = "content arm">arm 3</li> + <li class = "content x86">x86 1</li> + <li class = "content x86">x86 2</li> + <li class = "content x86 arm">x86 + arm</li> +</ul> + +<div class = "content arm">arm</div> +<div class = "content arm x86">arm x86</div> +<div class = "content x86">x86</div> +</code></pre> </main> diff --git a/web/src/tags.html b/web/src/tags.html new file mode 100644 index 0000000..25597ca --- /dev/null +++ b/web/src/tags.html @@ -0,0 +1,60 @@ +<script> +/// Map HTML elements to display kinds. +const elementToDisplay = (E) => { + 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); + }); +}; + +/// Initialize buttons and callbacks. +window.onload = () => { + // Handle to the filter placeholder. + const filter = document.getElementById("filter"); + + // Create buttons for each tag T. + ['arm', 'x86', 'clear'].forEach(T => { + const btn = document.createElement("button"); + btn.innerHTML = T; + btn.onclick = T === "clear" + ? (E) => { + showTag("content"); + filter.innerHTML = ""; + } + : (E) => { + showTag(T); + filter.innerHTML = `<p>filter: <mark>${T}</mark></p>`; + }; + + document.body.prepend(btn); + }); +} +</script> + +<div id = "filter"></div> + +<ul> + <li class = "content arm">arm 1</li> + <li class = "content arm">arm 2</li> + <li class = "content arm">arm 3</li> + <li class = "content x86">x86 1</li> + <li class = "content x86">x86 2</li> + <li class = "content x86 arm">x86 + arm</li> +</ul> + +<div class = "content arm">arm</div> +<div class = "content arm x86">arm x86</div> +<div class = "content x86">x86</div> |