1class PredictiveSearch extends HTMLElement{constructor(){super(),this.cachedResults={},this.input=this.querySelector('input[type="search"]'),this.predictiveSearchResults=this.querySelector("[data-predictive-search]"),this.isOpen=!1,this.setupEventListeners()}setupEventListeners(){const form=this.querySelector("form.search");form&&(form.addEventListener("submit",this.onFormSubmit.bind(this)),this.select=this.querySelector("select"),this.input.addEventListener("input",debounce(event=>{this.onChange(event)},300).bind(this)),this.select&&this.select.addEventListener("input",debounce(event=>{this.onChange(event)},300).bind(this)),this.input.addEventListener("focus",this.onFocus.bind(this)),this.addEventListener("focusout",this.onFocusOut.bind(this)),this.addEventListener("keyup",this.onKeyup.bind(this)),this.addEventListener("keydown",this.onKeydown.bind(this)))}getQuery(){return this.input.value.trim()}getSearchFilterType(){return this.select?this.select.dataset.type:""}getSearchFilterTypeQuery(){return this.select?this.select.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()})}onKeyup(event){switch(this.getQuery().length||this.close(!0),event.preventDefault(),event.code){case"ArrowUp":this.switchOption("up");break;case"ArrowDown":this.switchOption("down");break;case"Enter":this.selectOption();break}}onKeydown(event){(event.code==="ArrowUp"||event.code==="ArrowDown")&&event.preventDefault()}switchOption(direction){if(!this.getAttribute("open"))return;const moveUp=direction==="up",selectedElement=this.querySelector('[aria-selected="true"]'),allVisibleElements=Array.from(this.querySelectorAll("li, button.predictive-search-item-button")).filter(element=>element.offsetParent!==null);let activeElementIndex=0;if(moveUp&&!selectedElement)return;let selectedElementIndex=-1,i=0;for(;selectedElementIndex===-1&&i<=allVisibleElements.length;)allVisibleElements[i]===selectedElement&&(selectedElementIndex=i),i++;if(this.statusElement.textContent="",!moveUp&&selectedElement?activeElementIndex=selectedElementIndex===allVisibleElements.length-1?0:selectedElementIndex+1:moveUp&&(activeElementIndex=selectedElementIndex===0?allVisibleElements.length-1:selectedElementIndex-1),activeElementIndex===selectedElementIndex)return;const activeElement=allVisibleElements[activeElementIndex];activeElement.setAttribute("aria-selected",!0),selectedElement&&selectedElement.setAttribute("aria-selected",!1),this.input.setAttribute("aria-activedescendant",activeElement.id)}selectOption(){const selectedProduct=this.querySelector('[aria-selected="true"] a, [aria-selected="true"] button');selectedProduct&&selectedProduct.click()}getSearchResults(searchTerm){const filterType=this.getSearchFilterType(),filterTypeQuery=this.getSearchFilterTypeQuery(),queryKey=searchTerm.replaceAll(" ","-").toLowerCase()+"-"+filterType+"-"+filterTypeQuery.replaceAll(" ","-").toLowerCase();if(this.setLiveRegionLoadingState(),this.cachedResults[queryKey]){this.renderSearchResults(this.cachedResults[queryKey]);return}const limit=this.dataset.limit,limitScope=this.dataset.limitScope,resultTypes=this.dataset.types,showUnavailable=this.dataset.unavailable,query=encodeURIComponent(filterTypeQuery?`${filterType}:${filterTypeQuery}+* ${searchTerm}`:searchTerm);fetch(`${routes.predictive_search_url}?q=${query}&resources[type]=${resultTypes}&resources[limit_scope]=${limitScope}&resources[limit]=${limit}&options[prefix]=last&options[unavailable_products]=${showUnavailable}§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 resultsMarkup=new DOMParser().parseFromString(text,"text/html").querySelector("#shopify-section-predictive-search").innerHTML;this.cachedResults[queryKey]=resultsMarkup,this.renderSearchResults(resultsMarkup)}).catch(error=>{throw this.close(),error})}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.querySelector(".section-header").getBoundingClientRect().bottom,this.resultsMaxHeight}open(){if(this.predictiveSearchResults.style.maxHeight=this.resultsMaxHeight||`${this.getResultsMaxHeight()}px`,this.setAttribute("open",!0),this.input.setAttribute("aria-expanded",!0),!this.isOpen){const event=new CustomEvent("search:open");document.dispatchEvent(event)}this.isOpen=!0}close(clearSearchTerm=!1){clearSearchTerm&&(this.input.value="",this.removeAttribute("results"));const selected=this.querySelector('[aria-selected="true"]');if(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){const event=new CustomEvent("search:close");document.dispatchEvent(event)}this.isOpen=!1}}customElements.define("predictive-search",PredictiveSearch); 2//# sourceMappingURL=/cdn/shop/t/2/assets/predictive-search.js.map?v=156595463097128312131747788433
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.