1class PredictiveSearch extends HTMLElement{constructor(){super(),this.input=this.querySelector('input[type="search"]'),this.results=this.querySelector("#predictive-search"),this.alert=this.querySelector("#predictive-search-alert"),this.footer=this.closest("#offcanvas-search").querySelector(".offcanvas-footer"),this.popularProducts=this.closest("#offcanvas-search").querySelector("#search-popular-products-wrapper"),this.speechBtn=this.querySelector(".btn-search-by-voice"),this.input.addEventListener("input",this.debounce(event=>{this.onChange()},300).bind(this)),document.querySelector("#offcanvas-search")?.addEventListener("shown.bs.offcanvas",()=>{this.input.focus()}),window.SpeechRecognition||window.webkitSpeechRecognition?this.speechBtn?.addEventListener("click",()=>{this.speechRecognition()}):this.speechBtn.remove(),document.querySelectorAll("#offcanvas-search .btn-atc").forEach(btn=>{btn.addEventListener("click",()=>{setTimeout(()=>{bootstrap.Offcanvas.getOrCreateInstance("#offcanvas-search").hide()},300)})})}onChange(){const searchTerm=this.input.value.trim();if(this.footer.querySelector('[name="q"]').value=searchTerm,this.footer.querySelector(".btn").textContent=`${this.footer.querySelector(".btn").dataset.textSearchFor} "${searchTerm}"`,!searchTerm.length){this.close();return}this.getSearchResults(searchTerm)}async getSearchResults(searchTerm){let resourcesType="product";this.input.dataset.searchCollections==="true"&&(resourcesType=`${resourcesType},collection`),this.input.dataset.searchPages==="true"&&(resourcesType=`${resourcesType},page`),this.input.dataset.searchArticles==="true"&&(resourcesType=`${resourcesType},article`);const response=await fetch(`/search/suggest?q=${searchTerm}&resources[type]=${resourcesType}&resources[limit]=10§ion_id=predictive-search`);if(!response.ok){const error=new Error(response.status);throw this.close(),error}const text=await response.text(),resultsMarkup=new DOMParser().parseFromString(text,"text/html").querySelector("#shopify-section-predictive-search").innerHTML;this.results.innerHTML=resultsMarkup,this.open()}open(){this.results.style.display="block";const countResults=this.results.querySelectorAll(".product-item").length;switch(countResults){case 0:this.alert.textContent=this.alert.dataset.textNoResults;break;case 1:this.alert.textContent=this.alert.dataset.textResultFound;break;default:this.alert.textContent=this.alert.dataset.textResultsFound.replace("[count]",countResults);break}this.footer.removeAttribute("hidden"),window.SPR?.initDomEls(),window.SPR?.loadBadges(),this.popularProducts?.setAttribute("hidden","hidden")}close(){this.results.style.display="none",this.alert.textContent="",this.footer.setAttribute("hidden","hidden"),this.popularProducts?.removeAttribute("hidden")}speechRecognition(){var SpeechRecognition=SpeechRecognition||webkitSpeechRecognition;const recognition=new SpeechRecognition;recognition.onstart=()=>{console.log("on speech start"),this.speechBtn.classList.add("speech-started"),setTimeout(()=>{this.speechBtn.classList.remove("speech-started")},5e3)},recognition.onspeechend=event=>{console.log("on speech end",event),this.speechBtn.classList.remove("speech-started")},recognition.onresult=event=>{console.log("on speech result",event),event.results&&(this.input.value=event.results[0][0].transcript,this.onChange())},recognition.start()}debounce(fn,wait){let t;return(...args)=>{clearTimeout(t),t=setTimeout(()=>fn.apply(this,args),wait)}}}customElements.define("predictive-search",PredictiveSearch),window.closeSearchOffcanvas=(btn,event)=>{setTimeout(()=>{bootstrap.Offcanvas.getOrCreateInstance("#offcanvas-search").hide()},300)}; 2//# sourceMappingURL=/cdn/shop/t/35/assets/search.js.map?v=52289388508672221561775108815
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.