1(()=>{const HOLDER_SELECTOR='[id="CartDrawerRecommendations"]',RECS_URL="/recommendations/products",FALLBACK_COLL="ymi-best-sellers",VENDOR_COLLECTIONS={YMI:["ymi-best-sellers","ymi-all-jeans","ymi-menu-new"],GIRLS:["girls","ymi-girls-spring","girls-pants","girls-shorts-and-skirts"],"YMI GIRLS":["ymi-girls-spring","girls","ymi-girls-cargo"],"YMI JEANS":["ymi-best-sellers","ymi-all-jeans"],ROYALTYFORME:["ymi-best-sellers"],DEFAULT:["ymi-best-sellers"]},RETRY_DELAY=200,MAX_RETRIES=6,buildRecUrl=pid=>`${RECS_URL}?product_id=${pid}&limit=12&intent=related§ion_id=product-recommendations`,formatPrice=m=>(Number(m)>1e3?m/100:Number(m)).toLocaleString("en-US",{style:"currency",currency:"USD"}),getCartVendors=async()=>{try{const cart=await fetch("/cart.js").then(r=>r.json()),vendors=new Set;return cart.items&&cart.items.length>0&&cart.items.forEach(item=>{if(item.vendor){const vendor=item.vendor.toUpperCase().trim();vendors.add(vendor)}}),Array.from(vendors)}catch{return[]}},getVendorBasedCollection=vendors=>{if(!vendors||vendors.length===0)return VENDOR_COLLECTIONS.DEFAULT[0];for(const vendor of vendors)if(VENDOR_COLLECTIONS[vendor])return VENDOR_COLLECTIONS[vendor][0];if(vendors.some(v=>v.includes("YMI")&&v.includes("GIRLS")))return VENDOR_COLLECTIONS["YMI GIRLS"][0];const hasYMI=vendors.some(v=>v.includes("YMI")),hasGirls=vendors.some(v=>v.includes("GIRLS")||v.includes("GIRL"));return hasYMI&&hasGirls?VENDOR_COLLECTIONS["YMI GIRLS"][0]:hasYMI||vendors.some(v=>v.includes("JEANS"))?VENDOR_COLLECTIONS.YMI[0]:hasGirls?VENDOR_COLLECTIONS.GIRLS[0]:vendors.some(v=>v.includes("ROYALTY")||v.includes("RFM"))?VENDOR_COLLECTIONS.ROYALTYFORME[0]:VENDOR_COLLECTIONS.DEFAULT[0]},productCard=p=>{const img=p.images?.[0]?.src?p.images[0].src.replace(/(\.[a-z]+)(\?.*)?$/,"_400x$1"):"//cdn.shopify.com/s/assets/no-image-400x.gif";return` 2 <div class="grid__item grid-product small--one-half medium-up--one-quarter" 3 data-product-id="${p.id}" data-product-handle="${p.handle}"> 4 <a href="/products/${p.handle}" class="grid-product__link"> 5 <div class="grid-product__image-mask"> 6 7 <div class="image-wrap"><img src="${img}" alt="${p.title}" loading="lazy"></div> 8 </div> 9 </a> 10 <div class="grid-product__meta"> 11 <div class="grid-product__title">${p.title}</div> 12 <div class="grid-product__price">${formatPrice(p.variants[0].price)}</div> 13 </div> 14 </div>`},fetchFallback=async()=>{const vendors=await getCartVendors(),collection=getVendorBasedCollection(vendors),products=(await fetch(`/collections/${collection}/products.json?limit=12`).then(x=>x.json())).products||[];return{html:products.map(productCard).join(""),products}},renderQuickShopModals=products=>{const wrap=document.createElement("div");products.forEach(p=>{wrap.innerHTML+=`<div id="QuickShopModal-${p.id}" class="modal modal--square modal--quick-shop" data-product-id="${p.id}"> 15 <div class="modal__inner"> 16 <div class="modal__centered"> 17 <div class="modal__centered-content"> 18 <button type="button" class="modal__close js-modal-close text-link desktop-close-only"> 19 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"> 20 <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="m3.334 3.333 9.333 9.334M12.667 3.333l-9.333 9.334"></path> 21 </svg> 22 <span>Close</span> 23 </button> 24 <div id="QuickShopHolder-${p.handle}"></div> 25 </div> 26 </div> 27 </div> 28 </div>`}),document.body.appendChild(wrap)},injectBlock=(holder,title,markup,products=[])=>{holder.innerHTML=`<div class="header-part">${title}</div> 29 <div class="product-part" data-event="open">${markup}</div>`,products.length&&renderQuickShopModals(products),theme?.initQuickShop?.()},extractProductsFromSwiper=html=>{const tmp=document.createElement("div");tmp.innerHTML=html;const swiperSlides=tmp.querySelectorAll(".swiper-slide");if(swiperSlides.length>0){const products=[],productObjects=[];
29return swiperSlides.forEach(slide=>{const gridProduct=slide.querySelector(".grid__item.grid-product");if(gridProduct){gridProduct.className="grid__item grid-product small--one-half medium-up--one-quarter",products.push(gridProduct.outerHTML);const productId=gridProduct.getAttribute("data-product-id"),productHandle=gridProduct.getAttribute("data-product-handle");productId&&productHandle&&productObjects.push({id:productId,handle:productHandle})}}),{html:products.join(""),products:productObjects}}const gridProducts=tmp.querySelectorAll(".grid__item.grid-product");if(gridProducts.length>0){const products=[],productObjects=[];return Array.from(gridProducts).forEach(product=>{product.className="grid__item grid-product small--one-half medium-up--one-quarter",products.push(product.outerHTML);const productId=product.getAttribute("data-product-id"),productHandle=product.getAttribute("data-product-handle");productId&&productHandle&&productObjects.push({id:productId,handle:productHandle})}),{html:products.join(""),products:productObjects}}return{html:"",products:[]}},renderHolder=async(holder,pid)=>{holder.innerHTML="";const upsellCollection=holder.dataset.upsellCollection,fallbackCollection=holder.dataset.fallbackCollection;if(upsellCollection&&upsellCollection.trim()!==""){const products=(await fetch(`/collections/${upsellCollection}/products.json?limit=12`).then(x=>x.json())).products||[];if(products.length){injectBlock(holder,"Recommended For You",products.map(productCard).join(""),products);return}}const recUrl=pid?buildRecUrl(pid):null,hasVendorPreference=(await getCartVendors()).length>0;if(recUrl)try{const html=await fetch(recUrl).then(r=>r.text()),tmp=document.createElement("div");tmp.innerHTML=html;const recs=tmp.querySelector(".product-recommendations");
29if(recs&&recs.innerHTML.trim()){const{html:extractedHtml,products}=extractProductsFromSwiper(recs.innerHTML);if(extractedHtml){injectBlock(holder,"Frequently Bought Together",extractedHtml,products);return}}}catch{}if(fallbackCollection&&fallbackCollection.trim()!=="")try{const fallbackProducts=(await fetch(`/collections/${fallbackCollection}/products.json?limit=12`).then(x=>x.json())).products||[];if(fallbackProducts.length){const title=hasVendorPreference?"Recommended for You":"Best Sellers";injectBlock(holder,"Recommended for You",fallbackProducts.map(productCard).join(""),fallbackProducts);return}}catch{}},loadProductIdWithRetry=async()=>{for(let i=0;i<MAX_RETRIES;i++){try{const cart=await fetch("/cart.js").then(r=>r.json());if(cart.items?.[0]?.product_id)return cart.items[0].product_id}catch{}await new Promise(res=>setTimeout(res,RETRY_DELAY))}return null},renderAll=async()=>{const holders=[...document.querySelectorAll(HOLDER_SELECTOR)];if(!holders.length)return;const pid=await loadProductIdWithRetry();holders.forEach(h=>renderHolder(h,pid))};new MutationObserver(()=>{document.body.classList.contains("drawer--is-open")&&renderAll()}).observe(document.body,{attributes:!0,attributeFilter:["class"]});const origFetch=window.fetch;window.fetch=async(...a)=>{const resp=await origFetch(...a),url=typeof a[0]=="string"?a[0]:a[0].url;return/\/cart\/(add|change|update)(\.js)?/i.test(url)&&renderAll(),resp},document.addEventListener("DOMContentLoaded",renderAll)})(); 30//# sourceMappingURL=/cdn/shop/t/131/assets/upsell-products.js.map?v=99860665526715843391773947751
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.