PageSourceSearch

https://punkbunny.com/cdn/shop/t/13/assets/product-sticky-cta.js?v=858926299261534441786592245

js punkbunny.com collected 2026-10-10 02:37:48 UTC 12,019 bytes, 2 lines download raw bytes

1customElements.get("sticky-product-cta")||customElements.define("sticky-product-cta",class extends HTMLElement{constructor(){super(),this.mediaQuery=window.matchMedia("(max-width: 989px)"),this.placeholders=new Map,this.hasPassedSentinel=!1,this.handleTriggerClick=this.handleTriggerClick.bind(this),this.handleCloseClick=this.handleCloseClick.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.handleMediaQueryChange=this.handleMediaQueryChange.bind(this),this.handleSubmitIntent=this.handleSubmitIntent.bind(this),this.handleProductAdded=this.handleProductAdded.bind(this),this.handleProductSubmit=this.handleProductSubmit.bind(this),this.handleScroll=this.handleScroll.bind(this),this.handleCartUpdate=this.handleCartUpdate.bind(this)}connectedCallback(){this.productInfo=this.closest("product-info"),this.productInfo&&(this.trigger=this.querySelector("[data-sticky-cta-trigger]"),this.triggerLabel=this.querySelector(".pdp-sticky-cta__trigger-label"),this.overlay=this.querySelector(".pdp-sticky-cta__overlay"),this.sheet=this.querySelector(".pdp-sticky-cta__sheet"),this.closeButtons=this.querySelectorAll("[data-sticky-cta-close]"),this.slots={"variant-picker":this.querySelector('[data-sticky-cta-slot="variant-picker"]'),quantity:this.querySelector('[data-sticky-cta-slot="quantity"]'),"buy-buttons":this.querySelector('[data-sticky-cta-slot="buy-buttons"]')},this.bindEvents(),this.refresh(),this.observeMutations(),this.handleScroll())}disconnectedCallback(){this.closeSheet({restoreOnly:!0}),this.mutationObserver?.disconnect(),this.mediaQuery.removeEventListener("change",this.handleMediaQueryChange),window.removeEventListener("scroll",this.handleScroll),window.removeEventListener("resize",this.handleScroll),this.trigger?.removeEventListener("click",this.handleTriggerClick),this.closeButtons?.forEach(button=>button.removeEventListener("click",this.handleCloseClick)),document.removeEventListener("keydown",this.handleKeydown),this.productInfo?.removeEventListener("click",this.handleSubmitIntent,!0),this.removeEventListener("click",this.handleSubmitIntent,!0),this.productInfo?.removeEventListener("product-form:added",this.handleProductAdded),this.removeEventListener("product-form:added",this.handleProductAdded),this.productInfo?.removeEventListener("submit",this.handleProductSubmit,!0),this.removeEventListener("submit",this.handleProductSubmit,!0),this.cartUpdateUnsubscriber?.()}bindEvents(){this.trigger?.addEventListener("click",this.handleTriggerClick),this.closeButtons?.forEach(button=>button.addEventListener("click",this.handleCloseClick)),this.mediaQuery.addEventListener("change",this.handleMediaQueryChange),window.addEventListener("scroll",this.handleScroll,{passive:!0}),window.addEventListener("resize",this.handleScroll),document.addEventListener("keydown",this.handleKeydown),this.productInfo.addEventListener("click",this.handleSubmitIntent,!0),this.addEventListener("click",this.handleSubmitIntent,!0),this.productInfo.addEventListener("product-form:added",this.handleProductAdded),this.addEventListener("product-form:added",this.handleProductAdded),this.productInfo.addEventListener("submit",this.handleProductSubmit,!0),this.addEventListener("submit",this.handleProductSubmit,!0),typeof subscribe=="function"&&typeof PUB_SUB_EVENTS<"u"&&(this.cartUpdateUnsubscriber=subscribe(PUB_SUB_EVENTS.cartUpdate,this.handleCartUpdate))}handleMediaQueryChange(){this.mediaQuery.matches?(this.refresh(),this.handleScroll()):(this.closeSheet({restoreOnly:!0}),this.classList.remove("is-visible"))}handleScroll(){if(!this.mediaQuery.matches||!this.sentinel){this.hasPassedSentinel=!1,this.updateVisibility();return}const rect=this.sentinel.getBoundingClientRect();this.hasPassedSentinel=rect.top<=0,this.updateVisibility()}observeMutations(){this.mutationObserver?.disconnect(),this.mutationObserver=new MutationObserver(()=>this.refresh()),this.mutationObserver.observe(this.buyButtonsItem||this.productInfo,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["disabled","aria-disabled","class","value"]})}refresh(){this.buyButtonsItem=this.getItem("buy-buttons"),this.variantPickerItem=this.getItem("variant-picker"),this.quantityItem=this.getItem("quantity"),this.sentinel=this.productInfo.querySelector("[data-sticky-cta-sentinel]"),this.updateSheetSubmitLabel(),this.updateTriggerState(),this.handleScroll(),this.updateVisibility()}getItem(role){const selector=`[data-sticky-cta-item="${role}"]`;return this.productInfo?.querySelector(selector)||this.querySelector(selector)}getSubmitButton(){return this.querySelector(`#ProductSubmitButton-${this.dataset.section}`)||this.querySelector(".product-form__submit")||this.productInfo?.querySelector(`#ProductSubmitButton-${this.dataset.section}`)||this.productInfo?.querySelector(".product-form__submit")}getSubmitLabelElement(){return this.getItem("buy-buttons")?.querySelector(".product-form__submit .product-form__submit-label")||null}getSubmitLabelState(){const submitButton=this.getSubmitButton(),submitLabel=submitButton?.querySelector(".product-form__submit-label")||null,priceText=this.getPriceText(),isDisabled=!submitButton||submitButton.hasAttribute("disabled")||submitButton.getAttribute("aria-disabled")==="true";let currentLabel=submitLabel?.textContent?.trim()||submitButton?.textContent?.trim()||window.variantStrings?.addToCart||"Add to cart";if(priceText){const pricedSuffix=` - ${priceText}`;currentLabel.endsWith(pricedSuffix)&&(currentLabel=currentLabel.slice(0,currentLabel.length-pricedSuffix.length).trim())}return submitLabel&&!isDisabled&&currentLabel&&(submitLabel.dataset.base
1Label=currentLabel),{submitButton,submitLabel,priceText,isDisabled,baseLabel:(isDisabled?currentLabel:submitLabel?.dataset.baseLabel||currentLabel)||window.variantStrings?.addToCart||"Add to cart"}}getPriceText(){const priceRoot=this.productInfo?.querySelector(`#price-${this.dataset.section}`);return priceRoot&&(priceRoot.querySelector(".price__sale .price-item--sale")?.textContent?.trim()||priceRoot.querySelector(".price__regular .price-item--regular:not(.variant-item__old-price)")?.textContent?.trim())||""}hasVariantOptions(){return this.dataset.productHasVariants!=="true"?!1:!!this.variantPickerItem?.querySelector(".product-form__input, variant-selects")}hasAvailableVariants(){return this.dataset.productHasAvailableVariants==="true"}getCurrentVariantId(){return this.querySelector(`#product-form-${this.dataset.section} [name="id"]`)?.value||this.querySelector(`#product-form-installment-${this.dataset.section} [name="id"]`)?.value||this.querySelector(".product-variant-id")?.value||this.productInfo?.querySelector(`#product-form-${this.dataset.section} [name="id"]`)?.value||this.productInfo?.querySelector(`#product-form-installment-${this.dataset.section} [name="id"]`)?.value||this.productInfo?.querySelector(".product-variant-id")?.value||null}setLastSubmittedVariantIdFromTarget(target){const productForm=target?.closest?.("product-form")||target?.closest?.("form")?.closest?.("product-form")||null,form=productForm?.querySelector?.("form")||target?.closest?.("form")||null,variantId=productForm?.variantIdInput?.value||form?.querySelector?.('[name="id"]')?.value||this.getCurrentVariantId();this.lastSubmittedVariantId=variantId||null}updateSheetSubmitLabel(){const{submitLabel,priceText,isDisabled,baseLabel}=this.getSubmitLabelState();if(!submitLabel)return;const nextLabel=!isDisabled&&this.classList.contains("is-sheet-open")&&priceText?`${baseLabel} - ${priceText}`:baseLabel;submitLabel.textContent.trim()!==nextLabel&&(submitLabel.textContent=nextLabel)}updateTriggerState(){if(!this.trigger)return;const{submitButton,priceText,isDisabled,baseLabel}=this.getSubmitLabelState(),hasVariantOptions=this.hasVariantOptions(),hasAvailableVariants=this.hasAvailableVariants(),useVariantPickerTrigger=hasVariantOptions&&hasAvailableVariants,triggerIsDisabled=!submitButton||!useVariantPickerTrigger&&isDisabled,triggerBaseLabel=useVariantPickerTrigger&&isDisabled?window.variantStrings?.addToCart||"Add to cart":baseLabel,triggerLabel=!triggerIsDisabled&&priceText?`${triggerBaseLabel} - ${priceText}`:triggerBaseLabel;this.triggerLabel.textContent.trim()!==triggerLabel&&(this.triggerLabel.textContent=triggerLabel),this.trigger.disabled=triggerIsDisabled,this.classList.toggle("pdp-sticky-cta--has-variants",hasVariantOptions)}updateVisibility(){const shouldShow=this.mediaQuery.matches&&!!this.buyButtonsItem&&this.hasPassedSentinel&&!this.classList.contains("is-sheet-open");this.classList.toggle("is-visible",shouldShow)}handleTriggerClick(event){if(event.preventDefault(),!this.trigger?.disabled){if(this.hasVariantOptions()){this.openSheet();return}this.getSubmitButton()?.click()}}handleCloseClick(event){event.preventDefault(),this.closeSheet()}handleKeydown(event){event.key==="Escape"&&this.classList.contains("is-sheet-open")&&this.closeSheet()}handleSubmitIntent(event){if(!this.classList.contains("is-sheet-open"))return;const submitButton=event.target.closest('button[type="submit"], input[type="submit"], .product-form__submit');submitButton&&(this.setLastSubmittedVariantIdFromTarget(submitButton),window.setTimeout(()=>{this.classList.contains("is-sheet-open")&&this.closeSheet()},0))}handleProductSubmit(event){this.classList.contains("is-sheet-open")&&(this.setLastSubmittedVariantIdFromTarget(event.target),window.setTimeout(()=>{this.classList.contains("is-sheet-open")&&this.closeSheet()},0))}handleProductAdded(event){if(!this.classList.contains("is-sheet-open"))return;const addedVariantId=event?.detail?.productVariantId||null,candidateVariantIds=[this.lastSubmittedVariantId,this.getCurrentVariantId()].filter(Boolean).map(id=>String(id));addedVariantId&&candidateVariantIds.length&&!candidateVariantIds.includes(String(addedVariantId))||(this.closeSheet(),this.lastSubmittedVariantId=null)}handleCartUpdate(event={}){if(!this.classList.contains("is-sheet-open")||event?.source&&event.source!=="product-form")return;const updatedVariantId=event?.productVariantId||event?.data?.productVariantId||null,candidateVariantIds=[this.lastSubmittedVariantId,this.getCurrentVariantId()].filter(
1Boolean).map(id=>String(id));updatedVariantId&&candidateVariantIds.length&&!candidateVariantIds.includes(String(updatedVariantId))||(this.closeSheet(),this.lastSubmittedVariantId=null)}openSheet(){!this.mediaQuery.matches||this.classList.contains("is-sheet-open")||(this.portalItem("variant-picker"),this.portalItem("quantity"),this.portalItem("buy-buttons"),this.classList.add("is-sheet-open"),this.sheet?.setAttribute("aria-hidden","false"),document.documentElement.classList.add("pdp-sticky-cta-lock"),document.body.classList.add("pdp-sticky-cta-lock"),this.updateSheetSubmitLabel(),window.requestAnimationFrame(()=>{this.querySelector(".pdp-sticky-cta__sheet-close")?.focus()}))}closeSheet({restoreOnly=!1}={}){this.restoreItem("variant-picker"),this.restoreItem("quantity"),this.restoreItem("buy-buttons"),this.lastSubmittedVariantId=null,this.classList.remove("is-sheet-open"),this.sheet?.setAttribute("aria-hidden","true"),document.documentElement.classList.remove("pdp-sticky-cta-lock"),document.body.classList.remove("pdp-sticky-cta-lock"),this.updateSheetSubmitLabel(),restoreOnly||this.refresh()}portalItem(role){const item=this.getItem(role),target=this.slots[role];if(!item||!target||item.parentElement===target)return;const placeholder=document.createElement("div");placeholder.hidden=!0,placeholder.dataset.stickyCtaPlaceholder=role,item.before(placeholder),this.placeholders.set(role,placeholder),item.classList.add("is-in-sticky-sheet"),target.appendChild(item)}restoreItem(role){const item=this.getItem(role),placeholder=this.placeholders.get(role);!item||!placeholder||!placeholder.parentNode||(placeholder.parentNode.insertBefore(item,placeholder),item.classList.remove("is-in-sticky-sheet"),placeholder.remove(),this.placeholders.delete(role))}});
2//# sourceMappingURL=/cdn/shop/t/13/assets/product-sticky-cta.js.map?v=858926299261534441786592245

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.