1import VariantPicker from"@theme/variant-picker";import{Component}from"@theme/component";import{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),mediaQueryLarge.addEventListener("change",this.#handleQuickAdd),this.addEventListener("click",this.navigateToProduct),this.addEventListener(SlideshowSelectEvent.eventName,this.#handleSlideshowSelect)}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){if(slideshow){const{slides=[]}=slideshow.refs;for(const slide of slides)slide.getAttribute("variant-image")!=null?slide.hidden=!0:slide.hidden=!1;slideshow.select(0,void 0,{animate:!1})}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,slide.setAttribute("aria-hidden",slide.hidden?"true":"false"));slideshow.select({id:selectedImageId},void 0,{animate:!1})}}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)};previewImage(event){if(event.pointerType!=="mouse")return;const{slideshow}=this.refs;if(slideshow){if(this.variantPicker){if(slideshow.current===0){const selectedImageId=this.variantPicker.selectedOption?.dataset.optionMediaId;selectedImageId?slideshow.select({id:selectedImageId},void 0,{animate:!1}):slideshow.next(void 0,{animate:!1})}else slideshow.select(0,void 0,{animate:!1});return}this.#previousSlideIndex!=null&&this.#previousSlideIndex>0?slideshow.select(this.#previousSlideIndex,void 0,{animate:!1}):slideshow.next(void 0,{animate:!1})}}resetImage(event){if(event.pointerType!=="mouse")return;const{slideshow}=this.refs;if(slideshow){if(this.variantPicker){if(slideshow.current===0){const selectedImageId=this.variantPicker.selectedOption?.dataset.optionMediaId;selectedImageId&&slideshow.select({id:selectedImageId},void 0,{animate:!1})}else slideshow.select(0,void 0,{animate:!1});return}slideshow.select(0,void 0,{animate:!1})}}navigateToProduct=event=>{if(!(event.target instanceof Element)||this.hasAttribute("data-no-navigation"))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),window.Shopify.designMode||history.replaceState({},"",url.toString()),this.#navigateToURL(event,linkURL)}}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/2/assets/product-card.js.map?v=24548179682850908421776826762
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.