1import{CartUpdateEvent,ThemeEvents}from"@theme/events";const SELECTORS={open:"[data-c-cart-rodney-open]",close:"[data-c-cart-rodney-close]",shell:"[data-c-cart-rodney-shell]",drawer:".c-cart-rodney__drawer",title:"[data-c-cart-rodney-title]",items:"[data-c-cart-rodney-items]",subtotal:"[data-c-cart-rodney-subtotal]",checkout:"[data-c-cart-rodney-checkout]",error:"[data-c-cart-rodney-error]",add:"[data-c-cart-rodney-add]",offer:"[data-c-offer-cart]",offerCard:"[data-c-offer-cart-card]",offerToggle:"[data-c-offer-cart-toggle]",offerSizes:"[data-c-offer-cart-sizes]",offerTrack:"[data-c-offer-cart-track]"},OFFER_DRAG_THRESHOLD=5,focusableSelector=["a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(",");class CCartRodneyDrawer extends HTMLElement{#lastFocused=null;#comparePriceRequests=new Map;#comparePrices={};#offerDrag=null;connectedCallback(){this.openButton?.addEventListener("click",this.open),this.querySelectorAll(SELECTORS.close).forEach(button=>button.addEventListener("click",this.close)),this.addEventListener("click",this.#handleClick),document.addEventListener("keydown",this.#handleDocumentKeydown),document.addEventListener(ThemeEvents.cartUpdate,this.#handleCartUpdate);const offerTrack=this.querySelector(SELECTORS.offerTrack);offerTrack&&(window.addEventListener("resize",this.#updateOfferScroll),offerTrack.addEventListener("pointerdown",this.#handleOfferDragStart),offerTrack.addEventListener("pointermove",this.#handleOfferDragMove),offerTrack.addEventListener("pointerup",this.#handleOfferDragEnd),offerTrack.addEventListener("pointercancel",this.#handleOfferDragEnd),offerTrack.addEventListener("dragstart",this.#preventOfferDragImage)),this.#refreshCart(!1)}disconnectedCallback(){this.openButton?.removeEventListener("click",this.open),this.querySelectorAll(SELECTORS.close).forEach(button=>button.removeEventListener("click",this.close)),this.removeEventListener("click",this.#handleClick),document.removeEventListener("keydown",this.#handleDocumentKeydown),document.removeEventListener(ThemeEvents.cartUpdate,this.#handleCartUpdate);const offerTrack=this.querySelector(SELECTORS.offerTrack);offerTrack?.removeEventListener("pointerdown",this.#handleOfferDragStart),offerTrack?.removeEventListener("pointermove",this.#handleOfferDragMove),offerTrack?.removeEventListener("pointerup",this.#handleOfferDragEnd),offerTrack?.removeEventListener("pointercancel",this.#handleOfferDragEnd),offerTrack?.removeEventListener("dragstart",this.#preventOfferDragImage),window.removeEventListener("resize",this.#updateOfferScroll)}#preventOfferDragImage=event=>{event.preventDefault()};#handleOfferDragStart=event=>{if(event.pointerType==="touch"||event.button!==0)return;const track=event.currentTarget;track.scrollWidth-track.clientWidth<=1||(this.#offerDrag={startX:event.clientX,startScroll:track.scrollLeft,moved:!1,pointerId:event.pointerId})};#handleOfferDragMove=event=>{const drag=this.#offerDrag;if(!drag||event.pointerId!==drag.pointerId)return;const track=event.currentTarget,delta=event.clientX-drag.startX;!drag.moved&&Math.abs(delta)<OFFER_DRAG_THRESHOLD||(drag.moved||(drag.moved=!0,track.classList.add("is-dragging"),track.setPointerCapture?.(drag.pointerId)),track.scrollLeft=drag.startScroll-delta,event.preventDefault())};#handleOfferDragEnd=event=>{const drag=this.#offerDrag;if(!drag)return;this.#offerDrag=null;const track=event.currentTarget;if(track.classList.remove("is-dragging"),track.hasPointerCapture?.(drag.pointerId)&&track.releasePointerCapture(drag.pointerId),!drag.moved)return;const swallow=clickEvent=>{clickEvent.preventDefault(),clickEvent.stopPropagation()};track.addEventListener("click",swallow,{capture:!0,once:!0}),window.setTimeout(()=>track.removeEventListener("click",swallow,{capture:!0}),0)};#updateOfferScroll=()=>{const track=this.querySelector(SELECTORS.offerTrack);track&&track.classList.toggle("is-draggable",track.scrollWidth-track.clientWidth>1)};get openButton(){return this.querySelector(SELECTORS.open)}get shell(){return this.querySelector(SELECTORS.shell)}get drawer(){return this.querySelector(SELECTORS.drawer)}get isOpen(){return this.classList.contains("is-open")}open=()=>{this.isOpen||(this.#lastFocused=document.activeElement instanceof HTMLElement?document.activeElement:null,this.shell?.removeAttribute("hidden"),this.openButton?.setAttribute("aria-expanded","true"),document.body.classList.add("c-cart-rodney-lock"),requestAnimationFrame(()=>{this.classList.add("is-open"),this.drawer?.focus(),this.#refreshShippingProtection()}),this.#refreshCart(!1))};close=()=>{this.isOpen&&(this.classList.remove("is-open"),this.openButton?.setAttribute("aria-expanded","fal
1se"),document.body.classList.remove("c-cart-rodney-lock"),window.setTimeout(()=>{this.shell?.setAttribute("hidden",""),this.#lastFocused?.focus()},220))};#handleCartUpdate=event=>{event.target!==this&&(this.hasAttribute("auto-open")&&event.detail?.data?.source==="product-form-component"&&(document.documentElement.hasAttribute("data-c-offer-modal-claimed")||this.open()),this.#refreshCart(!1))};#handleDocumentKeydown=event=>{if(this.isOpen){if(event.key==="Escape"){event.preventDefault(),this.close();return}event.key==="Tab"&&this.#trapFocus(event)}};#trapFocus(event){const focusable=Array.from(this.drawer?.querySelectorAll(focusableSelector)||[]).filter(element=>element instanceof HTMLElement&&element.offsetParent!==null);if(focusable.length===0){event.preventDefault(),this.drawer?.focus();return}const first=focusable[0],last=focusable[focusable.length-1];event.shiftKey&&document.activeElement===first?(event.preventDefault(),last.focus()):!event.shiftKey&&document.activeElement===last&&(event.preventDefault(),first.focus())}#handleClick=event=>{const target=event.target;if(!(target instanceof Element))return;const quantityButton=target.closest("[data-c-cart-rodney-quantity]");if(quantityButton instanceof HTMLButtonElement){const key=quantityButton.dataset.key,quantity=parseInt(quantityButton.dataset.quantity||"0",10);key&&this.#changeQuantity(key,quantity);return}const removeButton=target.closest("[data-c-cart-rodney-remove]");if(removeButton instanceof HTMLButtonElement){const key=removeButton.dataset.key;key&&this.#changeQuantity(key,0);return}const offerToggle=target.closest(SELECTORS.offerToggle);if(offerToggle instanceof HTMLButtonElement){const sizes=offerToggle.parentElement?.querySelector(SELECTORS.offerSizes),opening=sizes?.hidden===!0;this.#closeOfferSizes(),sizes&&opening&&(sizes.hidden=!1,offerToggle.setAttribute("aria-expanded","true"),sizes.querySelector("[data-c-cart-rodney-add]")?.focus());return}const addButton=target.closest(SELECTORS.add);if(addButton instanceof HTMLButtonElement){const variantId=addButton.dataset.cCartRodneyAdd;variantId&&this.#addRecommendation(variantId)}};#closeOfferSizes(){for(const sizes of this.querySelectorAll(SELECTORS.offerSizes))sizes.hidden=!0;for(const toggle of this.querySelectorAll(SELECTORS.offerToggle))toggle.setAttribute("aria-expanded","false")}async#refreshCart(showLoading=!0){try{showLoading&&this.#setLoading(!0);const cart=await this.#request("/cart.js");await this.#render(cart),this.#hideError()}catch(error){this.#showError(error)}finally{this.#setLoading(!1)}}async#changeQuantity(key,quantity){try{this.#setLoading(!0);const cart=await this.#request("/cart/change.js",{method:"POST",body:JSON.stringify({id:key,quantity})});await this.#render(cart),this.#dispatchCartUpdate(cart,"c-cart-rodney-change"),this.#hideError()}catch(error){this.#showError(error)}finally{this.#setLoading(!1)}}async#addRecommendation(variantId){try{this.#setLoading(!0);const cart=await this.#request("/cart/add.js",{method:"POST",body:JSON.stringify({id:Number(variantId),quantity:1})}),refreshedCart=cart.items?cart:await this.#request("/cart.js");await this.#render(refreshedCart),this.#dispatchCartUpdate(refreshedCart,"c-cart-rodney-recommendation"),this.#hideError()}catch(error){this.#showError(error)}finally{this.#setLoading(!1)}}async#request(url,options={}){const response=await fetch(url,{credentials:"same-origin",headers:{Accept:"application/json","Content-Type":"application/json"},...options}),payload=await response.json();if(!response.ok||payload.errors)throw new Error(payload.description||payload.message||payload.errors||"Cart request failed.");return payload}async#render(cart){try{await this.#renderCart(cart)}finally{this.#refreshShippingProtection()}}#refreshShippingProtection(){typeof nvd_init=="function"&&nvd_init()}async#renderCart(cart){await this.#loadComparePrices(cart.items||[]);const itemCount=cart.item_count||0,title=this.querySelector(SELECTORS.title),items=this.querySelector(SELECTORS.items),subtotal=this.querySelector(SELECTORS.subtotal),checkout=this.querySelector(SELECTORS.checkout);if(this.#renderOfferPrompt(cart),title&&(title.textContent=`Your Cart (${itemCount})`),subtotal&&(subtotal.textContent=this.#formatMoney(cart.total_price||0,cart.currency)),checkout instanceof HTMLButtonElement&&(checkout.dataset.cartEmpty=itemCount===0?"true":"false",checkout.disabled=itemCount===0||this.classList.contains("is-loading")),!!items){if(itemCount===0){items.innerHTML=` 2 <div class="c-cart-rodney__empty"> 3 <div> 4 <h3>Your Cart Is Empty</h3> 5 <a href="/collections/all">Continue Shopping</a> 6 </div> 7 </div> 8 `;return}items.innerHTML=cart.items.map(item=>this.#renderItem(item,cart.currency)).join("")}}#renderOfferPrompt(cart){const offer=this.querySelector(SELECTORS.offer);if(!offer)return;this.#closeOfferSizes();const eligibleIds=(offer.dataset.eligibleProductIds??"").split(",").filter(
8Boolean),inCart=new Map;let eligibleUnits=0;for(const item of cart.items??[]){const id=String(item.product_id??"");if(!eligibleIds.includes(id))continue;const quantity=Number(item.quantity)||0;eligibleUnits+=quantity,inCart.set(id,(inCart.get(id)??0)+quantity)}if(offer.hidden=eligibleUnits!==1,offer.hidden)return;let visibleCards=0;for(const card of offer.querySelectorAll(SELECTORS.offerCard))card.hidden=inCart.has(String(card.dataset.productId)),card.hidden||(visibleCards+=1);if(visibleCards===0){offer.hidden=!0;return}requestAnimationFrame(this.#updateOfferScroll)}#renderItem(item,currency){const image=item.featured_image?.url||item.image||"",imageAlt=item.featured_image?.alt||item.product_title||item.title||"",comparePrice=this.#getComparePrice(item),currentPrice=item.final_price??item.price??0,options=this.#renderOptions(item);return` 9 <article class="c-cart-rodney__item" data-key="${this.#escapeAttribute(item.key)}"> 10 <a class="c-cart-rodney__item-image" href="${this.#escapeAttribute(item.url||"#")}"> 11 ${image?`<img src="${this.#escapeAttribute(image)}" alt="${this.#escapeAttribute(imageAlt)}" loading="lazy">`:""} 12 </a> 13 <div class="c-cart-rodney__item-main"> 14 <div> 15 <h3 class="c-cart-rodney__item-title">${this.#escapeHtml(item.product_title||item.title)}</h3> 16 ${options?`<p class="c-cart-rodney__item-options">${options}</p>`:""} 17 </div> 18 <button 19 class="c-cart-rodney__remove button-unstyled" 20 type="button" 21 data-c-cart-rodney-remove 22 data-key="${this.#escapeAttribute(item.key)}" 23 aria-label="Remove ${this.#escapeAttribute(item.product_title||item.title)}" 24 > 25 ${this.#removeIcon()} 26 </button> 27 <div class="c-cart-rodney__item-bottom"> 28 <div class="c-cart-rodney__quantity" aria-label="Quantity for ${this.#escapeAttribute(item.product_title||item.title)}"> 29 <button 30 type="button" 31 name="minus" 32 data-c-cart-rodney-quantity 33 data-key="${this.#escapeAttribute(item.key)}" 34 data-quantity="${Math.max((item.quantity||1)-1,0)}" 35 aria-label="Decrease quantity" 36 >${this.#minusIcon()}</button> 37 <span>${item.quantity||0}</span> 38 <button 39 type="button" 40 name="plus" 41 data-c-cart-rodney-quantity 42 data-key="${this.#escapeAttribute(item.key)}" 43 data-quantity="${(item.quantity||0)+1}" 44 aria-label="Increase quantity" 45 >${this.#plusIcon()}</button> 46 </div> 47 <div class="c-cart-rodney__price"> 48 ${comparePrice&&comparePrice>currentPrice?`<s class="c-cart-rodney__compare-price">${this.#formatMoney(comparePrice,currency)}</s>`:""} 49 <strong class="c-cart-rodney__current-price">${this.#formatMoney(currentPrice,currency)}</strong> 50 </div> 51 </div> 52 </div> 53 </article> 54 `}#renderOptions(item){const values=[];return Array.isArray(item.options_with_values)?item.options_with_values.forEach(option=>{option?.value&&option.value!=="Default Title"&&values.push(option.value)}):Array.isArray(item.variant_options)&&item.variant_options.forEach(option=>{option&&option!=="Default Title"&&values.push(option)}),values.map(value=>`<span>${this.#escapeHtml(value)}</span>`).join("")}async#loadComparePrices(items){await Promise.all(items.map(async item=>{const cacheKey=String(item.variant_id);if(!Object.prototype.hasOwnProperty.call(this.#comparePrices,cacheKey)){if(!item.handle){this.#comparePrices[cacheKey]=null;return}this.#comparePriceRequests.has(cacheKey)||this.#comparePriceRequests.set(cacheKey,this.#fetchComparePrice(item.handle,item.variant_id)),this.#comparePrices[cacheKey]=await this.#comparePriceRequests.get(cacheKey)}}))}async#fetchComparePrice(handle,variantId){try{return(await this.#request(`/products/${handle}.js`)).variants?.find(candidate=>String(candidate.id)===String(variantId))?.compare_at_price||null}catch{return null}}#getComparePrice(item){const variantComparePrice=this.#comparePrices[Str
54ing(item.variant_id)];return variantComparePrice||(item.original_price&&item.final_price&&item.original_price>item.final_price?item.original_price:null)}#dispatchCartUpdate(cart,source){this.dispatchEvent(new CartUpdateEvent(cart,"c-cart-rodney-drawer",{itemCount:cart.item_count||0,source}))}#setLoading(isLoading){this.classList.toggle("is-loading",isLoading),this.querySelectorAll("button").forEach(button=>{if(button instanceof HTMLButtonElement&&!(button.matches(SELECTORS.open)||button.matches(SELECTORS.close))){if(button.matches(SELECTORS.checkout)){button.disabled=isLoading||button.dataset.cartEmpty==="true";return}button.disabled=isLoading}})}#showError(error){const errorElement=this.querySelector(SELECTORS.error);errorElement&&(errorElement.textContent=error instanceof Error?error.message:"Unable to update the cart. Please try again.",errorElement.removeAttribute("hidden"))}#hideError(){const errorElement=this.querySelector(SELECTORS.error);errorElement&&(errorElement.textContent="",errorElement.setAttribute("hidden",""))}#formatMoney(cents,currency){const activeCurrency=currency||window.Shopify?.currency?.active||"USD";try{return new Intl.NumberFormat(void 0,{style:"currency",currency:activeCurrency,minimumFractionDigits:cents%100===0?0:2}).format(cents/100)}catch{return`$${(cents/100).toFixed(cents%100===0?0:2)}`}}#escapeHtml(value=""){return String(value).replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}#escapeAttribute(value=""){return this.#escapeHtml(value)}#minusIcon(){return'<svg aria-hidden="true" viewBox="0 0 20 20" focusable="false"><path d="M4 10h12" fill="none" stroke="currentColor" stroke-width="2"/></svg>'}#plusIcon(){return'<svg aria-hidden="true" viewBox="0 0 20 20" focusable="false"><path d="M10 4v12M4 10h12" fill="none" stroke="currentColor" stroke-width="2"/></svg>'}#removeIcon(){return'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M4 7H20" stroke="black" stroke-width="1.5" stroke-linecap="square" stroke-linejoin="round"/><path d="M5 7L6 19C6 19.5304 6.21071 20.0391 6.58579 20.4142C6.96086 20.7893 7.46957 21 8 21H16C16.5304 21 17.0391 20.7893 17.4142 20.4142C17.7893 20.0391 18 19.5304 18 19L19 7" stroke="black" stroke-width="1.5" stroke-linecap="square" stroke-linejoin="round"/><path d="M9 7V4C9 3.73478 9.10536 3.48043 9.29289 3.29289C9.48043 3.10536 9.73478 3 10 3H14C14.2652 3 14.5196 3.10536 14.7071 3.29289C14.8946 3.48043 15 3.73478 15 4V7" stroke="black" stroke-width="1.5" stroke-linecap="square" stroke-linejoin="round"/><path d="M10 12L14 16M14 12L10 16" stroke="black" stroke-width="1.5" stroke-linecap="square" stroke-linejoin="round"/></svg>'}}customElements.get("c-cart-rodney-drawer")||customElements.define("c-cart-rodney-drawer",CCartRodneyDrawer); 55//# sourceMappingURL=/cdn/shop/t/50/assets/c-cart-rodney-drawer.js.map?v=136744572900877627821790069109
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.