From 6dcec618d0ff0a2270f787f62267a0622275c69d Mon Sep 17 00:00:00 2001 From: Jieiku Date: Mon, 22 May 2023 22:37:44 -0700 Subject: Load Tinysearch/Stork On Demand --- static/tinysearch.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'static/tinysearch.js') 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 -}; -- cgit v1.3.1