diff options
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/static/search.js | 12 | ||||
-rw-r--r-- | frontend/templates/index.gotmpl | 4 |
2 files changed, 14 insertions, 2 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"), diff --git a/frontend/templates/index.gotmpl b/frontend/templates/index.gotmpl index 0211a5b..ee37c0f 100644 --- a/frontend/templates/index.gotmpl +++ b/frontend/templates/index.gotmpl @@ -25,7 +25,9 @@ {{- range $key, $value := .Sources }} <a {{ if eq $.Source.Name $value.Name }}class="current"{{ end }} - href="/{{ .Importer }}/{{ $key }}/search{{ and $.Query (printf "?query=%s" $.Query) }}" + href="/{{ .Importer }}/{{ $key }}/search{{ if and (ne $.Source.Name $value.Name) $.Query }} + {{- printf "?query=%s" $.Query -}} + {{ end }}" > {{- $value.Name -}} </a> |