PageSourceSearch

https://www.whiteouttequila.com/cdn/shop/t/9/assets/cart-additiona…?v=179095055575500979111781628297

js whiteouttequila.com collected 2026-10-04 13:24:31 UTC 11,668 bytes, 2 lines download raw bytes

1class CartAdditionalFeatures extends HTMLElement{static FOCUSABLE_SELECTOR='button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';connectedCallback(){this.triggers=this.querySelectorAll(".wt-cart-features__trigger"),this.drawers=this.querySelectorAll(".wt-cart-features__drawer"),this.overlay=this.querySelector("[data-overlay]"),this.closeButtons=this.querySelectorAll("[data-close]"),this.context=this.dataset.context||"page",this.shopCurrency=this.dataset.shopCurrency||"",this.lastTrigger=null;const ds=this.dataset;this.strings={shippingSelect:ds.i18nShippingSelect||"Please select a country and enter a postal code.",shippingCalculating:ds.i18nShippingCalculating||"Calculating\u2026",shippingNoRate:ds.i18nShippingNoRate||"There is no shipping rate for this destination. Try to check the address.",shippingOneRate:ds.i18nShippingOneRate||"There is one shipping rate for this destination:",shippingNRatesTpl:ds.i18nShippingNRates||"There are __COUNT__ shipping rates for this destination:",shippingFree:ds.i18nShippingFree||"Free",discountEnter:ds.i18nDiscountEnter||"Please enter a discount code.",discountApplying:ds.i18nDiscountApplying||"Applying\u2026",discountApplied:ds.i18nDiscountApplied||"Discount applied!",discountInvalid:ds.i18nDiscountInvalid||"Discount code is invalid or does not apply to the current cart.",discountError:ds.i18nDiscountError||"Something went wrong. Please try again."},this.onTriggerClick=this.onTriggerClick.bind(this),this.closeAll=this.closeAll.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.triggers.forEach(t=>t.addEventListener("click",this.onTriggerClick)),this.closeButtons.forEach(b=>b.addEventListener("click",this.closeAll)),this.overlay&&this.overlay.addEventListener("click",this.closeAll),this.addEventListener("keydown",this.onKeyDown),this.drawers.forEach(d=>{d.hasAttribute("open")||d.setAttribute("inert","")}),this.initNote(),this.initShipping(),this.initDiscount()}disconnectedCallback(){this.removeEventListener("keydown",this.onKeyDown)}onTriggerClick(event){const feature=event.currentTarget.dataset.feature,drawer=this.querySelector(`.wt-cart-features__drawer[data-drawer="${feature}"]`);if(drawer&&drawer.hasAttribute("open")){this.closeAll();return}this.openDrawer(feature)}openDrawer(feature){this.closeAll();const drawer=this.querySelector(`.wt-cart-features__drawer[data-drawer="${feature}"]`);if(!drawer)return;const trigger=this.querySelector(`.wt-cart-features__trigger[data-feature="${feature}"]`);if(this.lastTrigger=trigger||null,drawer.setAttribute("open",""),drawer.removeAttribute("inert"),trigger&&(trigger.classList.add("wt-cart-features__trigger--open"),trigger.setAttribute("aria-expanded","true")),this.overlay?.setAttribute("open",""),this.classList.add("wt-cart-features--open"),this.context==="drawer"){const firstField=drawer.querySelector(CartAdditionalFeatures.FOCUSABLE_SELECTOR);firstField&&setTimeout(()=>firstField.focus(),50)}}closeAll(){const wasOpen=this.classList.contains("wt-cart-features--open");this.drawers.forEach(d=>{d.removeAttribute("open"),d.setAttribute("inert","")}),this.triggers.forEach(t=>{t.classList.remove("wt-cart-features__trigger--open"),t.setAttribute("aria-expanded","false")}),this.overlay?.removeAttribute("open"),this.classList.remove("wt-cart-features--open"),wasOpen&&this.lastTrigger&&this.lastTrigger.focus(),this.lastTrigger=null}onKeyDown(event){if(this.classList.contains("wt-cart-features--open")){if(event.key==="Escape"){this.closeAll();return}if(event.key==="Tab"&&this.context==="drawer"){const openDrawer=this.querySelector(".wt-cart-features__drawer[open]");if(!openDrawer)return;const focusable=Array.from(openDrawer.querySelectorAll(CartAdditionalFeatures.FOCUSABLE_SELECTOR)).filter(el=>el.offsetParent!==null);if(focusable.length===0)return;const first=focusable[0],last=focusable[focusable.length-1],active=document.activeElement;event.shiftKey&&(active===first||!openDrawer.contains(active))?(event.preventDefault(),last.focus()):!event.shiftKey&&active===last&&(event.preventDefault(),first.focus())}}}initNote(){const textarea=this.querySelector("[data-note-textarea]"),saveBtn=this.querySelector("[data-note-save]");!textarea||!saveBtn||saveBtn.addEventListener("click",async()=>{saveBtn.disabled=!0;try{if(!(await fetch(`${window.Shopify.routes.root}cart/update.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({note:textarea.value})})).ok)throw new Error("Failed to save note");this.closeAll()}catch(err){console.error("[cart-features note]",err)}finally{saveBtn.disabled=!1}})}initShipping(){const submit=this.querySelector("[data-shipping-submit]");submit&&(this.shippingSubmit=submit,this.shippingResult=this.querySelector("[data-shipping-result]"),this.shippingCountry=this.querySelector("[data-shipping-country]"),this.shippingZip=this.querySelector("[data-shipping-zip]"),submit.addEventListener("click",this.onShippingSubmit.bind(this)))}async onShippingSubmit(){const country=this.shippingCountry?.value||"",zip=this.shippingZip?.value.trim()||"";if(!country||!zip){this.renderShippingResult(this.strings.shippingSelect,"error");return}this.shippingSubmit.disabled=!0,this.renderShippingResult(this.strings.shippingCalculating,"loading");try{const url=`${window.Shopify.routes.root}cart/shipping_rates.json?shipping_address[country]=${encodeURIComponent(country)}&shipping_address[zip]=${encodeURIComponent(zip)}`,response=await fetch(url);if(!response.ok)throw new Error(await response.text());const rates=(await response.json()).shipping_rates||[];rates.length===0?this.renderShippingResult(this.strings.shippingNoRate,"error"):this.renderShippingRates(rates)}catch(err){console.error("[cart-features shipping]",err),this.renderShippingResult(this.strings.shippingNoRate,"error")}finally{this.shippingSubmit.disabled=!1}}renderShippingRates(rates){const intro=rates.length===1?this.strings.shippingOneRate:this.strings.shippingNRatesTpl.replace("__COUNT__",String(rates.length)),items=rates.map(rate=>{const price=rate.price==="0.00"?this.strings.shippingFree:this.formatMoney(rate.price);return`<li>${this.escape(rate.name)}: ${price}</li>`}).join("");this.shippingResult.innerHTML=`<p>${intro}</p><ul class="wt-cart-features__rates">${items}</ul>`,this.shippingResult.dataset.state="success"}renderShippingResult(message,state){this.shippingResult.textContent=message,this.shippingResult.dataset.state=state}formatMoney(stringAmount){const baseAmount=parseFloat(stringAmount),presentment=window.Shopify?.currency?.active||"",rate=parseFloat(window.Shopify?.currency?.rate||"1")||1,baseCode=this.shopCurrency||presentment||"USD";let amount=baseAmount,code=baseCode;presentment&&rate&&rate!==1?(amount=baseAmount*rate,code=presentment):presentment&&(code=presentment);try{return new Intl.NumberFormat(void 0,{style:"currency",currency:code}).format(amount)}catch{return`${amount.toFixed(2)} ${code}`}}escape(str){const div=document.createElement("div");return div.textContent=str,div.innerHTML}initDiscount(){const applyBtn=this.querySelector("[data-discount-apply]");applyBtn&&(this.discountInput=this.querySelector("[data-discount-input]"),this.discountResult=this.querySelector("[data-discount-result]"),this.applyBtn=applyBtn,applyBtn.addEventListener("click",this.onDiscountApply.bind(this)),this.querySelectorAll("[data-discount-remove-code]").forEach(btn=>{btn.addEventListener("click",()=>this.onDiscountRemoveCode(btn.dataset.discountRemoveCode,btn))}),this.discountInput?.addEventListener("input",()=>{delete this.discountInput.dataset.error}))}async onDiscountApply(){const code=(this.discountInput?.value||"").trim();if(!code){this.renderDiscountResult(this.strings.discountEnter,"error");return}this.applyBtn.disabled=!0,this.renderDiscountResult(this.strings.discountApplying,"loading");try{const cartBefore=await fetch(`${window.Shopify.routes.root}cart.js`).then(r=>r.json()),codesString=[...(cartBefore?.discount_codes??[]).map(el=>el.code),code].join(",");await fetch(`${window.Shopify.routes.root}cart/update.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({discount:codesString})});const cartAfter=await fetch(`${window.Shopify.routes.root}cart.js`).then(r=>r.json());this.isDiscountApplied(cartAfter,code,cartBefore)?(this.renderDiscountResult(this.strings.discountApplied,"success"),this.refreshCart(),setTimeout(()=>this.closeAll(),1500)):(this.renderDiscountResult(this.strings.discountInvalid,"error"),this.discountInput&&(this.discountInput.dataset.error=""))}catch(err){console.error("[cart-features discount apply]",err),this.renderDiscountResult(this.strings.discountError,"error")}finally{this.applyBtn.disabled=!1}}isDiscountApplied(cartAfter,code,cartBefore){const normalCode=code.trim().toLowerCase(),apps=cartAfter.cart_level_discount_applications||[];return!!(apps.some(a=>a.title&&a.title.toLowerCase()===normalCode)||cartAfter.total_discount>(cartBefore.total_discount||0)||apps.length>(cartBefore.cart_level_discount_applications||[]).length)}async onDiscountRemoveCode(codeToRemove,btn){btn&&(btn.disabled=!0,btn.dataset.loading="");try{const remaining=(this.dataset.discountCodes||"").split(",").map(c=>c.trim()).filter(c=>c&&c.toLowerCase()!==codeToRemove.trim().toLowerCase()).join(",");console.log(remaining),await fetch(`${window.Shopify.routes.root}cart/update.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({discount:""})}),await fetch(`${window.Shopify.routes.root}cart/update.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({discount:remaining})}),this.refreshCart(),this.closeAll()}catch(err){console.error("[cart-features discount remove]",err)}finally{btn&&(btn.disabled=!1,delete btn.dataset.loading)}}renderDiscountResult(message,state){this.discountResult&&(this.discountResult.textContent=message,this.discountResult.dataset.state=state)}async refreshCart(){const cartDrawer=document.querySelector("cart-drawer");cartDrawer&&typeof cartDrawer.refreshCartDrawer=="function"&&cartDrawer.refreshCartDrawer();const cartItemsEl=document.getElementById("main-cart-items"),cartFooterEl=document.getElementById("main-cart-footer");
1if(cartItemsEl||cartFooterEl){const sectionIds=[];cartItemsEl?.dataset.id&&sectionIds.push(cartItemsEl.dataset.id),cartFooterEl?.dataset.id&&sectionIds.push(cartFooterEl.dataset.id),sectionIds.push("cart-icon-bubble");try{const data=await(await fetch(`${window.Shopify.routes.root}?sections=${sectionIds.join(",")}`)).json();[{key:cartItemsEl?.dataset.id,el:cartItemsEl,selector:".js-contents"},{key:cartFooterEl?.dataset.id,el:cartFooterEl,selector:".js-contents"},{key:"cart-icon-bubble",el:document.getElementById("shopify-section-cart-icon-bubble"),selector:".shopify-section"}].forEach(target=>{if(!target.key||!target.el||!data[target.key])return;const incoming=new DOMParser().parseFromString(data[target.key],"text/html").querySelector(target.selector),existing=target.el.querySelector(target.selector);incoming&&existing&&(existing.innerHTML=incoming.innerHTML)})}catch(err){console.error("[cart-features] section refresh",err)}}typeof publish=="function"&&typeof PUB_SUB_EVENTS<"u"&&publish(PUB_SUB_EVENTS.cartUpdate,{source:"cart-additional-features"})}}customElements.get("cart-additional-features")||customElements.define("cart-additional-features",CartAdditionalFeatures);
2//# sourceMappingURL=/cdn/shop/t/9/assets/cart-additional-features.js.map?v=179095055575500979111781628297

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.