1/*! Copyright (c) Safe As Milk. All rights reserved. */import Animations from"animations";class DynamicProductSearch extends HTMLElement{#boundLinksHandler;#boundLinksHandlerWithScroll;#boundPopStateHandler;constructor(){super(),this.#boundLinksHandler=this.#linksHandler.bind(this),this.#boundLinksHandlerWithScroll=this.#linksHandlerWithScroll.bind(this),this.#boundPopStateHandler=this.#popStateListener.bind(this)}connectedCallback(){this.abortController=null,this.listeners=[],this.section=this.closest(".section"),this.updateLoading(),this.#setUpListeners(),window.addEventListener("popstate",this.#boundPopStateHandler)}disconnectedCallback(){this.#removeListeners(),window.removeEventListener("popstate",this.#boundPopStateHandler)}renderError(e=window.theme.localize("ERROR_PRODUCTS")){this.previousElementSibling&&this.previousElementSibling.classList.contains("error")&&this.previousElementSibling.remove();const error=document.createElement("div");error.classList.add("error"),error.innerHTML=e,this.section.prepend(error)}renderCollection(params){const{query,updateURL,scrollUp}={query:"",updateURL:!0,scrollUp:!1,...params},currentFocusElementId=document.activeElement&&document.activeElement.getAttribute("id"),sectionClass=`.section--${this.dataset.section}`;this.abortController=new AbortController,this.updateLoading(!0),fetch(`${this.dataset.url}?${query}§ion_id=${this.dataset.section}`,{signal:this.abortController.signal}).then((response=>{if(response.ok)return response.text();throw new Error(window.theme.localize("ERROR_PRODUCTS"))})).then((responseText=>{this.dispatchEvent(new CustomEvent("on:dynamic-product-search:loading"));let sidebarContentOffset=0;const predictiveSearch=this.querySelector("predictive-search");predictiveSearch&&predictiveSearch.close();const openFiltersModal=this.querySelector('.modal--filters:not([aria-hidden="true"])');if(openFiltersModal){const content=openFiltersModal.querySelector(".collection-sidebar__wrapper");content&&(sidebarContentOffset=content.scrollTop)}const html=new DOMParser().parseFromString(responseText,"text/html"),destination=document.querySelector(sectionClass),source=html.querySelector(sectionClass);if(source&&destination){this.#removeListeners();const destinationMainContainer=destination.querySelector(".js-main-content"),sourceMainContainer=source.querySelector(".js-main-content");if(destinationMainContainer.children.length>0&&sourceMainContainer.children.length>0){const destinationResultsTotal=destination.querySelector(".js-results-total"),destinationSortForm=destination.querySelector(".js-sort-form"),destinationActiveFilters=destination.querySelector(".js-active-filters"),destinationFilters=destination.querySelector(".js-filters"),destinationActions=destination.querySelector(".js-actions"),destinationResultsContainer=destination.querySelector(".js-results-container"),destinationResults=destination.querySelector(".js-results"),destinationPagination=destination.querySelector(".js-pagination"),sourceResultsTotal=source.querySelector(".js-results-total"),sourceSortForm=source.querySelector(".js-sort-form"),sourceActiveFilters=source.querySelector(".js-active-filters"),sourceFilters=source.querySelector(".js-filters"),sourceActions=source.querySelector(".js-actions"),sourceResultsContainer=source.querySelector(".js-results-container"),sourceResults=source.querySelector(".js-results"),sourcePagination=source.querySelector(".js-pagination");destinationResultsTotal&&sourceResultsTotal&&(destinationResultsTotal.innerHTML=sourceResultsTotal.innerHTML),destinationResultsContainer&&sourceResultsContainer?(destinationSortForm&&sourceSortForm&&(destinationSortForm.innerHTML=sourceSortForm.innerHTML),destinationActiveFilters&&sourceActiveFilters&&(destinationActiveFilters.innerHTML=sourceActiveFilters.innerHTML),destinationFilters&&sourceFilters&&(destinationFilters.innerHTML=sourceFilters.innerHTML),destinationActions&&sourceActions&&(destinationActions.innerHTML=sourceActions.innerHTML),destinationResults&&sourceResults&&(destinationResults.innerHTML=sourceResults.innerHTML)):destinationResultsContainer?destinationResultsContainer.remove():destinationMainContainer.appendChild(sourceResultsContainer),destinationPagination&&sourcePagination?destinationPagination.innerHTML=sourcePagination.innerHTML:destinationPagination?destinationPagination.remove():sourcePagination&&destination.querySelector(".js-main-content").appendChild(sourcePagination)}else{const destinationSectionTitle=destination.querySelector(".js-section-title"),sourceSectionTitle=source.querySelector(".js-section-title");destinationSectionTitle&&sourceSectionTitle&&(destinationSectionTitle.innerHTML=sourceSectionTitle.innerHTML),destinationMainContainer&&sourceMainContainer&&(destinationMainContainer.innerHTML=sourceMainContainer.innerHTML)}this.#setUpListeners()}if(Animations.setup(document.querySelector(sectionClass)),openFiltersModal){const content=openFiltersModal.querySelector(".collection-sidebar__wrapper");content&&sidebarContentOffset!==0&&(content.scrollTop=sidebarContentOffset)}scrollUp&&this.scrollUp();const newPageTitle=document.querySelector(`${sectionClass} dynamic-product-search`).dataset.pageTitle;updateURL&&this.updateURL(query,newPageTitle),document.title=newPageTitle,this.updateLoading(!1),this.dataset.quickShopDynamicCheckout==="true"&&window.Shopify&&window.Shopify.PaymentButton&&window.Shopify.PaymentButton.init();const currentlyFocusedElement=document.getElementById(currentFocusElementId);currentlyFocusedElement&¤tlyFocusedElement.focus(),this.dispatchEvent(new CustomEvent("on:dynamic-product-search:loaded"))})).catch((async error=>
1{if(error.name&&error.name==="AbortError")return;this.updateLoading(!1),this.renderError(error);const openFiltersModal=this.querySelector('.modal--filters:not([aria-hidden="true"])');openFiltersModal&&await openFiltersModal.close(),this.scrollUp(),this.dispatchEvent(new CustomEvent("on:dynamic-product-search:failed"))}))}scrollUp(){const{top}=this.section.getBoundingClientRect();window.scrollBy({behavior:window.matchMedia("(prefers-reduced-motion: reduce)").matches?"instant":"smooth",top})}updateLoading(isLoading=!1){this.loading=isLoading,isLoading?this.section.classList.add("is-loading"):this.section.classList.remove("is-loading")}updateURL(query,title=""){this.dataset.updateUrl!=="false"&&window.history.pushState({},title,`${this.dataset.url}${query?`?${query}`:""}`)}#popStateListener(){const query=window.location.search.slice(1);this.renderCollection({updateURL:!1,query})}#linksHandler(e,scrollUp=!1){if(e.preventDefault(),!e.target.getAttribute("href")&&!e.target.dataset.url)return;const url=e.target.getAttribute("href")||e.target.dataset.url,query=url.split("?").length>0?url.split("?")[1]:"";this.renderCollection({query,scrollUp})}#linksHandlerWithScroll(e){this.#linksHandler(e,!0)}#filtersControl(){this.querySelectorAll(".js-filter-trigger").forEach((filter=>{filter.addEventListener("click",this.#boundLinksHandler),this.listeners.push({element:filter,event:"click",handler:this.#boundLinksHandler})}))}#paginationControl(){this.querySelectorAll(".pagination a").forEach((paginationLink=>{paginationLink.addEventListener("click",this.#boundLinksHandlerWithScroll),this.listeners.push({element:paginationLink,event:"click",handler:this.#boundLinksHandlerWithScroll})}))}#setUpListeners(){this.forms=[this.querySelector(".js-search-form"),this.querySelector(".js-sort-form"),this.querySelector(".js-filters-form")].filter((f=>f)),this.querySelector(".js-search-form")&&this.querySelector(".js-filters-form")&&this.querySelector('.js-filters-form input[name="q"]').remove(),this.forms.forEach((form=>{form.dataset.submitOnChange==="true"&&form.addEventListener("change",(()=>{form.requestSubmit()})),form.addEventListener("submit",(e=>{e.preventDefault(),this.abortController&&this.abortController.abort();let query="";if(e.target.classList.contains("js-search-form")){const paramsToKeep=["type","q","sort_by"];query=this.forms.reduce(((qs,f)=>{const thisFormData=new FormData(f);for(const[paramName]of thisFormData.entries())paramsToKeep.includes(paramName)||thisFormData.delete(paramName);const thisQueryString=new URLSearchParams(thisFormData).toString();return`${qs}${thisQueryString?`${qs?"&":""}${thisQueryString}`:""}`}),"")}else query=this.forms.reduce(((qs,f)=>{const thisFormData=new FormData(f),thisQueryString=new URLSearchParams(thisFormData).toString();return`${qs}${thisQueryString?`${qs?"&":""}${thisQueryString}`:""}`}),"");this.renderCollection({query})}))})),this.#filtersControl(),this.#paginationControl()}#removeListeners(){this.listeners.forEach((({element,event,handler})=>{element.removeEventListener(event,handler)}))}}customElements.get("dynamic-product-search")||customElements.define("dynamic-product-search",DynamicProductSearch); 2//# sourceMappingURL=/cdn/shop/t/19/assets/dynamic-product-search.js.map?v=113520355118072203791788876964
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.