Debounce search input
This commit is contained in:
parent
79de3635a3
commit
e7afa3173b
1 changed files with 9 additions and 5 deletions
|
|
@ -53,12 +53,16 @@ Array.from(firstByLetter.entries())
|
|||
});
|
||||
|
||||
const searchInput = document.getElementById("toc-search");
|
||||
let searchTimeout;
|
||||
searchInput?.addEventListener("input", (event) => {
|
||||
clearTimeout(searchTimeout);
|
||||
searchTimeout = setTimeout(() => {
|
||||
const query = event.target.value.trim().toLowerCase();
|
||||
Array.from(tocList?.querySelectorAll("li") ?? []).forEach((item) => {
|
||||
const text = item.textContent.toLowerCase();
|
||||
item.style.display = text.includes(query) ? "" : "none";
|
||||
});
|
||||
}, 150);
|
||||
});
|
||||
|
||||
// OCR/formatting errors from epub conversion
|
||||
|
|
|
|||
Loading…
Reference in a new issue