Added automatic removal of query parameter when search is closed

This commit is contained in:
squidfunk 2022-02-26 10:07:32 +01:00
parent 5acd0c3620
commit e3c26215de
8 changed files with 29 additions and 16 deletions

View File

@ -213,7 +213,7 @@
</script>
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.8aa65030.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.cd6d3f86.min.js' | url }}"></script>
{% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script>
{% endfor %}

View File

@ -16,5 +16,5 @@
{% endblock %}
{% block scripts %}
{{ super() }}
<script src="{{ 'overrides/assets/javascripts/bundle.90528257.min.js' | url }}"></script>
<script src="{{ 'overrides/assets/javascripts/bundle.068fb875.min.js' | url }}"></script>
{% endblock %}

View File

@ -44,7 +44,8 @@ import { translation } from "~/_"
import {
getLocation,
setToggle,
watchElementFocus
watchElementFocus,
watchToggle
} from "~/browser"
import {
SearchMessageType,
@ -101,6 +102,18 @@ export function watchSearchQuery(
map(() => searchParams.get("q") || "")
)
/* Remove query parameter when search is closed */
watchToggle("search")
.pipe(
filter(active => !active),
take(1)
)
.subscribe(() => {
const url = new URL(location.href)
url.searchParams.delete("q")
history.replaceState({}, "", `${url}`)
})
/* Set query from parameter */
param$.subscribe(value => { // TODO: not ideal - find a better way
if (value)

View File

@ -84,7 +84,7 @@ export function mountIconSearchQuery(
)
.subscribe(([, value]) => {
const path = document.location.pathname
if (value.length)
if (typeof ga === "function" && value.length)
ga("send", "pageview", `${path}?q=[icon]+${value}`)
})