https://www.seavees.com/cdn/shop/t/976/assets/product-mapped-produ…?v=153203017074372437011790606392
1class ProductMappedProductsSwitcher extends HTMLElement{constructor(){super(),this.inputs=[],this.sectionId=this.getAttribute("data-section-id"),this.productCache=new Map,this.onChange=this.onChange.bind(this)}connectedCallback(){this.inputs=Array.from(this.querySelectorAll('input[name="sibling-product"]')),this.attachEvents(),"requestIdleCallback"in window?requestIdleCallback(()=>this.preloadSiblings()):setTimeout(()=>this.preloadSiblings(),300)}get isInQuickAddModal(){return this.sectionId?.startsWith("quickadd-")?!0:this.closest("quick-add-modal")!==null}get quickAddModal(){return this.closest("quick-add-modal")}disconnectedCallback(){this.detachEvents()}attachEvents(){this.inputs.forEach(input=>input.addEventListener("change",this.onChange))}detachEvents(){this.inputs.forEach(input=>input.removeEventListener("change",this.onChange))}async onChange(event){const target=event.target;let currentSizeOptionValue=null;const productInfo=this.closest("product-info");if(productInfo&&(currentSizeOptionValue=productInfo.querySelector('variant-selects fieldset.option-size input[type="radio"]:checked')?.value||null),this.inputs.forEach(input=>{input.checked=!1}),target.checked=!0,!target?.value)return;const handle=target.value;
1try{const result=await this.getSectionForHandle(handle),newSection=result.desktopSection,mobileSection=result.mobileSection;if(!newSection)return;const newSectionClone=newSection.cloneNode(!0),newMobileSectionClone=mobileSection?.cloneNode(!0)??null,currentSection=document.getElementById(`MainProduct-${this.sectionId}`);if(!currentSection)return;if(!this.isInQuickAddModal){const url=new URL(window.location.href);url.pathname=`/products/${handle}`,url.search="",window.history.replaceState({path:url.toString()},"",url.toString())}this.preserveNonReplacable(currentSection,newSectionClone);try{const newProductModal=newSectionClone.querySelector(`#ProductModal-${this.sectionId}`);if(newProductModal){const existingProductModal=document.getElementById(`ProductModal-${this.sectionId}`);existingProductModal&&existingProductModal.replaceWith(newProductModal)}}catch(modalErr){console.warn("[SiblingProductSwitcher] Failed to replace product modal",modalErr)}currentSection.replaceWith(newSectionClone);try{const currentMobileSection=document.getElementById(`shopify-section-${window.mobileProductInfoSectionId}`);currentMobileSection&&newMobileSectionClone&¤tMobileSection.replaceWith(newMobileSectionClone)}catch(mobileErr){console.warn("[SiblingProductSwitcher] Failed to replace mobile section",mobileErr)}if(typeof enableZoomOnHover=="function")try{enableZoomOnHover(2)}catch(zoomErr){console.warn("[SiblingProductSwitcher] Failed to enable zoom on hover",zoomErr)}const productInfo2=this.closest("product-info");if(!productInfo2)return;const variantSelects=productInfo2.querySelector("variant-selects");if(!variantSelects)return;const previousSizeOptionInput=variantSelects.querySelector('input[value="'+currentSizeOptionValue+'"]');previousSizeOptionInput&&(previousSizeOptionInput.checked=!0,setTimeout(()=>
1{const changeEvent=new Event("change");previousSizeOptionInput.dispatchEvent(changeEvent),variantSelects.dispatchEvent(changeEvent)},100))}catch(e){console.error("[SiblingProductSwitcher] Failed to switch product",e)}}async getSectionForHandle(handle){const mobileSectionCacheKey=handle+"-mobile",parser=new DOMParser;if(this.productCache.has(handle)){const cachedDesktop=this.productCache.get(handle),cachedMobile=this.productCache.get(mobileSectionCacheKey)??null;if(window.mobileProductInfoSectionId&&!cachedMobile){const mobileSection2=await this.fetchMobileSection(handle,parser);return{desktopSection:cachedDesktop,mobileSection:mobileSection2}}return{desktopSection:cachedDesktop,mobileSection:cachedMobile}}const sectionId=this.sectionId.replace("quickadd-",""),htmlText=await(await fetch(`/products/${handle}?section_id=${sectionId}`)).text(),section=parser.parseFromString(htmlText,"text/html").getElementById(`MainProduct-${sectionId}`);this.isInQuickAddModal&§ion&&quickAddService.preprocessHTML(section,this.quickAddModal.modalContent),section&&this.productCache.set(handle,section);const mobileSection=await this.fetchMobileSection(handle,parser);return{desktopSection:section,mobileSection}}async fetchMobileSection(handle,parser){const mobileSectionCacheKey=handle+"-mobile";if(this.productCache.has(mobileSectionCacheKey))return this.productCache.get(mobileSectionCacheKey);if(!window.mobileProductInfoSectionId)return null;try{const mobileSectionId=window.mobileProductInfoSectionId,mobileHtmlText=await(await fetch(`/products/${handle}?section_id=${mobileSectionId}`)).text(),mobileSection=parser.parseFromString(mobileHtmlText,"text/html").getElementById(`shopify-section-${mobileSectionId}`);return mobileSection&&this.productCache.set(mobileSectionCacheKey,mobileSection),mobileSection}catch(err){return console.warn("[SiblingProductSwitcher] Failed to fetch mobile section",err),null}}preloadSiblings(){this.inputs.forEach(input=>{const handle=input.value;this.productCache.has(handle)||(this.getSectionForHandle(handle).catch(()=>{}),this.fetchMobileSection(handle).catch(()=>{}))})}preserveNonReplacable(currentSection,incomingSection){try{const currentList=Array.from(currentSection.querySelectorAll("[data-sibling-product-switcher-non-replacable]"));if(!currentList.length)return;const incomingList=Array.from(incomingSection.querySelectorAll("[data-sibling-product-switcher-non-replacable]")),count=Math.min(currentList.length,incomingList.length);for(let i=0;i<count;i++){const keepNode=currentList[i],replaceTarget=incomingList[i];!keepNode||!replaceTarget||replaceTarget.replaceWith(keepNode)}}catch(err){console.warn("[SiblingProductSwitcher] preserveNonReplacable failed",err)}}}customElements.get("product-mapped-products-switcher")||customElements.define("product-mapped-products-switcher",ProductMappedProductsSwitcher); 2//# sourceMappingURL=/cdn/shop/t/976/assets/product-mapped-products-switcher.js.map?v=153203017074372437011790606392
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.