document.addEventListener("DOMContentLoaded",function(){const modals={};Array.from(document.getElementsByClassName("ac-modal")).forEach(modalElement=>{const modal=modalElement,modalId=modalElement.getAttribute("id");modals[modalId]=modal}),Array.from(document.querySelectorAll(".ac-modal-trigger[data-ajax-url], .ac-modal-trigger[data-modal-target]")).forEach(trigger=>{const targetModalId=trigger.getAttribute("data-modal-target"),modal=modals[targetModalId];modal&&(trigger.addEventListener("click",()=>{onModalTriggerClick(trigger,modal)}),onModalClose(trigger,modal))})});async function onModalTriggerClick(trigger,modal){if(!trigger||!modal||trigger.dataset.ajaxLoaded)return;const ajaxUrl=trigger.getAttribute("data-ajax-url")||"",ajaxIframe=trigger.getAttribute("data-ajax-iframe")==="true",customCompare=trigger.getAttribute("data-custom-compare")==="true",txtUrl=trigger.getAttribute("data-txt-url")||"",txtPlain=trigger.getAttribute("data-txt-plain")||"false",contentUrl=txtUrl||ajaxUrl,isFullPageFallback=!txtUrl&&ajaxUrl;if(console.log("Modal trigger data:",{ajaxUrl,ajaxIframe,txtUrl,contentUrl,txtPlain}),!contentUrl){console.warn("No contentUrl (missing data-ajax-url and data-txt-url) on trigger:",trigger);return}toggleLoadingState(modal,!0);let html;try{const response=await fetch(contentUrl);if(!response.ok)throw new Error("Failed to load content: "+response.status);let txt=await response.text();if(txtPlain==="true")html=txt.replace(/&/g,"&").replace(/");else if(isFullPageFallback){const parser=new DOMParser,mainContent=parser.parseFromString(txt,"text/html").getElementById("MainContent");if(mainContent&&mainContent.innerHTML){const contentDoc=parser.parseFromString(mainContent.innerHTML.trim(),"text/html"),body=contentDoc.body;contentDoc.getElementById("modal-headline")?.remove(),body.querySelectorAll("#modal-headline, .main-page-title, .page-title, h1.visually-hidden").forEach(el=>el.remove());const firstH1=body.querySelector("h1");if(firstH1){const parent=firstH1.parentElement;firstH1.remove(),parent&&parent!==body&&!parent.textContent.trim()&&parent.remove()}const mainPageSection=body.querySelector(".apl-section-main-page, .shopify-section.apl-section-main-page");if(mainPageSection){const rte=mainPageSection.querySelector(".rte");rte&&mainPageSection.replaceWith(rte.cloneNode(!0))}let first=body.firstElementChild;for(;first&&first!==body&&!first.textContent.trim();){const next=first.nextElementSibling;first.remove(),first=next}html=body.innerHTML.trim()}else html=txt}else html=txt}catch(error){console.error("Error in onModalTriggerClick fetch:",error),toggleLoadingState(modal,!1);return}if(!html){toggleLoadingState(modal,!1);return}if(ajaxIframe){let iframe=modal.querySelector("iframe");iframe||(iframe=document.createElement("iframe"),iframe.style.width="100%",iframe.style.height="100%",iframe.style.border="none",modal.appendChild(iframe)),typeof openLinkInNewTab=="function"&&openLinkInNewTab(iframe),iframe.srcdoc=html}else{const template=SDG?.Data?.template||"";modal.innerHTML=html,executeScripts(modal),template?.includes("collection.plp")&&customCompare&&modal&&setTimeout(()=>{const $scripts=modal.querySelectorAll("script")||[];$scripts.length>0&&$scripts.forEach(script=>{if(script.textContent.includes("channelCompare")){let scriptContent=script.textContent.replace(/const reorderDOM/g,"var reorderDOM");const $compareHeader=modal.querySelectorAll("#interactive-compare-header"),newScript=document.createElement("script");newScript.textContent=scriptContent,modal.appendChild(newScript),$compareHeader&&typeof channelCompare<"u"&&channelCompare?.init&&channelCompare.init()}})},500)}trigger.dataset.ajaxLoaded="true",toggleLoadingState(modal,!1)}function executeScripts(element){if(!element)return;const scripts=element.querySelectorAll("script");!scripts||scripts.length===0||scripts.forEach(oldScript=>{const newScript=document.createElement("script");Array.from(oldScript.attributes).forEach(attribute=>{newScript.setAttribute(attribute.name,attribute.value)}),oldScript.textContent&&newScript.appendChild(document.createTextNode(oldScript.textContent)),oldScript.parentNode.replaceChild(newScript,oldScript)})}function openLinkInNewTab(iframe){iframe.onload=function(){for(var iframeDocument=iframe.contentWindow.document,links=iframeDocument.querySelectorAll("a"),i=0;i{window.adobeTrackMarketingPageIframeCtaClick(iframe),window.adobeTrackMarketingPageIframeScroll(iframe)},10)}}function toggleLoadingState($modal,isLoading){const $modalSpinnerParent=$modal.querySelector(".ac-progress-indicator")?.parentNode;isLoading?$modal.classList.add("is-loading"):($modal.classList.remove("is-loading"),$modalSpinnerParent&&$modal.removeChild($modalSpinnerParent))}function onModalClose($trigger,$modal){const observer=new MutationObserver(mutations=>{mutations.forEach(mutation=>{if(window.pauseAllMedia(),mutation.attributeName=="class"&&!mutation.target.classList.contains("modal-open")){const{ajaxUrl}=$trigger.dataset;if(ajaxUrl)setTimeout(()=>{const $modalContent=mutation.target.querySelector(".ac-modal");$modalContent.innerHTML=`
`,$trigger.removeAttribute("data-ajax-loaded")},500);else{const $video=mutation.target.querySelector("video");$video&&($video.pause(),$video.currentTime=0)}}})}),$modalRoot=$modal.closest(".modal");$modalRoot&&observer.observe($modalRoot,{attributes:!0})} //# sourceMappingURL=/cdn/shop/t/14/assets/ac-modal-custom.js.map?v=65753906577603767491742784888