1
0
em.0x45.cz/static/js/search.js
Emil Miler aa289de836 Search optimisation
These changes make the code more efficient, since going trough an array
with `forEach` is faster than iterating with a foor loop on every input
change. Using `indexOf()` instead of `includes()` is faster as well.
2022-12-09 13:17:29 +01:00

12 lines
398 B
JavaScript

function filter_name(str)
{
if (str.length == 0) {
articles.forEach(article => article.style.display = "block");
} else {
articles.forEach(article => article.style.display = article.dataset.title.indexOf(str.toLowerCase()) === -1 ? "none" : "block");
}
}
let articles = Array.from(document.getElementsByTagName("article"));
document.getElementById("search").style.display = "inline-block";