1(()=>{"use strict";if(customElements.get("ba-multi-add"))return;class BuffaloMultiAdd extends HTMLElement{connectedCallback(){if(this.initialized||(this.initialized=!0,this.inputs=[...this.querySelectorAll("[data-ba-quantity]")],this.submit=this.querySelector("[data-ba-add]"),this.message=this.querySelector("[data-ba-message]"),this.reset=this.querySelector("[data-ba-reset]"),this.count=this.querySelector("[data-ba-count]"),this.total=this.querySelector("[data-ba-total]"),this.scope=this.closest(".product__info-container, product-info"),!this.inputs.length||!this.submit||!this.scope||this.closest("quick-add-modal")))return;if(this.root=window.Shopify?.routes?.root||this.dataset.root||"/",this.root.endsWith("/")||(this.root+="/"),this.format=new Intl.NumberFormat(document.documentElement.lang||"en-CA",{style:"currency",currency:this.dataset.currency||"CAD"}),this.dataset.kind==="stickers"&&(window.BuffaloRewardsV20?.isClaimMode?window.BuffaloRewardsV20.isClaimMode():new URLSearchParams(location.search).get("sticker_reward")==="1")){window.BuffaloRewardsV20?.setupPicker?window.BuffaloRewardsV20.setupPicker(this):(this.scope.classList.add("ba-v6-stickers"),this.hidden=!1,this.submit.disabled=!0,this.message.textContent="The free-sticker selector could not load. Refresh this page or view your cart. No stickers have been added.");return}this.state="ready",this.inputs.forEach(input=>{input.dataset.originalDisabled=String(input.disabled),input.addEventListener("input",()=>this.update())}),this.querySelectorAll("[data-ba-step]").forEach(button=>{button.addEventListener("click",()=>{if(this.state!=="ready")return;const input=button.closest("[data-ba-row]").querySelector("[data-ba-quantity]");if(input.disabled)return;const minimum=Number(input.dataset.minimum)||1,step=Number(input.dataset.increment)||1;let value=/^\d+$/.test(input.value)?Number(input.value):0;button.dataset.baStep==="up"?value=value===0?minimum:value+step:value=value<=minimum?0:value-step;const max=input.max===""?1/0:Number(input.max);input.value=String(Math.max(0,Math.min(value,max))),this.update()})}),this.submit.addEventListener("click",()=>this.add()),this.reset.addEventListener("click",()=>{this.inputs.forEach(input=>{input.value="0"}),this.state="ready",this.lock(!1),this.reset.hidden=!0,this.message.textContent="New selection started. Items already in your cart have not been removed.",this.update()});const details=this.closest("[data-ba-size-mode]");details?(details.hidden=!1,details.addEventListener("toggle",()=>{this.scope.classList.toggle("ba-v6-size-mode",details.open),details.querySelector("[data-ba-mode-label]").textContent=details.open?"Back to choosing one size":"Add different sizes together"})):(this.dataset.kind==="stickers"||this.dataset.kind==="postcards")&&this.scope.classList.add("ba-v6-stickers"),this.hidden=!1,this.update()}selection(){const items=[];let count=0,cents=0,valid=!0;return this.inputs.forEach(input=>{const quantity=Number(input.value),max=input.max===""?1/0:Number(input.max),good=/^\d+$/.test(input.value)&&Number.isSafeInteger(quantity)&&quantity>=0&&quantity<=max&&(quantity===0||quantity>=Number(input.dataset.minimum||1)&&quantity%Number(input.dataset.increment||1)===0);input.setAttribute("aria-invalid",String(!good)),good||(valid=!1),good&&!input.disabled&&quantity>0&&(items.push({id:Number(input.dataset.variant),quantity}),count+=quantity,cents+=quantity*Number(input.dataset.price)),input.closest("[data-ba-row]").classList.toggle("ba-is-selected",good&&quantity>0&&!input.disabled)}),{items,count,cents,valid}}update(){if(this.state!=="ready")return;const chosen=this.selection();this.count.textContent=`${chosen.count} ${chosen.count===1?"item":"items"} selected`,this.total.textContent=this.format.format(chosen.cents/100),this.submit.disabled=!chosen.valid||chosen.count===0,this.submit.textContent=chosen.count?`Add ${chosen.count} ${chosen.count===1?"item":"items"} to cart`:"Choose quantities above"}lock(locked){this.setAttribute("aria-busy",String(locked)),this.inputs.forEach(input=>{input.disabled=locked||input.dataset.originalDisabled==="true"}),this.querySelectorAll("[data-ba-step]").forEach(button=>{const input=button.closest("[data-ba-row]").querySelector("[data-ba-quantity]");button.disabled=locked||input.dataset.originalDisabled==="true"}),this.submit.disabled=locked}async request(path,options={}){const controller=new AbortController,timer=setTimeout(()=>controller.abort(),2e4);try{const response=await fetch(this.root+path,{credentials:"same-origin",cache:"no-store",...options,signal:controller.signal}),data=await response.json();return{ok:response.ok,data}}finally{clearTimeout(timer)}}quantities(cart){if(!cart||!Array.isArray(cart.items))throw new Error("Cart verification failed.");const counts=new Map;
1return cart.items.forEach(item=>{const id=Number(item.variant_id||item.id);counts.set(id,(counts.get(id)||0)+Number(item.quantity))}),counts}renderBadge(data,cart){const bubble=document.getElementById("cart-icon-bubble"),html=data?.sections?.["cart-icon-bubble"];if(bubble&&typeof html=="string"){const doc=new DOMParser().parseFromString(html,"text/html"),replacement=doc.getElementById("cart-icon-bubble")||doc.querySelector(".shopify-section");replacement&&(bubble.innerHTML=replacement.innerHTML)}else if(bubble&&Number.isInteger(cart?.item_count)){let badge=bubble.querySelector(".cart-count-bubble");badge||(badge=document.createElement("span"),badge.className="cart-count-bubble",bubble.append(badge)),badge.textContent=String(cart.item_count),badge.setAttribute("aria-label",`${cart.item_count} items in cart`)}typeof publish=="function"&&typeof PUB_SUB_EVENTS<"u"&&publish(PUB_SUB_EVENTS.cartUpdate,{source:"buffalo-multi-add",cartData:cart})}async add(){if(this.state!=="ready")return;const chosen=this.selection();if(!chosen.valid||!chosen.count)return;if(window.buffaloBatchBusy){this.message.textContent="Please wait for the other cart addition to finish.";return}window.buffaloBatchBusy=!0,this.state="busy",this.lock(!0),this.reset.hidden=!0,this.submit.textContent="Adding your selection\u2026",this.message.textContent="Checking your cart\u2026";let sent=!1;try{const before=await this.request("cart.js");if(!before.ok)throw new Error("Your cart could not be loaded. Please try again.");const oldQuantities=this.quantities(before.data);sent=!0;const result=await this.request("cart/add.js",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({items:chosen.items,sections:["cart-icon-bubble"],sections_url:location.pathname+location.search})}),after=await this.request("cart.js");if(!after.ok)throw new Error("Your cart could not be verified.");const newQuantities=this.quantities(after.data);this.renderBadge(result.data,after.data);const complete=chosen.items.every(item=>(newQuantities.get(item.id)||0)-(oldQuantities.get(item.id)||0)===item.quantity);if(!result.ok||!complete){const detail=typeof result.data?.description=="string"?result.data.description:"Availability or quantity may have changed.";throw new Error(detail)}this.inputs.forEach(input=>{input.value="0"}),this.state="ready",this.lock(!1),this.update(),this.message.textContent=`${chosen.count} ${chosen.count===1?"item added":"items added"}. Continue choosing, or view your cart below.`,this.message.focus({preventScroll:!0})}catch(error){sent?(this.state="review",this.lock(!0),this.setAttribute("aria-busy","false"),this.submit.textContent="Check your cart before adding again",this.message.textContent=`${error.name==="AbortError"?"The connection timed out.":error.message} Some items may already have been added. Open your cart and check quantities before starting a new selection.`,this.reset.hidden=!1):(this.state="ready",this.lock(!1),this.update(),this.message.textContent="Your cart could not be loaded. No add request was sent. Please try again."),this.message.focus({preventScroll:!0})}finally{window.buffaloBatchBusy=!1}}}customElements.define("ba-multi-add",BuffaloMultiAdd)})(); 2//# sourceMappingURL=/cdn/shop/t/15/assets/ba-purchase-v6.js.map?v=176086886674435288401789863416
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.