1const VedgeSubscriptionsHandler=(function(){"use strict";const sellingPlanMap=[];let logicVersion=null,controlType="radio";return{init,createSellingPlanInput,addListeners,addSellingPlanMapEntry,updateSellingPlanInput:_updateSellingPlanInput};function init(_logicVersion,_controlType){logicVersion=_logicVersion,controlType=_controlType}function createSellingPlanInput(form,value){_deleteSellingPlanInput(form);var sellingPlanInput=document.createElement("input");sellingPlanInput.setAttribute("type","hidden"),sellingPlanInput.setAttribute("name","selling_plan"),sellingPlanInput.setAttribute("class","vedge_selling_plan_input"),sellingPlanInput.setAttribute("value",value),form.appendChild(sellingPlanInput)}function addListeners(form){const formVariantSelect=_findFormVariantSelect(form);formVariantSelect&&formVariantSelect.addEventListener("change",function(){_rebuildUiAfterVariantChange(form)});const formChosenSellingPlanSelect=form.querySelector('select[id="chosen_selling_plan_id"]');formChosenSellingPlanSelect&&formChosenSellingPlanSelect.addEventListener("change",function(){_updateSellingPlanInput(form)});const formOneTime=form.querySelector('input[id="selling_plan_onetime');formOneTime&&formOneTime.addEventListener("change",function(){_updateSellingPlanInput(form)});const formSubscribe=form.querySelector('input[id="selling_plan_subscribe');formSubscribe&&formSubscribe.addEventListener("change",function(){_updateSellingPlanInput(form)})}function addSellingPlanMapEntry(key,value){sellingPlanMap[key]=value}function _rebuildUiAfterVariantChange(form){const variantId=_findSelectedVariantId(form);_deleteChosenSellingPlanSelect(form);const formChosenSellingPlanSelect=form.querySelector('select[id="chosen_selling_plan_id"]');
1sellingPlanMap[variantId].forEach(plan=>{const sellingPlanId=plan.sellingPlanId,label=plan.label;_addSelectOption(formChosenSellingPlanSelect,sellingPlanId,label)}),_updateSellingPlanInput(form)}function _isSelectedOneTime(form){return form.querySelector('input[id="selling_plan_onetime').checked}function _isSelectedSubscription(form){return form.querySelector('input[id="selling_plan_subscribe').checked}function _updateSellingPlanInput(form){const sellingPlanId=form.querySelector('select[id="chosen_selling_plan_id"]').value;let shouldSubscribe=!1;switch(controlType){case"radio":_isSelectedOneTime(form)?_deleteSellingPlanInput(form):_isSelectedSubscription(form)&&(shouldSubscribe=!0,createSellingPlanInput(form,sellingPlanId));break;case"checkbox":_isSelectedSubscription(form)?(shouldSubscribe=!0,createSellingPlanInput(form,sellingPlanId)):_deleteSellingPlanInput(form);break}const variantId=_findSelectedVariantId(form),priceFull=VedgeProductPageHandler.getVariantPrice(variantId),priceSub=Math.round(priceFull*.85,2),priceTextFull="$"+priceFull/100,priceTextSub="$"+priceSub/100;let priceTextSelected=priceTextFull;shouldSubscribe&&(priceTextSelected=priceTextSub),_updatePriceElements(form,priceTextFull,priceTextSub,priceTextSelected)}function _updatePriceElements(form,priceTextFull,priceTextSub,priceTextSelected){form.querySelectorAll('[data-price-text-type="full"').forEach(el=>{el.innerHTML=priceTextFull}),form.querySelectorAll('[data-price-text-type="sub"').forEach(el=>{el.innerHTML=priceTextSub}),form.querySelectorAll('[data-price-text-type="selected"').forEach(el=>{el.innerHTML=priceTextSelected}),logicVersion==="v3"&&_runFunctionWithDelay(()=>{form.querySelector("#AddToCart").innerHTML=priceTextSelected+" - BUY NOW"})}function _runFunctionWithDelay(fn,delay=1e3){fn(),setTimeout(()=>{fn()},delay)}function _deleteSellingPlanInput(form){const existingSellingPlanInput=form.querySelector('input[name="selling_plan"]');existingSellingPlanInput&&existingSellingPlanInput.remove()}function _deleteChosenSellingPlanSelect(form){const formChosenSellingPlanSelect=form.querySelector('select[id="chosen_selling_plan_id"]');if(formChosenSellingPlanSelect)for(;formChosenSellingPlanSelect.lastChild;)formChosenSellingPlanSelect.removeChild(formChosenSellingPlanSelect.lastChild)}function _addSelectOption(selectEl,value,label){selectEl.options[selectEl.options.length]=new Option(label,value)}function _findFormVariantInput(form){return form.querySelector('[name="id"]')}function _findFormVariantSelect(form){let elSelect;if(elSelect=form.querySelector('select[name="id"]'),elSelect||(elSelect=form.querySelector('select[data-key="Flavor"]'),elSelect))return elSelect}function _findSelectedVariantId(form){return _findFormVariantInput(form).value}})(); 2//# sourceMappingURL=/cdn/shop/t/53/assets/vedge-handler-subscriptions.js.map?v=51447158654658348631771448183
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.