1const toggleAddon=async(button,variantId)=>{if(button.classList.contains("loading"))return;const isInCart=button.classList.contains("is-in-cart");button.classList.add("loading");const addUrl=`${window.Shopify.routes.root}cart/add.js`,changeUrl=`${window.Shopify.routes.root}cart/change.js`,requestUrl=isInCart?changeUrl:addUrl,payload=isInCart?{id:variantId.toString(),quantity:0}:{items:[{id:parseInt(variantId),quantity:1}]};try{const response=await fetch(requestUrl,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(payload)}),data=await response.json();if(!response.ok)throw new Error(data.description||"Error updating cart");button.classList.toggle("is-in-cart"),document.dispatchEvent(new CustomEvent("cart:refresh",{bubbles:!1,detail:{source:"product-addon"}})),updateSleekCartCount()}catch(error){console.error("Sleek Cart Update Error:",error)}finally{button.classList.remove("loading")}},updateSleekCartCount=async()=>{try{const cart=await(await fetch(`${window.Shopify.routes.root}cart.js`)).json();document.querySelectorAll(".header__cart-count, .cart-count, #CartCount").forEach(el=>{el.textContent=cart.item_count,el.classList.toggle("is-empty",cart.item_count===0),el.classList.remove("hidden","hide"),cart.item_count>0&&(el.style.display="")})}catch(e){console.error("Failed to update cart count manually",e)}};let syncInFlight=!1,syncDebounceTimer=null;const SYNC_DEBOUNCE_MS=300,syncAddonButtonStates=()=>{clearTimeout(syncDebounceTimer),syncDebounceTimer=setTimeout(async()=>{if(!syncInFlight){syncInFlight=!0;try{const cart=await(await fetch(`${window.Shopify.routes.root}cart.js`)).json(),cartVariantIds=new Set(cart.items.map(({variant_id})=>variant_id));document.querySelectorAll(".addon-card[data-variant-id]").forEach(card=>{const variantId=parseInt(card.dataset.variantId),button=card.querySelector(".addon-card__button");button&&button.classList.toggle("is-in-cart",cartVariantIds.has(variantId))})}catch(e){console.error("Failed to sync addon button states",e)}finally{syncInFlight=!1}}},SYNC_DEBOUNCE_MS)};let themeEventsActive=!1;["cart:updated","cart:change","cart:refresh"].forEach(eventName=>{document.addEventListener(eventName,e=>{e.detail?.source!=="product-addon"&&(themeEventsActive=!0,syncAddonButtonStates())})});const watchCartCountForChanges=()=>{const cartCountEl=document.querySelector(".header__cart-count, .cart-count, #CartCount");if(!cartCountEl)return;let lastCount=cartCountEl.textContent.trim();const observer=new MutationObserver(()=>{if(themeEventsActive){observer.disconnect();return}const newCount=cartCountEl.textContent.trim();newCount!==lastCount&&(lastCount=newCount,syncAddonButtonStates())});observer.observe(cartCountEl,{childList:!0,subtree:!0,characterData:!0})};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",watchCartCountForChanges):watchCartCountForChanges(); 2//# sourceMappingURL=/cdn/shop/t/18/assets/product-add-ons.js.map?v=30239727836277563091773368994
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.