mirror of
https://github.com/Findus23/lw1.at.git
synced 2024-09-10 05:13:46 +02:00
16 lines
626 B
TypeScript
16 lines
626 B
TypeScript
export function initSearch() {
|
|
const searchWrapper = document.getElementById("search") as HTMLInputElement
|
|
const cards: NodeListOf<HTMLDivElement> = document.querySelectorAll(".card")
|
|
if (searchWrapper) {
|
|
searchWrapper.addEventListener("input", () => {
|
|
const query = searchWrapper.value.toLowerCase()
|
|
cards.forEach((card: HTMLDivElement) => {
|
|
const title = card.dataset["title"]
|
|
if (!title) {
|
|
return
|
|
}
|
|
card.style.display = title.includes(query) ? "block" : "none"
|
|
})
|
|
})
|
|
}
|
|
}
|