1var BsubWidget=(function(){function BsubWidget2(){this.attrs={purchaseOptionOneTime:"data-bsub-purchase-option-one-time",sellingPlanGroupId:"data-bsub-selling-plan-group-id",sellingPlanIdInput:"data-bsub-selling-plan-id-input",widget:"data-bsub-widget",sellingPlanOptionsContainer:"data-bsub-selling-plan-options-container",sellingPlanOption:"data-bsub-selling-plan-option",sellingPlansContainer:"data-bsub-selling-plans-container",sellingPlanGroup:"data-bsub-selling-plan-group",sellingPlanGroupInput:"data-bsub-selling-plan-group-input",sellingPlan:"data-bsub-selling-plan",sellingPlanInput:"data-bsub-selling-plan-input",productJson:"data-bsub-product-json",groupDiscountSummary:"data-bsub-group-discount-summary",perDeliveryPrice:"data-bsub-per-delivery-price",cartPopupDetails:"data-bsub-cart-popup-details",cartPageDetails:"data-bsub-cart-page-details",moneyFormat:"data-bsub-money-format",pageTemplate:"data-bsub-page-template"},this.selectors={productForm:'form[action="/cart/add"]',variantIdInput:'[name="id"]',variantSelector:["#shappify-variant-id",".single-option-selector","select[name=id]","input[name=id]"]},Object.entries(this.attrs).forEach(function([key,value]){this.selectors[key]=`[${value}]`}.bind(this)),this.classes={hidden:"bsub__hidden"},this.products={},this.variants={},this.sellingPlanGroups={},this.pageTemplate=""}return BsubWidget2.prototype=Object.assign({},BsubWidget2.prototype,{init:function(){if(console.debug("BSUB: Initializing widgets..."),!document.querySelector(this.selectors.widget)){console.debug("BSUB: No widgets detected, skipping initialization.");return}this._parsePageTemplate(),this._parseProductJson(),this._addVariantChangeListener();var widgets=document.querySelectorAll(this.selectors.widget);widgets.forEach(function(widget){this._renderPrices(widget),this._renderGroupDiscountSummary(widget)}.bind(this)),window.addEventListener("pageshow",function(){this.syncAllVisuallySelected()}.bind(this)),console.debug("BSUB: Successfully initialized widgets.")},syncAllVisuallySelected:function(){var widgets=document.querySelectorAll(this.selectors.widget);widgets.forEach(this._syncVisuallySelected.bind(this))},_syncVisuallySelected:function(widget){var selectedGroupEl=widget.querySelector(`${this.selectors.sellingPlanGroupInput}:checked`);selectedGroupEl.dispatchEvent(new Event("change"))},_addVariantChangeListener:function(){var selectors=document.querySelectorAll(this.selectors.variantSelector.join());selectors.forEach(function(select){select&&select.addEventListener("change",function(event){var productForm=event.target.closest(this.selectors.productForm),widget=productForm.querySelector(this.selectors.widget);setTimeout(function(){this._renderPrices(widget),this._renderGroupDiscountSummary(widget)}.bind(this),100)}.bind(this))}.bind(this))},_parsePageTemplate:function(){var pageTemplateInputEl=document.querySelector(this.selectors.pageTemplate);pageTemplateInputEl!==null&&(this.pageTemplate=pageTemplateInputEl.value)},_parseProductJson:function(){var productJsonElements=document.querySelectorAll(this.selectors.productJson);productJsonElements.forEach(function(element){var productJson=JSON.parse(element.innerHTML);this.products[element.dataset.bsubProductId]=productJson,productJson.selling_plan_groups.forEach(function(sellingPlanGroup){this.sellingPlanGroups[sellingPlanGroup.id]=sellingPlanGroup}
1.bind(this)),productJson.variants.forEach(function(variant){this.variants[variant.id]=variant}.bind(this))}.bind(this))},renderAllPrices:function(){var widgets=document.querySelectorAll(this.selectors.widget);widgets.forEach(this._renderPrices.bind(this))},_renderPrices:function(widget){typeof widget>"u"&&(widget=document.querySelector(this.selectors.widget));var planRadioEls=widget.querySelectorAll(this.selectors.sellingPlan),variantId=this._getVariantId(widget);variantId&&planRadioEls.forEach(function(element){var sellingPlanId=element.dataset.bsubSellingPlanId,sellingPlanAllocation=this._getSellingPlanAllocation(variantId,sellingPlanId),priceEl=element.querySelector(this.selectors.perDeliveryPrice),price=sellingPlanAllocation.per_delivery_price,formattedPrice=this._formatPrice(price);priceEl.innerHTML=formattedPrice}.bind(this))},renderAllGroupDiscountSummary:function(){var widgets=document.querySelectorAll(this.selectors.widget);widgets.forEach(this._renderGroupDiscountSummary.bind(this))},_renderGroupDiscountSummary:function(widget){var productJsonEl=widget.querySelector(this.selectors.productJson),productId=productJsonEl.dataset.bsubProductId,groupRadioEls=widget.querySelectorAll(this.selectors.sellingPlanGroup);groupRadioEls.forEach(function(element){var groupId=element.dataset.bsubSellingPlanGroupId,product=this.products[productId],sellingPlanGroup=product.selling_plan_groups.find(function(group){return group.id===groupId}),discounts=sellingPlanGroup.selling_plans.map(function(plan){return plan.price_adjustments.length===0?{value:0,type:""}:{value:plan.price_adjustments[0].value,type:plan.price_adjustments[0].value_type}}),maxDiscount=discounts.reduce(function(a,b){return a.value>b.value?a:b});if(maxDiscount.value!==0){var upTo=discounts.some(function(discount){return discount.value!==maxDiscount.value}),summaryEl=element.querySelector(this.selectors.groupDiscountSummary),summaryString="(Save ";upTo&&(summaryString+="up to "),maxDiscount.type==="fixed_amount"?summaryString+=this._formatPrice(maxDiscount.value):summaryString+=` ${maxDiscount.value}%`,summaryString+=")",summaryEl.innerHTML=summaryString}}.bind(this))},handleSellingPlanGroupChange:function(event){var groupRadioEl=event.target,groupId=groupRadioEl.value,widget=groupRadioEl.closest(this.selectors.widget),plansContainers=widget.querySelectorAll(this.selectors.sellingPlansContainer);if(plansContainers.forEach(function(plansContainer){var plansContainerGroupId=plansContainer.dataset.bsubSellingPlanGroupId;plansContainerGroupId===groupId&&groupRadioEl.checked?plansContainer.classList.remove(this.classes.hidden):plansContainer.classList.add(this.classes.hidden)}.bind(this)),groupId==="once"){this._setSellingPlanIdInput(widget,"");return}var sellingPlanId=this._getActiveSellingPlanId(widget,groupId);this._setSellingPlanIdInput(widget,sellingPlanId)},handleSellingPlanChange:function(event){var planRadioEl=event.target,widget=planRadioEl.closest(this.selectors.widget);this._setSellingPlanIdInput(widget,planRadioEl.value)},handleSellingPlanOptionChange:function(event){var widget=event.target.closest(this.selectors.widget),sellingPlanGroupId=event.target.dataset.bsubSellingPlanGroupId,selectedOptions=this._getSellingPlanOptions(widget,sellingPlanGroupId),sellingPlan=this._getSellingPlanFromOptions(sellingPlanGroupId,selectedOptions);this._setSellingPlanIdInput(sellingPlan.id)},_setSellingPlanIdInput:function(widget,sellingPlanId){var sellingPlanIdInput=widget.querySelector(this.selectors.sellingPlanIdInput),variantId=this._getVariantId(widget);sellingPlanIdInput.value=sellingPlanId,/.*(product).*/.test(this.pageTemplate)&&this._updateHistoryState(variantId,sellingPlanId)},_getSellingPlanGroup:function(groupId){if(!this.sellingPlanGroups[groupId]){console.error("BSUB: Selling plan group data not found.");return}return this.sellingPlanGroups[groupId]},_getSellingPlanOptions:function(widget,sellingPlanGroupId){var sellingPlanOptions=widget.querySelectorAll(`${this.selectors.sellingPlanOption}[${this.attrs.sellingPlanGroupId}="${sellingPlanGroupId}"]:checked`),selectedOptions=[];return sellingPlanOptions.forEach(function(optionElement){selectedOptions.push({index:optionElement.dataset.bsubOptionIndex,value:optionElement.value})}),selectedOptions},_getSellingPlanFromOptions:function(groupId,selectedOptions){var sellingPlans=this._getSellingPlanGroup(groupId).selling_plans,planFromOptions=sellingPlans.find(function(plan){return selectedOptions.every(function(option){return plan.options[option.index].value===option.value})});return planFromOptions},_getVariantId:function(widget){var productForm=widget.closest(this.selectors.productForm);if(!productForm)return console.error("BSUB: Could not find product form."),null;var variantIdInput=productForm.querySelector(this.selectors.variantIdInput);return variantIdInput.value},_getActiveSellingPlanId:function(widget,groupId){var activePlanInputEl=widget.querySelector(`input[name=bsub-selling-plan-${groupId}]:checked`);return activePlanInputEl||console.error(`BSUB: Could not find active plan ID for group ${groupId}.`),activePlanInputEl.value},_updateHistoryState:function(variantId,sellingPlanId){if(!(!history.replaceState||!variantId)){var newurl=window.location.protocol+"//"+window.location.host+window.location.pathname+"?";sellingPlanId&&(newurl+="selling_plan="+sellingPlanId+"&"),newurl+="variant="+variantId,window.history.replaceState({path:newurl},"",newurl)}},_getSellingPlanAllocation(variantId,sellingPlanId){var variant=this.variants[variantId];return variant?variant.selling_plan_allocations.find(function(plan){return`${plan.selling_plan_id}`===sellingPlanId}):(console.error(`BSUB: Could not find variant ID ${variantId}`),null)},_formatPrice(cents,format){var moneyElement=document.querySelector(this.selectors.moneyFormat),moneyFormat=moneyElement?moneyElement.getAttribute("data-bsub-money-format"):null;typeof cents=="string"&&(cents=cents.replace(".",""));var value="",placeholderRegex=/\{\{\s*(\w+)\s*\}\}/,themeMoneyFormat=this._getThemeMoneyFormat(),formatString=format||moneyFormat||themeMoneyFormat;function formatWithDelimiters(number,precision,thousands,decimal){if(thousands=thousands||",",decimal=decimal||".",isNaN(number)||number===null)return 0;number=(number/100).toFixed(precision);var parts=number.split("."),dollarsAmount=parts[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1"+thousands),centsAmount=parts[1]?decimal+parts[1]:"";return dollarsAmount+centsAmount}switch(formatString.match(placeholderRegex)[1]){case"amount":value=formatWithDelimiters(cents,2);break;case"amount_no_decimals":value=formatWithDelimiters(cents,0);break;case"amount_with_comma_separator":value=formatWithDelimiters(cents,2,".",",");break;case"amount_no_decimals_with_comma_separator":value=formatWithDelimiters(cents,0,".",",");break;case"amount_no_decimals_with_space_separator":value=formatWithDelimiters(cents,0," ");break;case"amount_with_apostrophe_separator":value=formatWithDelimiters(cents,2,"'");break}return formatString.replace(placeholderRegex,value)},_getThemeMoneyFormat(){if(typeof Shopify<"u"&&typeof Shopify.money_format<"u")return Shopify.money_format;if(typeof theme<"u"){if(typeof theme.moneyFormat<"u")return theme.moneyFormat;if(typeof theme.strings<"u"&&typeof theme.strings.moneyFormat<"u")return theme.strings.moneyFormat;if(typeof theme.shop<"u"&&typeof theme.shop.money_format<"u")return theme.shop.money_format}return"${{ amount }}"}}),BsubWidget2})();document.addEventListener("DOMContentLoaded",function(){window.BOLD=window.BOLD||{},window.BOLD.BsubWidget=new BsubWidget,window.BOLD.BsubWidget.init()}); 2//# sourceMappingURL=/cdn/shop/t/186/assets/bsub.js.map?v=158520562351594542841788444715
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.