diff options
author | Alan Pearce | 2024-05-17 23:10:04 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-17 23:10:04 +0200 |
commit | 6ea953b1c9f9c352a9619e42a6f0ce80d183d7f8 (patch) | |
tree | 9cd4c3408e01a7d93bda9ca437ea79bf5c6adc32 /frontend/static/search.js | |
parent | 934a0693213df901078cd1bc75a5b7e1b5c87555 (diff) | |
download | searchix-6ea953b1c9f9c352a9619e42a6f0ce80d183d7f8.tar.lz searchix-6ea953b1c9f9c352a9619e42a6f0ce80d183d7f8.tar.zst searchix-6ea953b1c9f9c352a9619e42a6f0ce80d183d7f8.zip |
feat(ui): enable resetting form by clicking current source link
Diffstat (limited to 'frontend/static/search.js')
-rw-r--r-- | frontend/static/search.js | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/frontend/static/search.js b/frontend/static/search.js index d9993e4..b16cf30 100644 --- a/frontend/static/search.js +++ b/frontend/static/search.js @@ -100,7 +100,7 @@ queryInput.addEventListener("input", function (ev) { for (const el of nav.children) { if (el.nodeName === "A") { const url = new URL(el.href); - if (ev.target.value) { + if (ev.target.value && !el.classList.contains("current")) { url.searchParams.set("query", ev.target.value); } else { url.searchParams.delete("query"); @@ -126,6 +126,16 @@ if (pagination !== null) { addPaginationEventListeners(pagination); } +document.querySelector("a.current").addEventListener("click", function (ev) { + search.reset(); + state.input = null; + range.deleteContents(); + state.fragment = ""; + history.pushState(state, null, ev.target.href); + ev.preventDefault(); + queryInput.value = ""; +}); + if (state.opened.length > 0) { state.opened.forEach((id) => document.getElementById(id).setAttribute("open", "open"), |