PageSourceSearch

https://xeroshoes.com/cdn/shop/t/152/assets/component-cart-form.js?v=177658051933825227151774526387

js xeroshoes.com collected 2026-09-24 18:02:15 UTC 8,072 bytes, 2 lines download raw bytes

1class AjaxCart extends HTMLElement{constructor(){super(),this.cartForm=this.querySelector("form[data-cart-form]"),this.cartDrawer=document.querySelector("#component-cart-drawer"),this.updateEvents(),this._handleKeydown=e=>{(e.key==="Enter"||e.keyCode===13)&&e.preventDefault()},this.cartForm&&this.cartForm.addEventListener("keydown",this._handleKeydown),this.removeDraftVariant(),this._handleCartUpdate=data=>{const{action,item,section,elementToFocus}=data.data;this._updateCart(section,elementToFocus)};const userAgent=window.navigator.userAgent||"";/\biPhone\b/i.test(userAgent)&&document.documentElement.style.setProperty("--viewport-height",`${window.innerHeight}px`)}static get observedAttributes(){return["updating"]}removeDraftVariant(){this.cartForm.querySelectorAll("[data-item-remove]").forEach(button=>{(button.getAttribute("data-remove")==!0||button.getAttribute("data-remove")=="true")&&button.dispatchEvent(new Event("click"))})}updateEvents(){this.cartForm.querySelectorAll("[data-item-remove]").forEach(button=>button.addEventListener("click",this.removeItem.bind(this))),this.cartForm.querySelectorAll("[data-item-remove]").forEach(button=>{button.addEventListener("keyup",e=>{(e.key==="Enter"||e.keyCode===13)&&this.removeItem(e)})}),this.cartForm.querySelectorAll("[data-qty-input]").forEach(button=>button.addEventListener("change",evt=>{this.onQtyChange(evt)})),window.globalSpace?.settings?.enable_kit_bundles&&(this.cartForm.querySelectorAll("[data-kit-remove]").forEach(btn=>{btn.addEventListener("click",e=>this._removeKit(e))}),this.cartForm.querySelectorAll("[data-kit-qty-btn]").forEach(btn=>{btn.addEventListener("click",e=>this._onKitQtyBtn(e))}),this.cartForm.querySelectorAll("[data-kit-qty-input]").forEach(input=>{input.addEventListener("change",e=>this._updateKitQty(e))})),window?.Shopify?.PaymentButton?.init()}initCartDrawer(elementTofocus){this.cartDrawer?this.cartDrawer.openDrawer(elementTofocus):window.location.href=window.routes.cart_fetch_url||"/cart"}getCartData(){const cartRoute=`${window.location.pathname}?sections=${this.dataset.sectionId}`;fetch(cartRoute).then(response=>response.json()).then(response=>{this._updateCart(response)}).catch(e=>{console.error(e)}).finally(()=>{})}_updateCart(response,openDrawerBtn=null){if(response===null)return;this.setAttribute("updating",!0);let cartHTML=response[this.dataset.sectionId]||response["template-cart"];cartHTML=new DOMParser().parseFromString(cartHTML,"text/html");const cartJSONEle=cartHTML.querySelector("[data-cartScriptJSON]");window.globalSpace.cart=JSON.parse(cartJSONEle.textContent),Utility.updateSourceFromDestination(`#cart-sales-motivator-${this.dataset.sectionId}`,cartHTML),Utility.updateSourceFromDestination(`#cart-form-${this.dataset.sectionId}`,cartHTML),Utility.updateSourceFromDestination(`#cart-subtotal-${this.dataset.sectionId}`,cartHTML),Utility.updateSourceFromDestination(`#cart-discount-${this.dataset.sectionId}`,cartHTML),Utility.updateSourceFromDestination(`#cart-total-${this.dataset.sectionId}`,cartHTML),Utility.updateSourceFromDestination(`#cart-discount-codes-${this.dataset.sectionId}`,cartHTML),Utility.updateSourceFromDestination(`#cart-item-count-${this.dataset.sectionId}`,cartHTML),updateCartCountInHeader();const cartFormContainer=this.querySelector(`#cart-form-container-${this.dataset.sectionId}`);window.globalSpace.cart.item_count<=0?cartFormContainer.classList.add("empty_cart"):cartFormContainer.classList.remove("empty_cart"),this.updateEvents(),this.cartDrawer&&openDrawerBtn&&this.initCartDrawer(openDrawerBtn),lazyImageObserver.observe()}updateItemQty(line,quantity){const lineItem=document.querySelectorAll("[data-cart-item]");lineItem.length>0&&lineItem.forEach(item=>item.classList.add("updating"));const body=JSON.stringify({line:parseInt(line),quantity:parseInt(quantity),sections:`${this.dataset.sectionId}`});fetch(`${routes.cart_change_url}`,{...Utility.fetchConfig(),body}).then(response=>response.text()).then(_state=>{const dataJSON=typeof _state=="object"?_state:JSON.parse(_state);if(dataJSON.errors){Utility.handleError(dataJSON.errors,"Cart Update");
1const cartItem=window.globalSpace.cart.items[line-1],qtyInput=this.cartForm.querySelector(`input[data-qty-input][data-index="${line}"]`);qtyInput&&(qtyInput.value=cartItem.quantity);return}eventBus.publish(PUB_SUB_EVENTS.cartUpdate,{data:{action:quantity==0?"remove-item":"update-qty",item:quantity==0?dataJSON.items_removed:dataJSON.items_added,sections:dataJSON.sections}}),this._updateCart(dataJSON.sections)}).catch(error=>{Utility.handleError(error,"Cart Update")}).finally(()=>{setTimeout(()=>{lineItem.length>0&&lineItem.forEach(item=>item.classList.remove("updating"))},500)})}removeItem(event){event.preventDefault();const{currentTarget}=event,itemIndex=currentTarget.dataset.index||null;itemIndex!==null&&this.updateItemQty(itemIndex,0)}onQtyChange(evt){evt.preventDefault();const $qtyInput=evt.currentTarget,qtyValue=$qtyInput.value,itemIndex=$qtyInput.dataset.index||null;itemIndex&&this.updateItemQty(itemIndex,qtyValue)}_removeKit(event){event.preventDefault();const kitKeys=event.currentTarget.dataset.kitKeys;if(!kitKeys)return;const keys=kitKeys.split(","),updates={};keys.forEach(key=>{updates[key]=0});const lineItems=document.querySelectorAll("[data-cart-item]");lineItems.length>0&&lineItems.forEach(item=>item.classList.add("updating"));const body=JSON.stringify({updates,sections:this.dataset.sectionId});fetch(routes.cart_update_url+".js",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body}).then(response=>response.json()).then(data=>{if(data.errors){Utility.handleError(data.errors,"Cart Update");return}eventBus.publish(PUB_SUB_EVENTS.cartUpdate,{data:{action:"remove-item",item:null,sections:data.sections}}),this._updateCart(data.sections)}).catch(error=>Utility.handleError(error,"Cart Update")).finally(()=>{setTimeout(()=>{lineItems.length>0&&lineItems.forEach(item=>item.classList.remove("updating"))},500)})}_onKitQtyBtn(event){event.preventDefault();const btn=event.currentTarget,direction=btn.dataset.for,kitId=btn.dataset.kitId,qtyInput=this.cartForm.querySelector(`input[data-kit-qty-input][data-kit-id="${kitId}"]`);if(!qtyInput)return;let qty=parseInt(qtyInput.value,10)||1;direction==="increase"?qty+=1:direction==="decrease"&&(qty=Math.max(0,qty-1)),qtyInput.value=qty,qtyInput.dispatchEvent(new Event("change"))}_updateKitQty(event){event.preventDefault();const input=event.currentTarget,kitKeys=input.dataset.kitKeys,prevQty=input.dataset.prevQty||input.defaultValue||input.value,newQty=parseInt(input.value,10);if(!kitKeys||isNaN(newQty))return;input.dataset.prevQty=prevQty;const keys=kitKeys.split(","),updates={};keys.forEach(key=>{updates[key]=newQty});const lineItems=document.querySelectorAll("[data-cart-item]");lineItems.length>0&&lineItems.forEach(item=>item.classList.add("updating"));const rollbackQty=()=>{input.value=prevQty},body=JSON.stringify({updates,sections:this.dataset.sectionId});fetch(routes.cart_update_url+".js",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body}).then(response=>response.json()).then(data=>{if(data.errors){rollbackQty(),Utility.handleError(data.errors,"Cart Update");return}eventBus.publish(PUB_SUB_EVENTS.cartUpdate,{data:{action:newQty===0?"remove-item":"update-qty",item:null,sections:data.sections}}),this._updateCart(data.sections)}).catch(error=>{rollbackQty(),Utility.handleError(error,"Cart Update")}).finally(()=>{setTimeout(()=>{lineItems.length>0&&lineItems.forEach(item=>item.classList.remove("updating"))},500)})}disconnectedCallback(){this.cartForm&&this._handleKeydown&&(this.cartForm.removeEventListener("keydown",this._handleKeydown),this._handleKeydown=null),this.unsubscribeCartUpdate&&(this.unsubscribeCartUpdate(),this.unsubscribeCartUpdate=null),this.cartForm=null,this.cartDrawer=null,this._handleCartUpdate=null}}customElements.define("cart-form",AjaxCart);
2//# sourceMappingURL=/cdn/shop/t/152/assets/component-cart-form.js.map?v=177658051933825227151774526387

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.