aboutsummaryrefslogtreecommitdiff
path: root/static/js/fixedsearch.ts
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/fixedsearch.ts')
-rw-r--r--static/js/fixedsearch.ts30
1 files changed, 14 insertions, 16 deletions
diff --git a/static/js/fixedsearch.ts b/static/js/fixedsearch.ts
index 0a7e9da..1e44601 100644
--- a/static/js/fixedsearch.ts
+++ b/static/js/fixedsearch.ts
@@ -4,7 +4,8 @@
*/
(function () {
- self.addEventListener("DOMContentLoaded", function () {
+ ["DOMContentLoaded", "URLChangedCustomEvent"].forEach(function (event) {
+ self.addEventListener(event, function () {
const form = document.getElementById("search-form"); // targets <form>
const query = document.getElementById("search-input"); // targets <input>
const submit = document.getElementById("search-submit"); // targets <button>
@@ -109,7 +110,7 @@
if (dropdown && document.activeElement == query) {
event.preventDefault();
head.focus();
- self.window.location = document.activeElement.href;
+ head.click();
}
}
});
@@ -151,14 +152,14 @@
local.items = local.items.concat(remote.items);
}
if (paginated) {
- fetchJson(remote.next_url, function (request) {
+ fetch(remote.next_url, function (request) {
appendItemsTo(local, JSON.parse(request.responseText));
});
}
data = local;
}
- function fetchJson(url, callback) {
+ function fetch(url, callback) {
const http = new XMLHttpRequest();
http.onreadystatechange = function () {
if (http.readyState === 4 && http.status === 200 && callback) {
@@ -171,7 +172,7 @@
/* Load script based on https://stackoverflow.com/a/55451823 */
- function loadScript(url) {
+ function script(url) {
return new Promise(function (resolve, reject) {
const script = document.createElement("script");
script.onerror = reject;
@@ -181,22 +182,20 @@
script,
document.currentScript,
);
- } else {
- document.head.appendChild(script);
- }
+ } else document.head.appendChild(script);
script.src = url;
});
}
- let firstRun = true;
+ let boot = true;
function initialize() {
- if (firstRun) {
- loadScript(window.location.origin + "/js/fuzzysort.js")
+ if (boot) {
+ script(window.location.origin + "/js/fuzzysort.js")
.then(function () {
- firstRun = false;
+ boot = false;
- fetchJson("/index.json", function (request) {
+ fetch("/index.json", function (request) {
appendItemsTo({}, JSON.parse(request.responseText));
});
@@ -246,9 +245,7 @@
"</span>",
);
- if (highlight === null) {
- highlight = title;
- }
+ if (highlight === null) highlight = title;
items = items +
'\n<li>\n<a href="'.concat(
@@ -260,4 +257,5 @@
dropdown.innerHTML = items;
}
});
+ });
})();