diff options
author | siikamiika <siikamiika@users.noreply.github.com> | 2019-10-26 16:39:43 +0300 |
---|---|---|
committer | siikamiika <siikamiika@users.noreply.github.com> | 2019-10-26 16:39:43 +0300 |
commit | bebd70b4e2d8da54b556b488d68a5111f3ff20c1 (patch) | |
tree | 0d8a8f288d47ada9523f33eb8b853359ae1ee100 | |
parent | 50769feea71943051eaf12f1d96bc6305746959f (diff) |
remember search history
-rw-r--r-- | ext/bg/js/search.js | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index 6481e16a..d66e68b8 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -58,6 +58,8 @@ class DisplaySearch extends Display { window.wanakana.bind(this.query); } + window.addEventListener('popstate', (e) => this.onPopState(e)); + this.updateSearchButton(); } catch (e) { this.onError(e); @@ -95,10 +97,23 @@ class DisplaySearch extends Display { const query = this.query.value; const queryString = query.length > 0 ? `?query=${encodeURIComponent(query)}` : ''; - window.history.replaceState(null, '', `${window.location.pathname}${queryString}`); + window.history.pushState({query}, '', `${window.location.pathname}${queryString}`); this.onSearchQueryUpdated(query, true); } + onPopState(e) { + let query = ''; + if (e.state && e.state.query) { + query = e.state.query + } + + if (this.query !== null) { + this.query.value = query; + } + + this.onSearchQueryUpdated(query, false); + } + onKeyDown(e) { const key = Display.getKeyFromEvent(e); |