PageSourceSearch

https://www.gl-inet.com/cdn/shop/t/263/assets/custom-predictive-search-D9smDPvY.js

js gl-inet.com collected 2026-10-02 04:08:18 UTC 5,580 bytes, 1 lines download raw bytes

1class a extends HTMLElement{constructor(){super(),this.input=this.querySelector('input[type="search"]'),this.form=this.querySelector("form"),this.removeBtn=this.querySelector(".search-remove"),this.recommendContainer=this.querySelector(".recommend-container"),this.storageKey="gl_search_history",this.predictiveSearchResults=this.querySelector("#predictive-search"),this.searchesItems=this.querySelectorAll(".searches-item"),this.topSearches=this.querySelector(".top-searches"),this.abortController=null,this.lastSearchTerm="",this.predictiveSearchSupported=this.isPredictiveSearchSupported(),this.input.addEventListener("input",this.debounce(e=>{this.onChange(e)},100).bind(this)),this.removeBtn.addEventListener("click",()=>{this.input.value="",this.close()}),this.recommendContainer.addEventListener("click",e=>{const i=e.target;if(i.closest(".clear-all-history")){e.preventDefault(),e.stopPropagation(),localStorage.setItem(this.storageKey,JSON.stringify([]));const r=this.querySelector(".bottom-searches");if(r){const o=r.querySelectorAll(".searches-item");o.forEach((s,c)=>{setTimeout(()=>{s.style.opacity="0",s.style.transform="scale(0.9)",s.style.transition="all 0.3s ease"},c*50)}),setTimeout(()=>{r.remove()},o.length*50+300)}return}const t=e.target.closest(".searches-item");if(t)if(i.classList.contains("clear-item-history")){e.preventDefault(),e.stopPropagation();let r=JSON.parse(localStorage.getItem(this.storageKey)||"[]");const o=r.indexOf(t.dataset.search);o>-1&&(r.splice(o,1),localStorage.setItem(this.storageKey,JSON.stringify(r))),t.style.opacity="0",t.style.transform="scale(0.9)",t.style.transition="all 0.3s ease",setTimeout(()=>{t.remove();const s=this.querySelector(".bottom-searches");s&&s.querySelectorAll(".searches-item").length===0&&s.remove()},300)}else this.form.classList.add("is-submitting"),this.input.value=t.dataset.search||t.textContent,this.form.submit(),this.saveSearchHistory(this.input.value.trim())}),this.form.addEventListener("submit",e=>{const i=this.input.value.trim();this.saveSearchHistory(i)}),document.querySelector("form.productgrid--search-form")?.addEventListener("submit",e=>{const i=document.querySelector("form.productgrid--search-form input").value.trim();this.saveSearchHistory(i)})}saveSearchHistory(e){if(!e||!e.trim())return;e=e.trim();const i=localStorage.getItem(this.storageKey);let t=i?JSON.parse(i):[];t=t.filter(r=>r!==e),t.unshift(e),t.length>5&&(t=t.slice(0,5)),localStorage.setItem(this.storageKey,JSON.stringify(t))}onChange(){const e=this.input.value.trim();if(!this.predictiveSearchSupported){this.close();return}if(!(e===this.lastSearchTerm&&this.isResultsVisible())){if(this.lastSearchTerm=e,this.abortController&&this.abortController.abort(),!e.length){this.close();return}this.abortController=new AbortController,this.getSearchResults(e,this.abortController.signal)}}async getSearchResults(e,i){if(!e.length){this.close();return}const t=this.predictiveSearchResults.innerHTML;this.predictiveSearchResults.innerHTML="";try{const r=window.Theme?.routes?.predictive_search_url||"/search/suggest",o=await fetch(`${r}?q=${encodeURIComponent(e)}&section_id=predictive-search&resources[type]=product,page,article`,{signal:i});if(i.aborted)return;if(o.status===417){this.predictiveSearchSupported=!1,this.predictiveSearchResults.innerHTML=t,this.close();return}if(!o.ok)throw new Error(`Predictive search request failed: ${o.status}`);const s=await o.text();if(i.aborted||e!==this.input.value.trim())return;this.predictiveSearchResults.innerHTML="";const c=new DOMParser().parseFromString(s,"text/html").querySelector("#shopify-section-predictive-search");if(!c)throw new Error("Predictive search response is missing its section container");const n=c.innerHTML;this.predictiveSearchResults.innerHTML=n,this.open(),document.dispatchEvent(new CustomEvent("gl.custom.euroPriceFormat",{detail:{container:document.getElementById("predictive-search")}})),setTimeout(()=>{document.dispatchEvent(new CustomEvent("gl.custom.euroPriceFormat",{detail:{container:document.getElementById("predictive-search")}}))},3e3)}catch(r){if(this.predictiveSearchResults.innerHTML=t,r.name==="AbortError")return;console.error("Search error:",r),this.close()}}open(){this.predictiveSearchResults.style.display="block";const e=document.querySelector(".gl-search-content");e&&e.classList.add("open-style")}close(){this.predictiveSearchResults.style.display="none",this.lastSearchTerm="";const e=document.querySelector(".gl-search-content");e&&e.classList.remove("open-style")}isResultsVisible(){return this.predictiveSearchResults.style.display==="block"}isPredictiveSearchSupported(){const i=(window.Shopify?.shop_locale||document.documentElement.lang||"").toLowerCase().split("-")[0];return!new Set(["hi","ja","zh"]).has(i)}debounce(e,i){let t;return(...r)=>{clearTimeout(t),t=setTimeout(()=>e.apply(this,r),i)}}flyToInput(e,i){const t=e.getBoundingClientRect(),r=i.getBoundingClientRect(),o=window.pageYOffset||document.documentElement.scrollTop,s=document.createElement("div");s.className="search-word-fly",s.textContent=e.textContent,s.style.position="fixed",s.style.left=t.left+"px",s.style.top=t.top+o+"px",s.style.opacity="1",s.style.transform="scale(1)",document.body.appendChild(s),requestAnimationFrame(()=>{const c=r.left+35,n=r.top+o+r.height/2;s.style.left=c+"px",s.style.top=n+"px",s.style.transform="scale(0.4)",s.style.opacity="0.3"}),e.classList.add("flying-source"),setTimeout(()=>{s&&s.parentNode&&s.parentNode.removeChild(s),e.classList.remove("flying-source")},300)}}customElements.define("predictive-search",a);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.