newblog/static/js/search_tinysearch.min.js

1 line
5.3 KiB
JavaScript
Raw Permalink Normal View History

2024-07-01 15:20:09 +02:00
function closeSearchNow(){document.querySelector("main").innerHTML=window.main}function goSearchNow(){var e=document.querySelector("main"),t=(window.main||(window.main=e.innerHTML),document.getElementById("suggestions")),n=t.cloneNode(!0),o=(n.id="results",document.createElement("div")),a='<form name="closeSearch"><h2><button type="submit" title="Close Search"><i class="svgs x"></i></button> <i class="svgs search"></i> '.concat(document.getElementById("searchinput").value,"</h2></form>");return o.innerHTML=a,n.insertBefore(o,n.firstChild),e.innerHTML=n.outerHTML,t.innerHTML="",document.getElementById("searchinput").value="",document.body.contains(document.closeSearch)&&(document.closeSearch.onsubmit=function(){closeSearchNow()}),!1}async function lazyLoad(){var e=document.querySelector("meta[name='base']").getAttribute("content");await init((e="/"==e.slice(-1)?e.slice(0,-1):e)+"/tinysearch_engine_bg.wasm")}function closeAllLists(e){for(var t=document.getElementById("suggestions");t.firstChild;)t.removeChild(t.firstChild)}function markTerm(e,t){return e.replace(RegExp("(^|)("+t+")(|$)","ig"),"$1<mark><b>$2</b></mark>$3")}function autocomplete(e){e.addEventListener("input",function(e){var t=this.value;if(closeAllLists(),!t)return!1;for(var n=document.getElementById("suggestions"),o=search(t,99),a=0;a<o.length;a++){var c,r,i,s,u=o[a];(s=document.createElement("DIV")).innerHTML="<a href><span></span><span></span></a>",c=s.querySelector("a"),r=s.querySelector("span:first-child"),i=s.querySelector("span:nth-child(2)"),c.href=u[1]+"?q="+encodeURIComponent(t),r.innerHTML=markTerm(u[0],t),i.innerHTML=markTerm(u[2],t),n.appendChild(s)}})}function suggestionFocus(t){191===t.keyCode&&"INPUT"!==document.activeElement.tagName&&"TEXTAREA"!==document.activeElement.tagName&&(t.preventDefault(),searchinput.focus(),suggestions.classList.remove("d-none")),27===t.keyCode&&(searchinput.blur(),suggestions.classList.add("d-none"),closeAllLists());var n=suggestions.querySelectorAll("a");if(!suggestions.classList.contains("d-none")&&0!==n.length){var o=[...n],a=o.indexOf(document.activeElement);let e=0;38===t.keyCode?(t.preventDefault(),n[e=0<a?a-1:0].focus()):40===t.keyCode&&(t.preventDefault(),n[e=1+a<o.length?1+a:a].focus())}}function getUint8Memory0(){return cachegetUint8Memory0=null!==cachegetUint8Memory0&&cachegetUint8Memory0.buffer===wasm.memory.buffer?cachegetUint8Memory0:new Uint8Array(wasm.memory.buffer)}function getStringFromWasm0(e,t){return cachedTextDecoder.decode(getUint8Memory0().subarray(e,e+t))}function addHeapObject(e){heap_next===heap.length&&heap.push(heap.length+1);var t=heap_next;return heap_next=heap[t],heap[t]=e,t}function passStringToWasm0(n,o,t){if(void 0===t){let e=cachedTextEncoder.encode(n),t=o(e.length);return getUint8Memory0().subarray(t,t+e.length).set(e),WASM_VECTOR_LEN=e.length,t}let a=n.length,c=o(a);var r=getUint8Memory0();let i=0;for(;i<a;i++){let e=n.charCodeAt(i);if(127<e)break;r[c+i]=e}if(i!==a){0!==i&&(n=n.slice(i)),c=t(c,a,a=i+3*n.length);let e=getUint8Memory0().subarray(c+i,c+a);i+=encodeString(n,e).written}return WASM_VECTOR_LEN=i,c}function getObject(e){return heap[e]}function dropObject(e){e<36||(heap[e]=heap_next,heap_next=e)}function takeObject(e){var t=getObject(e);return dropObject(e),t}function search(e,t){var e=passStringToWasm0(e,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),n=WASM_VECTOR_LEN;return takeObject(wasm.search(e,n,t))}async function load(e,t){if("function"==typeof Response&&e instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if("application/wasm"==e.headers.get("Content-Type"))throw t}var n=await e.arrayBuffer();return WebAssembly.instantiate(n,t)}return(n=await WebAssembly.instantiate(e,t))instanceof WebAssembly.Instance?{instance:n,module:e}:n}async function init(e){var t=document.querySelector("meta[name='base']").getAttribute("content"),t=("/"==t.slice(-1)&&(t=t.slice(0,-1)),void 0===e&&(e=new URL(t+"/tinysearch_engine_bg.wasm")),{wbg:{}}),{instance:e,module:t}=(t.wbg.__wbindgen_json_pa