1customElements.get("sub-widget")||customElements.define("sub-widget",class extends HTMLElement{constructor(){super()}connectedCallback(){this.init()}init(){this.handlePlanClick=this.handlePlanClick.bind(this),this.sellingPlanInput=this.querySelector("input[type='hidden']"),this.allPlans=this.querySelectorAll(".wt-subscription-widget__plans"),this.addEventListeners(),this.setInitialPlan()}setInitialPlan(){const initialPlanSelected=this.querySelector(".wt-subscription-widget__plans--selected");initialPlanSelected&&this.handlePlanClick(initialPlanSelected)}reinit(){this.sellingPlanInput=this.querySelector("input[type='hidden']"),this.allPlans=this.querySelectorAll(".wt-subscription-widget__plans"),this.allPlans.forEach(plan=>{plan.addEventListener("click",()=>this.handlePlanClick(plan))}),this.addSelectListeners(),this.setInitialPlan()}addEventListeners(){this.allPlans.forEach(plan=>{plan.addEventListener("click",()=>this.handlePlanClick(plan))}),this.addSelectListeners(),this.unsubscribeVariantChange=subscribe(PUB_SUB_EVENTS.variantChange,e=>{const wrapper=this.closest("[data-section-id]"),sectionId=wrapper?.dataset?.sectionId,originalSectionId=wrapper?.dataset?.originalSectionId;if(sectionId&&e.data.sectionId!==sectionId&&e.data.sectionId!==originalSectionId)return;const parsedHTML=e.data.html.querySelector(".wt-subscription-widget__container");if(!parsedHTML)return;const currentContainer=this.querySelector(".wt-subscription-widget__container");if(currentContainer&&(currentContainer.innerHTML=parsedHTML.innerHTML,this.reinit(),originalSectionId)){const hiddenInput=this.querySelector('input[name="selling_plan"]');hiddenInput&&hiddenInput.setAttribute("form",`product-form-${sectionId}`)}})}addSelectListeners(){this.querySelectorAll(".wt-subscription-widget__plan-content__select").forEach(select=>{select.addEventListener("change",e=>{e.stopPropagation(),this.handleSelectChange(select)})})}handleSelectChange(select){const plan=select.closest(".wt-subscription-widget__plans");if(!plan||!plan.classList.contains("wt-subscription-widget__plans--selected"))return;const selectedOption=select.options[select.selectedIndex];if(!selectedOption)return;this.sellingPlanInput.value=selectedOption.value;const compareAtPrice=selectedOption.dataset.compareAtPrice,price=selectedOption.dataset.price;this.updatePrice(plan,compareAtPrice,price),this.updateURLParamsIfEnabled(selectedOption.value);const priceData={price:selectedOption.dataset.priceFormatted,compareAtPrice:selectedOption.dataset.compareAtPriceFormatted,priceRaw:Number(selectedOption.dataset.priceRaw),compareAtPriceRaw:Number(selectedOption.dataset.compareAtPriceRaw)};this.updatePriceBlock(priceData),this.updateStickyPriceBlock(priceData)}handlePlanClick(plan){this.allPlans.forEach(item=>{item.classList.remove("wt-subscription-widget__plans--selected")}),plan.classList.add("wt-subscription-widget__plans--selected");const selectedPlanValue=plan.querySelector("select")?.value;if(selectedPlanValue){this.sellingPlanInput.value=selectedPlanValue;const selectedOption=[...plan.querySelector("select").options].find(option=>option.value===selectedPlanValue);if(selectedOption){const compareAtPrice=selectedOption.dataset.compareAtPrice,price=selectedOption.dataset.price;this.updatePrice(plan,compareAtPrice,price);const priceData={price:selectedOption.dataset.priceFormatted,compareAtPrice:selectedOption.dataset.compareAtPriceFormatted,priceRaw:Number(selectedOption.dataset.priceRaw),compareAtPriceRaw:Number(selectedOption.dataset.compareAtPriceRaw)};this.updatePriceBlock(priceData),this.updateStickyPriceBlock(priceData)}}else{this.sellingPlanInput.value="";const priceData={price:plan.dataset.priceFormatted,compareAtPrice:plan.dataset.compareAtPriceFormatted,priceRaw:Number(plan.dataset.priceRaw),compareAtPriceRaw:Number(plan.dataset.compareAtPriceRaw)};this.updatePriceBlock(priceData),this.updateStickyPriceBlock(priceData)}this.updateURLParamsIfEnabled(selectedPlanValue)}updatePrice(plan,compareAtPrice,price){const priceElement=plan.querySelector(".wt-subscription-widget__plan-header__price-regular"),compareAtPriceElement=plan.querySelector(".wt-subscription-widget__plan-header__price-sale");compareAtPrice&&compareAtPriceElement&&(compareAtPriceElement.innerHTML=compareAtPrice),priceElement&&(compareAtPrice?priceElement.classList.add("wt-subscription-widget__plan-header__price-regular--sale"):priceElement.classList.remove("wt-subscription-widget__plan-header__price-regular--sale"),price&&(priceElement.innerHTML=price))}updatePriceBlock({price,compareAtPrice,priceRaw,compareAtPriceRaw}){const sectionId=this.closest("[data-section-id]")?.dataset?.sectionId;if(!sectionId)return;const priceBlock=document.getElementById(`price-${sectionId}`);if(!priceBlock)return;const priceContainer=priceBlock.querySelector(".price");if(!priceContainer)return;const isOnSale=compareAtPriceRaw>priceRaw;priceContainer.classList.toggle("price--on-sale",isOnSale);const regularPriceEl=priceContainer.querySelector(".price__regular .wt-product__price__final");regularPriceEl&&(regularPriceEl.innerHTML=price);const salePriceEl=priceContainer.querySelector(".price__sale .wt-product__price__final");salePriceEl&&(salePriceEl.innerHTML=price);const saleDiv=priceContainer.querySelector(".price__sale");saleDiv&&(saleDiv.classList.toggle("visible",isOnSale),saleDiv.classList.remove("visible-main-product"));const compareEl=priceContainer.querySelector(".wt-product__price__compare");compareEl&&(compareEl.innerHTML=isOnSale?compareAtPrice:"",compareEl.classList.toggle("hidden",!isOnSale));let percentEl=priceContainer.querySelector(".price-item--percent");if(isOnSale){const percent=Math.round((compareAtPriceRaw-priceRaw)/compareAtPriceRaw*100);if(percentEl)percentEl.textContent=`-${percent}%`;else{const wrapper=priceContainer.querySelector(".price__sale__details-wrapper");wrapper&&(percentEl=document.createElement("span"),percentEl.className="price-item--percent",percentEl.textContent=`-${percent}%`,wrapper.appendChild(percentEl))}}else percentEl&&percentEl.remove()}updateStickyPriceBlock({price,compareAtPrice,priceRaw,compareAtPriceRaw}){const sectionId=this.closest("[data-section-id]")?.dataset?.sectionId;if(!sectionId)return;const stickyPriceBlock=document.getElementById(`sticky-price-${sectionId}`);if(!stickyPriceBlock)return;const priceContainer=stickyPriceBlock.querySelector(".price");if(!priceContainer)return;const isOnSale=compareAtPriceRaw>priceRaw;priceContainer.classList.toggle("price--on-sale",isOnSale);const regularPriceEl=priceContainer.querySelector(".price__regular .wt-product__price__final");regularPriceEl&&(regularPriceEl.innerHTML=price);const salePriceEl=priceContainer.querySelector(".price__sale .wt-product__price__final");salePriceEl&&(salePriceEl.innerHTML=price);const saleDiv=priceContainer.querySelector(".price__sale");saleDiv&&(saleDiv.classList.toggle("visible",isOnSale),saleDiv.classList.remove("visible-main-product"));const compareEl=priceContainer.querySelector(".wt-product__price__compare");compareEl&&(compareEl.innerHTML=isOnSale?compareAtPrice:"",compareEl.classList.toggle("hidden",!isOnSale));let percentEl=priceContainer.querySelector(".price-item--percent");if(isOnSale){const percent=Math.round((compareAtPriceRaw-priceRaw)/compareAtPriceRaw*100);if(percentEl)percentEl.textContent=`-${percent}%`;else{const wrapper=priceContainer.querySelector(".price__sale__details-wrapper");wrapper&&(percentEl=document.createElement("span"),percentEl.className="price-item--percent",percentEl.textContent=`-${percent}%`,wrapper.appendChild(percentEl))}}else percentEl&&percentEl.remove()}updateURLParamsIfEnabled(planId){if(this.closest("[data-update-url-on-plan-change]")?.dataset.updateUrlOnPlanChange==="false")return;
1const urlParams=new URLSearchParams(window.location.search);planId?urlParams.set("selling_plan",planId):urlParams.delete("selling_plan"),window.history.pushState({},"",`${window.location.pathname}?${urlParams.toString()}`)}disconnectedCallback(){typeof this.unsubscribeVariantChange=="function"&&this.unsubscribeVariantChange()}}); 2//# sourceMappingURL=/cdn/shop/t/9/assets/subscription-widget.js.map?v=146319152729814171061781628344
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.