1import VariantPicker from"@theme/variant-picker";import{Component}from"@theme/component";import{debounce,isDesktopBreakpoint,mediaQueryLarge}from"@theme/utilities";import{ThemeEvents,SlideshowSelectEvent}from"@theme/events";import{morph}from"@theme/morph";export class ProductCard extends Component{requiredRefs=["productCardLink"];get productPageUrl(){return this.refs.productCardLink.href}#fetchProductPageHandler=()=>{this.refs.quickAdd?.cachedProductHtml||this.refs.quickAdd?.fetchProductPage(this.productPageUrl)};#navigateToURL=(event,url)=>{if(event instanceof MouseEvent&&(event.metaKey||event.ctrlKey||event.shiftKey||event.button===1)){event.preventDefault(),window.open(url.href,"_blank");return}else window.location.href=url.href};connectedCallback(){if(super.connectedCallback(),!(this.refs.productCardLink instanceof HTMLAnchorElement))throw new Error("Product card link not found");this.#handleQuickAdd(),this.addEventListener(ThemeEvents.variantUpdate,this.#handleVariantUpdate),this.addEventListener(ThemeEvents.variantSelected,this.#handleVariantSelected),this.addEventListener(SlideshowSelectEvent.eventName,this.#handleSlideshowSelect),mediaQueryLarge.addEventListener("change",this.#handleQuickAdd),this.addEventListener("click",this.navigateToProduct),setTimeout(()=>{this.refs.slideshow?.isNested&&this.#preloadNextPreviewImage()})}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this.navigateToProduct)}#preloadNextPreviewImage(){this.refs.slideshow?.slides?.[this.refs.slideshow?.current]?.nextElementSibling?.querySelector('img[loading="lazy"]')?.removeAttribute("loading")}#handleQuickAdd=()=>{this.removeEventListener("pointerenter",this.#fetchProductPageHandler),this.removeEventListener("focusin",this.#fetchProductPageHandler),isDesktopBreakpoint()&&(this.addEventListener("pointerenter",this.#fetchProductPageHandler),this.addEventListener("focusin",this.#fetchProductPageHandler))};#handleVariantSelected=event=>{event.target!==this.variantPicker&&this.variantPicker?.updateSelectedOption(event.detail.resource.id)};#handleVariantUpdate=event=>{event.stopPropagation(),this.updatePrice(event),this.#isUnavailableVariantSelected(event),this.#updateProductUrl(event),this.refs.quickAdd?.fetchProductPage(this.productPageUrl),event.target!==this.variantPicker&&this.variantPicker?.updateVariantPicker(event.detail.data.html),this.#updateVariantImages(),this.#previousSlideIndex=null};updatePrice(event){const priceContainer=this.querySelectorAll("product-price [ref='priceContainer']")[1],newPriceElement=event.detail.data.html.querySelector("product-price [ref='priceContainer']");newPriceElement&&priceContainer&&morph(priceContainer,newPriceElement)}#updateProductUrl(event){const anchorElement=event.detail.data.html?.querySelector("product-card a"),featuredMediaUrl=event.detail.data.html?.querySelector("product-card-link")?.getAttribute("data-featured-media-url");if(featuredMediaUrl&&this.closest("product-card-link")&&this.closest("product-card-link")?.setAttribute("data-featured-media-url",featuredMediaUrl),anchorElement instanceof HTMLAnchorElement){if(anchorElement.getAttribute("href")?.trim()==="")return;this.refs.productCardLink.href=anchorElement.href}}#isUnavailableVariantSelected(event){const allVariants=event.detail.data.html.querySelectorAll("input:checked");for(const variant of allVariants)this.#toggleAddToCartButton(variant.dataset.optionAvailable==="true")}#toggleAddToCartButton(enable){const addToCartButton=this.querySelector(".add-to-cart__button button");addToCartButton instanceof HTMLButtonElement&&(addToCartButton.disabled=!enable)}#updateVariantImages(){const{slideshow}=this.refs;if(!this.variantPicker?.selectedOption)return;const selectedImageId=this.variantPicker?.selectedOption.dataset.optionMediaId;if(slideshow&&selectedImageId){const{slides=[]}=slideshow.refs;for(const slide of slides)slide.getAttribute("variant-image")!=null&&(slide.hidden=slide.getAttribute("slide-id")!==selectedImageId)}}get allVariants(){return this.querySelectorAll("input[data-variant-id]")}get variantPicker(){return this.querySelector("swatches-variant-picker-component")}#previousSlideIndex=null;#handleSlideshowSelect=event=>{event.detail.userInitiated&&(this.#previousSlideIndex=event.detail.index)};previewVariant(id){const{slideshow}=this.refs;slideshow&&(this.resetVariant.cancel(),slideshow.select({id},void 0,{animate:!1}))}previewImage(event){const{slideshow}=this.refs;!slideshow||event.pointerType!=="mouse"||(this.resetVariant.cancel(),this.#previousSlideIndex!=null&&this.#previousSlideIndex>0?slideshow.select(this.#previousSlideIndex,void 0,{animate:!1}):(slideshow.next(void 0,{animate:!1}),setTimeout(()=>this.#preloadNextPreviewImage())))}resetImage(){const{slideshow}=this.refs;if(this.variantPicker)this.#resetVariant();
1else{if(!slideshow)return;slideshow.previous(void 0,{animate:!1})}}#resetVariant=()=>{const{slideshow}=this.refs;if(!slideshow)return;const defaultSlide=slideshow.defaultSlide,slideId=defaultSlide?.getAttribute("slide-id");if(defaultSlide&&slideshow.slides?.includes(defaultSlide)&&slideId){slideshow.select({id:slideId},void 0,{animate:!1});return}else if(!this.variantPicker?.selectedOption){slideshow.previous(void 0,{animate:!1});return}const id=this.variantPicker.selectedOption.dataset.optionMediaId;if(!id){slideshow.previous(void 0,{animate:!1});return}slideshow.select({id},void 0,{animate:!1})};navigateToProduct=event=>{if(!(event.target instanceof Element))return;const interactiveElement=event.target.closest('button, input, label, select, a, [tabindex="1"]');if(interactiveElement&&interactiveElement!==this.refs.productCardLink)return;const link=this.refs.productCardLink;if(!link.href)return;const linkURL=new URL(link.href),productCardAnchor=link.getAttribute("id");if(!productCardAnchor)return;const url=new URL(window.location.href),parent=this.closest("li");url.hash=productCardAnchor,parent&&parent.dataset.page&&url.searchParams.set("page",parent.dataset.page),history.replaceState({},"",url.toString()),this.#navigateToURL(event,linkURL)};resetVariant=debounce(this.#resetVariant,100)}customElements.get("product-card")||customElements.define("product-card",ProductCard);class SwatchesVariantPickerComponent extends VariantPicker{showAllSwatches(event){event?.preventDefault();const{overflowList}=this.refs;overflowList instanceof OverflowList&&overflowList.showAll()}}customElements.get("swatches-variant-picker-component")||customElements.define("swatches-variant-picker-component",SwatchesVariantPickerComponent); 2//# sourceMappingURL=/cdn/shop/t/796/assets/product-card.js.map?v=46085189543194988631783022037
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.