1(async()=>{const{Core}=await importModule("Core"),{$fetch,debounce,$toggleDisplay,$replaceContent,scrollLock}=await importModule("Utils"),ATTR_ONLY_STOCK="only-stock-products",ATTR_MIN_CHARS="min-chars",ATTR_LIMIT="results-limit",ATTR_WITH_SUGGESTIONS="with-suggestions",ATTR_WITH_RECENT="with-recent",ATTR_SOURCES="sources",RQ_SECTION="r_predictive-search",ATTR_NO_RESULTS="data-empty-results",DEFAULT_MIN_CHARS=3,DEFAULT_LIMIT=5,CN_ACTIVE="!active",CN_LOADING="!loading";customElements.define("predictive-search",class extends Core{elements={form:"form",input:'input[name="q"]',button:'[data-element="button"]',results:"[data-results]",wrapper:"[data-wrapper]",initial:"[data-initial]",suggestions:"*[data-suggestion]"};subscriptions={"recentSearches:select":"_updateInputValue"};cache={};render(){this.addEventListener("click",e=>{this.$input.focus()}),this._disableAutocomplete(),this._handleInput(),this._handleButtonClick(),this._handleOuterClick(),this._handleSuggestions(),this._handleRecentSearches()}_disableAutocomplete(){this.$input.setAttribute("autocomplete","off")}_handleInput(){this.$input.addEventListener("focus",this._handleFocus.bind(this)),this.$input.addEventListener("blur",this._handleBlur.bind(this)),this.$input.addEventListener("input",debounce(this._inputHandler.bind(this),300).bind(this))}_handleButtonClick(){this.$button.addEventListener("click",this._handleButtonOnEmpty.bind(this))}_handleButtonOnEmpty(e){this.$input.value||(e.preventDefault(),this.$input.focus())}_handleFocus(){this._handleActiveState(),this.lights=!1}_handleBlur(e){this.lights=!0}_handleActiveState(){this.isEmptyResults?(this.showInitial=!1,this.active=!0):(this.showInitial=!0,this.active=!!this.minQueryChars||!!this.$initial)}async _inputHandler(){if(!this.minQueryChars){this.showResults=!1,this.isEmptyResults=!1,this._handleActiveState();return}this.loading=!0,await this._getQueryResults(),this._renderQueryResults()}async _getQueryResults(){if(!this.cache[`${this.query}`]){const $resultsDoc=await this._fetchResultsDoc(),empty=$resultsDoc.hasAttribute(ATTR_NO_RESULTS);this.cache[`${this.query}`]={empty,content:$resultsDoc}}}async _fetchResultsDoc(){return $fetch(`${routes.predictive_search_url}?${this.searchParams}`,{select:"[data-template]"})}_renderQueryResults(){$replaceContent(this.$results,this.cache[`${this.query}`].content);const isEmpty=this.cache[`${this.query}`].empty;this.isEmptyResults=!isEmpty,this._handleActiveState(),this.loading=!1,this.showResults=!0}_handleOuterClick(){document.addEventListener("click",e=>{!this.contains(e.target)&&this.active&&(this.active=!1)})}_handleSuggestions(){this.withSuggestions&&this.$suggestions.map($suggestion=>{$suggestion.addEventListener("click",e=>{e.preventDefault(),this.$input.value=e.currentTarget.dataset.suggestion,this.$input.focus(),this.$input.dispatchEvent(new Event("input"))})})}_handleRecentSearches(){this.withRecent&&(this.subscribe("recentSearches:select"),this.addEventListener("click",e=>{e.target.href&&this._publishQuery(this.query)}),this.$form.addEventListener("submit",e=>{e.preventDefault();const query=new FormData(this.$form).get("q");this._publishQuery(query),this.$form.submit()},{once:!0}))}_updateInputValue({value}){this.$input.value=value,this.$input.focus()}_publishQuery(query){this.publish("search:query",{query})}set loading(state){this.classList.toggle(CN_LOADING,state)}set showInitial(state){this.$initial&&$toggleDisplay(this.$initial,state)}set showResults(state){$toggleDisplay(this.$results,state)}set active(state){this.$wrapper.classList.toggle(CN_ACTIVE,state),scrollLock(state),this._active=state}get active(){return!!this._active}get lights(){return this._lights}set lights(state){this.publish("lights-out",!state),this._lights=state}get minQueryChars(){return this.query.length>=this.minChars}get query(){return this.$input.value.trim()}get minChars(){return this.hasAttribute(ATTR_MIN_CHARS)?this.getAttribute(ATTR_MIN_CHARS):DEFAULT_MIN_CHARS}get searchParams(){return new URLSearchParams({q:this.query,"resources[type]":this.sources,"resources[options][unavailable_products]":this.onlyStock,"resources[limit]":this.limit,section_id:RQ_SECTION}).toString()}get sources(){return this.hasAttribute(ATTR_SOURCES)?this.getAttribute(ATTR_SOURCES).split(",").filter(
1Boolean).join(","):""}get onlyStock(){return this.hasAttribute(ATTR_ONLY_STOCK)?"hide":"last"}get limit(){return this.hasAttribute(ATTR_LIMIT)?this.getAttribute(ATTR_LIMIT):DEFAULT_LIMIT}get withSuggestions(){return this.hasAttribute(ATTR_WITH_SUGGESTIONS)}get withRecent(){return this.hasAttribute(ATTR_WITH_RECENT)}})})(); 2//# sourceMappingURL=/cdn/shop/t/105/assets/predictive-search.js.map?v=158614072739864310291790349718
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.