PageSourceSearch

https://crownandcoastal.com/cdn/shop/t/16/assets/cart-checkbox-upsell.js?v=84649628755235268891773511259

js crownandcoastal.com collected 2026-10-04 18:05:06 UTC 3,528 bytes, 2 lines download raw bytes

1class CartCheckboxUpsell{constructor(cartItemsInstance){this.cartItemsInstance=cartItemsInstance,this.baseUrl="/cart",this.checkboxUpsellVariantId=this.getUpsellCheckboxVariantId(),this.initEventDelegation(),document.addEventListener("cartUpdated",this.handleCartUpdate.bind(this)),this.updateCheckboxState()}initEventDelegation(){document.body.addEventListener("change",event=>{event.target.id==="cart-upsell-checkbox"&&(event.target.checked?this.addUpsellCheckboxToCart():this.removeUpsellCheckboxFromCart())})}getUpsellCheckboxVariantId(){return document.querySelector("#cart-upsell-checkbox")?.getAttribute("data-variant-id")}updateCheckboxState(){fetch(`${this.baseUrl}.js`).then(response=>response.json()).then(cart=>{const hasUpsellCheckbox=cart.items.some(item=>item.variant_id.toString()===this.checkboxUpsellVariantId),checkboxUpsellCheckbox=document.querySelector("#cart-upsell-checkbox");checkboxUpsellCheckbox&&(checkboxUpsellCheckbox.checked=hasUpsellCheckbox)}).catch(error=>{console.error("Error fetching cart:",error)})}handleCartUpdate(){setTimeout(()=>this.updateCheckboxState(),500)}addUpsellCheckboxToCart(){const formData=new FormData;formData.append("id",this.checkboxUpsellVariantId),formData.append("quantity",1),fetch(`${this.baseUrl}/add.js`,{method:"POST",body:formData}).then(response=>(response.ok&&this.cartItemsInstance&&typeof this.cartItemsInstance.onCartUpdate=="function"&&(this.cartItemsInstance.onCartUpdate(),this.onCartUpdateCheckboxUpsell()),response.json())).catch(error=>{console.error("Error adding cart upsell:",error)})}removeUpsellCheckboxFromCart(){fetch("/cart.js").then(response=>response.json()).then(cart=>{const lineItemIndex=cart.items.findIndex(item=>item.variant_id.toString()===this.checkboxUpsellVariantId);if(lineItemIndex!==-1){const line=lineItemIndex+1;this.cartItemsInstance.updateQuantity(line,0,null,null)}else console.error("Cart upsell product not found in cart.")}).catch(error=>{console.error("Error fetching cart for cart upsell removal:",error)})}getSectionsToRenderCheckboxUpsell(){const mainCartFooter=document.getElementById("main-cart-footer");return[...mainCartFooter?[{id:"main-cart-footer",section:mainCartFooter.dataset.id,selector:"#main-cart-footer .js-contents"}]:[],{id:"cart-icon-bubble",section:"cart-icon-bubble",selector:"#cart-icon-bubble"}]}onCartUpdateCheckboxUpsell(){this.getSectionsToRenderCheckboxUpsell().forEach(section=>{fetch(`${routes.cart_url}?section_id=${section.section}`).then(response=>response.text()).then(html=>{const container=document.querySelector(section.selector);if(!container){console.error(`Container not found for selector: ${section.selector}`);return}if(section.id==="main-cart-footer"){const jsContents=new DOMParser().parseFromString(html,"text/html").querySelector(".js-contents");jsContents?container.innerHTML=jsContents.innerHTML:console.error(`.js-contents not found in fetched HTML for section: ${section.id}`)}else section.id==="cart-icon-bubble"&&(container.innerHTML=html)}).catch(error=>console.error(`Error updating section ${section.id}:`,error))})}}document.addEventListener("DOMContentLoaded",function(){const cartItemsInstance=document.querySelector("cart-items");let activeCartInstance=document.querySelector("cart-drawer-items")||cartItemsInstance;activeCartInstance?new CartCheckboxUpsell(activeCartInstance):console.log("Neither cart-items nor cart-drawer-items found in the DOM.")});
2//# sourceMappingURL=/cdn/shop/t/16/assets/cart-checkbox-upsell.js.map?v=84649628755235268891773511259

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.