Reduced a size of a code for a mindflow. Removed check for empty name property because there's no plans to add more buttons. Click handler function defined outside to eliminate definition of many same functions. Used for ... of instead of traditional for for code reduce and it doesn't drastically affect performance actually. Especially at such low array sizes. Used force arg of a toggle method to reduce code.
This commit is contained in:
parent
b40dfe2d0d
commit
0f9c658d10
@ -1,13 +1,12 @@
|
|||||||
const buttons = document.getElementsByTagName("button");
|
|
||||||
const articles = document.getElementsByTagName("article");
|
const articles = document.getElementsByTagName("article");
|
||||||
|
|
||||||
document.getElementById("filter").classList.remove("hidden");
|
document.getElementById("filter").classList.remove("hidden");
|
||||||
|
|
||||||
for (let i = 0; i < buttons.length; ++i)
|
function filter(e) {
|
||||||
if (buttons[i].name !== "")
|
for (const a of articles)
|
||||||
buttons[i].addEventListener("click", e => {
|
a.classList.toggle("hidden",
|
||||||
for (let j = 0; j < articles.length; ++j)
|
!(e.target.name === "all" || a.id.startsWith(e.target.name)));
|
||||||
if (articles[j].id.startsWith(e.target.name) || e.target.name === "all")
|
}
|
||||||
articles[j].classList.remove("hidden");
|
|
||||||
else
|
for (const b of document.getElementsByTagName("button"))
|
||||||
articles[j].classList.add("hidden"); });
|
b.addEventListener("click", filter);
|
Loading…
Reference in New Issue
Block a user