aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2024-02-02 19:42:49 -0500
committertdro <tdro@noreply.example.com>2024-02-02 19:42:49 -0500
commit8dedf83b22c0da44e0d83a9940291e0d1f0497e4 (patch)
tree4a1ab92c2a9d65adcc3e04ae672c4a8b06a3d4e1
parente3d4279567d1fb6bf1ac9523fe7b2251ba8f0944 (diff)
downloadcanory-8dedf83b22c0da44e0d83a9940291e0d1f0497e4.tar.gz
canory-8dedf83b22c0da44e0d83a9940291e0d1f0497e4.tar.bz2
canory-8dedf83b22c0da44e0d83a9940291e0d1f0497e4.zip
static/js/fixedsearch: Avoid search conflict
Add some guards
-rw-r--r--assets/js/index.js22
-rw-r--r--static/js/fixedsearch.ts16
2 files changed, 23 insertions, 15 deletions
diff --git a/assets/js/index.js b/assets/js/index.js
index f417396..176959d 100644
--- a/assets/js/index.js
+++ b/assets/js/index.js
@@ -542,24 +542,32 @@
function initialize() {
if (boot) {
script(window.location.origin + "/js/fuzzysort.js").then(function() {
- boot = false;
fetch("/index.json", function(request) {
appendItemsTo({}, JSON.parse(request.responseText));
+ search(query.value, data.items, options);
+ boot = false;
});
const options = {
key: [
"title"
]
};
- query.addEventListener("keyup", function() {
- search(query.value, data.items, options);
- });
- query.addEventListener("focusin", function() {
- search(query.value, data.items, options);
+ [
+ "keyup",
+ "focusin"
+ ].forEach(function(event) {
+ query.addEventListener(event, function() {
+ if (data.items) search(query.value, data.items, options);
+ else {
+ boot = true;
+ initialize();
+ }
+ });
});
- search(query.value, data.items, options);
}).catch(function(error) {
console.error("ERROR: Failed to load fuzzy search", error);
+ boot = true;
+ initialize();
});
}
}
diff --git a/static/js/fixedsearch.ts b/static/js/fixedsearch.ts
index 1e44601..6d91dfe 100644
--- a/static/js/fixedsearch.ts
+++ b/static/js/fixedsearch.ts
@@ -193,25 +193,25 @@
if (boot) {
script(window.location.origin + "/js/fuzzysort.js")
.then(function () {
- boot = false;
fetch("/index.json", function (request) {
appendItemsTo({}, JSON.parse(request.responseText));
+ search(query.value, data.items, options);
+ boot = false;
});
const options = { key: ["title"] };
- query.addEventListener("keyup", function () {
- search(query.value, data.items, options);
- });
-
- query.addEventListener("focusin", function () {
- search(query.value, data.items, options);
+ ["keyup", "focusin"].forEach(function (event) {
+ query.addEventListener(event, function () {
+ if (data.items) search(query.value, data.items, options);
+ else { boot = true; initialize(); }
+ });
});
- search(query.value, data.items, options);
}).catch(function (error) {
console.error("ERROR: Failed to load fuzzy search", error);
+ boot = true; initialize();
});
}
}