1if(!customElements.get("sa-shop-product")){class SaShopProduct extends HTMLElement{constructor(){super(),this.handleSwatchClick=this.handleSwatchClick.bind(this),this.handlePrev=this.handlePrev.bind(this),this.handleNext=this.handleNext.bind(this),this.handleScroll=this.handleScroll.bind(this),this.handleTaglineMore=this.handleTaglineMore.bind(this),this.handleAtcClick=this.handleAtcClick.bind(this),this.handlePageShow=this.handlePageShow.bind(this)}connectedCallback(){this.isMobileGrid=this.classList.contains("sa-shop-product--mobile-grid"),this.track=this.querySelector(".sa-shop-product__track"),this.prevBtn=this.querySelector(".sa-shop-product__ctrl-btn--prev"),this.nextBtn=this.querySelector(".sa-shop-product__ctrl-btn--next"),this.progressBar=this.querySelector(".sa-shop-product__progress-bar"),this.addEventListener("click",this.handleSwatchClick),this.addEventListener("click",this.handleTaglineMore),this.addEventListener("click",this.handleAtcClick),window.addEventListener("pageshow",this.handlePageShow),this.prevBtn&&this.prevBtn.addEventListener("click",this.handlePrev),this.nextBtn&&this.nextBtn.addEventListener("click",this.handleNext),!this.isMobileGrid&&this.track&&this.track.addEventListener("scroll",this.handleScroll,{passive:!0}),this.isMobileGrid||this.updateProgress(),this.initTaglines(),this.alignInfoHeights()}disconnectedCallback(){this.removeEventListener("click",this.handleSwatchClick),this.removeEventListener("click",this.handleTaglineMore),this.removeEventListener("click",this.handleAtcClick),window.removeEventListener("pageshow",this.handlePageShow),this.prevBtn&&this.prevBtn.removeEventListener("click",this.handlePrev),this.nextBtn&&this.nextBtn.removeEventListener("click",this.handleNext),this.track&&this.track.removeEventListener("scroll",this.handleScroll)}handleSwatchClick(e){const swatch=e.target.closest(".sa-shop-product__swatches .option-item");if(!swatch)return;const card=swatch.closest(".sa-shop-product__card");if(!card)return;const value=swatch.dataset.value||"",position=parseInt(swatch.parentElement.dataset.position||"",10);if(!value||!position)return;const activeImg=card.querySelector(".product-img.active");if(!activeImg)return;const parts=(activeImg.dataset.title||"").split(" / ");parts[position-1]=value;const newTitle=parts.join(" / "),allImgs=card.querySelectorAll(".product-img"),newImg=Array.from(allImgs).find(el=>el.dataset.title===newTitle);if(!newImg)return;const variantId=newImg.dataset.id||"",available=newImg.dataset.available==="true",price=newImg.dataset.price||"",comparePrice=newImg.dataset.comparePrice||"";activeImg.classList.remove("active"),newImg.classList.add("active");const prevActive=swatch.parentElement.querySelector(".option-item.active");if(prevActive&&prevActive.classList.remove("active"),swatch.classList.add("active"),card.dataset.autoPrice==="true"){const priceAmount=card.querySelector(".sa-shop-product__price-amount");priceAmount&&price&&(priceAmount.textContent=price);const comparePriceEl=card.querySelector(".sa-shop-product__compare-price");comparePriceEl&&(comparePrice?(comparePriceEl.textContent=comparePrice,comparePriceEl.style.display=""):comparePriceEl.style.display="none")}const buyBtn=card.querySelector(".sa-shop-product__btn-buy");if(buyBtn)if(buyBtn.classList.contains("sa-shop-product__btn-buy--atc"))buyBtn.dataset.variantId=variantId,available&&variantId?(buyBtn.disabled=!1,buyBtn.classList.remove("sa-shop-product__btn-buy--disabled")):(buyBtn.disabled=!0,buyBtn.classList.add("sa-shop-product__btn-buy--disabled"));else{const cartBase=buyBtn.dataset.cartBase;available&&cartBase&&variantId?(buyBtn.href=cartBase+"/"+variantId+":1",buyBtn.classList.remove("sa-shop-product__btn-buy--disabled")):(buyBtn.href="#",buyBtn.classList.add("sa-shop-product__btn-buy--disabled"))}}handleAtcClick(e){const btn=e.target.closest(".sa-shop-product__btn-buy--atc");if(!btn||btn.disabled||btn.classList.contains("sa-shop-product__btn-buy--loading"))return;e.preventDefault();const variantId=parseInt(btn.dataset.variantId||"",10);if(!variantId)return;btn.classList.add("sa-shop-product__btn-buy--loading"),btn.disabled=!0,btn.setAttribute("aria-busy","true");const cart=document.querySelector("cart-notification")||document.querySelector("cart-drawer"),canRenderSections=cart&&typeof cart.getSectionsToRender=="function",body={items:[{id:variantId,quantity:1}],sections:canRenderSections?cart.getSectionsToRender().map(section=>section.id):[],sections_url:window.location.pathname};fetch(window.routes&&window.routes.cart_add_url||"/cart/add",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(body)}).then(res=>res.json()).then(response=>{if(response.status||response.errors){console.error("sa-shop-product add to cart failed:",response.description||response.errors),this.resetAtcButton(btn);return}cart?(this.updateCartCount(),this.updateCartSections(cart,response),typeof cart.open=="function"&&cart.open(),this.resetAtcButton(btn)):window.location.href=window.routes&&window.routes.cart_url||"/cart"}).catch(error=>{console.error("sa-shop-product add to cart failed:",error),this.resetAtcButton(btn)})}resetAtcButton(btn){btn.classList.remove("sa-shop-product__btn-buy--loading"),btn.setAttribute("aria-busy","false"),btn.classList.contains("sa-shop-product__btn-buy--disabled")||(btn.disabled=!1)}handlePageShow(e){e.persisted&&this.querySelectorAll(".sa-shop-product__btn-buy--atc.sa-shop-product__btn-buy--loading").forEach(btn=>this.resetAtcButton(btn))}updateCartCount(){fetch("/cart.json").then(res=>res.json()).then(cartData=>{if(cartData.item_count===void 0)return;document.querySelectorAll(".cart-count").forEach(el=>{el.classList.contains("cart-count-drawer")?el.innerHTML=`(${cartData.item_count})`:el.innerHTML=cartData.item_count>100?"~":cartData.item_count});const headerTotal=document.querySelector("header-total-price");headerTotal&&headerTotal.updateTotal(cartData);const cartFreeShip=document.querySelector("free-ship-progress-bar");cartFreeShip&&cartFreeShip.init(cartData.items_subtotal_price)}).catch(error=>{console.error("Error updating cart count:",error)})}updateCartSections(cart,response){!response.sections||typeof cart.getSectionsToRender!="function"||(cart.getSectionsToRender().forEac
1h(section=>{const elementToReplace=document.getElementById(section.id),inner=new DOMParser().parseFromString(response.sections[section.id]||"","text/html").querySelector("#minicart-form");elementToReplace&&inner&&(elementToReplace.innerHTML=inner.innerHTML)}),typeof cart.cartAction=="function"&&cart.cartAction())}initTaglines(){this.querySelectorAll(".sa-shop-product__tagline").forEach(el=>{const style=getComputedStyle(el);let lh=parseFloat(style.lineHeight);isNaN(lh)&&(lh=parseFloat(style.fontSize)*1.4),el.scrollHeight>lh*3+1&&el.classList.add("sa-shop-product__tagline--clamped")})}handleTaglineMore(e){const btn=e.target.closest(".sa-shop-product__tagline-more");if(!btn)return;e.preventDefault(),e.stopPropagation();const tagline=btn.closest(".sa-shop-product__tagline");tagline&&(tagline.classList.remove("sa-shop-product__tagline--clamped"),tagline.classList.add("sa-shop-product__tagline--expanded"),this.alignInfoHeights())}alignInfoHeights(){const infos=this.querySelectorAll(".sa-shop-product__info");if(!infos.length)return;infos.forEach(el=>{el.style.minHeight=""});let max=0;infos.forEach(el=>{max=Math.max(max,el.offsetHeight)}),max>0&&infos.forEach(el=>{el.style.minHeight=max+"px"})}getCardWidth(){if(!this.track)return 200;const card=this.track.querySelector(".sa-shop-product__card");if(!card)return 200;const gap=parseFloat(getComputedStyle(this.track).gap)||10;return card.offsetWidth+gap}handlePrev(){this.isMobileGrid||this.track&&this.track.scrollBy({left:-this.getCardWidth(),behavior:"smooth"})}handleNext(){this.isMobileGrid||this.track&&this.track.scrollBy({left:this.getCardWidth(),behavior:"smooth"})}handleScroll(){this.isMobileGrid||this.updateProgress()}updateProgress(){if(this.isMobileGrid||!this.track||!this.progressBar)return;const{scrollLeft,scrollWidth,clientWidth}=this.track,maxScroll=scrollWidth-clientWidth;if(maxScroll<=0){this.progressBar.style.width="100%",this.prevBtn&&(this.prevBtn.disabled=!0),this.nextBtn&&(this.nextBtn.disabled=!0);return}const pct=scrollLeft/maxScroll*100;this.progressBar.style.width=Math.min(100,Math.max(0,pct))+"%",this.prevBtn&&(this.prevBtn.disabled=scrollLeft<=1),this.nextBtn&&(this.nextBtn.disabled=scrollLeft>=maxScroll-1)}}customElements.define("sa-shop-product",SaShopProduct)} 2//# sourceMappingURL=/cdn/shop/t/125/assets/sa-shop-product.js.map?v=57271731544161408871784201124
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.