Skip to content

Commit 6e721dd

Browse files
committed
search: pick up query from location hash
This is the reason we put the query into the hash in the first place. I just hadn’t wired it up before.
1 parent 16e7318 commit 6e721dd

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

internal/assets/search.html.tmpl

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,32 @@
119119
}, 500);
120120
}
121121
122+
function queryFromHash() {
123+
const hash = window.location.hash;
124+
if (hash !== undefined && hash !== "" && hash !== "#") {
125+
const params = hash.substr(1); // strip #
126+
var p = new URLSearchParams(params);
127+
return p.get('q');
128+
}
129+
return '{{ .Query }}';
130+
}
131+
132+
window.addEventListener("hashchange", () => {
133+
const newQuery = queryFromHash();
134+
console.log("query has changed to", newQuery, "(from hash)");
135+
if (newQuery !== '') {
136+
q.value = newQuery;
137+
search(newQuery);
138+
}
139+
});
140+
122141
const submit = document.getElementById('bull_submit');
123142
submit.style.display = 'none';
124143
submit.onclick = function(event) {
125144
event.preventDefault();
126145
}
127146
128-
var query = '{{ .Query }}';
129-
const hash = window.location.hash;
130-
if (hash !== undefined && hash !== "" && hash !== "#") {
131-
const params = hash.substr(1); // strip #
132-
var p = new URLSearchParams(params);
133-
query = p.get('q');
134-
}
147+
const query = queryFromHash();
135148
136149
if (query.length > 0) {
137150
console.log('restoring search for', query, 'from URL hash');

0 commit comments

Comments
 (0)