1import{executeJSmodules}from"@archetype-themes/utils/utils";import{EVENTS}from"@archetype-themes/utils/events";export default class CartForm{constructor(form){this.selectors={products:"[data-products]",discounts:"[data-discounts]",subTotal:"[data-subtotal]",locales:"[data-locales]",termsCheckbox:".cart__terms-checkbox",checkoutBtn:".cart__checkout"},this.classes={btnLoading:"btn--loading"},this.config={requiresTerms:!1},form&&(this.form=form,this.wrapper=form.parentNode,this.products=form.querySelector(this.selectors.products),this.submitBtn=form.querySelector(this.selectors.checkoutBtn),this.discounts=form.querySelector(this.selectors.discounts),this.subtotal=form.querySelector(this.selectors.subTotal),this.termsCheckbox=form.querySelector(this.selectors.termsCheckbox),this.locales=JSON.parse(this.form.querySelector(this.selectors.locales).textContent),this.termsCheckbox&&(this.config.requiresTerms=!0),this.init())}init(){document.addEventListener("cart:quantity",this.quantityChanged.bind(this)),this.form.addEventListener("submit",this.onSubmit.bind(this)),document.addEventListener("cart:build",function(){this.buildCart()}.bind(this))}onSubmit(evt){if(this.submitBtn.classList.add(this.classes.btnLoading),document.documentElement.classList.contains("js-drawer-open")&&this.cartItemsUpdated||document.documentElement.classList.contains("cart-open")&&this.cartItemsUpdated)return this.submitBtn.classList.remove(this.classes.btnLoading),evt.preventDefault(),!1;if(this.config.requiresTerms&&!this.termsCheckbox.checked)return alert(this.locales.cartTermsConfirmation),this.submitBtn.classList.remove(this.classes.btnLoading),evt.preventDefault(),!1}_parseProductHTML(text){const html=document.createElement("div");return html.innerHTML=text,{items:html.querySelector(".cart__items"),discounts:html.querySelector(".cart__discounts"),subtotal:html.querySelector(".cart__subtotal"),count:html.querySelector(".cart-link__bubble")}}buildCart(){return this.getCartProductMarkup().then(this.cartMarkup.bind(this))}cartMarkup(text){const markup=this._parseProductHTML(text),items=markup.items,count=parseInt(items.dataset.count),subtotal=markup.subtotal.innerHTML;this.updateCartDiscounts(markup.discounts),count>0?this.wrapper.classList.remove("is-empty"):this.wrapper.classList.add("is-empty"),this.products.innerHTML="",this.products.append(items);const scripts=this.products.querySelectorAll('script[type="module"]');executeJSmodules(scripts),this.subtotal.innerHTML=subtotal,Shopify&&Shopify.StorefrontExpressButtons&&Shopify.StorefrontExpressButtons.initialize()}updateCartDiscounts(markup){this.discounts&&(this.discounts.innerHTML="",this.discounts.append(markup))}quantityChanged(evt){const key=evt.detail[0],qty=evt.detail[1],el=evt.detail[2];!key||!qty||(el&&el.classList.add("is-loading"),this.changeItem({id:key,quantity:qty,sections:"cart-ajax"}).then(state=>{this.cartMarkup(state.sections["cart-ajax"]),document.dispatchEvent(new CustomEvent(EVENTS.cartUpdated,{detail:{cart:state}}))}).catch(async response=>{const data=await response.json();alert(data.description),el.classList.remove("is-loading"),el.firstElementChild.value=el.firstElementChild.dataset.initialValue}))}changeItem(body){return fetch(`${window.Shopify.routes.root}cart/change.js`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(body)}).then(response=>{if(!response.ok)throw response;return response.json()})}getCartProductMarkup(){let url=`${window.Shopify.routes.root}?section_id=cart-ajax`;return fetch(url,{credentials:"same-origin",method:"GET"}).then(response=>response.text()).catch(e=>console.error(e))}} 2//# sourceMappingURL=/cdn/shop/t/40/assets/cart-form.js.map?v=112467115607385685851789141389
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.