PageSourceSearch

https://www.zeaaustralia.us/cdn/shop/t/161/assets/loop-widget.js?v=10627014465394858361791432627

js zeaaustralia.us collected 2026-10-10 02:25:45 UTC 58,928 bytes, 10 lines download raw bytes

1"use strict";const APP_ID="5284869",CREATE_BUNDLE_TRANSACTION_API="https://api-service.loopwork.co/bundleTransaction",FILTER_BUNDLE_SP_API="https://apiv2.loopwork.co/bundleStorefront/filterBundleSellingPlanIds",GET_PRODUCT_BUNDLE_DATA_API="https://apiv2.loopwork.co/bundleStorefront/getChildVariants?id=",PRODUCT_QUANTITY_SELECTOR=".quantity__input",GET_PREPAID_SELLING_PLAN_DATA_URL="https://api.loopwork.co/api/merchant/sellingPlanGroups/sellingPlansWithDetails?shopifyIds=",productDataClass="loopProductQuickJson",loopSubscriptionContainerId="loop-subscription-container",oneTimePurchaseOptionClass="loop-one-time-purchase-option",subscriptionGroupClass="loop-subscription-group",purchaseOptionName="loop_purchase_option",sellingPlanSelectorClass="loop-selling-plan-selector",useCompareAtPrice=!0;async function initLoopWidget(productId2){try{console.log("Daf"),log(`start application: ${productId2}`);const productData=getLoopProductData(productId2);setupLoopDomListeners(productId2),initializeWindowLoopProps();const loopSellingPlanGroups=getLoopSellingPlanGroups(productData?.selling_plan_groups);console.log(loopSellingPlanGroups),productData.selling_plan_groups=loopSellingPlanGroups;const loopProductVariants=getLoopProductVariants(productData.variants,loopSellingPlanGroups);console.log(loopProductVariants),productData.variants=loopProductVariants,window.loopProps[productId2]={product:productData},await setLoopUIProperties(Shopify.shop),await getLoopBundleSpgs(productId2),showSellingPlanFieldsetLoop(productId2),showLoopPurchaseOptionsLabel(productId2),initializeLoopUI(productData),await processLoopBundleProduct(productId2),listenLoopCustomEvent(),hideDifferentVariantSellingPlansLoop(productData),displayLoopWidget(productId2),observeFormChangesLoop(productData)}catch(error){logError(error)}}function setupLoopDomListeners(productId2){log(`setup dom listeners for ${productId2}`);const parentContainer=getLoopSubscriptionContainer(productId2),oneTimeOptions=parentContainer.querySelectorAll(`.${oneTimePurchaseOptionClass}`),sellingPlanGroupOptions=parentContainer.querySelectorAll(`.${subscriptionGroupClass}`),purchaseOptions=parentContainer.querySelectorAll(`input[name=${purchaseOptionName}]`),deliveryOptions=parentContainer.querySelectorAll(`.${sellingPlanSelectorClass}`);for(const option of oneTimeOptions)option.addEventListener("click",clickOnSellingPlanGroupContainerLoop);for(const option of sellingPlanGroupOptions)option.addEventListener("click",clickOnSellingPlanGroupContainerLoop);for(const option of purchaseOptions)option.addEventListener("click",changeInSellingPlanGroupLoop);for(const option of deliveryOptions)option.addEventListener("change",changeInDeliveryOptionLoop);log(`setup dom listeners complete for ${productId2}`)}function initializeWindowLoopProps(){window.loopProps||(window.loopProps={})}function getLoopSellingPlanGroups(sellingPlanGroups){return Array.isArray(sellingPlanGroups)?sellingPlanGroups.filter(s=>s.app_id===APP_ID):[]}function getLoopProductVariants(variants,loopSellingPlanGroups){const loopSpgSet=new Set(loopSellingPlanGroups.map(s=>s.id));return variants.map(v=>({...v,selling_plan_allocations:v.selling_plan_allocations.filter(s=>loopSpgSet.has(s.selling_plan_group_id))}))}async function setLoopUIProperties(shopifyDomain){const loopUIProps=await fetchLoopUIProperties(shopifyDomain);window.loopPropsUI={...loopUIProps}}async function fetchLoopUIProperties(shopifyDomain){log(`fetch loop subscription UI props: ${shopifyDomain}`);const endpoint=`https://d217z8zw4dqir.cloudfront.net/${shopifyDomain}.json`;return await(await fetch(endpoint)).json()??{}}function showSellingPlanFieldsetLoop(productId2){const loopSubscriptionWidget=getLoopSubscriptionContainer(productId2).querySelector("#loop-selling-plan-fieldset");loopSubscriptionWidget&&loopSubscriptionWidget.classList.remove("loop-display-none","loop-display-none-by-variant")}function showLoopPurchaseOptionsLabel(productId2){const elements=getLoopSubscriptionContainer(productId2).querySelectorAll(".loop-purchase-options-label");if(elements)for(const e of elements)e.classList.remove("loop-display-none","loop-display-none-by-variant")}function initializeLoopUI(productData){let variantId=getVariantIdFromURLLoop(productData.variants);variantId||(variantId=getFirstAvailableVariantVariantIdLoop(productData.id)),loopInit({productId:productData.id,product:productData,variantId})}function getVariantIdFromURLLoop(variants){const currentPageUrl=document.URL,variantIdFromUrl=new URL(currentPageUrl).searchParams.get("variant")||"";return new Set(variants?.map(v=>v.id)).has(Number(variantIdFromUrl))?variantIdFromUrl:null}function getFirstAvailableVariantVariantIdLoop(productId2){return getLoopProductData(productId2)?.variants.find(v2=>v2.available)?.id}function displayLoopWidget(productId2){const loopWidget=getLoopSubscriptionContainer(productId2);loopWidget&&loopWidget.classList.remove("loop-display-none")}function observeFormChangesLoop(productData){document.querySelectorAll("form").forEach(form=>{const variantElement=form.querySelector('[name="id"]'),loopVariantElement=form.querySelector('[name="loop_variant_id"]');loopVariantElement&&variantElement?.value&&(loopVariantElement.value=variantElement.value);const variantIdSet=new Set(productData?.variants?.map(v=>v.id));if(variantElement?.value&&variantIdSet.has(Number(variantElement?.value))){const config={attributes:!0,childList:!0,subtree:!0},callback=(mutationsList,observer2)=>{const variantId=variantElement?.value??"",loopVariantElementId=loopVariantElement?.value??"";variantId&&loopVariantElement&&variantId!==loopVariantElementId&&(loopVariantElement.value=variantId,loopVariantChanged({loopProduct:productData,variantId}))};new MutationObserver(callback).observe(form,config)}})}const loopPriceSelectors=[".price:not(.price--on-sale) .price__regular .price-item--regular",".price.price--on-sale .price__sale .price-item--sale",".product-single__prices .product__price:not(.product__price--compare)",".product-pricing .product--price .price--main .money","[data-zp-product-discount-price]",".product-single__header .product__price",".modal_price .current_price",".product-area__col--price .current-price.theme-money",'[data-product-type="price"][data-pf-type="ProductPrice"]',".product__price .fs-heading-4-base[data-price]","#product-price .money[data-product-price]","#ProductPrice",".product-single__price",".price:not(.price--on-sale) span.price-item--regular",".product-price .price .money:not(.original)",".price-box #price .price",".product__price span[data-product-price]",".product-form--price-wrapper .product-form--price",".product-page--pricing--variant-price #price-field",".price-reviews .product-price"],arrToInstanceCountObjLoop=arr=>arr.reduce((obj,e)=>(obj[e]=(obj[e]||0)+1,obj),{});function findSelectedVariantLoop(productId2,variantId){const product=getProductFromLoopProps(productId2)||getLoopProductData(productId2),selectedVariantId=determineSelectedVariantIdLoop(variantId,productId2,product);return findVariantByIdLoop(product,selectedVariantId)}function getProductFromLoopProps(productId2){return window.loopProps?.[productId2]?.product}function determineSelectedVariantIdLoop(variantId,productId2,product){return variantId||(window.loopProps?.[productId2]?.selectedVariantId?window.loopProps[productId2].selectedVariantId:product.variants?.[0]?.id)}function findVariantByIdLoop(product,variantId){return product.variants?.find(variant=>Number(variant.id)===Number(variantId))}function defaultSelectFirstSellingPlanLoop(variant,productId2){const loopPurchaseOptions=getLoopSubscriptionContainer(productId2).querySelectorAll("input[name=loop_purchase_option]")||[];let isFirstOption=!0;const{selling_plan_allocations}=variant,spgIds=selling_plan_allocations?.map(spg=>spg.selling_plan_group_id)||[];loopPurchaseOptions.forEach(element=>{Number(element.dataset.variantId)===Number(variant.id)&&(window.loopProps[productId2].previousSPGId&&spgIds.includes(window.loopProps[productId2].previousSPGId)?element.dataset.id==window.loopProps[productId2].previousSPGId:isFirstOption)&&(isFirstOption=!1,element.checked=!0,setTimeout(()=>{if(loopIsTouchDevice()){const{dataset}=element;changeInSellingPlanGroupLoopMobile(dataset.id,dataset.name,dataset.productId)}element.click()},300))})}function hideLoopPurchaseOptionsLabel(productId2){const elements=getLoopSubscriptionContainer(productId2).querySelectorAll(".loop-purchase-options-label");if(elements)for(const e of elements)e.classList.add("loop-display-none","loop-display-none-by-variant")}function addLoopPurchaseOptionLabelText(productId2){let elements=getLoopSubscriptionContainer(productId2).querySelectorAll(".loop-purchase-options-label");
1elements&&elements.forEach(element=>{element&&(element.innerHTML=`${window.loopPropsUI.loopPurchaseOptionslabel||"Purchase Options"}`)})}function addLoopOneTimePurchaseOptionLabelText(productId2){let elements=getLoopSubscriptionContainer(productId2).querySelectorAll(".loop-one-time-purchase-option-label");elements&&elements.forEach(element=>{element&&(element.innerHTML=`${window.loopPropsUI.loopOneTimePurchaselabel||"One time Purchase"}`)})}function showOneTimePurchaseOptionAtBottomLoop(productId2){const loopContainer=getLoopSubscriptionContainer(productId2),elementAtTop=loopContainer.querySelector("#loop-one-time-purchase-option-at-top"),elementAtBottom=loopContainer.querySelector("#loop-one-time-purchase-option-at-bottom");elementAtTop&&elementAtBottom&&elementAtTop.innerHTML&&(elementAtBottom.innerHTML=elementAtTop.innerHTML,elementAtTop.innerHTML=""),loopContainer.querySelectorAll(".loop-subscription-group").forEach(element=>{element.classList.remove("loop-subscription-group-border-top"),element.classList.add("loop-subscription-group-border-bottom")})}function hideEachLabelForPriceLoop(){[".loop-subscription-group-price-quantity",".loop-one-time-purchase-option-price-quantity"].forEach(selector=>{document.querySelectorAll(selector).forEach(element=>{element.classList.add("loop-display-none")})})}function displayLoopTooltip(productId2){const loopContainer=getLoopSubscriptionContainer(productId2),tooltipElement=loopContainer.querySelector("#loop-tooltip");if(!tooltipElement)return;tooltipElement.classList.remove("loop-display-none"),updateLoopTooltipContent(loopContainer,"#loop-tooltip-label",window.loopPropsUI.subscriptionPopupLabel),updateLoopTooltipContent(loopContainer,"#loop-tooltip-description",window.loopPropsUI.subscriptionPopupDescription);const label=loopContainer.querySelector("#loop-tooltip-label"),description=loopContainer.querySelector("#loop-tooltip-description");label&&description&&(label.style.fill=window.getComputedStyle(description).color)}function updateLoopTooltipContent(container,selector,content){const element=container.querySelector(selector);element&&content&&(element.innerHTML=content)}function hideLoopTooltip(productId2){const element=getLoopSubscriptionContainer(productId2).querySelector("#loop-tooltip");element&&element.classList.add("loop-display-none")}function addExtraLoopStyles(){if(window&&window.loopPropsUI&&window.loopPropsUI.style){let classList={purchase_option_label:[".loop-purchase-options-label"],widget_feildset:[".loop-selling-plan-fieldset"],selling_plan_group_container:[".loop-one-time-purchase-option",".loop-subscription-group"],selling_plan_group_label:[".loop-one-time-purchase-option-label",".loop-subscription-group-label"],selling_plan_label:[".loop-selling-plan-selector-label"],selling_plan_selector:[".loop-selling-plan-selector"],selling_plan_price_label:[".loop-one-time-purchase-option-price-amount",".loop-subscription-group-price-amount"],selling_plan_price_subtitle_label:[".loop-one-time-purchase-option-price-quantity",".loop-subscription-group-price-quantity"],selling_plan_description_label:[".loop-selling-plan-selector-description"],selling_plan_discount_badge_style:[".loop-subscription-group-discount-badge"],subscription_details_label:[".loop-tooltip-label"],subscription_details_popup:[".loop-tooltiptext",".loop-container-arrow",".loop-tooltip-description"],selling_plan_group_selected:[".loop-selected-selling-plan-group"],selling_plan_group_radio:[".loop-subscription-group-radio",".loop-one-time-purchase-option-radio"]};const getProperties=({id,data})=>{if(data){let keys=Object.keys(data),properties="";return keys.forEach(key=>{let value=data[key];properties=` ${properties} ${key}: ${value} !important;`}),properties}else return""},getClassName=({id,data})=>classList[id]||[];let extraClasses="";const{style}=window.loopPropsUI;style.map(st=>{getClassName(st).map(className=>{extraClasses=extraClasses+`
2                 ${className} {
3                     ${getProperties(st)}
4                 }
5             `})});let loopStyles=document.querySelectorAll(".loop-style");
5loopStyles&&loopStyles.forEach(element=>{element.innerHTML=`${element.innerHTML}
6                 ${extraClasses}
7             `})}if(window&&window.loopPropsUI&&window.loopPropsUI.cssClassess){let loopStyles=document.querySelectorAll(".loop-style");loopStyles&&loopStyles.forEach(element=>{element.innerHTML=`${element.innerHTML}
8                 ${window.loopPropsUI.cssClassess}
9             `})}}function hideLoopSellingPlanFieldset(productId2){const loopSubscriptionWidget=getLoopSubscriptionContainer(productId2).querySelector("#loop-selling-plan-fieldset");loopSubscriptionWidget&&loopSubscriptionWidget.classList.add("loop-display-none","loop-display-none-by-variant")}function applyLoopSettings({productId:productId2}){let product=window.loopProps[productId2].product;const variant=findSelectedVariantLoop(productId2);if(window&&window.loopPropsUI&&window.loopPropsUI.displayLoopPurchaseOptionLabel===!1&&hideLoopPurchaseOptionsLabel(productId2),window&&window.loopPropsUI&&window.loopPropsUI.loopPurchaseOptionslabel&&addLoopPurchaseOptionLabelText(productId2),window&&window.loopPropsUI&&window.loopPropsUI.loopOneTimePurchaselabel&&addLoopOneTimePurchaseOptionLabelText(productId2),window&&window.loopPropsUI&&window.loopPropsUI.displayOneTimePurchaseOptionAtBottom&&(showOneTimePurchaseOptionAtBottomLoop(productId2),getLoopSubscriptionContainer(productId2).querySelectorAll(".loop-one-time-purchase-option").forEach(option=>{option.addEventListener("click",clickOnSellingPlanGroupContainerLoop)}),getLoopSubscriptionContainer(productId2).querySelectorAll("input[name=loop_purchase_option]").forEach(option=>{option.addEventListener("click",changeInSellingPlanGroupLoop)})),window&&window.loopPropsUI&&window.loopPropsUI.displayEachLabelForPrice===!1&&hideEachLabelForPriceLoop(),window&&window.loopPropsUI&&window.loopPropsUI.hidePlanSelectorIfOnlyOne){const{availableSellingPlanAllocations=[]}=window.loopProps[productId2];let ids=[];availableSellingPlanAllocations.map(a=>{ids.push(a.selling_plan_group_id)});let idCount=arrToInstanceCountObjLoop(ids);Object.keys(idCount).forEach(key=>{if(idCount[key]===1){let id=`#loop-selling-plan-container-${variant.id}-${key}`,parentElement=document.querySelector(id);if(parentElement){let label=parentElement.querySelector(".loop-selling-plan-selector-label"),labelPlan=parentElement.querySelector(`#loop-selling-plan-first-delivery-options-${variant.id}-${key}`),planSelector=parentElement.querySelector(".loop-selling-plan-selector");label&&label.classList.add("loop-display-none"),labelPlan&&labelPlan.classList.add("loop-display-none"),planSelector&&planSelector.classList.add("loop-display-none")}}})}if(window&&window.loopPropsUI&&window.loopPropsUI.showPlanSelectorAsTextIfOnlyOnePlan&&!window.loopPropsUI.hidePlanSelectorIfOnlyOne){const{availableSellingPlanAllocations=[]}=window.loopProps[productId2];let ids=[];availableSellingPlanAllocations.map(a=>{ids.push(a.selling_plan_group_id)});let idCount=arrToInstanceCountObjLoop(ids);Object.keys(idCount).forEach(key=>{if(idCount[key]===1){let id=`#loop-selling-plan-first-delivery-options-${variant.id}-${key}`,element=document.querySelector(id);element&&element.classList&&element.classList.remove("loop-display-none"),id=`#loop-select-${variant.id}-${key}`,element=document.querySelector(id),element&&element.classList.add("loop-display-none")}})}if(window&&window.loopPropsUI&&window.loopPropsUI.hideWholeWidgetIfOnlyOnePlan&&product.requires_selling_plan&&variant.selling_plan_allocations&&variant.selling_plan_allocations.length===1&&(hideLoopSellingPlanFieldset(productId2),hideLoopPurchaseOptionsLabel(productId2)),window&&window.loopPropsUI&&window.loopPropsUI.hideRadioButtonIfOnlyOnePlan&&product.requires_selling_plan){const{availableSellingPlanAllocations}=window.loopProps[productId2];let ids=[];availableSellingPlanAllocations.map(a=>{ids.push(a.selling_plan_group_id)});let idCount=arrToInstanceCountObjLoop(ids),onlyOneSellingPlanGroup=!1;if(Object.keys(idCount).length===1?onlyOneSellingPlanGroup=!0:onlyOneSellingPlanGroup=!1,onlyOneSellingPlanGroup){let loopSubscriptionGroupRadio=getLoopSubscriptionContainer(productId2).querySelectorAll(".loop-subscription-group-radio");
9loopSubscriptionGroupRadio&&loopSubscriptionGroupRadio.forEach(element=>{element.classList.add("loop-display-none")});let elements=getLoopSubscriptionContainer(productId2).querySelectorAll(".loop-subscription-group-selling-plans-container");elements&&elements.forEach(element=>{element.classList.add("loop-left-margin-0")})}}if(addExtraLoopStyles(),window&&window.loopPropsUI&&window.loopPropsUI.displaySubscriptionPopup&&variant&&variant.selling_plan_allocations&&variant.selling_plan_allocations.length?displayLoopTooltip(productId2):hideLoopTooltip(productId2),product&&product.requires_selling_plan&&Array.isArray(variant.selling_plan_allocations)&&variant.selling_plan_allocations.length){let parentId=`#loop-product-variant-${variant.id}`,parentElement=getLoopSubscriptionContainer(productId2).querySelector(parentId);if(window&&window.loopPropsUI&&window.loopPropsUI.displayOneTimePurchaseOptionAtBottom){let elements=parentElement.querySelectorAll(".loop-subscription-group");if(elements&&elements.length){let last=elements[elements.length-1];last.style.borderBottom="0",last.classList.remove("loop-subscription-group-border-bottom")}}else{let elements=parentElement.querySelectorAll(".loop-subscription-group");if(elements&&elements.length){let first=elements[0];first.style.borderTop="0",first.classList.remove("loop-subscription-group-border-top")}}}if(window&&window.loopPropsUI&&window.loopPropsUI.displayDiscountBadge)displayLoopDiscountBadge({productId:productId2});else{let loopSubscriptionDiscountBadge=document.querySelectorAll(".loop-subscription-group-discount-badge");loopSubscriptionDiscountBadge&&loopSubscriptionDiscountBadge.forEach(element=>{element&&element.classList.add("loop-display-none")})}if(window&&window.loopPropsUI&&window.loopPropsUI.translationData){let translationData=window.loopPropsUI.translationData||{},mapElements={widget_price_label_text:[".loop-one-time-purchase-option-price-quantity",".loop-subscription-group-price-quantity"]};Object.keys(mapElements).forEach(key=>{translationData&&translationData[key]&&mapElements[key].map(id=>{let elements=document.querySelectorAll(id);elements&&elements.forEach(element=>{element.innerText=translationData[key]})})})}}function clickOnSellingPlanGroupContainerLoop(event){const container=event.target.closest(".loop-subscription-group")||event.target.closest(".loop-one-time-purchase-option");if(!container)return;const radio=container.querySelector('input[type="radio"]'),selectedPlanGroupId=window.loopProps[radio.dataset.productId]?.sellingPlanGroupId;radio?.dataset?.id!==selectedPlanGroupId&&radio.click()}function loopVariantChanged({loopProduct,variantId}){loopInit({productId:loopProduct.id,product:JSON.parse(JSON.stringify(loopProduct)),variantId})}function checkVariantsSellingPlanAllocationLoop(variant,productId2){variant?.selling_plan_allocations?.length>0?(showSellingPlanFieldsetLoop(productId2),showLoopPurchaseOptionsLabel(productId2)):(hideLoopSellingPlanFieldset(productId2),hideLoopPurchaseOptionsLabel(productId2))}function defaultSelectOneTimePurchaseOptionLoop(variant,productId2){const onetimeCheckRadioLoop=getLoopSubscriptionContainer(productId2).querySelector(`#loop-one-time-purchase-${productId2}`);if(onetimeCheckRadioLoop){if(onetimeCheckRadioLoop.checked=!0,onetimeCheckRadioLoop.click(),loopIsTouchDevice()){const{dataset}=onetimeCheckRadioLoop;changeInSellingPlanGroupLoopMobile(dataset.id,dataset.name,dataset.productId)}}else defaultSelectFirstSellingPlanLoop(variant,productId2)}function loopInit({productId:productId2,product,variantId}){updateLoopProperties({product,productId:productId2,variantId});const selectedVariant=findSelectedVariantLoop(productId2,variantId);toggleVariantDisplayLoop(product,selectedVariant.id),checkVariantsSellingPlanAllocationLoop(selectedVariant,productId2),applyLoopSettings({productId:productId2}
9),applyDefaultSelectionBasedOnLoopSettings(selectedVariant,productId2)}function toggleVariantDisplayLoop(product,selectedVariantId){product.variants.forEach(variant=>{const displayStyle=variant.id===selectedVariantId?"block":"none";document.querySelector(`#loop-product-variant-${variant.id}`).style.display=displayStyle})}function applyDefaultSelectionBasedOnLoopSettings(selectedVariant,productId2){window.loopPropsUI?.byDefaultChooseSubscriptionOption?defaultSelectFirstSellingPlanLoop(selectedVariant,productId2):defaultSelectOneTimePurchaseOptionLoop(selectedVariant,productId2)}function updateSelectDropDownDefaultValuesLoop({productId:productId2,variant,sellingPlanGroupId}){const sellingPlanGroups=window.loopProps[productId2].product.selling_plan_groups;!Array.isArray(sellingPlanGroups)||!sellingPlanGroups.length||sellingPlanGroups.forEach(spg=>{sellingPlanGroupId!==spg.id&&resetSelectDropdownLoop(variant.id,spg.id)})}function resetSelectDropdownLoop(variantId,sellingPlanGroupId){const selectTag=document.getElementById(`loop-select-${variantId}-${sellingPlanGroupId}`);selectTag&&(selectTag.options[0].selected=!0)}function changeInSellingPlanGroupLoopMobile(sellingPlanGroupId,sellingPlanGroupName,productId2){window.loopProps[productId2].previousSPG||(window.loopProps[productId2].previousSPGId=sellingPlanGroupId);const variant=findSelectedVariantLoop(productId2,window.loopProps[productId2].selectedVariantId);let sellingPlans=variant.selling_plan_allocations.filter(spa=>spa.selling_plan_group_id===sellingPlanGroupId)||[],sellingPlan=sellingPlans&&sellingPlans.length?sellingPlans[0]:{},sellingPlanId=sellingPlan.selling_plan_id;updateLoopProperties({productId:productId2,variantId:variant.id,sellingPlanGroupId,sellingPlanGroupName,sellingPlanId,sellingPlan}),updateSelectDropDownDefaultValuesLoop({productId:productId2,variant,sellingPlanGroupId}),updatePriceInParentElementsLoop({productId:productId2}),updateLoopSellingPlanDescriptionUI({productId:productId2}),displayLoopDiscountBadge({productId:productId2}),updateCartButtonTextLoop({productId:productId2}),updatePriceInUILoop({productId:productId2}),updatePrepaidPriceInUILoop({productId:productId2}),applyLoopBundleDiscount(productId2),checkAllowCheckoutIfBundle(productId2);let elements=getLoopSubscriptionContainer(productId2).querySelectorAll(".loop-selected-selling-plan-group");if(elements&&elements.forEach(element=>{element&&element.classList.remove("loop-selected-selling-plan-group")}),sellingPlanGroupId==="loop-one-time-purchase"){let elements2=getLoopSubscriptionContainer(productId2).querySelectorAll(".loop-one-time-purchase-option");elements2&&elements2.forEach(element=>{element.classList.add("loop-selected-selling-plan-group")})}else{let elementId=`#loop-${variant.id}-${sellingPlanGroupId}`,element=getLoopSubscriptionContainer(productId2).querySelector(elementId);element&&element.classList.add("loop-selected-selling-plan-group")}}function changeInSellingPlanGroupLoop(option){let sellingPlanGroupId=option.target.dataset.id,sellingPlanGroupName=option.target.dataset.name,productId2=option.target.dataset.productId;window.loopProps[productId2].previousSPG||(window.loopProps[productId2].previousSPGId=sellingPlanGroupId);const variant=findSelectedVariantLoop(productId2,window.loopProps[productId2].selectedVariantId);let sellingPlans=variant.selling_plan_allocations.filter(spa=>spa.selling_plan_group_id===sellingPlanGroupId)||[],sellingPlan=sellingPlans&&sellingPlans.length?sellingPlans[0]:{},sellingPlanId=sellingPlan.selling_plan_id;updateLoopProperties({productId:productId2,variantId:variant.id,sellingPlanGroupId,sellingPlanGroupName,sellingPlanId,sellingPlan}),updateSelectDropDownDefaultValuesLoop({productId:productId2,variant,sellingPlanGroupId:option.target.dataset.id}),updatePriceInParentElementsLoop({productId:productId2}),updateLoopSellingPlanDescriptionUI({productId:productId2}),displayLoopDiscountBadge({productId:productId2}),updateCartButtonTextLoop({productId:productId2}),updatePriceInUILoop({productId:productId2}),updatePrepaidPriceInUILoop({productId:productId2}),applyLoopBundleDiscount(productId2),checkAllowCheckoutIfBundle(productId2);let elements=getLoopSubscriptionContainer(productId2).querySelectorAll(".loop-selected-selling-plan-group");
9if(elements&&elements.forEach(element=>{element&&element.classList.remove("loop-selected-selling-plan-group")}),sellingPlanGroupId==="loop-one-time-purchase"){let elements2=getLoopSubscriptionContainer(productId2).querySelectorAll(".loop-one-time-purchase-option");elements2&&elements2.forEach(element=>{element.classList.add("loop-selected-selling-plan-group")})}else{let elementId=`#loop-${variant.id}-${sellingPlanGroupId}`,element=getLoopSubscriptionContainer(productId2).querySelector(elementId);element&&element.classList.add("loop-selected-selling-plan-group")}}function changeInDeliveryOptionLoop(option){let sellingPlanId=option.target.value,productId2=option.target.dataset.productId;updateLoopProperties({productId:productId2,sellingPlanId}),updatePriceInParentElementsLoop({productId:productId2}),updateLoopSellingPlanDescriptionUI({productId:productId2}),displayLoopDiscountBadge({productId:productId2}),updatePriceInUILoop({productId:productId2}),updatePrepaidPriceInUILoop({productId:productId2}),applyLoopBundleDiscount(productId2),checkAllowCheckoutIfBundle(productId2)}function displayLoopDiscountBadge({productId:productId2}){const HARDCODED_DISCOUNT_PRODUCTS=["6702088192088","6702098350168","6766507982936"],variant=findSelectedVariantLoop(productId2),{selling_plan_groups}=window.loopProps[productId2].product;window&&window.loopProps&&window.loopPropsUI.displayDiscountBadge?selling_plan_groups.map(spg=>{const{selling_plans}=spg;let discountList=[];selling_plans.map(sp=>{const{price_adjustments}=sp;let priceAdj=price_adjustments.length?price_adjustments[0]:{};discountList.push({value:priceAdj.value,value_type:priceAdj.value_type,amount:priceAdj.value_type==="fixed_amount"?priceAdj.value:priceAdj.value_type==="price"?Number(variant.price)-Number(priceAdj.value):Number(variant.price)*priceAdj.value/100})});let selectedDiscount=discountList.reduce((prev,current)=>prev.amount>current.amount?prev:current),id=`#loop-discount-badge-${variant.id}-${spg.id}`,element=getLoopSubscriptionContainer(productId2).querySelector(id);if(window.loopProps[productId2]&&spg.id===window.loopProps[productId2].sellingPlanGroupId){let ssp=selling_plans.find(sp=>sp.id===Number(window.loopProps[productId2].sellingPlanId))||{};ssp.price_adjustments?.length&&(selectedDiscount=ssp.price_adjustments[0])}if(element){const isHardcodedProduct=HARDCODED_DISCOUNT_PRODUCTS.includes(String(productId2));let discountText="";isHardcodedProduct?discountText="15%":selectedDiscount&&selectedDiscount.value_type==="fixed_amount"?discountText=loopFormatMoney(selectedDiscount.value,!0):selectedDiscount&&selectedDiscount.value_type==="percentage"?discountText=`${selectedDiscount.value}%`:selectedDiscount&&selectedDiscount.value_type==="price"&&(discountText=loopFormatMoney(Number(variant.price)-Number(selectedDiscount.value)>0?Number(variant.price)-Number(selectedDiscount.value):0,!0));let discountLabelText=(window?.loopPropsUI?.discountBadgeText||" ").replace("{discount_value}",discountText);element.innerHTML=discountLabelText,!isHardcodedProduct&&(!selectedDiscount?.value&&!Number(selectedDiscount?.value)||selectedDiscount&&selectedDiscount.value_type==="price"&&Number(variant.price)-Number(selectedDiscount.value)<=0)?element.classList.add("loop-display-none"):element.classList.remove("loop-display-none")}}):selling_plan_groups.map(spg=>{let id=`#loop-discount-badge-${variant.id}-${spg.id}`,element=document.querySelector(id);element&&element.classList.add("loop-display-none")})}function calculateCurrentSellingPlanLoop({productId:productId2,availableSellingPlanAllocations}){const loopProductProps=window.loopProps[productId2],{sellingPlanId,sellingPlanGroupId}=loopProductProps;return availableSellingPlanAllocations.find(sellingPlan=>sellingPlan.selling_plan_group_id!==sellingPlanGroupId?!1:sellingPlanId?Number(sellingPlan.selling_plan_id)===Number(sellingPlanId):!0)||{}}function updateLoopProperties({product,productId:productId2,variantId,sellingPlanGroupId,sellingPlanGroupName,sellingPlanId}){let loopProperties=getLoopSubscriptionContainer(productId2).querySelector("#loop-selling-plan-fieldset");variantId&&(Number(variantId)!==Number(loopProperties.dataset.selectedVariantId)&&(loopProperties.dataset.sellingPlanGroupId="",loopPro
9perties.dataset.sellingPlanGroupName="",loopProperties.dataset.sellingPlanId=""),loopProperties.dataset.selectedVariantId=variantId),sellingPlanGroupId&&(loopProperties.dataset.sellingPlanGroupId=sellingPlanGroupId),sellingPlanGroupName&&(loopProperties.dataset.sellingPlanGroupName=sellingPlanGroupName),product&&(loopProperties.dataset.product=JSON.stringify(product)),sellingPlanId?loopProperties.dataset.sellingPlanId=sellingPlanId:sellingPlanGroupId==="loop-one-time-purchase"&&(loopProperties.dataset.sellingPlanId="",loopProperties.dataset.sellingPlan={},loopProperties.dataset.sellingPlan={}),window.loopProps||(window.loopProps={},window.loopProps[productId2]={product,productId:productId2});const productBundleData=window.loopProps[productId2].productBundleData,previousSPGId=window.loopProps[productId2].previousSPGId,prepaidSellingPlans=window.loopProps[productId2].prepaidSellingPlans;window.loopProps[productId2]={...loopProperties.dataset,productId:productId2},window.loopProps[productId2].productBundleData=productBundleData,window.loopProps[productId2].previousSPGId=previousSPGId,window.loopProps[productId2].prepaidSellingPlans=prepaidSellingPlans,loopProperties.dataset&&loopProperties.dataset.product&&(window.loopProps[productId2]={...window.loopProps[productId2],product:JSON.parse(window.loopProps[productId2].product)});let variant=findSelectedVariantLoop(productId2),availableSellingPlanAllocations=variant&&Array.isArray(variant.selling_plan_allocations)?variant.selling_plan_allocations:[];window.loopProps[productId2].availableSellingPlanAllocations=availableSellingPlanAllocations,window.loopProps[productId2].variant=variant;let sellingPlan=calculateCurrentSellingPlanLoop({availableSellingPlanAllocations,productId:productId2}),selectedSellingPlanId=sellingPlan.selling_plan_id||"";window.loopProps[productId2].sellingPlan=sellingPlan;let sellingPlanAllocation=availableSellingPlanAllocations.find(aspa=>{if(selectedSellingPlanId&&Number(aspa.selling_plan_id)===Number(selectedSellingPlanId))return!0});window.loopProps[productId2].sellingPlanAllocation=sellingPlanAllocation;const{selling_plan_groups}=window.loopProps[productId2].product;window.loopProps[productId2].sellingPlanDefination={},window.loopProps[productId2].sellingPlanPriceAdjustments=[],selling_plan_groups&&Array.isArray(selling_plan_groups)&&selling_plan_groups.map(spg=>{if(spg.id===window.loopProps[productId2].sellingPlanGroupId){const{selling_plans}=spg;selling_plans.map(sp=>{sp.id===Number(window.loopProps[productId2].sellingPlanId)&&(window.loopProps[productId2].sellingPlanDefination=sp,window.loopProps[productId2].sellingPlanPriceAdjustments=sp.price_adjustments)})}});let sellingPlanRadio=getLoopSubscriptionContainer(productId2).querySelector('[name="selling_plan"]');sellingPlanRadio&&(sellingPlanRadio.value=selectedSellingPlanId),document.querySelectorAll(`form[data-loop-product-id="${productId2}"]`).forEach(form=>{const existingInputs=form.querySelectorAll('input[name="selling_plan"]');existingInputs.length&&existingInputs.forEach(existingInput=>{existingInput.remove()});const hiddenInput=document.createElement("input");hiddenInput.type="hidden",hiddenInput.name="selling_plan",hiddenInput.value=selectedSellingPlanId,form.appendChild(hiddenInput)}),hideLoopBundleSPG(productId2)}function updateCartButtonTextLoop({productId:productId2}){const parentElement=document.querySelector(`[data-loop-product-id="${productId2}"]`)||document,isOneTimeOrder=determineOneTimeOrderLoop(productId2),addToCartButton=getAddToCartButtonLoop(parentElement);if(!addToCartButton)return;const buttonText=getButtonTextLoop(isOneTimeOrder,productId2);updateButtonInnerHTMLLoop(addToCartButton,buttonText)}function determineOneTimeOrderLoop(productId2){const sellingPlanGroupId=window?.loopProps[productId2]?.sellingPlanGroupId;return!sellingPlanGroupId||sellingPlanGroupId==="loop-one-time-purchase"}function getAddToCartButtonLoop(parentElement){const selectors=["button[type='submit'][name='add']","button[type='button'][name='add']"];let addToCartBtn=null;return selectors.map(selector=>{addToCartBtn||(addToCartBtn=parentElement.querySelector(selector)),addToCartBtn||(addToCartBtn=document.querySelector(selector))}),addToCartBtn}function getButtonTextLoop(isOneTimeOrder,productId2){return isOneTimeOrder?window.loopProps[productId2].variant.available?window?.loopPro
9psUI?.translationData?.widget_add_to_cart_button_for_one_time_purchase||"Add to cart":window?.loopPropsUI?.translationData?.widget_out_of_stock_text||"Out of Stock":window?.loopPropsUI?.translationData?.widget_add_to_cart_button_for_subscription||"Add subscription to cart"}function updateButtonInnerHTMLLoop(button,text){button.firstElementChild?button.firstElementChild.innerHTML=text:button.innerHTML=text}function loopFormatMoney(price,removeEach){if(Shopify.locale&&Shopify.country&&Shopify.currency.active)return loopFormatPriceNew(price,Shopify.locale,Shopify.country,Shopify.currency.active);const moneyFormat=document.querySelector("#loop-price-money-format").innerText,moneyWithoutCurrency=document.querySelector("#loop-price-money_without_currency-format").innerText;let formattedPrice=loopFormatPrice(price,moneyFormat,moneyWithoutCurrency);return removeEach&&(formattedPrice=formattedPrice.replace("each","")),formattedPrice.trim()}function loopFormatPriceNew(value,locale,countryCode,currencyCode){const decimalValue=value/100;return new Intl.NumberFormat(`${locale}-${countryCode}`,{style:"currency",currency:`${currencyCode}`}).format(decimalValue)}function loopFormatPrice(price,moneyFormat,moneyWithoutCurrency){const priceValue=price/100;if(moneyFormat.includes("0.00"))return moneyFormat.replace("0.00",priceValue.toFixed(2));if(moneyFormat.includes("0,00"))return moneyFormat.replace("0,00",priceValue.toFixed(2).replace(".",","));if(moneyFormat.includes("0")){const wholeNumberValue=Number(moneyWithoutCurrency.replace("0",priceValue)).toFixed(0);return moneyFormat.replace("0",wholeNumberValue)}return moneyFormat}function getSavedPriceLabel(priceAdjustments){if(!Array.isArray(priceAdjustments)||!priceAdjustments.length)return"";const pa=priceAdjustments[0];return pa.value_type==="percentage"?`Save ${pa.value}%`:`Save ${loopFormatMoney(pa.value,!0)}`}function updateLoopSellingPlanDescriptionUI({productId:productId2}){const variant=findSelectedVariantLoop(productId2),loopPropsProduct=window.loopProps?.[productId2];if(!loopPropsProduct?.sellingPlanGroupId)return;const descriptionValue=loopPropsProduct?.sellingPlanDefination?.description||"",descriptionElement=document.querySelector(`#loop-selling-plan-description-${variant.id}-${loopPropsProduct.sellingPlanGroupId}`);updateLoopSellingPlanDescriptionElement(descriptionElement,descriptionValue)}function updateLoopSellingPlanDescriptionElement(descriptionElement,descriptionValue){descriptionElement&&(descriptionElement.innerHTML=descriptionValue,descriptionValue?descriptionElement.classList.remove("loop-display-none"):descriptionElement.classList.add("loop-display-none"))}function updatePriceInParentElementsLoop({productId:productId2}){const currentPath=getCurrentPathLoop();if(window?.loopProps[productId2]?.product?.handle!==currentPath)return;const variant=findSelectedVariantLoop(productId2),price=determinePriceLoop(productId2,variant);loopPriceSelectors.push(`.loop-product-${productId2}`)}function determinePriceLoop(productId2,variant){const sellingPlanPrice=window?.loopProps[productId2]?.sellingPlanAllocation?.price;return loopFormatMoney(sellingPlanPrice||variant.price,!0)}function updatePricesInUILoop(price){}function updatePriceInUILoop({productId:productId2}){let variant=findSelectedVariantLoop(productId2,window.loopProps[productId2].selectedVariantId),sellingPlan=window.loopProps&&window.loopProps[productId2]?window.loopProps[productId2].sellingPlan:{};const product=window.loopProps[productId2]?.product||{},{selling_plan_groups}=product,{selling_plan_allocations}=variant;if(selling_plan_groups.map(spg=>{if(Array.isArray(spg.selling_plans)&&spg.selling_plans.length){let firstSellingPlan=spg.selling_plans[0],sellingPlanAllc
9otion=selling_plan_allocations.find(a=>Number(a.selling_plan_id)===Number(firstSellingPlan.id))||{};const{selling_plan_group_id,per_delivery_price}=sellingPlanAllcotion;let element=document.querySelector(`#loop-price-${variant.id}-${selling_plan_group_id}`);element&&(element.innerHTML=loopFormatMoney(per_delivery_price,!0))}}),sellingPlan&&sellingPlan.selling_plan_group_id){const{selling_plan_group_id,per_delivery_price}=sellingPlan;let element=document.querySelector(`#loop-price-${variant.id}-${selling_plan_group_id}`);element&&(element.innerHTML=loopFormatMoney(per_delivery_price,!0))}let loopOneTimePrice=getLoopSubscriptionContainer(productId2).querySelector("#loop-price-one-time");loopOneTimePrice&&(loopOneTimePrice.innerHTML=loopFormatMoney(variant.price,!0))}function log(message){console.log(message)}function logError(error){console.error(error)}function initializeLoopData(productId2){window.LoopSubscriptions||(window.LoopSubscriptions={}),window.LoopSubscriptions[productId2]=getLoopProductData(productId2)}function getLoopProductData(productId2){const textData=document.querySelector(`.${productDataClass}-${productId2}`).textContent;return JSON.parse(textData)}function getLoopSubscriptionContainer(productId2){return document.querySelector(`#${loopSubscriptionContainerId}-${productId2}`)}function getCurrentPathLoop(){const pathParts=window.location.pathname.split("/");return pathParts[pathParts.length-1]}function loopIsTouchDevice(){return"ontouchstart"in document.documentElement}async function getLoopBundleSpgs(productId2){const spgs=loopProps[productId2]?.product?.selling_plan_groups?.flatMap(spg=>spg?.selling_plans?.map(sp=>({selling_plan_group_id:spg.id,selling_plan_id:sp.id})))||[],sps=loopProps[productId2]?.product?.selling_plan_groups?.flatMap(spg=>spg?.selling_plans.map(sp=>sp.id))||[],body={domain:window.Shopify.shop,sellingPlanIds:sps,product_shopify_id:productId2},spidsAsString=sps.join(","),prepaidUrl=`${GET_PREPAID_SELLING_PLAN_DATA_URL}${spidsAsString}`;try{const[bundleRes,prepaidRes]=await Promise.all([fetch(FILTER_BUNDLE_SP_API,{method:"POST",body:JSON.stringify(body),headers:{"Content-Type":"application/json"}}),fetch(prepaidUrl,{method:"GET",headers:{"Content-Type":"application/json"}})]),sps2=(await bundleRes.json()).data;let bundleSellingPlanGroupIds=[],nonBundleSellingPlanGroupIds=[];for(const spg of spgs)sps2.includes(spg.selling_plan_id)?bundleSellingPlanGroupIds.push(spg.selling_plan_group_id):nonBundleSellingPlanGroupIds.push(spg.selling_plan_group_id);window.loopProps[productId2].bundleSPGS=[...new Set(bundleSellingPlanGroupIds)],window.loopProps[productId2].nonBundleSPGS=[...new Set(nonBundleSellingPlanGroupIds)],hideLoopBundleSPG(productId2);const prepaidData=(await prepaidRes.json()).data;window.loopProps[productId2].prepaidSellingPlans=prepaidData?.sellingPlans||null}
9catch(error){console.error("getLoopBundleSpgs",error)}}function hideLoopBundleSPG(productId2){if(!window.loopProps?.[productId2]?.productBundleData?.isBundleProduct){const loopProps2=window.loopProps[productId2],loopContainer=getLoopSubscriptionContainer(productId2);if(loopContainer){const bspgs=loopProps2.bundleSPGS;bspgs?.length&&(bspgs.forEach(spgId=>{const bundlespg=loopContainer.querySelectorAll(`#loop-selling_plan_group-${spgId}`);bundlespg?.length&&bundlespg.forEach(spg=>{spg.classList.add("loop-display-none")})}),clickUpdatedSPGLoop(productId2))}}}function clickUpdatedSPGLoop(productId2){showSellingPlanFieldsetLoop(productId2),window&&window.loopPropsUI&&window.loopPropsUI.displayLoopPurchaseOptionLabel?showLoopPurchaseOptionsLabel(productId2):hideLoopPurchaseOptionsLabel(productId2);const selectedVariant=window.loopProps[productId2].selectedVariantId,nonBundleSpgs=window.loopProps[productId2].nonBundleSPGS??[];if(nonBundleSpgs.length!==0&&window.loopPropsUI.byDefaultChooseSubscriptionOption){const firstAvailableNonBundleSpg=nonBundleSpgs[0];getLoopSubscriptionContainer(productId2).querySelectorAll(`#loop-selling_plan_group-${firstAvailableNonBundleSpg}`).forEach(node=>{node.querySelectorAll(`#loop-allocation-${firstAvailableNonBundleSpg}`).forEach(ele=>{ele.querySelectorAll(`#loop-${selectedVariant}-${firstAvailableNonBundleSpg}`).forEach(targetNode=>{targetNode.click()})})})}else defaultSelectOneTimePurchaseOptionLoop(selectedVariant,productId2),nonBundleSpgs.length===0&&hideLoopWidget(productId2)}function hideLoopWidget(productId2){const loopWidgetContainer=document.getElementById(`loop-subscription-container-${productId2}`);loopWidgetContainer&&(loopWidgetContainer.style.display="none")}async function getBundleDataByProductId(productId2){return(await(await fetch(`${GET_PRODUCT_BUNDLE_DATA_API}${productId2}`)).json()).data}function handleBundleWidgetVisibility(productId2){window.loopProps[productId2].productBundleData.purchaseType==="SUBSCRIPTION"?hideOneTimePurchaseOptionLoop(productId2):window.loopProps[productId2].productBundleData.purchaseType==="ONETIME"&&(hideLoopSellingPlanFieldset(productId2),hideLoopPurchaseOptionsLabel(productId2),defaultSelectOneTimePurchaseOptionLoop(null,productId2))}async function processLoopBundleProduct(productId2){try{const bundleData=await getBundleDataByProductId(productId2);bundleData&&(window.loopProps[productId2].productBundleData=bundleData,bundleData.isBundleProduct&&(overrideAddToCartButtonLoop(productId2,bundleData.mapping),handleBundleWidgetVisibility(productId2),applyLoopBundleDiscount(productId2),checkAllowCheckoutIfBundle(productId2)))}catch(error){console.error("processLoopBundleProduct",error)}}function checkAllowCheckoutIfBundle(productId2){enableAddToCartBtnLoop(productId2);const selectedVariantId=window.loopProps[productId2].selectedVariantId;if(window.loopProps[productId2]?.productBundleData?.isBundleProduct){const selectedVariant=window.loopProps[productId2].productBundleData.mapping[selectedVariantId],allowCheckout=selectedVariant?.allowCheckout,outOfStock=selectedVariant?.outOfStock;if(outOfStock){const buttonText=window?.loopPropsUI?.translationData?.widget_out_of_stock_text||"Out of Stock",parentElement=document.querySelector(`[data-loop-product-id="${productId2}"]`)||document,addToCartButton=getAddToCartButtonLoop(parentElement);addToCartButton&&setTimeout(()=>{updateButtonInnerHTMLLoop(addToCartButton,buttonText)},500)}(!allowCheckout||outOfStock)&&disableAddToCartBtnLoop(productId2)}}function applyLoopBundleDiscount(productId2){if(!window.loopProps[productId2]?.productBundleData?.isBundleProduct)return;const productBundleData=window.loopProps[productId2].productBundleData;let variant=findSelectedVariantLoop(productId2,window.loopProps[productId2].selectedVariantId),selectedVariantId=window.loopProps[productId2].selectedVariantId;if(!productBundleData.productVariantDiscountMapping?.[selectedVariantId])return;const conversionRate=window.Shopify.currency.rate;let sellingPlan=window.loopProps&&window.loopProps[productId2]?window.loopProps[productId2].sellingPlan:{};const product=window.loopProps[productId2]?.product||{},{selling_plan_groups}=product,{selling_plan_allocations}=variant;if(selling_plan_groups.map(spg=>{if(Array.isArray(spg.selling_plans)&&spg.selling_plans.length){let firstSellingPlan=spg.selling_plans[0],sellingPlanAllocation=selling_plan_allocations.find(a=>Number(a.selling_plan_id)===Number(firstSellingPlan.id))||{};const{selling_plan_group_id,price,compare_at_price}=sellingPlanAllocation,originaPrice=compare_at_price||variant.price;let element=document.querySelector(`#loop-price-${variant.id}-${selling_plan_group_id}`),elementOriginal=document.querySelector(`#loop-price-original-${variant.id}-${selling_plan_group_id}`);if(elementOriginal&&(elementOriginal.innerHTML=loopFormatMoney(originaPrice,!0),elementOriginal.classList.remove("loop-display-none"),elementOriginal.style.textDecorationLine="line-through"),element){let bundlePrice=originaPrice;productBundleData.productVariantsFinalValues[selectedVariantId][firstSellingPlan.id]&&(bundlePrice=productBundleData.productVariantsFinalValues[selectedVariantId][firstSellingPlan.id]*100*conversionRate),element.innerHTML=loopFormatMoney(bundlePrice,!0);let totalDiscount=Math.round((originaPrice-bundlePrice)/originaPrice*100);const discountEle=document.querySelector(`#loop-discount-badge-${variant.id}-${selling_plan_group_id}`);let discountText=`${totalDiscount>0?totalDiscount:0}
9%`,discountLabelText=(window?.loopPropsUI?.discountBadgeText||" ").replace("{discount_value}",discountText);discountEle.innerHTML=`${discountLabelText}`,totalDiscount>0?discountEle.classList.remove("loop-display-none"):discountEle.classList.add("loop-display-none")}elementOriginal&&element?.innerHTML==elementOriginal?.innerHTML&&elementOriginal.classList.add("loop-display-none")}}),sellingPlan&&sellingPlan.selling_plan_group_id){const{selling_plan_group_id,price,compare_at_price}=sellingPlan,originaPrice=compare_at_price||variant.price;let element=document.querySelector(`#loop-price-${variant.id}-${selling_plan_group_id}`),elementOriginal=document.querySelector(`#loop-price-original-${variant.id}-${selling_plan_group_id}`);if(elementOriginal&&(elementOriginal.innerHTML=loopFormatMoney(originaPrice,!0),elementOriginal.classList.remove("loop-display-none"),elementOriginal.style.textDecorationLine="line-through"),element){let bundlePrice=originaPrice;productBundleData.productVariantsFinalValues[selectedVariantId][sellingPlan.selling_plan_id]&&(bundlePrice=productBundleData.productVariantsFinalValues[selectedVariantId][sellingPlan.selling_plan_id]*100*conversionRate),element.innerHTML=loopFormatMoney(bundlePrice,!0);let totalDiscount=Math.round((originaPrice-bundlePrice)/originaPrice*100);const discountEle=document.querySelector(`#loop-discount-badge-${variant.id}-${selling_plan_group_id}`);let discountText=`${totalDiscount>0?totalDiscount:0}%`,discountLabelText=(window?.loopPropsUI?.discountBadgeText||" ").replace("{discount_value}",discountText);discountEle.innerHTML=`${discountLabelText}`,totalDiscount>0?discountEle.classList.remove("loop-display-none"):discountEle.classList.add("loop-display-none")}elementOriginal&&element?.innerHTML==elementOriginal?.innerHTML&&elementOriginal.classList.add("loop-display-none")}const originaPriceOnetime=variant.compare_at_price||variant.price,bundlePriceOnetimeDiscounted=productBundleData?.productVariantsFinalValues?.[selectedVariantId]?.ONETIME;let loopOneTimePrice=getLoopSubscriptionContainer(productId2).querySelector("#loop-price-one-time"),loopOneTimePriceOriginal=getLoopSubscriptionContainer(productId2).querySelector("#loop-price-one-time-original"),bundlePriceOnetime=originaPriceOnetime;if(loopOneTimePrice&&(bundlePriceOnetimeDiscounted&&(bundlePriceOnetime=bundlePriceOnetimeDiscounted*100*conversionRate),loopOneTimePrice.innerHTML=loopFormatMoney(bundlePriceOnetime,!0)),loopOneTimePriceOriginal){let val=originaPriceOnetime;if(loopOneTimePriceOriginal.innerHTML=loopFormatMoney(val,!0),loopOneTimePriceOriginal.classList.remove("loop-display-none"),loopOneTimePriceOriginal.style.textDecorationLine="line-through",bundlePriceOnetimeDiscounted){let totalDiscount=Math.round((originaPriceOnetime-bundlePriceOnetimeDiscounted*100*conversionRate)/originaPriceOnetime*100);const discountEle=document.querySelector("#loop-discount-badge-onetime");let discountText=`${totalDiscount>0?totalDiscount:0}%`,discountLabelText=(window?.loopPropsUI?.discountBadgeText||" ").replace("{discount_value}",discountText);discountEle.innerHTML=`${discountLabelText}`,totalDiscount>0}}loopOneTimePrice&&loopOneTimePriceOriginal&&loopOneTimePrice.innerHTML==loopOneTimePriceOriginal.innerHTML&&loopOneTimePriceOriginal.classList.add("loop-display-none")}function listenLoopCustomEvent(){document.addEventListener("loopPresetAddToCartSuccessEvent",function(event){const productId2=event.detail.productId,response=event.detail.response;window.location.href="/cart",console.log(`Loop Product ${productId2} added to cart. Response:`,response)})}function removeAllEventListenersLoop(element){const clone=element.cloneNode(!0);return element.parentNode.replaceChild(clone,element),clone}function overrideAddToCartButtonLoop(productId2,bundleVariants2){document.querySelectorAll(`[data-loop-product-id="${productId2}"]`).forEach(form=>{let submitButtons=form.querySelectorAll("button[type=submit]");submitButtons.length===0&&(submitButtons=form.querySelectorAll("button")),submitButtons.forEach(btn=>{btn=removeAllEventListenersLoop(btn),btn.addEventListener("click",event=>{const clickedProductId=form.getAttribute("data-loop-product-id"),quantity=document.querySelector(PRODUCT_QUANTITY_SELECTOR);loopHandleAddToCart(event,clickedProductId,quantity?.value,bundleVariants2)})})})}async function applyShopifyDiscountLoop(discountCodes){try{const endpoint=`${window?.Shopify?.routes?.root}discount/${discountCodes}`;await fetch(endpoint,{method:"GET",headers:{"Content-Type":"application/json"}})}catch{enableAddToCartBtnLoop(productId)}}async function createBundleTransaction(payload){try{return(await(await fetch(CREATE_BUNDLE_TRANSACTION_API,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(payload)})).json()).loopBundleGuid}catch(error){throw console.error("createBundleTransaction",error),error}}function hideOneTimePurchaseOptionLoop(productId2){document.querySelectorAll(`form[data-loop-product-id="${productId2}"]`).forEach(form=>{form.querySelectorAll(".loop-one-time-purchase-option").forEach(option=>{option.classList.add("loop-display-none")})})}function disableAddToCartBtnLoop(productId2){document.querySelectorAll(`[data-loop-product-id="${productId2}"]`).forEach(form=>{form.querySelectorAll("button").forEach(btn=>{btn.disabled=!0})})}function enableAddToCartBtnLoop(productId2){document.querySelectorAll(`[data-loop-product-id="${productId2}"]`).forEach(form=>{form.querySelectorAll("button").forEach(btn=>{btn.disabled=!1})})}function createBundleTransactionPayload(productId2,quantity,selectedSellingPlan){const selectedVariant=window.loopProps[productId2].selectedVariantId,bundleData=window.loopProps[productId2].productBundleData;let bundleDiscountId=null,bundleVariantDiscount={};if(selectedSellingPlan){let disc=bundleData?.productVariantDiscountMapping?.[selectedVariant]?.find(d=>d.purchaseType==="SUBSCRIPTION");disc&&(bundleVariantDiscount=disc,bundleDiscountId=disc.bundleDiscountId)}else{let disc=bundleData?.productVariantDiscountMapping?.[selectedVariant]?.find(d=>d.purchaseType!=="SUBSCRIPTION");disc&&(bundleVariantDiscount=disc,bundleDiscountId=disc.bundleDiscountId)}return bundleDiscountId?{payload:{bundleId:bundleData.bundleId,bundleVariantId:bundleData?.productVariantMapping?.[selectedVariant],bundleDiscountId,sellingPlanId:bundleData?.productVariantSellingPlanMapping?.[selectedSellingPlan],productsQuantity:Number(quantity)},bundleVariantDiscount}:{payload:null,bundleVariantDiscount:null}}
9async function handleBundleTransaction(productId2,quantity,selectedSellingPlan){try{const{payload,bundleVariantDiscount}=createBundleTransactionPayload(productId2,quantity,selectedSellingPlan),bundleTransactionId=await createBundleTransaction(payload);return bundleTransactionId||enableAddToCartBtnLoop(productId2),{bundleTransactionId,bundleVariantDiscount}}catch{enableAddToCartBtnLoop(productId2)}}function getSelectedSellingPlanLoop(productId2){let sp=null;return document.querySelectorAll(`form[data-loop-product-id="${productId2}"]`).forEach(form=>{const existingInput=form.querySelector('input[name="selling_plan"]');existingInput?.value&&(sp=Number(existingInput.value))}),sp}async function getBundleDiscountAttributesLoop(){const url=`https://${Shopify.cdnHost.split("/cdn")[0]}/cart.json`,res=await(await fetch(url)).json(),loopBundleDiscountAttributes=res.attributes?._loopBundleDiscountAttributes?JSON.parse(res.attributes._loopBundleDiscountAttributes):{},bundleIdsInCart=new Set(res.items.map(item=>item.properties?._bundleId).filter(id=>id));return Object.keys(loopBundleDiscountAttributes).filter(key=>bundleIdsInCart.has(key)).reduce((obj,key)=>(obj[key]=loopBundleDiscountAttributes[key],obj),{})}async function createAddToCartPayloadLoop(bundleTransactionId,bundleVariantDiscount,selectedSellingPlan,selectedBundleVariantId,quantity,bundleData){const formData={items:[],attributes:{_loopBundleDiscountAttributes:{}}},oldAttr=await getBundleDiscountAttributesLoop(),currentDiscountAttribute={};currentDiscountAttribute[bundleTransactionId]={discountType:bundleVariantDiscount.bundleDiscountType,discountValue:bundleVariantDiscount.bundleDiscountValue,discountComputedValue:bundleVariantDiscount?selectedSellingPlan?bundleVariantDiscount.spbpDiscount[selectedSellingPlan]*quantity:bundleVariantDiscount.bundleDiscountComputedValue*quantity:0},formData.attributes._loopBundleDiscountAttributes=JSON.stringify({...oldAttr,...currentDiscountAttribute});const selectedBundleVariantProducts=bundleData.mapping?.[selectedBundleVariantId].childProducts??bundleVariants[selectedBundleVariantId].childProducts;return selectedBundleVariantProducts?.length&&selectedBundleVariantProducts.forEach(product=>{const obj={id:product.childVariantId,quantity:product.quantity*quantity,selling_plan:selectedSellingPlan,properties:{_bundleId:bundleTransactionId,_isPresetBundleProduct:!0}};bundleData.showBundleName?obj.properties.bundleName=bundleData?.loopBundleName??"":obj.properties._bundleName=bundleData?.loopBundleName??"",formData.items.push(obj)}),formData}async function shopifyAddToCartByLoop(payload,productId2){const endpoint=`${window.Shopify.routes.root}cart/add.js`;fetch(endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(payload)}).then(response=>response.json()).then(async response=>{await dispatchLoopAddCartEvent(productId2,response,null)}
9).catch(error=>{console.error("shopifyAddToCartByLoop",error),enableAddToCartBtnLoop(productId2)})}async function loopHandleAddToCart(event,productId2,quantity=1,bundleVariants2){event.preventDefault(),event.stopPropagation(),disableAddToCartBtnLoop(productId2);const selectedBundleVariantId=window.loopProps[productId2].selectedVariantId;if(!bundleVariants2[selectedBundleVariantId].allowCheckout){console.warn("cannot checkout bundle product"),disableAddToCartBtnLoop(productId2);return}const bundleData=window.loopProps[productId2].productBundleData;let selectedSellingPlan=getSelectedSellingPlanLoop(productId2);const{bundleTransactionId,bundleVariantDiscount}=await handleBundleTransaction(productId2,quantity,selectedSellingPlan);if(!bundleTransactionId)return;const payload=await createAddToCartPayloadLoop(bundleTransactionId,bundleVariantDiscount,selectedSellingPlan,selectedBundleVariantId,quantity,bundleData);await shopifyAddToCartByLoop(payload,productId2)}async function dispatchLoopAddCartEvent(productId2,response,commaSeparatedDiscountString){const addToCartEvent=new CustomEvent("loopPresetAddToCartSuccessEvent",{detail:{productId:productId2,response}});document.dispatchEvent(addToCartEvent)}function updatePrepaidPriceInUILoop({productId:productId2}){const prepaidSellingPlans=window.loopProps[productId2].prepaidSellingPlans;if(!window.loopProps[productId2]?.prepaidSellingPlans)return;let variant=findSelectedVariantLoop(productId2,window.loopProps[productId2].selectedVariantId),sellingPlan=window.loopProps&&window.loopProps[productId2]?window.loopProps[productId2].sellingPlan:{};const product=window.loopProps[productId2]?.product||{},{selling_plan_groups}=product,{selling_plan_allocations}=variant;if(selling_plan_groups.map(spg=>{if(Array.isArray(spg.selling_plans)&&spg.selling_plans.length){let firstSellingPlan=spg.selling_plans[0];if(!prepaidSellingPlans[firstSellingPlan.id]||!prepaidSellingPlans[firstSellingPlan.id]?.isPrepaidV2)return;const deliveriesPerBillingCycle=prepaidSellingPlans[firstSellingPlan.id]?.deliveriesPerBillingCycle||1;
9let sellingPlanAllcotion=selling_plan_allocations.find(a=>Number(a.selling_plan_id)===Number(firstSellingPlan.id))||{};const{selling_plan_group_id,per_delivery_price}=sellingPlanAllcotion;let element=document.querySelector(`#loop-price-${variant.id}-${selling_plan_group_id}`);element&&(element.innerHTML=loopFormatMoney(per_delivery_price/deliveriesPerBillingCycle,!0))}}),sellingPlan&&sellingPlan.selling_plan_group_id){const{selling_plan_group_id,per_delivery_price}=sellingPlan;if(!prepaidSellingPlans[sellingPlan.selling_plan_id]||!prepaidSellingPlans[sellingPlan.selling_plan_id]?.isPrepaidV2)return;const deliveriesPerBillingCycle=prepaidSellingPlans[sellingPlan.selling_plan_id]?.deliveriesPerBillingCycle||1;let element=document.querySelector(`#loop-price-${variant.id}-${selling_plan_group_id}`);element&&(element.innerHTML=loopFormatMoney(per_delivery_price/deliveriesPerBillingCycle,!0))}}function hideDifferentVariantSellingPlansLoop(productData){productData.variants.forEach(variant=>{var sellingPlanIds=variant.selling_plan_allocations.map(allocation=>allocation.selling_plan_id.toString());variant.selling_plan_allocations.forEach(allocation=>{const selectEle=document.querySelector(`#loop-select-${variant.id}-${allocation.selling_plan_group_id}`);selectEle&&selectEle.querySelectorAll("option.loop-selling-plan-selector-option").forEach(function(option){sellingPlanIds.includes(option.value)||(option.style.display="none")})})})}
10//# sourceMappingURL=/cdn/shop/t/161/assets/loop-widget.js.map?v=10627014465394858361791432627

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.