1import{Component}from"@theme/component";import{ThemeEvents}from"@theme/events";import{morph}from"@theme/morph";class StickyAddToCart extends Component{requiredRefs=["stickyBar","addToCartButton","addToCartSpinner","addToCartText"];#abortController=new AbortController;#buyButtonsIntersectionObserver=null;#footerSectionObserver=null;#isSticky=!1;#hiddenInFooter=!1;connectedCallback(){super.connectedCallback(),this.#setupIntersectionObserver();const{signal}=this.#abortController,target=this.closest(".shopify-section");target?.addEventListener(ThemeEvents.variantUpdate,this.#handleVariantUpdate,{signal}),target?.addEventListener(ThemeEvents.variantSelected,this.#handleVariantSelected,{signal}),document.addEventListener(ThemeEvents.cartUpdate,this.#handleCartAddComplete,{signal}),document.addEventListener(ThemeEvents.cartError,this.#handleCartAddComplete,{signal})}disconnectedCallback(){super.disconnectedCallback(),this.#buyButtonsIntersectionObserver?.disconnect(),this.#footerSectionObserver?.disconnect(),this.#abortController.abort()}updatedCallback(){super.updatedCallback?.(),this.#buyButtonsIntersectionObserver?.disconnect(),this.#footerSectionObserver?.disconnect(),this.#setupIntersectionObserver()}#setupIntersectionObserver(){const productForm=this.#getProductForm();if(!productForm)return;const buyButtonsBlock=productForm.closest(".buy-buttons-block");if(!buyButtonsBlock)return;const footer=document.querySelector("footer")??document.querySelector(".shopify-section-group-footer-group");footer&&(this.#buyButtonsIntersectionObserver=new IntersectionObserver(entries=>{const[entry]=entries;
1if(entry)if(!entry.isIntersecting&&!this.#isSticky){const rect=entry.target.getBoundingClientRect();(rect.bottom<0||rect.top<0)&&this.#show()}else this.#isSticky&&entry.isIntersecting&&(this.#hiddenInFooter=!1,this.#hide())}),this.#footerSectionObserver=new IntersectionObserver(entries=>{const[entry]=entries;if(entry){if(entry.isIntersecting&&this.#isSticky)this.#hiddenInFooter=!0,this.#hide();else if(!entry.isIntersecting&&this.#hiddenInFooter){const rect=buyButtonsBlock.getBoundingClientRect();(rect.bottom<0||rect.top<0)&&(this.#hiddenInFooter=!1,this.#show())}}},{rootMargin:"0px 0px -200px 0px"}),this.#buyButtonsIntersectionObserver.observe(buyButtonsBlock),this.#footerSectionObserver.observe(footer))}#handleVariantUpdate=event=>{if(event.detail.data.productId!==this.dataset.productId)return;const variant=event.detail.resource,newStickyAddToCart=event.detail.data?.html?.querySelector("sticky-add-to-cart");if(!newStickyAddToCart)return;const newStickyBar=newStickyAddToCart.querySelector('[ref="stickyBar"]');if(!newStickyBar)return;const currentSticky=this.refs.stickyBar.getAttribute("data-sticky")||"false",variantAvailable=newStickyAddToCart.dataset.variantAvailable;morph(this.refs.stickyBar,newStickyBar,{childrenOnly:!0}),this.refs.stickyBar.setAttribute("data-sticky",currentSticky),this.dataset.variantAvailable=variantAvailable,variant&&variant.id&&(this.dataset.currentVariantId=variant.id);const isSoldOut=variant&&!variant.available&&variant.inventory_management==="shopify";this.#updateButtonText(variant?.available,isSoldOut),variant==null&&this.#handleVariantUnavailable()};#handleVariantSelected=event=>{const variantId=event.detail.resource?.id;variantId&&(this.dataset.currentVariantId=variantId)};#handleVariantUnavailable=()=>{this.dataset.currentVariantId="";const variantTitleElement=this.querySelector(".sticky-add-to-cart__variant"),productId=this.dataset.productId,variantPicker=document.querySelector(`variant-picker[data-product-id="${productId}"]`);if(!variantTitleElement||!variantPicker)return;const hasInputs=variantPicker.querySelector("input[type='radio']")!==null;let selectedOptions="";hasInputs?selectedOptions=Array.from(variantPicker.querySelectorAll("input:checked")).map(option=>option.value).filter(value=>value!=="").join(" / "):selectedOptions=Array.from(variantPicker.querySelectorAll("select.variant-option__select")).map(select=>{const selectedOption=select.options[select.selectedIndex];return selectedOption?selectedOption.value:""}).filter(value=>value!=="").join(" / "),selectedOptions&&(variantTitleElement.textContent=selectedOptions,this.#updateButtonText(!1))};handleAddToCartClick=()=>{const targetButton=this.#getProductForm()?.querySelector('[ref="addToCartButton"]');targetButton&&(this.#addLoading(),targetButton.click())};#handleCartAddComplete=()=>{this.#removeLoading()};#updateButtonText=(isAvailable,isSoldOut=!1)=>{const{addToCartText,addToCartButton}=this.refs;addToCartText&&(isAvailable?addToCartText.textContent=addToCartButton.dataset.addToCartText:isSoldOut?addToCartText.textContent=addToCartButton.dataset.soldOutText:addToCartText.textContent=addToCartButton.dataset.unavailableText)};#getProductForm(){const productId=this.dataset.productId;if(!productId)return null;const sectionElement=this.closest(".shopify-section");if(!sectionElement)return null;const sectionId=sectionElement.id.replace("shopify-section-","");return document.querySelector(`#shopify-section-${sectionId} product-form-component[data-product-id="${productId}"]`)}#show(){const{stickyBar}=this.refs;this.#isSticky=!0,stickyBar.dataset.sticky="true"}#hide(){const{stickyBar}=this.refs;this.#isSticky=!1,stickyBar.dataset.sticky="false"}#addLoading(){this.refs.addToCartButton.classList.add("btn--loading"),this.refs.addToCartSpinner.classList.remove("hidden")}#removeLoading(){this.refs.addToCartButton.classList.remove("btn--loading"),this.refs.addToCartSpinner.classList.add("hidden")}}customElements.get("sticky-add-to-cart")||customElements.define("sticky-add-to-cart",StickyAddToCart); 2//# sourceMappingURL=/cdn/shop/t/19/assets/sticky-add-to-cart.js.map?v=100130869134554753861775830099
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.