From 8dedf83b22c0da44e0d83a9940291e0d1f0497e4 Mon Sep 17 00:00:00 2001 From: tdro Date: Fri, 2 Feb 2024 19:42:49 -0500 Subject: static/js/fixedsearch: Avoid search conflict Add some guards --- static/js/fixedsearch.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'static') 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(); }); } } -- cgit v1.2.3