1import"@archetype-themes/scripts/helpers/utils";theme.Variants=(function(){function Variants(options){this.container=options.container,this.variants=options.variants,this.singleOptionSelector=options.singleOptionSelector,this.originalSelectorId=options.originalSelectorId,this.enableHistoryState=options.enableHistoryState,this.dynamicVariantsEnabled=options.dynamicVariantsEnabled,this.currentlySelectedValues=this._getCurrentOptions(),this.currentVariant=this._getVariantFromOptions(),this.container.querySelectorAll(this.singleOptionSelector).forEach(el=>{el.addEventListener("change",this._onSelectChange.bind(this))})}return Variants.prototype=Object.assign({},Variants.prototype,{_getCurrentOptions:function(){var result=[];return this.container.querySelectorAll(this.singleOptionSelector).forEach(el=>{var type=el.getAttribute("type");type==="radio"||type==="checkbox"?el.checked&&result.push({value:el.value,index:el.dataset.index}):result.push({value:el.value,index:el.dataset.index})}),result=theme.utils.compact(result),result},_numberFromOptionKey:function(key){return parseInt(key.substr(-1))},_getWeightedOptionMatchCount:function(variant){return this._getCurrentOptions().reduce((count,{value,index})=>{const weightedCount=4-this._numberFromOptionKey(index);return variant[index]===value?count+weightedCount:count},0)},_getFullMatch(needsToBeAvailable){const currentlySelectedOptions=this._getCurrentOptions();return this.variants.find(variant=>{const isMatch=currentlySelectedOptions.every(({value,index})=>variant[index]===value);return needsToBeAvailable?isMatch&&variant.available:isMatch})},_getClosestAvailableMatch:function(lastSelectedOption){if(!lastSelectedOption)return null;const currentlySelectedOptions=this._getCurrentOptions(),variants=this.variants;return(lastSelectedOption&&variants.filter(variant=>currentlySelectedOptions.filter(({value,index})=>this._numberFromOptionKey(index)<=this._numberFromOptionKey(lastSelectedOption.index)).every(({value,index})=>variant[index]===value)&&variant.available)).reduce((bestMatch,variant)=>{if(bestMatch===null)return variant;const bestMatchCount=this._getWeightedOptionMatchCount(bestMatch,lastSelectedOption);return this._getWeightedOptionMatchCount(variant,lastSelectedOption)>bestMatchCount?variant:bestMatch},null)},_getVariantFromOptions:function(lastSelectedOption){const availableFullMatch=this._getFullMatch(!0),closestAvailableMatch=this._getClosestAvailableMatch(lastSelectedOption),fullMatch=this._getFullMatch(!1);return this.dynamicVariantsEnabled?availableFullMatch||closestAvailableMatch||fullMatch||null:fullMatch||null},_updateInputState:function(variant,el){return input=>{if(variant===null)return;const index=input.dataset.index,value=input.value,type=input.getAttribute("type");type==="radio"||type==="checkbox"?input.checked=variant[index]===value:input.value=variant[index]}},_onSelectChange:function({srcElement}){const optionSelectElements=this.container.querySelectorAll(this.singleOptionSelector),variant=this._getVariantFromOptions({index:srcElement.dataset.index,value:srcElement.value});optionSelectElements.forEach(this._updateInputState(variant,srcElement));const currentlySelectedValues=this.currentlySelectedValues=this._getCurrentOptions(),detail={variant,currentlySelectedValues,value:srcElement.value,index:srcElement.parentElement.dataset.index};this.container.dispatchEvent(new CustomEvent("variantChange",{detail})),document.dispatchEvent(new CustomEvent("variant:change",{detail})),variant&&(this._updateMasterSelect(variant),this._updateImages(variant),this._updatePrice(variant),this._updateUnitPrice(variant),this._updateSKU(variant),this.currentVariant=variant,this.enableHistoryState&&this._updateHistoryState(variant))},_updateImages:function(variant){variant.featured_image&&this.container.dispatchEvent(new CustomEvent("variantImageChange",{detail:{variant}}))},_updatePrice:function(variant){this.currentVariant&&variant.price===this.currentVariant.price&&variant.compare_at_price===this.currentVariant.compare_at_price||this.container.dispatchEvent(new CustomEvent("variantPriceChange",{detail:{variant}}
1))},_updateUnitPrice:function(variant){this.currentVariant&&variant.unit_price===this.currentVariant.unit_price||this.container.dispatchEvent(new CustomEvent("variantUnitPriceChange",{detail:{variant}}))},_updateSKU:function(variant){this.currentVariant&&variant.sku===this.currentVariant.sku||this.container.dispatchEvent(new CustomEvent("variantSKUChange",{detail:{variant}}))},_updateHistoryState:function(variant){if(!(!history.replaceState||!variant)){var newurl=window.location.protocol+"//"+window.location.host+window.location.pathname+"?variant="+variant.id;window.history.replaceState({path:newurl},"",newurl)}},_updateMasterSelect:function(variant){let masterSelect=this.container.querySelector(this.originalSelectorId);masterSelect&&(masterSelect.value=variant.id,masterSelect.dispatchEvent(new Event("change",{bubbles:!0})))}}),Variants})(); 2//# sourceMappingURL=/cdn/shop/t/14/assets/variants.js.map?v=3033049893411379561714100891
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.