PageSourceSearch

https://store.edmprod.com/cdn/shop/t/16/assets/aov-cart-drawer.js?v=117775680506963760041788908321

js edmprod.com collected 2026-09-24 17:54:35 UTC 12,276 bytes, 2 lines download raw bytes

1import{DialogComponent,DialogOpenEvent,DialogCloseEvent}from"@theme/dialog";import{ThemeEvents,CartUpdateEvent}from"@theme/events";import{sectionRenderer}from"@theme/section-renderer";import{morph}from"@theme/morph";import{fetchConfig}from"@theme/utilities";const SOURCE="aov-cart-drawer",INNER_ID="AovDrawerInner";function themeGlobal(){return(typeof Theme<"u"?Theme:window.Theme)||{}}function themeRoutes(){return themeGlobal().routes||{}}class AovCartDrawer extends DialogComponent{#seenOffers=new Set;connectedCallback(){super.connectedCallback(),document.addEventListener(ThemeEvents.cartUpdate,this.#onCartUpdate),document.addEventListener("visitorConsentCollected",this.#onConsent),this.addEventListener("click",this.#onClick),this.addEventListener(DialogOpenEvent.eventName,this.#onDialogOpen),this.addEventListener(DialogCloseEvent.eventName,this.#onDialogClose),this.addEventListener("submit",this.#onSubmit),this.hasAttribute("hijack-links")&&document.addEventListener("click",this.#onDocumentClick,!0),window.Shopify?.designMode&&(document.addEventListener("shopify:section:select",this.#onEditorSelect),document.addEventListener("shopify:section:deselect",this.closeDialog)),this.limitOne&&setTimeout(()=>this.#normalizeQuantities(),1500)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(ThemeEvents.cartUpdate,this.#onCartUpdate),document.removeEventListener("visitorConsentCollected",this.#onConsent),this.removeEventListener("click",this.#onClick),this.removeEventListener(DialogOpenEvent.eventName,this.#onDialogOpen),this.removeEventListener(DialogCloseEvent.eventName,this.#onDialogClose),this.removeEventListener("submit",this.#onSubmit),document.removeEventListener("click",this.#onDocumentClick,!0),window.Shopify?.designMode&&(document.removeEventListener("shopify:section:select",this.#onEditorSelect),document.removeEventListener("shopify:section:deselect",this.closeDialog))}get sectionId(){return this.dataset.sectionId||"aov-cart-drawer"}get limitOne(){return this.hasAttribute("limit-one")}get inner(){return this.querySelector(`#${INNER_ID}`)}open(){this.showDialog()}close(){this.closeDialog()}refresh(){return this.#refresh()}refreshAndOpen(){this.#refreshOrNormalize(),this.showDialog()}async#refreshOrNormalize(){this.limitOne&&await this.#normalizeQuantities()||this.#refresh()}#onCartUpdate=async event=>{const detail=event.detail??{};if((detail.data?.source??detail.sourceId)===SOURCE||detail.data?.didError)return;const fromCartPage=detail.data?.source==="cart-items-component";this.hasAttribute("auto-open")&&!fromCartPage&&!this.refs.dialog.open&&this.showDialog(),await this.#normalizeQuantities()||this.#refresh()};async#normalizeQuantities(){if(!this.limitOne)return!1;try{const cart=await(await fetch(`${themeRoutes().cart_url||"/cart"}.js`)).json(),updates={},seenProducts=new Set;for(const item of cart.items)if(!item.gift_card){if(seenProducts.has(item.product_id)){updates[item.key]=0;continue}seenProducts.add(item.product_id),item.quantity>1&&(updates[item.key]=1)}if(Object.keys(updates).length===0)return!1;const response=await fetch(`${themeRoutes().cart_update_url||"/cart/update"}.js`,{...fetchConfig("json",{headers:{"X-AOV-Internal":"1"},body:JSON.stringify({updates,sections:this.sectionId})})}),updated=await response.json();if(!response.ok||updated.status)throw new Error(updated.message||"Cart error");return await this.#reconcile(updated.sections?.[this.sectionId]),this.#dispatchCartUpdate(updated),!0}catch(error){return console.error("[aov-cart-drawer] quantity normalize failed",error),!1}}#onEditorSelect=event=>{event.target instanceof Element&&event.target.contains(this)&&this.showDialog()};#onClick=event=>{const target=event.target instanceof Element?event.target:null;if(!target)return;const closeTrigger=target.closest("[data-aov-close]");if(closeTrigger){closeTrigger.tagName==="BUTTON"&&event.preventDefault(),this.closeDialog();return}const removeTrigger=target.closest("[data-aov-remove]");if(removeTrigger){event.preventDefault(),this.#removeLine(removeTrigger.getAttribute("data-aov-remove"),removeTrigger);return}const addTrigger=target.closest("[data-aov-add]");if(addTrigger){event.preventDefault();const offerId=addTrigger.getAttribute("data-aov-offer-id"),replaceKeys=(addTrigger.getAttribute("data-aov-replace")||"").split(",").filter(
1Boolean);let source="empty-state";offerId&&(source=replaceKeys.length?`upgrade:${offerId}`:`offer:${offerId}`),this.#addVariant(addTrigger.getAttribute("data-aov-add"),addTrigger,source,offerId,replaceKeys)}};#onConsent=()=>{this.#seenOffers.clear(),this.#trackImpressions()};#onDialogOpen=()=>{this.#track("aov_drawer_open",this.#cartContext()),this.#trackImpressions()};#onDialogClose=()=>{this.#seenOffers.clear()};#onSubmit=event=>{event.target instanceof HTMLFormElement&&event.target.classList.contains("aov-drawer__checkout-form")&&this.#track("aov_checkout_click",this.#cartContext())};#onDocumentClick=event=>{if(event.defaultPrevented||event.button!==0||event.metaKey||event.ctrlKey||event.shiftKey||event.altKey)return;const link=(event.target instanceof Element?event.target:null)?.closest("a[href]");if(!link||this.contains(link)||link.target&&link.target!=="_self")return;let url;try{url=new URL(link.href,window.location.href)}catch{return}if(url.origin!==window.location.origin)return;const cartPath=themeRoutes().cart_url||"/cart";(url.pathname.replace(/\/$/,"")||"/")===cartPath&&(event.preventDefault(),this.refreshAndOpen())};async#reconcile(html){if(!this.#morphInner(html)&&!await this.#refresh())throw new Error("Cart changed but could not be displayed")}#showError(message="We could not confirm the latest cart. Review your cart before retrying or checking out."){let box=this.querySelector("[data-aov-error]");box||(box=document.createElement("p"),box.dataset.aovError="",box.setAttribute("role","alert"),box.style.cssText="padding:16px;margin:8px;color:#fff;background:#7f1d1d",this.refs.dialog.prepend(box)),box.replaceChildren(document.createTextNode(message+" "));const link=document.createElement("a");link.href=themeRoutes().cart_url||"/cart",link.textContent="Review cart",link.style.cssText="color:inherit;text-decoration:underline",box.append(link)}async#refresh(){this.setAttribute("aria-busy","true");try{const html=await sectionRenderer.getSectionHTML(this.sectionId,!1);if(!this.#morphInner(html))throw new Error("Cart section unavailable");return!0}catch(error){return console.error("[aov-cart-drawer] refresh failed",error),this.#showError(),!1}finally{this.removeAttribute("aria-busy")}}#morphInner(html){if(!html)return!1;const fresh=new DOMParser().parseFromString(html,"text/html").getElementById(INNER_ID),current=this.inner;return!fresh||!current?!1:(morph(current,fresh),this.querySelector("[data-aov-error]")?.remove(),this.#restoreFocus(),this.#trackImpressions(),!0)}#restoreFocus(){if(!this.refs.dialog.open||this.contains(document.activeElement)&&document.activeElement!==document.body)return;const fallback=this.querySelector("[data-aov-remove]")||this.querySelector("[data-aov-close]");fallback instanceof HTMLElement&&fallback.focus()}async#removeLine(key,trigger){if(key){trigger?.setAttribute("disabled",""),this.setAttribute("aria-busy","true");try{const response=await fetch(`${themeRoutes().cart_change_url||"/cart/change"}.js`,{...fetchConfig("json",{headers:{"X-AOV-Internal":"1"},body:JSON.stringify({id:key,quantity:0,sections:this.sectionId})})}),cart=await response.json();if(!response.ok||cart.status)throw new Error(cart.message||cart.description||"Cart error");await this.#reconcile(cart.sections?.[this.sectionId]),this.#announce("Item removed"),this.#dispatchCartUpdate(cart)}catch(error){console.error("[aov-cart-drawer] remove failed",error),this.#showError(),trigger?.removeAttribute("disabled")}finally{this.removeAttribute("aria-busy")}}}async#addVariant(variantId,trigger,source="drawer",offerId=null,replaceKeys=[]){if(variantId){trigger?.setAttribute("disabled",""),this.setAttribute("aria-busy","true");try{const response=await fetch(themeRoutes().cart_add_url||"/cart/add.js",{...fetchConfig("json",{headers:{"X-AOV-Internal":"1"},body:JSON.stringify({items:[{id:Number(variantId),quantity:1,properties:{_aov_source:source}}],sections:this.sectionId})})});if(!response.ok)throw new Error(`Cart add failed (${response.status})`);const result=await response.json();if(result.status)throw new Error(result.message||result.description||"Cart error");let sectionsHtml=result.sections?.[this.sectionId],upgradeSucceeded=replaceKeys.length===0,rollbackSucceeded=!1;if(replaceKeys.length)try{const updates={};for(const key of replaceKeys)updates[key]=0;const swapResponse=await fetch(`${themeRoutes().cart_update_url||"/cart/update"}.js`,{...fetchConfig("json",{headers:{"X-AOV-Internal":"1"},body:JSON.stringify({updates,sections:this.sectionId})})});if(!swapResponse.ok)throw new Error(`Upgrade swap failed (${swapResponse.status})`);const swapped=await swapResponse.json();if(swapped.status)throw new Error(swapped.message||swapped.description||"Upgrade swap failed");upgradeSucceeded=!0,sectionsHtml=swapped.sections?.[this.sectionId]}catch(error){console.error("[aov-cart-drawer] upgrade swap failed",error),sectionsHtml=void 0;const addedKey=result.items?.[0]?.key||result.key;if(addedKey)try{const rollbackResponse=await fetch(`${themeRoutes().cart_
1change_url||"/cart/change"}.js`,{...fetchConfig("json",{headers:{"X-AOV-Internal":"1"},body:JSON.stringify({id:addedKey,quantity:0,sections:this.sectionId})})});if(!rollbackResponse.ok)throw new Error(`Upgrade rollback failed (${rollbackResponse.status})`);const rolledBack=await rollbackResponse.json();if(rolledBack.status)throw new Error(rolledBack.message||rolledBack.description||"Upgrade rollback failed");rollbackSucceeded=!0,sectionsHtml=rolledBack.sections?.[this.sectionId]}catch(rollbackError){console.error("[aov-cart-drawer] upgrade rollback failed",rollbackError)}}const cartResponse=await fetch(`${themeRoutes().cart_url||"/cart"}.js`);if(!cartResponse.ok)throw new Error(`Cart refresh failed (${cartResponse.status})`);const cart=await cartResponse.json();if(await this.#reconcile(sectionsHtml),this.#dispatchCartUpdate(cart),replaceKeys.length&&!upgradeSucceeded){this.#showError(rollbackSucceeded?"Upgrade was not completed. Please try again.":"Upgrade was not completed. Review your cart before checkout."),offerId&&this.#track("aov_offer_error",{offer_id:offerId,variant_id:variantId,mode:"upgrade",rollback_succeeded:rollbackSucceeded,cart_total:cart.total_price,item_count:cart.item_count});return}this.#announce(replaceKeys.length?"Upgraded":themeGlobal().translations?.added||"Added to cart"),offerId&&this.#track("aov_offer_add",{offer_id:offerId,variant_id:variantId,mode:replaceKeys.length?"upgrade":"add",cart_total:cart.total_price,item_count:cart.item_count})}catch(error){console.error("[aov-cart-drawer] add failed",error),this.#showError(),trigger?.removeAttribute("disabled")}finally{this.removeAttribute("aria-busy")}}}#dispatchCartUpdate(cart){document.dispatchEvent(new CartUpdateEvent(cart,SOURCE,{itemCount:cart.item_count,source:SOURCE}))}#announce(message){const live=this.querySelector("[data-aov-live]");live&&(live.textContent=message)}#trackImpressions(){if(!(!this.refs.dialog.open||!this.#analyticsAllowed()))for(const card of this.querySelectorAll("div[data-aov-offer-id]")){const id=card.getAttribute("data-aov-offer-id");!id||this.#seenOffers.has(id)||(this.#seenOffers.add(id),this.#track("aov_offer_impression",{...this.#cartContext(),offer_id:id,product:card.getAttribute("data-aov-offer-product")||void 0,mode:card.getAttribute("data-aov-mode")||void 0}))}}#cartContext(){return{cart_total:Number(this.inner?.dataset.cartTotal||0),item_count:Number(this.inner?.dataset.itemCount||0)}}#analyticsAllowed(){return this.hasAttribute("data-analytics")&&window.Shopify?.customerPrivacy?.analyticsProcessingAllowed?.()===!0}#track(name,data){this.#analyticsAllowed()&&(window.dataLayer=window.dataLayer||[],window.dataLayer.push({event:name,...data}))}}customElements.get("aov-cart-drawer")||customElements.define("aov-cart-drawer",AovCartDrawer);
2//# sourceMappingURL=/cdn/shop/t/16/assets/aov-cart-drawer.js.map?v=117775680506963760041788908321

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.