1document.addEventListener("DOMContentLoaded",function(){const collectionMenu=document.getElementById("collectionMenu"),collectionList=collectionMenu?collectionMenu.querySelector(".collection-list"):null,collectionProducts=document.getElementById("collectionProducts");if(!collectionProducts)return;function fetchCollectionProducts(collectionHandle){const url=`/collections/${collectionHandle}/products.json`;fetch(url).then(response=>response.json()).then(data=>{renderProducts(data.products)}).catch(error=>{console.error("Error fetching collection products:",error)})}function renderProducts(products){collectionProducts.innerHTML="",products.slice(0,12).forEach(product=>{const imageUrl=product.images.length>0?product.images[0].src:"path/to/default-image.jpg",price=product.variants[0].price,compareAtPrice=product.variants[0].compare_at_price?product.variants[0].compare_at_price:null;let priceHTML=`$${price}`;compareAtPrice&&(priceHTML=`<span style="text-decoration: line-through;">$${compareAtPrice}</span> $${price}`);const productHTML=` 2 <div class="product-card add-to-cart product-card-gift grid__item" data-variant-id="${product.variants[0].id}"> 3 <img src="${imageUrl}" alt="${product.title}"> 4 <div class="product-card-gift--content"> 5 <div class="prod-title">${product.title}</div> 6 <div class="price"><b>${priceHTML}</b></div> 7 </div> 8 </div> 9 `;collectionProducts.innerHTML+=productHTML}),document.querySelectorAll(".add-to-cart").forEach(button=>{button.addEventListener("click",function(){const variantId=this.getAttribute("data-variant-id");addToCart(variantId)})})}function showPopup(message,isSuccess=!0){const popup=document.createElement("div");popup.className=`popup-notice ${isSuccess?"success":"error"}`,popup.textContent=message,document.body.appendChild(popup),setTimeout(()=>{popup.classList.add("show")},10),setTimeout(()=>{popup.classList.remove("show"),setTimeout(()=>{document.body.removeChild(popup)},300)},3e3)}function addToCart(variantId){fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({id:variantId,quantity:1})}).then(response=>response.json()).then(data=>{console.log("Product added to cart:",data),showPopup(`${data.title} successfully added to cart`,!0),updateCart()}).catch(error=>{console.error("Error adding product to cart:",error),showPopup("Failed to add product to cart. Please try again.",!1)})}function updateCart(){fetch("/cart?view=drawer").then(response=>response.text()).then(html=>{const doc=new DOMParser().parseFromString(html,"text/html"),cartDrawer=document.querySelector("cart-drawer,#CartDrawer, [data-cart-drawer]");if(cartDrawer){const newDrawerContent=doc.querySelector("cart-drawer,#CartDrawer, [data-cart-drawer]").innerHTML;cartDrawer.innerHTML=newDrawerContent,cartDrawer.querySelectorAll(".cart-item").length>0&&cartDrawer.classList.remove("is-empty")}else console.error("Cart drawer element not found");const cartIconBubble=document.querySelector("#cart-icon-bubble");if(cartIconBubble){const newBubbleContent=doc.querySelector("#cart-icon-bubble").innerHTML;cartIconBubble.innerHTML=newBubbleContent}else console.error("Cart icon bubble not found")}).catch(error=>{console.error("Error updating cart drawer:",error)})}function resolveIntent(){const ownCollections=(collectionMenu.getAttribute("data-product-collections")||"").split(",").filter(Boolean);function usable(candidate){if(!candidate||!Array.isArray(candidate.tabs))return null;const tabs=candidate.tabs.filter(function(tab){return tab&&tab.handle&&ownCollections.indexOf(tab.handle)===-1});return tabs.length?Object.assign({},candidate,{tabs}):null}const fromHistory=window.FFEIntent&&typeof window.FFEIntent.getForCollections=="function"?usable(window.FFEIntent.getForCollections(ownCollections)):null;if(fromHistory)return fromHistory;const fallbacks=Array.isArray(window.FFEIntentFallbacks)?window.FFEIntentFallbacks:window.FFEIntentFallback?[window.FFEIntentFallback]:[];for(let i=0;i<fallbacks.length;i++){const match=usable(fallbacks[i]);if(match)return match}return null}function renderIntentMenu(intent){const remainingTabs=Array.prototype.filter.call(collectionList.querySelectorAll(".collection-list--item"),function(item){const handle=item.getAttribute("data-handle");return!intent.tabs.some(function(tab){return tab.handle===handle})});collectionList.innerHTML=intent.tabs.map(function(tab,index){const image=tab.image?`<img src="${tab.image}" alt="${tab.title}" />`:"";return` 10 <a href="javascript:void(0);" class="grid__item collection-list--item${index===0?" selected":""}" data-handle="${tab.handle}"> 11 ${image} 12 <div class="collection-title">${tab.title}</div> 13 </a> 14 `}).join(""),collectionMenu.removeAttribute("data-upsell-default");const seeAllButton=collectionMenu.querySelector(".upsell-see-all");!seeAllButton||!remainingTabs.length||(seeAllButton.hidden=!1,seeAllButton.addEventListener("click",function(){remainingTabs.forEac
14h(function(item){item.classList.remove("selected"),collectionList.appendChild(item)}),seeAllButton.hidden=!0},{once:!0}))}function initializeCollectionHandle(){const intent=collectionList?resolveIntent():null;if(intent){renderIntentMenu(intent),fetchCollectionProducts(intent.tabs[0].handle);return}const defaultHandle="extra-wow",defaultItem=collectionList?collectionList.querySelector(`.collection-list--item[data-handle="${defaultHandle}"]`):null;defaultItem&&defaultItem.classList.add("selected"),fetchCollectionProducts(defaultHandle)}initializeCollectionHandle(),collectionMenu&&collectionMenu.addEventListener("click",function(event){const target=event.target,item=target&&target.closest?target.closest(".collection-list--item"):null;if(!item)return;collectionMenu.querySelectorAll(".collection-list--item").forEach(function(el){el.classList.remove("selected")}),item.classList.add("selected");const collectionHandle=item.getAttribute("data-handle");collectionHandle&&fetchCollectionProducts(collectionHandle)})});const style=document.createElement("style");style.textContent=` 15 .popup-notice { 16 position: fixed; 17 bottom: 20px; 18 left: 50%; 19 transform: translateX(-50%); 20 background-color: #4caf50; 21 color: white; 22 padding: 15px; 23 border-radius: 5px; 24 font-size: 16px; 25 opacity: 0; 26 transition: opacity 0.3s, bottom 0.3s; 27 z-index: 1000; 28 } 29 30 .popup-notice.error { 31 background-color: #f44336; 32 } 33 34 .popup-notice.show { 35 opacity: 1; 36 bottom: 40px; 37 } 38 39 @media (max-width: 600px) { 40 .popup-notice { 41 width: 90%; 42 font-size: 14px; 43 padding: 10px; 44 bottom: 10px; 45 } 46 47 .popup-notice.show { 48 bottom: 20px; 49 } 50 } 51`,document.head.appendChild(style); 52//# sourceMappingURL=/cdn/shop/t/29/assets/upsells.js.map?v=89613549354296087311789013930
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.