1import{EVENTS}from"@archetype-themes/utils/events";import{debounce}from"@archetype-themes/utils/utils";class PredictiveSearch extends HTMLElement{constructor(){super(),this.enabled=this.getAttribute("data-enabled"),this.context=this.getAttribute("data-context"),this.input=this.querySelector('input[type="search"]'),this.predictiveSearchResults=this.querySelector("#predictive-search"),this.closeBtn=this.querySelector(".btn--close-search"),this.screen=this.querySelector("[data-screen]"),this.SearchModal=this.closest("#SearchModal")||null,this.SearchModal&&new MutationObserver(mutations=>{mutations.forEach(mutation=>{mutation.attributeName==="class"&&mutation.target.className.indexOf("modal--is-active")>-1&&setTimeout(()=>{this.input.focus()},100)})}).observe(this.SearchModal,{attributes:!0})}connectedCallback(){this.enabled!=="false"&&(this.abortController=new AbortController,document.addEventListener(EVENTS.predictiveSearchOpen,e=>{e.detail.context===this.context&&(this.classList.add("is-active"),setTimeout(()=>{this.input.focus()},100),document.body.classList.add("predictive-overflow-hidden"))},{signal:this.abortController.signal}),this.input.addEventListener("keydown",()=>{this.classList.add("is-active")}),this.input.addEventListener("input",debounce(300,event=>{this.onChange(event)}).bind(this)),document.addEventListener(EVENTS.predictiveSearchClose,()=>{this.close()},{signal:this.abortController.signal}),document.addEventListener("keydown",evt=>{evt.keyCode===27&&this.close()},{signal:this.abortController.signal}),this.closeBtn.addEventListener("click",evt=>{evt.preventDefault(),this.close()},{signal:this.abortController.signal}),this.screen?.addEventListener("click",()=>{this.close()},{signal:this.abortController.signal}),document.addEventListener(EVENTS.headerSearchClose,()=>{this.close()}))}disconnectedCallback(){this.abortController.abort()}onChange(){const searchTerm=this.input.value.trim();searchTerm.length&&this.getSearchResults(searchTerm)}getSearchResults(searchTerm){const searchObj={q:searchTerm,"resources[limit]":3,"resources[limit_scope]":"each","resources[options][unavailable_products]":"last"},params=this.paramUrl(searchObj);fetch(`${window.Shopify.routes.root}search/suggest?${params}§ion_id=search-results`).then(response=>{if(!response.ok){const error=new Error(response.status);throw this.close(),error}return response.text()}).then(text=>{const resultsMarkup=new DOMParser().parseFromString(text,"text/html").querySelector("#shopify-section-search-results").innerHTML;this.predictiveSearchResults.innerHTML=resultsMarkup,this.open()}).catch(error=>{throw this.close(),error})}open(){this.predictiveSearchResults.style.display="block"}close(){this.predictiveSearchResults.style.display="none",this.predictiveSearchResults.innerHTML="",this.classList.remove("is-active"),document.body.classList.remove("predictive-overflow-hidden"),this.contains(document.activeElement)&&document.activeElement.blur(),this.dispatchEvent(new CustomEvent(EVENTS.predictiveSearchCloseAll,{bubbles:!0}))}paramUrl(obj){return Object.keys(obj).map(function(key){return key+"="+encodeURIComponent(obj[key])}).join("&")}}customElements.define("predictive-search",PredictiveSearch); 2//# sourceMappingURL=/cdn/shop/t/3/assets/predictive-search.js.map?v=165210660372665716981744275110
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.