1(function(){let originalFormState=null,originalUrl=null,applyButtonClicked=!1,filteringApplied=!1;document.addEventListener("click",function(event){const filterButton=event.target.closest('button[aria-controls="facets-drawer"]');if(!filterButton)return;const drawerId=filterButton.getAttribute("aria-controls");if(!drawerId)return;const drawer=document.getElementById(drawerId);drawer&&drawer.addEventListener("dialog:show",function onceHandler(){const form=drawer.querySelector("facets-form form");form&&(originalFormState=new FormData(form),originalUrl=window.location.href),drawer.removeEventListener("dialog:show",onceHandler)},{once:!0})}),document.addEventListener("click",function(event){const applyButton=event.target.closest("dialog-close-button");!applyButton||!applyButton.closest("facets-drawer")||applyButton.hasAttribute("data-action")&&applyButton.getAttribute("data-action")==="close"||(applyButtonClicked=!0,originalFormState=null,originalUrl=null)}),document.addEventListener("click",function(event){if(applyButtonClicked){applyButtonClicked=!1;return}const dialogClose=event.target.closest('.drawer__overlay, dialog-close-button[data-action="close"]');if(!dialogClose)return;const drawer=dialogClose.closest(".drawer")||document.querySelector(".drawer[open]");!drawer||!drawer.matches("facets-drawer")||(originalUrl&&(window.location.href=originalUrl,event.preventDefault(),event.stopPropagation()),originalFormState=null,originalUrl=null)}),document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll("facets-drawer").forEach(drawer=>{const newDrawer=drawer.cloneNode(!0);drawer.parentNode&&drawer.parentNode.replaceChild(newDrawer,drawer)})});function preserveCheckedState(oldForm,newForm){oldForm.querySelectorAll('input[type="checkbox"]:checked, input[type="radio"]:checked').forEach(oldInput=>{const name=oldInput.name,value=oldInput.value,newInput=newForm.querySelector(`input[name="${name}"][value="${value}"]`);newInput&&(newInput.checked=!0)}),oldForm.querySelectorAll('input[type="text"], input[type="number"], select').forEach(oldInput=>{const name=oldInput.name,value=oldInput.value;if(value){const newInput=newForm.querySelector(`[name="${name}"]`);newInput&&(newInput.value=value)}})}function hideUnavailableColorSwatches(swatchCounts=null){if(!filteringApplied&&!swatchCounts)return;document.querySelectorAll("facets-form").forEach(form=>{form.querySelectorAll('input[id*="filter."]').forEach(input=>{const colorSwatch=form.querySelector(`label[for="${input.id}"]`);if(!colorSwatch||!colorSwatch.classList.contains("color-swatch"))return;let count=1,shouldShow=!0;if(swatchCounts&&swatchCounts.has(input.id))count=swatchCounts.get(input.id),shouldShow=count>0;else if(filteringApplied)if(input.checked)shouldShow=!0;else{const parentWithCount=colorSwatch.closest("div");if(parentWithCount&&parentWithCount.querySelectorAll("label").forEach(label=>{const labelText=label.textContent.trim();if(labelText.includes("(")&&labelText.includes(")")){const matches=labelText.match(/\((\d+)\)/);matches&&matches[1]&&label.getAttribute("for")===input.id&&(count=parseInt(matches[1],10),shouldShow=count>0)}}),shouldShow&&colorSwatch.dataset.count!==void 0&&(count=parseInt(colorSwatch.dataset.count,10),shouldShow=count>0),shouldShow){const colorParent=colorSwatch.parentNode;if(colorParent){const countMatch=colorParent.textContent.trim().match(/\((\d+)\)/);countMatch&&countMatch[1]&&(count=parseInt(countMatch[1],10),shouldShow=count>0)}}}colorSwatch.dataset.count=count,shouldShow?(colorSwatch.style.display="",input.style.display=""):(colorSwatch.style.display="none",input.style.display="none")})})}function extractColorSwatchCount(colorSwatch,inputId){if(!colorSwatch)return 0;const input=document.getElementById(inputId);if(input&&input.checked)return 1;let count=1;const parentWithCount=colorSwatch.closest("div");if(parentWithCount){const allLabels=parentWithCount.querySelectorAll("label");for(const label of allLabels){const labelText=label.textContent.trim();if(labelText.includes("(")&&labelText.includes(")")){const matches=labelText.match(/\((\d+)\)/);if(matches&&matches[1]&&label.getAttribute("for")===inputId){count=parseInt(matches[1],10);break}}}}if(count===1&&colorSwatch.dataset.count!==void 0&&(count=parseInt(colorSwatch.dataset.count,10)),count===1){const colorParent=colorSwatch.parentNode;if(colorParent){const countMatch=colorParent.textContent.trim().match(/\((\d+)\)/);countMatch&&countMatch[1]&&(count=parseInt(countMatch[1],10))}}return count}function applyFilters(form){const formClone=form.cloneNode(!0);document.body.appendChild(formClone),formClone.style.display="none";const formData=new FormData(form);formClone.addEventListener("submit",function(e){const facetsDrawer=form.closest("facets-drawer");if(facetsDrawer){e.preventDefault();const url=new URL(formClone.action);url.search=new URLSearchParams(formData).toString(),fetch(url.toString(),{headers:{Accept:"text/html","X-Requested-With":"XMLHttpRequest"}}).then(response=>response.text()).then(html=>{filteringApplied=!0;const doc=new DOMParser().parseFromString(html,"text/html"),newContent=doc.querySelector(".collection__main");if(newContent){const currentContent=document.querySelector(".collection__main");currentContent&&(currentContent.innerHTML=newContent.innerHTML)}const newProductCount=doc.querySelector(".collection-toolbar__products-count"),currentProductCount=document.querySelector(".collection-toolbar__products-count");newProductCount&¤tProductCount&&(currentProductCount.innerHTML=newProductCount.innerHTML);const newDrawerFacets=doc.querySelector("facets-drawer facets-form"),newSidebarFacets=doc.querySelector(".facets-sidebar facets-form");if(facetsDrawer&&newDrawerFacets){const currentFacetsForm=facetsDrawer.querySelector("facets-form"),expandedDetails=[];
1currentFacetsForm.querySelectorAll("details").forEach(details=>{details.hasAttribute("open")&&expandedDetails.push(details.querySelector("summary").textContent.trim())});const checkedInputs=new Map;currentFacetsForm.querySelectorAll('input[type="checkbox"]:checked, input[type="radio"]:checked').forEach(input=>{checkedInputs.set(`${input.name}-${input.value}`,!0)});const swatchCounts=new Map;newDrawerFacets.querySelectorAll('input[id*="filter."]').forEach(input=>{const colorSwatch=newDrawerFacets.querySelector(`label[for="${input.id}"]`);if(colorSwatch&&colorSwatch.classList.contains("color-swatch")){const count=extractColorSwatchCount(colorSwatch,input.id);swatchCounts.set(input.id,count)}});const oldFilterGroups=currentFacetsForm.querySelectorAll("details"),newFilterGroups=newDrawerFacets.querySelectorAll("details");oldFilterGroups.forEach((oldGroup,index)=>{if(index<newFilterGroups.length){const newGroup=newFilterGroups[index],oldSummary=oldGroup.querySelector("summary"),groupName=oldSummary?oldSummary.textContent.trim():"";if(!(oldGroup.querySelectorAll(".color-swatch").length>0))oldGroup.innerHTML=newGroup.innerHTML,expandedDetails.includes(groupName)&&oldGroup.setAttribute("open","");else{const oldContent=oldGroup.querySelector(".v-stack"),newContent2=newGroup.querySelector(".v-stack");oldContent&&newContent2&&(oldContent.innerHTML=newContent2.innerHTML,expandedDetails.includes(groupName)&&oldGroup.setAttribute("open",""))}}}),checkedInputs.forEach((isChecked,key)=>{const[name,value]=key.split("-"),input=currentFacetsForm.querySelector(`input[name="${name}"][value="${value}"]`);input&&(input.checked=!0)}),hideUnavailableColorSwatches(swatchCounts)}const currentSidebarFacets=document.querySelector(".facets-sidebar facets-form");if(currentSidebarFacets&&newSidebarFacets){const checkedInputs=new Map;currentSidebarFacets.querySelectorAll('input[type="checkbox"]:checked, input[type="radio"]:checked').forEach(input=>{checkedInputs.set(`${input.name}-${input.value}`,!0)});const sidebarSwatchCounts=new Map;newSidebarFacets.querySelectorAll('input[id*="filter."]').forEach(input=>{const colorSwatch=newSidebarFacets.querySelector(`label[for="${input.id}"]`);if(colorSwatch&&colorSwatch.classList.contains("color-swatch")){const count=extractColorSwatchCount(colorSwatch,input.id);sidebarSwatchCounts.set(input.id,count)}
1}),currentSidebarFacets.innerHTML=newSidebarFacets.innerHTML,checkedInputs.forEach((isChecked,key)=>{const[name,value]=key.split("-"),input=currentSidebarFacets.querySelector(`input[name="${name}"][value="${value}"]`);input&&(input.checked=!0)}),hideUnavailableColorSwatches(sidebarSwatchCounts)}const newUrl=url.toString();window.history.replaceState({path:newUrl},"",newUrl),attachColorSwatchListeners()}).catch(error=>{console.error("Error applying filters:",error)})}else return!0}),HTMLFormElement.prototype.requestSubmit?formClone.requestSubmit():formClone.dispatchEvent(new Event("submit",{bubbles:!0,cancelable:!0})),setTimeout(()=>{document.body.removeChild(formClone)},100)}function attachColorSwatchListeners(){document.querySelectorAll(".color-swatch").forEach(swatch=>{swatch.hasAttribute("data-processed")||(swatch.setAttribute("data-processed","true"),swatch.addEventListener("click",function(event){event.preventDefault();const inputId=swatch.getAttribute("for");if(!inputId)return;const input=document.getElementById(inputId);!input||!input.closest("facets-form form")||(input.type==="checkbox"?input.checked=!input.checked:input.type==="radio"&&(input.checked=!0),input.dispatchEvent(new Event("change",{bubbles:!0})))}))})}document.addEventListener("change",function(event){const input=event.target;if(!input.matches('input[type="checkbox"], input[type="radio"], input[type="text"], input[type="number"], select'))return;const form=input.closest("facets-form form");form&&applyFilters(form)}),document.addEventListener("DOMContentLoaded",function(){attachColorSwatchListeners()})})(); 2//# sourceMappingURL=/cdn/shop/t/38/assets/custom-filters.js.map?v=66178609771061018661778656590
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.