diff options
Diffstat (limited to 'assets')
-rw-r--r-- | assets/js/index.js | 22 |
1 files changed, 15 insertions, 7 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(); }); } } |