1const hiddenClass="selling_plan_theme_integration--hidden";class SellingPlansWidget{constructor(sellingPlansWidgetContainer){this.sellingPlansWidgetContainer=sellingPlansWidgetContainer,this.updatePurchasingFrequencyLabels(),this.appendSellingPlanInputs(),this.updateSellingPlanInputsValues(),this.listenToVariantChange(),this.initialSellingPlanCheck(),this.listenToRadioButtonChange()}get sectionId(){return this.sellingPlansWidgetContainer.getAttribute("data-section-id")}get shopifySection(){return document.querySelector(`#shopify-section-${this.sectionId}`)}get variantIdInput(){return this.addToCartForms[1]?.querySelector('input[name="id"]')||this.addToCartForms[1]?.querySelector('select[name="id"]')||this.addToCartForms[0].querySelector('input[name="id"]')||this.addToCartForms[0].querySelector('select[name="id"]')}get visibleSellingPlanForm(){return this.shopifySection.querySelector(`section[data-variant-id^="${this.variantIdInput.value}"]`)}get sellingPlanInput(){return this.shopifySection.querySelector(".selected-selling-plan-id")}get addToCartForms(){return this.shopifySection.querySelectorAll('.product-info__buy-buttons [action*="/cart/add"]')}appendSellingPlanInputs(){this.addToCartForms.forEach(addToCartForm=>{addToCartForm.appendChild(this.sellingPlanInput.cloneNode())})}showSellingPlanForm(sellingPlanFormForSelectedVariant){sellingPlanFormForSelectedVariant?.classList?.remove(hiddenClass)}hideSellingPlanForms(sellingPlanFormsForUnselectedVariants){sellingPlanFormsForUnselectedVariants.forEac
1h(element=>{element.classList.add(hiddenClass)})}handleSellingPlanFormVisibility(){const sellingPlanFormForSelectedVariant=this.shopifySection.querySelector(`section[data-variant-id="${this.variantIdInput.value}"]`),sellingPlanFormsForUnselectedVariants=this.shopifySection.querySelectorAll(`.selling_plan_theme_integration:not([data-variant-id="${this.variantIdInput.value}"])`);this.showSellingPlanForm(sellingPlanFormForSelectedVariant),this.hideSellingPlanForms(sellingPlanFormsForUnselectedVariants)}handleVariantChange(){this.handleSellingPlanFormVisibility(),this.initialSellingPlanCheck(),this.listenToRadioButtonChange(),this.updateSellingPlanInputsValues()}listenToVariantChange(){this.listenToAddToCartForms(),this.variantIdInput.tagName==="INPUT"&&new MutationObserver(mutationList=>{mutationList.forEach(mutationRecord=>{this.handleVariantChange(mutationRecord.target.value)})}).observe(this.variantIdInput,{attributes:!0})}listenToAddToCartForms(){this.addToCartForms.forEach(addToCartForm=>{addToCartForm.addEventListener("change",()=>{this.handleVariantChange()})})}updatePurchasingFrequencyLabels(){this.sellingPlansWidgetContainer.querySelectorAll(".product-purchasing-allocations label span").forEach(label=>{const match=label.innerText.match(/\d+/);match&&(label.innerText=match[0])})}get sellingPlanInputs(){return this.shopifySection.querySelectorAll(".selected-selling-plan-id")}updateSellingPlanInputsValues(){this.sellingPlanInputs.forEach(sellingPlanInput=>{sellingPlanInput.value=this.sellingPlanInputValue})}get sellingPlanInputValue(){return this.selectedPurchaseOption?.dataset.sellingPlanId??null}get selectedPurchaseOption(){return this._selectedPurchaseOption}set selectedPurchaseOption(selectedPurchaseOption){this._selectedPurchaseOption=selectedPurchaseOption}handleRadioButtonChange(selectedPurchaseOption){this.selectedPurchaseOption=selectedPurchaseOption,this.updateSellingPlanInputsValues()}initialSellingPlanCheck(){const purchasingOptions=this.visibleSellingPlanForm?.querySelectorAll(".product-purchasing-option");purchasingOptions&&purchasingOptions.forEach(option=>{if(!option.classList.contains("active"))return;const parentInput=option.querySelector("input.purchase-option-parent"),purchasingFrequency=option.querySelector(".product-purchasing-frequency");if(purchasingFrequency){const selectedOption=purchasingFrequency.querySelector('.popover-listbox__option[aria-selected="true"]');this.handleRadioButtonChange(selectedOption)}else parentInput&&this.handleRadioButtonChange(parentInput)})}listenToRadioButtonChange(){const form=this.visibleSellingPlanForm;if(!form||form._listenersBound)return;form._listenersBound=!0;const purchasingOptions=form.querySelectorAll(".product-purchasing-option"),radioButtons=form.querySelectorAll('input[type="radio"]'),popoverWrapper=form.querySelector(".product-purchasing-frequency"),popover=form.querySelector(".popover-listbox");radioButtons.forEach(radio=>{radio.addEventListener("change",event=>{if(radio.classList.contains("purchase-option-parent")){purchasingOptions.forEach(option=>{option.classList.remove("active")});const radioParent=radio.closest(".product-purchasing-option");radioParent.classList.add("active");const purchasingFrequency=radioParent.querySelector(".product-purchasing-frequency");if(event.isTrusted)if(purchasingFrequency){const selectedOption=popover.querySelector('.popover-listbox__option[aria-selected="true"]');this.handleRadioButtonChange(selectedOption)}else this.handleRadioButtonChange(event.target)}})}),popover&&new MutationObserver(mutations=>{for(const mutation of mutations)if(mutation.type==="attributes"&&mutation.attributeName==="aria-selected"){const selectedOption=popover.querySelector('.popover-listbox__option[aria-selected="true"]');if(!selectedOption)return;this.handleRadioButtonChange(selectedOption);const parentInput=popoverWrapper.closest(".product-purchasing-option")?.querySelector("input.purchase-option-parent");return parentInput&&!parentInput.checked&&(parentInput.checked=!0,parentInput.dispatchEvent(new Event("change",{bubbles:!0}))),selectedOption}}).observe(popover,{subtree:!0,attributes:!0,attributeFilter:["aria-selected"]})}}document.querySelectorAll(".selling_plan_app_container").forEach(sellingPlansWidgetContainer=>{window.sellingPlanWidgets=window.sellingPlanWidgets||[],window.sellingPlanWidgets.push(new SellingPlansWidget(sellingPlansWidgetContainer))}); 2//# sourceMappingURL=/cdn/shop/t/304/assets/product-purchasing-options.js.map?v=77189348203257406261790778379
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.