1const{formatMoney,getElements,getElement}=window.BAO.Utils,selectors={addToCart:"[data-product-add-to-cart]",addToCartText:"[data-product-add-to-cart-text]",addToCartIcon:"[data-product-add-to-cart-icon]",form:"[data-product-form]",price:"[data-product-price]",priceCompare:"[data-product-price-compare]",priceCompareText:"[data-product-price-compare-text]",sku:"[data-product-sku]",wishlistTrigger:"[data-product-wishlist-trigger]"};class Variant{constructor(data){this.data=data}setPrice(){unhidePriceEls(),getElements(selectors.price).forEach(el=>el.innerHTML=formatMoney(this.data.price).replace(".00","")),getElements(selectors.priceCompare).forEach(el=>el.innerHTML=formatMoney(this.data.compare_at_price).replace(".00","")),this.data.compare_at_price||hidePriceCompareElements();const variantQuantity=getElement("[variant-quantity]");variantQuantity&&(variantQuantity.dataset.variantId=this.id)}setAvailability(){getElements(selectors.addToCart).forEach(el=>el.disabled=!this.data.available),getElements(selectors.addToCartText).forEach(el=>el.textContent=this.data.available?window.theme.strings.addToCart:window.theme.strings.soldOut),getElements(selectors.addToCartIcon).forEach(el=>el.setAttribute("aria-hidden","false"))}updateInput(){getElements('form[action*="/cart/add"] [name="id"]').forEach(input=>{input.value=this.id,input.dispatchEvent(new Event("change",{bubbles:!0}))})}setUrl(){window.history.replaceState({path:this.url.toString()},"",this.url.toString())}setShareUrl(){const shareButtons=getElements("share-button");shareButtons.length!==0&&shareButtons.forEach(shareButton=>{shareButton.updateUrl(this.url.toString())})}updateWishlistTrigger(){const triggers=getElements(selectors.wishlistTrigger);let allHaveAttribute=!0;triggers.forEach(el=>{if(!el.hasAttribute("data-wishlist-active")){allHaveAttribute=!1;return}el.setAttribute("data-variant-id",this.id)}),allHaveAttribute&&document.dispatchEvent(new CustomEvent("checkIsInWishlist"))}get id(){return this.data.id}get url(){const params=new URLSearchParams(window.location.search);params.set("variant",this.id.toString());const url=new URL(window.location.href);return url.search=params.toString(),url}}export class VariantOptions extends window.BAO.CustomElement(){static get requiredElements(){return["data","option","option-choice"]}constructor(){super(),this.collectedVariants=[new Variant(this.defaultVariant)]}setupListeners(){super.setupListeners(),this.onVariantChange=this.onVariantChange.bind(this),this.listeners.add(this,"change",this.onVariantChange),this.listeners.add(this,"change",this.setOption)}async onVariantChange(){await this.onProductOptionChange();const variant=this.getVariant(),optionCategorySize=this.els.option.elements.length;if(this.els["option-choice"].elements.filter(el=>el.checked).length===optionCategorySize&&variant.setAvailability(),variant.setPrice(),variant.updateInput(),variant.updateWishlistTrigger(),!this.currentVariant){this.resetPage(variant);return}variant.setUrl(),variant.setShareUrl()}setOption(event){this.els["option-choice"].elements.forEach(option=>{const optionCategory=option.closest('[data-variant-radios-el="option"]').getAttribute("data-name");event.target.value===option.value&&event.target.name===optionCategory?option.setAttribute("aria-current","true"):event.target.value!==option.value&&event.target.name===optionCategory&&option.setAttribute("aria-current","false")})}resetPage(variant){window.history.replaceState({path:window.location.pathname},"",window.location.pathname)}createVariant(data){const variant=new Variant(data);return this.collectedVariants.push(variant),variant}getVariant(){if(!this.currentVariant)return this.collectedVariants[0];const existingVariant=this.collectedVariants.find(variant=>variant.id===this?.currentVariant?.id);return existingVariant||this.createVariant(this.currentVariant)}async onProductOptionChange(){const productUrl=this.dataset.url,shouldFetchFullPage=!1,selectedOptionValues=this.selectedOptions.map(option=>option.id);await this.fetchProductDetails({requestUrl:this.buildRequestUrlWithParams(productUrl,selectedOptionValues,shouldFetchFullPage),callback:this.renderProductDetails(productUrl)})}buildRequestUrlWithParams(url,optionValues,shouldFetchFullPage=!1){const params=[];return!shouldFetchFullPage&¶ms.push(`section_id=${this.sectionId}`),optionValues.length&¶ms.push(`option_values=${optionValues.join(",")}`),`${url}?${params.join("&")}`}async fetchProductDetails({requestUrl,callback}){this.abortController?.abort(),this.abortController=new AbortController;try{const text=await fetchProductData(requestUrl,this.abortController.signal);this.pendingRequestUrl=void 0;const html=new DOMParser().parseFromString(text,"text/html");callback(html)}catch(e){e.name==="AbortError"?console.info("Fetch aborted by user"):console.error(e)}}renderProductDetails(){return html=>{this.currentVariant=this.getSelectedVariant(html)}}getSelectedVariant(productInfoNode){const selectedVariantDataEl=productInfoNode.querySelector('[data-variant-radios-el="data"]');return selectedVariantDataEl?JSON.parse(selectedVariantDataEl.innerHTML):null}get selectedOptions(){return this.throwError("selectedOptions needs to be implemented on this class"),[]}get defaultVariant(){return this.data}set currentVariant(variant){this._currentVariant=variant}get currentVariant(){return this._currentVariant}get data(){return JSON.parse(this.els.data.element.innerText)}get sectionId(){return this.dataset.originalSection||this.dataset.section}}export class VariantRadios extends VariantOptions{get selectedOptions(){return this.els.option.elements.map(el=>{const{name}=el.dataset,choice=getElements(this.els["option-choice"].selector,{context:el}).find(el2=>el2.checked)?.value,id=getElements(this.els["option-choice"].selector,{context:el}).find(el2=>el2.checked)?.dataset.id;return{label:name,value:choice,id}})}}export class VariantSelects extends VariantOptions{get selectedOptions(){return this.els.option.elements.map(el=>{const{name}=el.dataset;return{label:name,value:el.querySelector("select").value}})}}customElements.get("variant-radios")||customElements.define("variant-radios",VariantRadios),customElements.get("variant-selects")||customElements.define("variant-selects",VariantSelects);
1function hideElements(elements){elements.forEach(el=>el.hidden=!0)}function unhideElements(elements){elements.forEach(el=>el.hidden=!1)}function unhidePriceEls(){unhideElements(getElements(`${selectors.price}, ${selectors.priceCompare}`))}function hidePriceCompareElements(){hideElements(getElements(selectors.priceCompare))}class ProductVariantCache{constructor(){this.cache=new Map}has(key){return this.cache.has(key)}set(key,value){this.cache.set(key,value)}get(key){return this.cache.get(key)}delete(key){this.cache.delete(key)}}const cache=new ProductVariantCache;async function fetchProductData(requestUrl,abortSignal=void 0){if(cache.has(requestUrl))return cache.get(requestUrl);const text=await(await fetch(requestUrl,{signal:abortSignal})).text();return cache.set(requestUrl,text),text} 2//# sourceMappingURL=/cdn/shop/t/291/assets/variants.js.map?v=40920191635882196201763028289
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.