File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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');
You can’t perform that action at this time.
0 commit comments