mirror of
https://gitlab.com/tavo-wasd/conex-pages.git
synced 2025-06-06 13:03:29 -06:00
25 lines
1.1 KiB
JavaScript
25 lines
1.1 KiB
JavaScript
document.addEventListener("DOMContentLoaded", () => {
|
|
const removeClass = className => Array.from(document.getElementsByClassName(className)).forEach(e => e.classList.remove(className));
|
|
removeClass("js-only");
|
|
|
|
const cards = document.querySelectorAll("#cardscontainer a");
|
|
const search = document.getElementById("search");
|
|
const cardscontainer = document.getElementById("cardscontainer");
|
|
|
|
search.addEventListener("input", () => {
|
|
const normalizeText = text => text.toLowerCase().trim().normalize('NFD').replace(/\p{Diacritic}/gu, "");
|
|
const searchTerms = normalizeText(search.value).split(" ");
|
|
const hasFilter = searchTerms.length > 0;
|
|
|
|
cardscontainer.classList.toggle("list-searched", hasFilter);
|
|
|
|
cards.forEach(card => {
|
|
const cardText = normalizeText(`${card.textContent} ${card.dataset.tags}`);
|
|
const isMatch = searchTerms.every(term => cardText.includes(term));
|
|
|
|
card.hidden = !isMatch;
|
|
card.classList.toggle("matched-card", hasFilter && isMatch);
|
|
});
|
|
});
|
|
});
|
|
|