1class PredictiveSearch extends HTMLElement{constructor(){super(),this.cachedResults={},this.input=this.querySelector('input[type="search"]'),this.predictiveSearchResults=this.querySelector("[data-predictive-search]"),this.predictiveSearchResultsInitial=this.querySelector("[data-predictive-search]").innerHTML,this.isOpen=!1,this.clearBtn=this.querySelector(".js-search-clear"),this.form=this.querySelector("form.search"),this.redirectResult=!1,this.noResults=!1,this.doneTyping=!1,this.setupEventListeners()}setupEventListeners(){const _this=this,onChange=debounce(event=>{_this.onSearch(event)},300).bind(this);_this.input.addEventListener("input",onChange),_this.input.addEventListener("focus",_this.onFocus.bind(this)),_this.addEventListener("focusout",_this.onFocusOut.bind(this)),_this.clearBtn.addEventListener("click",_this.clearSearch.bind(this)),_this.input.addEventListener("keyup",_this.setInputFocus.bind(this)),_this.input.addEventListener("focusout",_this.removeInputFocus.bind(this))}setInputFocus(event){(event.shiftKey&&event.key==="Tab"||event.key==="Tab")&&this.form.classList.add("is-clicked"),this.doneTyping=!1;let timer;clearTimeout(timer),timer=setTimeout(()=>{this.doneTyping=!0},1e3)}removeInputFocus(){this.form.classList.remove("is-clicked")}clearSearch(event){event.stopPropagation(),this.input.value="",this.input.focus(),this.predictiveSearchResults.innerHTML=this.predictiveSearchResultsInitial}isMobileDevice(){return window.matchMedia("(max-width: 990px)").matches}getQuery(){return this.input.value.trim()}onSearch(){const searchTerm=this.getQuery();if(!searchTerm.length){this.predictiveSearchResults.innerHTML=this.predictiveSearchResultsInitial,this.close(!0);return}this.redirectResult?this.redirectSearchResultPage(searchTerm):this.getSearchResults(searchTerm)}onFocus(){const searchTerm=this.getQuery();searchTerm.length&&(this.getAttribute("results")==="true"?this.open():this.isMobileDevice()||this.getSearchResults(searchTerm))}onFocusOut(event){setTimeout(()=>{this.contains(document.activeElement)||this.close()})}getSearchResultData(searchTerm){const queryKey=searchTerm.replace(" ","-").toLowerCase();if(this.setLiveRegionLoadingState(),this.cachedResults[queryKey]){this.renderSearchResults(this.cachedResults[queryKey]);return}fetch(`${routes.predictive_search_url}?q=${encodeURIComponent(searchTerm)}§ion_id=predictive-search`).then(response=>{if(!response.ok){var error=new Error(response.status);throw this.close(),error}return response.text()}).then(text=>{const noResults=new DOMParser().parseFromString(text,"text/html").querySelector("div[data-no-search-results]")?.getAttribute("data-no-search-results");this.noResults=noResults;const resultsMarkup=new DOMParser().parseFromString(text,"text/html").querySelector("#shopify-section-predictive-search").innerHTML;this.renderSearchResults(resultsMarkup)}).catch(error=>{throw this.close(),error})}redirectSearchResultPage(searchTerm){fetch(`${routes.predictive_search_url}.json?q=${encodeURIComponent(searchTerm)}`).then(response=>{if(!response.ok){var error=new Error(response.status);throw this.close(),error}return response.json()}).then(data=>{const results=data?.resources?.results||{};results?.collections?.length?location.href=`/search?q=${encodeURIComponent(searchTerm)}`:results?.queries?.length?location.href=`/search?q=${encodeURIComponent(searchTerm)}`:location.href=`/search?_pos=1&_psq=${encodeURIComponent(searchTerm)}&_ss=e&_v=1.0&q=${encodeURIComponent(searchTerm)}`}).catch(error=>{throw this.close(),error})}getSearchResults(searchTerm){this.getSearchResultData(searchTerm)}setLiveRegionLoadingState(){this.statusElement=this.statusElement||this.querySelector(".predictive-search-status"),this.loadingText=this.loadingText||this.getAttribute("data-loading-text"),this.setLiveRegionText(this.loadingText),this.setAttribute("loading",!0)}setLiveRegionText(statusText){this.statusElement.setAttribute("aria-hidden","false"),this.statusElement.textContent=statusText,setTimeout(()=>{this.statusElement.setAttribute("aria-hidden","true")},1e3)}renderSearchResults(resultsMarkup){this.predictiveSearchResults.innerHTML=resultsMarkup,this.setAttribute("results",!0),this.setLiveRegionResults(),this.open()}setLiveRegionResults(){this.removeAttribute("loading"),this.setLiveRegionText(this.querySelector("[data-predictive-search-live-region-count-value]").textContent)}getResultsMaxHeight(){return this.resultsMaxHeight=window.innerHeight-document.getElementById("shopify-section-header").getBoundingClientRect().bottom,this.resultsMaxHeight}open(){this.setAttribute("open",!0),this.input.setAttribute("aria-expanded",!0),this.isOpen=!0}close(clearSearchTerm=!1){clearSearchTerm&&(this.input.value="",this.removeAttribute("results"),this.removeAttribute("open"));const selected=this.querySelector('[aria-selected="true"]');selected&&selected.setAttribute("aria-selected",!1),this.input.setAttribute("aria-activedescendant",""),this.removeAttribute("open"),this.input.setAttribute("aria-expanded",!1),this.resultsMaxHeight=!1,this.predictiveSearchResults.removeAttribute("style"),this.isOpen=!1}}customElements.define("predictive-search",PredictiveSearch);class SearchPopover extends HTMLElement{connectedCallback(){const input=this.querySelector("#predictive_search_input");this.addEventListener("toggle",event=>
1{const open=event.newState=="open",headerWrapper=document.querySelector(".header-wrapper"),header=document.querySelector("header.header");headerWrapper.classList.toggle("header-wrapper--search-open",open),open?(document.body.classList.add("scroll-lock"),header.querySelector(".header__inline-menu")?.setAttribute("inert",!0),document.querySelector("main")?.setAttribute("inert",!0),input?.focus()):(document.body.classList.remove("scroll-lock"),header.querySelector(".header__inline-menu")?.removeAttribute("inert"),document.querySelector("main")?.removeAttribute("inert"))}),document.querySelector("[popovertarget='search_popover']").addEventListener("pointerdown",async event=>{const fakeInput=document.querySelector("#placeholder-input");fakeInput&&(fakeInput.classList.remove("hidden"),fakeInput.focus({preventScroll:!0}),fakeInput.click(),event.preventDefault(),await new Promise(resolve=>{setTimeout(()=>{resolve(!0)},500)}),input.focus({preventScroll:!0}),input.click(),fakeInput.classList.add("hidden"))})}}customElements.define("search-popover",SearchPopover); 2//# sourceMappingURL=/cdn/shop/t/767/assets/predictive-search.js.map?v=50116629860500890641788207951
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.