aboutsummaryrefslogtreecommitdiff
path: root/static/tinysearch.js
diff options
context:
space:
mode:
authorJieiku2023-05-22 22:37:44 -0700
committerJieiku2023-05-22 22:37:44 -0700
commit6dcec618d0ff0a2270f787f62267a0622275c69d (patch)
treef0dd674fe43331db55ddae38808749de0323f030 /static/tinysearch.js
parent71d977d49afbf93e0c736815e36d59664991fa18 (diff)
downloadabridge-6dcec618d0ff0a2270f787f62267a0622275c69d.tar.gz
abridge-6dcec618d0ff0a2270f787f62267a0622275c69d.tar.bz2
abridge-6dcec618d0ff0a2270f787f62267a0622275c69d.zip
Load Tinysearch/Stork On Demand
Diffstat (limited to 'static/tinysearch.js')
-rw-r--r--static/tinysearch.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/static/tinysearch.js b/static/tinysearch.js
index ab099ca..b6f8b07 100644
--- a/static/tinysearch.js
+++ b/static/tinysearch.js
@@ -27,8 +27,17 @@ function goSearchNow() {
document.body.contains(document.closeSearch) && (document.closeSearch.onsubmit = function() { closeSearchNow() })
return false
}
+var loaded = false;
window.onload = function() {
document.body.contains(document.goSearch) && (document.goSearch.onsubmit = function() { return goSearchNow() })
+ document.getElementById('searchinput').onfocus = function() {
+ if (!loaded) {
+ lazyLoad();
+ loaded = true;
+ document.body.contains(document.goSearch) && (document.goSearch.onsubmit = function() { return goSearchNow() })
+ }
+ document.getElementById('searchinput').onfocus = '';
+ }
};
async function lazyLoad() {
@@ -39,13 +48,6 @@ async function lazyLoad() {
await init(baseUrl + "/tinysearch_engine_bg.wasm")
}
-var loaded = false;
-if (!loaded) {
- lazyLoad();
- loaded = true;
- document.body.contains(document.goSearch) && (document.goSearch.onsubmit = function() { return goSearchNow() })
-}
-
/* Close search suggestion popup list */
function closeAllLists(elmnt) {
var suggestions = document.getElementById("suggestions");
@@ -227,7 +229,7 @@ async function init(e) {
if (baseUrl.slice(-1) == "/") {
baseUrl = baseUrl.slice(0, -1);
}
- void 0 === e && (e = new URL(baseUrl + "/tinysearch_engine_bg.wasm", import.meta.url));
+ void 0 === e && (e = new URL(baseUrl + "/tinysearch_engine_bg.wasm"));
const t = {
wbg: {}
};
@@ -240,7 +242,3 @@ async function init(e) {
} = await load(await (e = "string" == typeof e || "function" == typeof Request && e instanceof Request || "function" == typeof URL && e instanceof URL ? fetch(e) : e), t);
return wasm = e.exports, init.__wbindgen_wasm_module = n, wasm
}
-export default init;
-export {
- search
-};