PageSourceSearch

https://www.oghamskincare.com/cdn/shop/t/9/assets/sticky-add-to-cart.js?v=137428914568904088491783954963

js oghamskincare.com collected 2026-10-07 16:37:18 UTC 8,611 bytes, 2 lines download raw bytes

1import{Component}from"@theme/component";import{ThemeEvents}from"@theme/events";const ADD_TO_CART_TEXT_ANIMATION_DURATION=2e3;class StickyAddToCart extends Component{requiredRefs=["button","buttonText","buttonLabel","price"];#intersectionObserver;#buttonObserver;#priceObserver;#abortController;#animationTimeout;#cleanupTimeout;#priceSyncFrame;#priceSyncTimeout;#mainBuyButtons=null;#mainAddToCartButton=null;#mainPrice=null;connectedCallback(){if(super.connectedCallback(),!window.matchMedia("(max-width: 749px)").matches)return;const section=this.#getSection();if(!section||(this.#mainBuyButtons=section.querySelector(".buy-buttons-block"),this.#mainAddToCartButton=section.querySelector('.buy-buttons-block [ref="addToCartButton"]'),this.#mainPrice=this.#findMainPrice(section),!this.#mainBuyButtons||!this.#mainAddToCartButton))return;this.#abortController=new AbortController,this.removeAttribute("hidden"),this.#syncFromMainButton(),this.#syncPrice(),this.#observeVisibility(),this.#observeMainButton(),this.#observeMainPrice(),this.#observePurchaseOptionChanges(section);const{signal}=this.#abortController;section.addEventListener(ThemeEvents.variantUpdate,this.#onVariantUpdate,{signal}),section.addEventListener(ThemeEvents.variantSelected,this.#onVariantSelected,{signal}),this.refs.button.addEventListener("click",this.#onStickyClick,{signal})}disconnectedCallback(){super.disconnectedCallback(),this.#intersectionObserver?.disconnect(),this.#buttonObserver?.disconnect(),this.#priceObserver?.disconnect(),this.#abortController?.abort(),this.#animationTimeout&&clearTimeout(this.#animationTimeout),this.#cleanupTimeout&&clearTimeout(this.#cleanupTimeout),this.#priceSyncFrame&&cancelAnimationFrame(this.#priceSyncFrame),this.#priceSyncTimeout&&clearTimeout(this.#priceSyncTimeout)}#getSection(){return this.closest(".shopify-section")}#observeVisibility(){this.#mainBuyButtons&&(this.#intersectionObserver=new IntersectionObserver(([entry])=>{const shouldShow=!!(entry&&!entry.isIntersecting);this.classList.toggle("sticky-atc--visible",shouldShow),this.setAttribute("aria-hidden",shouldShow?"false":"true")},{threshold:0}),this.#intersectionObserver.observe(this.#mainBuyButtons))}#observeMainButton(){this.#mainAddToCartButton&&(this.#buttonObserver=new MutationObserver(()=>{this.#syncFromMainButton()}),this.#buttonObserver.observe(this.#mainAddToCartButton,{attributes:!0,attributeFilter:["disabled","class"],childList:!0,subtree:!0,characterData:!0}))}#observeMainPrice(){this.#mainPrice&&(this.#priceObserver=new MutationObserver(()=>{this.#queuePriceSync()}),this.#priceObserver.observe(this.#mainPrice,{childList:!0,subtree:!0,characterData:!0}))}#observePurchaseOptionChanges(section){const{signal}=this.#abortController??{};if(!signal)return;const sync=()=>{this.#queuePriceSync(),this.#priceSyncTimeout&&clearTimeout(this.#priceSyncTimeout),this.#priceSyncTimeout=setTimeout(()=>this.#syncPrice(),0)};section.addEventListener("change",event=>{const target=event.target;target instanceof HTMLInputElement&&target.matches('[data-radio-type], [data-variant-price], [name="selling_plan"], [name^="purchaseOption"]')&&sync()},{signal,capture:!0}),section.addEventListener("click",event=>{const target=event.target;target instanceof Element&&target.closest(".shopify_subscriptions_app_block, .subscription_group, .group_list_item, .plan_card, [data-radio-type]")&&sync()},{signal,capture:!0})}#findMainPrice(section){const productId=this.dataset.productId,candidates=Array.from(section.querySelectorAll("product-price"));return candidates.find(el=>
1el.dataset.productId===productId&&!this.contains(el))??candidates.find(el=>!this.contains(el))??null}#queuePriceSync(){this.#priceSyncFrame&&cancelAnimationFrame(this.#priceSyncFrame),this.#priceSyncFrame=requestAnimationFrame(()=>{this.#priceSyncFrame=void 0,this.#syncPrice()})}#getSelectedPurchaseOption(){const section=this.#getSection();return section?section.querySelector('.shopify_subscriptions_app_block input[type="radio"][data-radio-type]:checked')||section.querySelector('.subscription_group input[type="radio"][data-variant-price]:checked')||section.querySelector('input[type="radio"][data-variant-price]:checked'):null}#syncPrice=()=>{this.#syncPriceFromPurchaseOption()||this.#syncPriceFromMain()};#syncPriceFromPurchaseOption(){const option=this.#getSelectedPurchaseOption(),price=option?.dataset?.variantPrice?.trim();if(!option||!price)return!1;const compareAt=option.dataset.variantCompareAtPrice?.trim()||"",hasCompare=!!(compareAt&&compareAt!==price),container=document.createElement("div");if(container.setAttribute("ref","priceContainer"),hasCompare){const compareGroup=document.createElement("span");compareGroup.setAttribute("role","group");const compareEl=document.createElement("span");compareEl.className="compare-at-price",compareEl.textContent=compareAt,compareGroup.appendChild(compareEl),container.appendChild(compareGroup)}const priceGroup=document.createElement("span");priceGroup.setAttribute("role","group");const priceEl=document.createElement("span");priceEl.className="price",priceEl.textContent=price,priceGroup.appendChild(priceEl),container.appendChild(priceGroup);const current=this.refs.price.querySelector('[ref="priceContainer"]')??this.refs.price.firstElementChild,nextSignature=`${price}|${hasCompare?compareAt:""}`;return`${current?.querySelector(".price")?.textContent?.trim()||""}|${current?.querySelector(".compare-at-price")?.textContent?.trim()||""}`!==nextSignature&&this.refs.price.replaceChildren(container),!0}#syncPriceFromMain=()=>{const section=this.#getSection();if(section&&(this.#mainPrice=this.#findMainPrice(section)??this.#mainPrice),!this.#mainPrice)return;const liveClone=(this.#mainPrice.querySelector('[ref="priceContainer"]')??this.#mainPrice).cloneNode(!0);if(!(liveClone instanceof Element))return;liveClone.querySelector(".tax-note")?.remove(),liveClone.querySelector(".installments")?.remove();const currentPrice=this.refs.price.querySelector('[ref="priceContainer"]')??this.refs.price.firstElementChild;currentPrice instanceof Element?currentPrice.innerHTML.trim()!==liveClone.innerHTML.trim()&&currentPrice.replaceWith(liveClone):this.refs.price.replaceChildren(liveClone)};#syncFromMainButton=()=>{const mainButton=this.#mainAddToCartButton;if(!mainButton)return;const{button,buttonLabel,buttonText}=this.refs,isDisabled=mainButton.hasAttribute("disabled")||mainButton.getAttribute("disabled")==="true";button.disabled=isDisabled,button.classList.toggle("sticky-atc__button--disabled",isDisabled);const mainLabel=mainButton.querySelector(".add-to-cart-text__content");mainLabel?.textContent!=null&&(buttonLabel.textContent=mainLabel.textContent.trim());const hasIcon=!!mainButton.querySelector(".add-to-cart-text")?.querySelector(".add-to-cart-icon"),stickyIcon=buttonText.querySelector(".add-to-cart-icon");stickyIcon&&stickyIcon.toggleAttribute("hidden",!hasIcon||isDisabled)};#onVariantUpdate=event=>{const detail=event.detail??{},data=detail.data??{};if(!data.html)return;if(data.newProduct)this.dataset.productId=String(data.newProduct.id);else if(data.productId&&String(data.productId)!==this.dataset.productId)return;const newMediaSrc=detail.resource?.featured_media?.preview_image?.src,image=this.refs.media?.querySelector("img");if(image&&newMediaSrc){const nextSrc=newMediaSrc.includes("width=")?newMediaSrc:`${newMediaSrc}&width=96`;image.src=nextSrc,image.srcset=`${nextSrc.replace(/width=\d+/,"width=48")} 48w, ${nextSrc.replace(/width=\d+/,"width=96")} 96w`}requestAnimationFrame(()=>{this.#mainAddToCartButton=this.#getSection()?.querySelector('.buy-buttons-block [ref="addToCartButton"]')??this.#mainAddToCartButton,this.#syncFromMainButton(),this.#syncPrice(),setTimeout(()=>this.#syncPrice(),50),setTimeout(()=>this.#syncPrice(),200)})};#onVariantSelected=()=>{this.refs.button.disabled=!0,this.refs.button.classList.add("sticky-atc__button--disabled")};#onStickyClick=()=>{this.refs.button.disabled||!this.#mainAddToCartButton||(this.#animateAddToCart(),this.#mainAddToCartButton.click())};#animateAddToCart(){const{button}=this.refs;this.#animationTimeout&&clearTimeout(this.#animationTimeout),this.#cleanupTimeout&&clearTimeout(this.#cleanupTimeout),button.classList.add("atc-added"),this.#animationTimeout=setTimeout(()=>{this.#cleanupTimeout=setTimeout(()=>{button.classList.remove("atc-added")},10)},ADD_TO_CART_TEXT_ANIMATION_DURATION)}}customElements.get("sticky-add-to-cart")||customElements.define("sticky-add-to-cart",StickyAddToCart);
2//# sourceMappingURL=/cdn/shop/t/9/assets/sticky-add-to-cart.js.map?v=137428914568904088491783954963

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.