1(function(){if(window.customElements.get("shipping-protection"))return;var HANDLE="esther-shipping-protection",root=(window.Shopify&&window.Shopify.routes&&window.Shopify.routes.root||"/").replace(/\/$/,"");function postJSON(path,payload){return fetch(root+path,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(payload)}).then(function(res){if(!res.ok)throw new Error("Cart request failed: "+res.status);return res.json()})}function getCart(){return fetch(root+"/cart.js",{headers:{Accept:"application/json"}}).then(function(res){if(!res.ok)throw new Error("Could not read cart");return res.json()})}function protectionLine(cart){for(var i=0;i<cart.items.length;i+=1)if(cart.items[i].handle===HANDLE)return cart.items[i];return null}function refreshCart(){var forms=document.querySelectorAll("cart-form");forms.length?Array.prototype.forEach.call(forms,function(form){typeof form.refresh=="function"&&form.refresh()}):document.dispatchEvent(new CustomEvent("dispatch:cart-drawer:refresh"))}class ShippingProtection extends HTMLElement{connectedCallback(){this.input=this.querySelector(".shipping-protection__input"),this.variantId=Number(this.dataset.variantId),this.correcting=!1,this.input&&this.input.addEventListener("change",this.onChange.bind(this)),this.onCartEvent=this.sync.bind(this),document.addEventListener("on:cart:after-merge",this.onCartEvent,!0),document.addEventListener("on:line-item:change",this.onCartEvent,!0),this.sync()}disconnectedCallback(){document.removeEventListener("on:cart:after-merge",this.onCartEvent,!0),document.removeEventListener("on:line-item:change",this.onCartEvent,!0)}setBusy(state){state?this.setAttribute("aria-busy","true"):this.removeAttribute("aria-busy"),this.input&&(this.input.disabled=state)}setQuantity(quantity){return getCart().then(function(cart){var line=protectionLine(cart);return line?postJSON("/cart/change.js",{id:String(line.key),quantity}):null})}onChange(){var self=this,wanted=this.input.checked;this.setBusy(!0);var op=wanted?postJSON("/cart/add.js",{items:[{id:this.variantId,quantity:1}]}):this.setQuantity(0);op.then(function(){return refreshCart(),self.sync()}).catch(function(){self.input.checked=!wanted,self.setBusy(!1)})}sync(){var self=this;return this.correcting?Promise.resolve():getCart().then(function(cart){var protectionQty=0,otherQty=0;if(cart.items.forEach(function(item){item.handle===HANDLE?protectionQty+=item.quantity:otherQty+=item.quantity}),protectionQty>0&&otherQty===0)return self.correcting=!0,self.setQuantity(0).then(function(){self.correcting=!1,refreshCart(),self.hidden=!0,self.input&&(self.input.checked=!1),self.setBusy(!1)});if(protectionQty>1)return self.correcting=!0,self.setQuantity(1).then(function(){self.correcting=!1,refreshCart(),self.hidden=!1,self.input&&(self.input.checked=!0),self.setBusy(!1)});self.hidden=otherQty===0,self.input&&(self.input.checked=protectionQty===1),self.setBusy(!1)}).catch(function(){self.correcting=!1,self.setBusy(!1)})}}window.customElements.define("shipping-protection",ShippingProtection)})(); 2//# sourceMappingURL=/cdn/shop/t/569/assets/shipping-protection.js.map?v=156399710084942383251790152707
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.