1class PredictiveSearch extends HTMLElement{constructor(){super(),this.cachedResults={},this.input=this.querySelector('input[type="search"]'),this.predictiveSearchResults=this.querySelector(".predictive-search__results"),this.overlay=this.querySelector(".predictive-search__overlay"),this.isOpen=!1,this.controller=new AbortController,this.working=!1,this.hasPlaceholder=!1,this.timeoutQuery,this.setupEventListeners()}setupEventListeners(){this.querySelector("form.search").addEventListener("submit",this.onFormSubmit.bind(this)),this.input.addEventListener("input",event=>{this.open(),this.setLiveRegionLoadingState(),this.timeoutQuery&&(clearTimeout(this.timeoutQuery),this.working=!1),this.timeoutQuery=setTimeout(this.onChange.bind(this),300)}),this.input.addEventListener("focus",this.onFocus.bind(this)),this.addEventListener("focusout",this.onFocusOut.bind(this)),this.overlay.addEventListener("click",this.onClickOverlay.bind(this))}getQuery(){return this.input.value.trim()}onChange(){const searchTerm=this.getQuery();if(!searchTerm.length){this.close(!0);return}this.getSearchResults(searchTerm)}onFormSubmit(event){(!this.getQuery().length||this.querySelector('[aria-selected="true"] a'))&&event.preventDefault()}onFocus(){const searchTerm=this.getQuery();searchTerm.length&&(this.getAttribute("results")==="true"?this.open():this.getSearchResults(searchTerm))}onFocusOut(){setTimeout(()=>{this.contains(document.activeElement)||this.close()})}onClickOverlay(){this.close()}getSearchResults(searchTerm){const queryKey=searchTerm.replace(" ","-").toLowerCase();if(!Shopify.designMode&&this.cachedResults[queryKey]){this.renderSearchResults(this.cachedResults[queryKey]);return}this.working&&(this.controller.abort(),this.controller=new AbortController);const signal=this.controller.signal;this.working=!0,fetch(`${routes.predictive_search_url}?q=${encodeURIComponent(searchTerm)}&${encodeURIComponent("resources[limit]")}=10§ion_id=predictive-search`,{signal}).then(response=>{if(!response.ok){var error=new Error(response.status);throw this.close(),error}return response.text()}).then(text=>{const resultsMarkup=getDomHtmlFromText(text,"#shopify-section-predictive-search");this.cachedResults[queryKey]=resultsMarkup,this.renderSearchResults(resultsMarkup)}).catch(error=>{throw this.close(),error}).finally(()=>{this.working=!1})}setLiveRegionLoadingState(){if(this.setAttribute("loading",!0),!this.hasPlaceholder){const placeholder=document.getElementById("predictive-search-placeholder-tpl").content.cloneNode(!0);this.querySelector(".predictive-search__loading-state").append(placeholder),this.hasPlaceholder=!0}}renderSearchResults(resultsMarkup){this.predictiveSearchResults.innerHTML=resultsMarkup.innerHTML,this.predictiveSearchResults.querySelectorAll("script").forEach(oldScriptTag=>{const newScriptTag=document.createElement("script");Array.from(oldScriptTag.attributes).forEach(attribute=>{newScriptTag.setAttribute(attribute.name,attribute.value)}),newScriptTag.appendChild(document.createTextNode(oldScriptTag.innerHTML)),oldScriptTag.parentNode.replaceChild(newScriptTag,oldScriptTag)}),this.setAttribute("results",!0),this.setLiveRegionResults()}setLiveRegionResults(){this.removeAttribute("loading")}open(){this.isOpen||(this.classList.contains("run-top")||this.timeoutRunTop||(this.timeoutRunTop=setTimeout(()=>{this.classList.add("run-top"),this.timeoutRunTop=null},500)),this.setAttribute("open",!0),this.input.setAttribute("aria-expanded",!0),this.isOpen=!0)}close(clearSearchTerm=!1){clearSearchTerm&&(this.input.value="",this.removeAttribute("results")),this.classList.remove("run-top"),this.input.setAttribute("aria-activedescendant",""),this.removeAttribute("open"),this.input.setAttribute("aria-expanded",!1),this.isOpen=!1,this.nextElementSibling&&this.nextElementSibling.classList.contains("search-modal__close-button")&&this.nextElementSibling.dispatchEvent(new Event("click"))}}customElements.define("predictive-search",PredictiveSearch); 2//# sourceMappingURL=/cdn/shop/t/19/assets/predictive-search.js.map?v=87425587959083120531715280487
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.