1class CartRemoveButton extends HTMLElement{constructor(){super(),this.addEventListener("click",event=>{event.preventDefault(),(this.closest("cart-items")||this.closest("cart-drawer-items")).updateQuantity(this.dataset.index,0)})}}customElements.define("cart-remove-button",CartRemoveButton);class CartItems extends HTMLElement{constructor(){super(),this.lineItemStatusElement=document.getElementById("shopping-cart-line-item-status")||document.getElementById("CartDrawer-LineItemStatus");const debouncedOnChange=debounce(event=>{this.onChange(event)},ON_CHANGE_DEBOUNCE_TIMER);this.addEventListener("change",debouncedOnChange.bind(this));const cartUpsellToggle=document.getElementById("cart-upsell-toggle");cartUpsellToggle&&cartUpsellToggle.addEventListener("change",this.onCartUpsellToggle.bind(this))}cartUpdateUnsubscriber=void 0;connectedCallback(){this.cartUpdateUnsubscriber=subscribe(PUB_SUB_EVENTS.cartUpdate,event=>{event.source!=="cart-items"&&this.onCartUpdate()}),this.tagName!=="CART-DRAWER-ITEMS"&&fetch(`${routes.cart_url}.js`).then(response=>response.json()).then(parsedState=>{this.updateCartUpsellToggleState(),this.updateCartUpsellVisibility(parsedState.item_count)}).catch(e=>{console.error(e)})}disconnectedCallback(){this.cartUpdateUnsubscriber&&this.cartUpdateUnsubscriber()}onChange(event){this.updateQuantity(event.target.dataset.index,event.target.value,document.activeElement.getAttribute("name"),event.target.dataset.quantityVariantId)}onCartUpdate(){this.tagName==="CART-DRAWER-ITEMS"?fetch(`${routes.cart_url}?section_id=cart-drawer`).then(response=>response.text()).then(responseText=>{const html=new DOMParser().parseFromString(responseText,"text/html"),selectors=["cart-drawer-items",".cart-drawer__footer"];for(const selector of selectors){const targetElement=document.querySelector(selector),sourceElement=html.querySelector(selector);targetElement&&sourceElement&&targetElement.replaceWith(sourceElement)}const parsedStateElement=html.querySelector("[data-cart-drawer-state]"),parsedState=parsedStateElement?JSON.parse(parsedStateElement.textContent):null;this.updateCartUpsellToggleState(),parsedState&&this.updateCartUpsellVisibility(parsedState.item_count)}).catch(e=>{console.error(e)}):fetch(`${routes.cart_url}?section_id=main-cart-items`).then(response=>response.text()).then(responseText=>{const html=new DOMParser().parseFromString(responseText,"text/html"),sourceQty=html.querySelector("cart-items");this.innerHTML=sourceQty.innerHTML;const parsedStateElement=html.querySelector("[data-cart-state]"),parsedState=parsedStateElement?JSON.parse(parsedStateElement.textContent):null;this.updateCartUpsellToggleState(),parsedState&&this.updateCartUpsellVisibility(parsedState.item_count)}).catch(e=>{console.error(e)})}updateCartUpsellToggleState(){const cartUpsellToggle=document.getElementById("cart-upsell-toggle"),scriptTag=document.querySelector("script[data-cart-upsell-variant-id]"),cartUpsellVariantId=scriptTag?scriptTag.dataset.cartUpsellVariantId:"",cartItems=document.querySelectorAll(".cart-item"),upsellItem=Array.from(cartItems).find(item=>{const input=item.querySelector("input[data-quantity-variant-id]");return input&&input.getAttribute("data-quantity-variant-id")===cartUpsellVariantId});cartUpsellToggle&&cartUpsellToggle.checked!==!!upsellItem&&(cartUpsellToggle.checked=!!upsellItem)}updateCartUpsellVisibility(itemCount){const cartUpsellContainer=document.querySelector(".cart-upsell-toggle-container");cartUpsellContainer&&(itemCount===0?cartUpsellContainer.classList.add("hidden"):cartUpsellContainer.classList.remove("hidden"))}onCartUpsellToggle(event){const scriptTag=document.querySelector("script[data-cart-upsell-variant-id]"),cartUpsellVariantId=scriptTag?scriptTag.dataset.cartUpsellVariantId:"";event.target.checked?this.addUpsellProduct(cartUpsellVariantId):this.removingUpsellProduct||(this.removingUpsellProduct=!0,this.removeUpsellProduct(cartUpsellVariantId),this.tagName==="CART-DRAWER-ITEMS"&&event.stopImmediatePropagation())}async addUpsellProduct(cartUpsellVariantId){const upsellFormData=new FormData;upsellFormData.append("id",cartUpsellVariantId),upsellFormData.append("quantity",1);const config=fetchConfig("javascript");config.headers["X-Requested-With"]="XMLHttpRequest",delete config.headers["Content-Type"],config.body=upsellFormData;const response=await fetch(`${routes.cart_add_url}`,config);if(!response.ok){const errorText=await response.text();throw console.error("Failed to add upsell product:",errorText),new Error("Failed to add upsell product")}this.onCartUpdate()}async removeUpsellProduct(cartUpsellVariantId){const cartItems=document.querySelectorAll(".cart-item"),upsellItem=Array.from(cartItems).find(item=>{const input=item.querySelector("input[data-quantity-variant-id]");return input&&input.getAttribute("data-quantity-variant-id")===cartUpsellVariantId});if(!upsellItem){console.error("Upsell product not found in the cart.");return}const upsellIndex=upsellItem.querySelector("input[data-index]").dataset.index;try{await this.updateQuantity(upsellIndex,0,null,cartUpsellVariantId),this.removingUpsellProduct=!1}catch(error){console.error("Error removing upsell product:",error),this.removingUpsellProduct=!1}}getSectionsToRender(){return[{id:"main-cart-items",section:document.getElementById("main-cart-items").dataset.id,selector:".js-contents"},{id:"cart-icon-bubble",section:"cart-icon-bubble",selector:".shopify-section"},{id:"cart-live-region-text",section:"cart-live-region-text",selector:".shopify-section"},{id:"main-cart-footer",section:document.getElementById("main-cart-footer").dataset.id,selector:".js-contents"}]}updateQuantity(line,quantity,name,variantId){this.enableLoading(line);const body=JSON.stringify({line,quantity,sections:this.getSectionsToRender().map(section=>section.section),sections_url:window.location.pathname});
1fetch(`${routes.cart_change_url}`,{...fetchConfig(),body}).then(response=>response.text()).then(state=>{const parsedState=JSON.parse(state),quantityElement=document.getElementById(`Quantity-${line}`)||document.getElementById(`Drawer-quantity-${line}`),items=document.querySelectorAll(".cart-item");if(parsedState.errors){quantityElement.value=quantityElement.getAttribute("value"),this.updateLiveRegions(line,parsedState.errors);return}this.classList.toggle("is-empty",parsedState.item_count===0);const cartDrawerWrapper=document.querySelector("cart-drawer"),cartFooter=document.getElementById("main-cart-footer");cartFooter&&cartFooter.classList.toggle("is-empty",parsedState.item_count===0),cartDrawerWrapper&&cartDrawerWrapper.classList.toggle("is-empty",parsedState.item_count===0),this.getSectionsToRender().forEach(section=>{const elementToReplace=document.getElementById(section.id).querySelector(section.selector)||document.getElementById(section.id);elementToReplace.innerHTML=this.getSectionInnerHTML(parsedState.sections[section.section],section.selector)});const updatedValue=parsedState.items[line-1]?parsedState.items[line-1].quantity:void 0;let message="";items.length===parsedState.items.length&&updatedValue!==parseInt(quantityElement.value)&&(typeof updatedValue>"u"?message=window.cartStrings.error:message=window.cartStrings.quantityError.replace("[quantity]",updatedValue)),this.updateLiveRegions(line,message);const lineItem=document.getElementById(`CartItem-${line}`)||document.getElementById(`CartDrawer-Item-${line}`);lineItem&&lineItem.querySelector(`[name="${name}"]`)?cartDrawerWrapper?trapFocus(cartDrawerWrapper,lineItem.querySelector(`[name="${name}"]`)):lineItem.querySelector(`[name="${name}"]`).focus():parsedState.item_count===0&&cartDrawerWrapper?trapFocus(cartDrawerWrapper.querySelector(".drawer__inner-empty"),cartDrawerWrapper.querySelector("a")):document.querySelector(".cart-item")&&cartDrawerWrapper&&trapFocus(cartDrawerWrapper,document.querySelector(".cart-item__name"));const updatedCartTotal=parsedState.total_price;this.updateProgressBar(updatedCartTotal),publish(PUB_SUB_EVENTS.cartUpdate,{source:"cart-items",cartData:parsedState,variantId}),this.updateCartUpsellToggleState(),this.updateCartUpsellVisibility(parsedState.item_count)}).catch(()=>{this.querySelectorAll(".loading__spinner").forEach(overlay=>overlay.classList.add("hidden"));const errors=document.getElementById("cart-errors")||document.getElementById("CartDrawer-CartErrors");errors.textContent=window.cartStrings.error}).finally(()=>{this.disableLoading(line)})}updateProgressBar(cartTotalCents){const progressWrapper=document.getElementById("cart-progress-wrapper");if(!progressWrapper)return;const currencyFormat=progressWrapper.dataset.currencyFormat,thresholds=progressWrapper.dataset.thresholds.split(",").map(Number),preGoalMessages=progressWrapper.dataset.preGoalMessages.split("||"),postGoalMessages=progressWrapper.dataset.postGoalMessages.split("||"),goalPositions=progressWrapper.dataset.goalPositions.split(",").map(Number),totalThreshold=thresholds[thresholds.length-1],progressPercentage=Math.min(cartTotalCents/totalThreshold*100,100),progressBar=document.getElementById("cart-progress-bar"),goalIcons=document.querySelectorAll(".goal-icon"),goalMessageElement=document.querySelector(".goal-message");if(cartTotalCents===0)progressWrapper.style.display="none",goalMessageElement.style.display="none",progressBar.style.width="0%";else{progressWrapper.style.display="block";const previousWidth=parseFloat(progressBar.style.width)||0;progressBar.style.width=`${progressPercentage}%`,progressPercentage>=100?progressWrapper.classList.add("full"):progressWrapper.classList.remove("full");let nextGoalIndex=-1;for(let i=0;i<thresholds.length;i++)if(cartTotalCents<thresholds[i]){nextGoalIndex=i;break}if(goalIcons.forEach((goalIcon,index)=>{const cartTotalDiff=cartTotalCents-thresholds[index],icon=goalIcon.querySelector("img"),goalNumber=goalIcon.dataset.index;if(icon)if(cartTotalDiff<0){const regularIconUrl=goalIcon.dataset.regularIcon;regularIconUrl&&(icon.src=regularIconUrl,icon.srcset=`${regularIconUrl} 50w`,icon.alt=`Goal ${goalNumber}`)}else{const reachedIconUrl=goalIcon.dataset.reachedIcon;reachedIconUrl&&(icon.src=reachedIconUrl,icon.srcset=`${reachedIconUrl} 50w`,icon.alt=`Goal ${goalNumber} Reached`)}}),goalMessageElement.style.display="block",nextGoalIndex===-1){const message=postGoalMessages[postGoalMessages.length-1];goalMessageElement.innerHTML=message}
1else{const remainingAmount=(thresholds[nextGoalIndex]-cartTotalCents)/100,remainingAmountFormatted=this.formatCurrency(currencyFormat,remainingAmount),message=preGoalMessages[nextGoalIndex].replace("[x]",remainingAmountFormatted);goalMessageElement.innerHTML=message}}}formatCurrency(currencyFormat,amount){let formattedAmount="";return formattedAmount=currencyFormat.replace("{{amount}}",amount.toFixed(2)).replace("{{amount_no_decimals}}",amount.toFixed(0)).replace("{{amount_with_comma_separator}}",amount.toFixed(2).replace(".",",")).replace("{{amount_no_decimals_with_comma_separator}}",amount.toFixed(0).replace(".",",")).replace("{{amount_with_apostrophe_separator}}",amount.toFixed(2).replace(".","'")).replace("{{amount_no_decimals_with_space_separator}}",amount.toFixed(0).replace(/\\B(?=(\\d{3})+(?!\\d))/g," ")).replace("{{amount_with_space_separator}}",amount.toFixed(2).replace(/\\B(?=(\\d{3})+(?!\\d))/g," ").replace(".",",")).replace("{{amount_with_period_and_space_separator}}",amount.toFixed(2).replace(/\\B(?=(\\d{3})+(?!\\d))/g," ")),formattedAmount}formatCurrency(currencyFormat,amount){let formattedAmount="";return formattedAmount=currencyFormat.replace("{{amount}}",amount.toFixed(2)).replace("{{amount_no_decimals}}",amount.toFixed(0)).replace("{{amount_with_comma_separator}}",amount.toFixed(2).replace(".",",")).replace("{{amount_no_decimals_with_comma_separator}}",amount.toFixed(0).replace(".",",")).replace("{{amount_with_apostrophe_separator}}",amount.toFixed(2).replace(".","'")).replace("{{amount_no_decimals_with_space_separator}}",amount.toFixed(0).replace(/\\B(?=(\\d{3})+(?!\\d))/g," ")).replace("{{amount_with_space_separator}}",amount.toFixed(2).replace(/\\B(?=(\\d{3})+(?!\\d))/g," ").replace(".",",")).replace("{{amount_with_period_and_space_separator}}",amount.toFixed(2).replace(/\\B(?=(\\d{3})+(?!\\d))/g," ")),formattedAmount}updateLiveRegions(line,message){const lineItemError=document.getElementById(`Line-item-error-${line}`)||document.getElementById(`CartDrawer-LineItemError-${line}`);lineItemError&&(lineItemError.querySelector(".cart-item__error-text").innerHTML=message),this.lineItemStatusElement.setAttribute("aria-hidden",!0);const cartStatus=document.getElementById("cart-live-region-text")||document.getElementById("CartDrawer-LiveRegionText");cartStatus.setAttribute("aria-hidden",!1),setTimeout(()=>{cartStatus.setAttribute("aria-hidden",!0)},1e3)}getSectionInnerHTML(html,selector){return new DOMParser().parseFromString(html,"text/html").querySelector(selector).innerHTML}enableLoading(line){(document.getElementById("main-cart-items")||document.getElementById("CartDrawer-CartItems")).classList.add("cart__items--disabled");const cartItemElements=this.querySelectorAll(`#CartItem-${line} .loading__spinner`),cartDrawerItemElements=this.querySelectorAll(`#CartDrawer-Item-${line} .loading__spinner`);
1[...cartItemElements,...cartDrawerItemElements].forEach(overlay=>overlay.classList.remove("hidden")),document.activeElement.blur(),this.lineItemStatusElement.setAttribute("aria-hidden",!1)}disableLoading(line){(document.getElementById("main-cart-items")||document.getElementById("CartDrawer-CartItems")).classList.remove("cart__items--disabled");const cartItemElements=this.querySelectorAll(`#CartItem-${line} .loading__spinner`),cartDrawerItemElements=this.querySelectorAll(`#CartDrawer-Item-${line} .loading__spinner`);cartItemElements.forEach(overlay=>overlay.classList.add("hidden")),cartDrawerItemElements.forEach(overlay=>overlay.classList.add("hidden"))}}customElements.define("cart-items",CartItems),customElements.get("cart-note")||customElements.define("cart-note",class extends HTMLElement{constructor(){super(),this.addEventListener("change",debounce(event=>{const body=JSON.stringify({note:event.target.value});fetch(`${routes.cart_update_url}`,{...fetchConfig(),body})},ON_CHANGE_DEBOUNCE_TIMER))}});const cartUpdatedEvent=new CustomEvent("cartUpdated",{detail:{message:"Cart was updated"}});document.dispatchEvent(cartUpdatedEvent); 2//# sourceMappingURL=/cdn/shop/t/20/assets/cart.js.map?v=103542094622053638521764675109
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.