instant search: add/remove hash from url when opening/closing (#4706)

chrome doesn't update history.state when navigating to the same url
as the one currently in the address bar: this had the effect of
re-opening instant search when clicking on the homepage link,
when instant search has been opened from the homepage

adding a hash to the url means it changes, and works around this
behaviour in chrome

https://github.com/mozilla/sumo-project/issues/795
This commit is contained in:
Leo McArdle 2021-03-09 16:42:28 +00:00 коммит произвёл GitHub
Родитель 7f6f91aae7
Коммит 857fb748b2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 3 добавлений и 3 удалений

Просмотреть файл

@ -78,9 +78,9 @@
if (history.state?.query) {
// if a search is already the latest point in history, replace it
// to avoid filling history with partial searches
history.replaceState(historyState, searchTitle);
history.replaceState(historyState, searchTitle, "#search");
} else {
history.pushState(historyState, searchTitle);
history.pushState(historyState, searchTitle, "#search");
}
var base_url = search.lastQueryUrl();
@ -144,7 +144,7 @@
window.k.InstantSearchSettings.showContent();
if (history.state?.query) {
history.pushState({}, searchTitle);
history.pushState({}, searchTitle, location.href.replace("#search", ""));
}
} else if ($this.val() !== search.lastQuery) {
if (searchTimeout) {