aboutsummaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2024-02-05 02:09:53 -0500
committertdro <tdro@noreply.example.com>2024-02-05 02:09:53 -0500
commit219ffd9dd76638810271cc0733ff7732d873eac8 (patch)
tree7440d9c765a0e0c4455c3853e27a1796591bbaad /static
parent78855c919aa825c5fff2c99cd137cb2eee6878a4 (diff)
downloadcanory-219ffd9dd76638810271cc0733ff7732d873eac8.tar.gz
canory-219ffd9dd76638810271cc0733ff7732d873eac8.tar.bz2
canory-219ffd9dd76638810271cc0733ff7732d873eac8.zip
static/js/fixedsearch: Warm this up a bit
Not a database
Diffstat (limited to 'static')
-rw-r--r--static/js/fixedsearch.ts47
1 files changed, 23 insertions, 24 deletions
diff --git a/static/js/fixedsearch.ts b/static/js/fixedsearch.ts
index 6d91dfe..537ddf2 100644
--- a/static/js/fixedsearch.ts
+++ b/static/js/fixedsearch.ts
@@ -13,8 +13,10 @@
const container = document.getElementById("search-frame"); // targets parent
function first(element) {
+ if (element.firstChild.nextElementSibling) {
return element.firstChild.nextElementSibling.firstChild
.nextElementSibling;
+ }
}
function last(element) {
@@ -138,27 +140,6 @@
}
});
- let data = {};
-
- function isEmpty(obj) {
- return Object.keys(obj).length === 0;
- }
-
- function appendItemsTo(local, remote) {
- const paginated = Object.keys(remote).includes("next_url");
- if (isEmpty(local)) {
- local = remote;
- } else {
- local.items = local.items.concat(remote.items);
- }
- if (paginated) {
- fetch(remote.next_url, function (request) {
- appendItemsTo(local, JSON.parse(request.responseText));
- });
- }
- data = local;
- }
-
function fetch(url, callback) {
const http = new XMLHttpRequest();
http.onreadystatechange = function () {
@@ -187,8 +168,28 @@
});
}
+ let data = {};
let boot = true;
+ const options = { key: ["title"] };
+
+ function isEmpty(obj) { return Object.keys(obj).length === 0; }
+
+ function appendItemsTo(local, remote) {
+ const paginated = Object.keys(remote).includes("next_url");
+ if (isEmpty(local)) {
+ local = remote;
+ } else {
+ local.items = local.items.concat(remote.items);
+ }
+ if (paginated) {
+ fetch(remote.next_url, function (request) {
+ appendItemsTo(local, JSON.parse(request.responseText));
+ });
+ } else search(query.value, data.items, options);
+ data = local;
+ }
+
function initialize() {
if (boot) {
script(window.location.origin + "/js/fuzzysort.js")
@@ -196,11 +197,10 @@
fetch("/index.json", function (request) {
appendItemsTo({}, JSON.parse(request.responseText));
- search(query.value, data.items, options);
+ search("", data.items, options);
boot = false;
});
- const options = { key: ["title"] };
["keyup", "focusin"].forEach(function (event) {
query.addEventListener(event, function () {
@@ -211,7 +211,6 @@
}).catch(function (error) {
console.error("ERROR: Failed to load fuzzy search", error);
- boot = true; initialize();
});
}
}