1class FiltersForm extends HTMLElement{constructor(){super(),this.DEBOUNCE_DELAY=500,FiltersForm.isBlog=this.hasAttribute("data-is-blog"),this.onActiveFilterClick=this.onActiveFilterClick.bind(this),this.form=this.querySelector("[data-filters-form]"),this.apply=this.querySelector("[data-filter-apply]"),this.debouncedOnSubmit=debounce(event=>this.onSubmitHandler(event),this.DEBOUNCE_DELAY),this.form.addEventListener("input",this.debouncedOnSubmit.bind(this)),this.isBlog=this.dataset.isBlog==="true",this.addDrawerAccordionSelectListener()}static setListeners(){const onHistoryChange=event=>{const searchParams=event.state?event.state.searchParams:FiltersForm.searchParamsInitial;searchParams!==FiltersForm.searchParamsPrev&&FiltersForm.renderPage(searchParams,null,!1)};window.addEventListener("popstate",onHistoryChange)}static toggleActiveFacets(disable=!0){document.querySelectorAll("[data-filters-refinements]").forEach(element=>{element.classList.toggle("disabled",disable)})}static renderPage(searchParams,event,updateURLHash=!0){FiltersForm.searchParamsPrev=searchParams,FiltersForm.getSections().forEach(section=>{let url=`${window.location.pathname}?section_id=${section.section}&${searchParams}`;FiltersForm.isBlog&&(url=`${`${document.querySelector("[data-filters]").dataset.url}${searchParams?"/tagged/"+searchParams:""}`}?section_id=${section.section}`);const filterDataUrl=element=>element.url===url;FiltersForm.filterData.some(filterDataUrl)?FiltersForm.renderSectionFromCache(filterDataUrl,event):FiltersForm.renderSectionFromFetch(url,event)}),updateURLHash&&FiltersForm.updateURLHash(searchParams)}static renderSectionFromFetch(url,event){fetch(url).then(response=>response.text()).then(responseText=>{const html=new DOMParser().parseFromString(responseText,"text/html");FiltersForm.filterData=[...FiltersForm.filterData,{html,url}],FiltersForm.renderFunctions(html,event)})}static renderSectionFromCache(filterDataUrl,event){const html=FiltersForm.filterData.find(filterDataUrl).html;FiltersForm.renderFunctions(html,event)}static renderFunctions(html){FiltersForm.renderFilters(html),FiltersForm.renderResultsContainer(html),FiltersForm.renderResultsCount(html),FiltersForm.renderDesktopFooterActiveFacetsBar(html),FiltersForm.renderPagination(html),FiltersForm.renderActiveFilterCount(html),FiltersForm.renderDrawerAccordionSortActiveLabel(html)}static renderResultsContainer(html){const gridContainer=html.querySelector("[data-results-grid]"),newGridContainer=document.querySelector("[data-results-grid]");newGridContainer.innerHTML=gridContainer.innerHTML}static renderActiveFilterCount(html){const count=html.querySelectorAll("[data-filter-active-count]");document.querySelectorAll("[data-filter-active-count]").forEach((element,index)=>{element.innerHTML=count[index].innerHTML})}static renderResultsCount(html){const count=html.querySelectorAll("[data-results-count]");document.querySelectorAll("[data-results-count]").forEach((element,index)=>{element.innerHTML=count[index].innerHTML})}static renderFilters(html){const filterOptionsDesktop=html.querySelectorAll("[data-filters-desktop] [data-filter]"),filterOptionsMobile=html.querySelectorAll("[data-filters-drawer] [data-filter]");FiltersForm.renderDeviceFilters(filterOptionsDesktop),FiltersForm.renderDeviceFilters(filterOptionsMobile,"drawer"),FiltersForm.renderActiveFacets(html)}static renderDeviceFilters(filters,type="desktop"){Array.from(filters).forEach(element=>{const index=element.dataset.index,options=element.querySelector("[data-filter-options]"),newOptions=document.querySelector(`[data-filters-${type}] [data-filter][data-index="${index}"]`).querySelector("[data-filter-options]");options&&newOptions&&(newOptions.innerHTML=options.innerHTML)})}static renderActiveFacets(html){["[data-filters-refinements]"].forEach(selector=>{const activeFacetsElement=html.querySelector(selector),newActiveFacetsElement=document.querySelector(selector);!activeFacetsElement||!newActiveFacetsElement||(newActiveFacetsElement.innerHTML=activeFacetsElement.innerHTML)}),FiltersForm.toggleActiveFacets(!1)}static renderDrawerAccordionSortActiveLabel(html){const sortSelectLabel=html.querySelector("[data-filters-accordion-sort-label]"),newSortSelectLabel=document.querySelector("[data-filters-accordion-sort-label]");sortSelectLabel&&newSortSelectLabel&&(newSortSelectLabel.innerHTML=sortSelectLabel.innerHTML)}static renderDesktopFooterActiveFacetsBar(html){const footer=html.querySelector("[data-filter-footer]"),newFooter=document.querySelector("[data-filter-footer]");footer&&newFooter&&(newFooter.innerHTML=footer.innerHTML)}static renderPagination(html){const pagination=html.querySelector("[data-pagination]"),newPagination=document.querySelector("[data-pagination]"),resultsSection=document.querySelector("[data-results-section]");newPagination&&pagination&&newPagination.replaceWith(pagination),newPagination&&!pagination&&(newPagination.innerHTML=""),!newPagination&&pagination&&resultsSection.insertAdjacentElement("afterend",pagination)}static updateURLHash(searchParams){if(FiltersForm.isBlog){const path=`${document.querySelector("[data-filters]").dataset.url}${searchParams?"/tagged/"+searchParams:""}`;history.pushState({searchParams},"",`${path}`)}else history.pushState({searchParams},"",`${window.location.pathname}${searchParams&&"?".concat(searchParams)}`)}static getSections(){return[{section:document.querySelector("[data-results-grid]").dataset.section}]}addSyncInputListener(event,form){const target=event.target;if(target.type==="checkbox"){const name=target.name,value=target.value;form.querySelectorAll(`input[name="${name}"][value="${value}"]`).forEach(input=>{input!==target&&(input.checked=target.checked)})}}addDrawerAccordionSelectListener(){const select=this.querySelector("[data-filters-accordion-sort]");if(!select)return;const options=select.querySelectorAll("[data-filters-accordion-sort-option]"),activeLabel=select.querySelector("[data-filters-accordion-sort-label]");options.forEach(option=>{option.addEventListener("click",()=>{activeLabel.innerHTML=option.innerHTML,publish(PUB_SUB_EVENTS.selectOption,option.dataset.value)})})}createSearchParams(form){const formData=new FormData(form),formProps=Object.fromEntries(formData);return FiltersForm.isBlog?Object.values(formProps).toString():new URLSearchParams(formData).toString()}onSubmitForm(searchParams,event){FiltersForm.renderPage(searchParams,event)}onSubmitHandler(event){event.preventDefault();const form=document.querySelector("[data-filters-form]");this.addSyncInputListener(event,form),this.onSubmitForm(this.createSearchParams(form),event)}onActiveFilterClick(event){event.preventDefault(),FiltersForm.toggleActiveFacets();const href=event.target.href;let url=FiltersForm.isBlog?href:href.indexOf("?")===-1?"":href.slice(href.indexOf("?")+1);FiltersForm.isBlog&&(url=href.indexOf("/tagged/")===-1?"":href.slice(href.indexOf("/tagged/")+8)),FiltersForm.renderPage(url)}}FiltersForm.filterData=[],FiltersForm.searchParamsInitial=window.location.search.slice(1),FiltersForm.searchParamsPrev=window.location.search.slice(1),FiltersForm.setListeners(),customElements.define("filters-form",FiltersForm);class FilterRemove extends HTMLElement{constructor(){super(),this.addListeners()}addListeners(){this.addEventListener("click",event=>this.closeFilter(event)),this.addEventListener("keyup",event=>{event.code==="Enter"&&this.closeFilter(event)})}closeFilter(event){event.preventDefault(),this.closest("[data-filters]").onActiveFilterClick(event)}}customElements.define("filter-remove",FilterRemove); 2//# sourceMappingURL=/cdn/shop/t/67/assets/filters.js.map?v=120321549708425633801779963644
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.