PageSourceSearch

https://labelleboucle.fr/cdn/shop/t/258/assets/featured-collections-nosto.js?v=134117741856776280771790931185

js labelleboucle.fr collected 2026-10-03 21:22:21 UTC 10,866 bytes, 2 lines download raw bytes

1(function(){if(typeof window>"u"||window.__featuredCollectionsNostoInstalled)return;window.__featuredCollectionsNostoInstalled=!0;const SECTION_NAME="card-product-nosto-reco",RECO_SELECTOR="[data-nosto-recommendation]",NOSTO_TIMEOUT_MS=1e4,FALLBACK_TIMEOUT_MS=5e3,NOSTO_POLL_MS=100,SWIPER_POLL_MS=100,SWIPER_TIMEOUT_MS=5e3,placementCache=new Map;function waitForNosto(){return new Promise(function(resolve,reject){let spent=0;const tick=function(){if(typeof window.nostojs=="function")return resolve();if(spent>=NOSTO_TIMEOUT_MS)return reject(new Error("Nosto load timeout"));spent+=NOSTO_POLL_MS,setTimeout(tick,NOSTO_POLL_MS)};tick()})}function extractProductsFromHtml(root){const seen=new Set,products=[];return root.querySelectorAll('a[href*="/products/"]').forEach(function(a){const url=a.getAttribute("href");if(!url)return;const handle=url.split("?")[0].replace(/\/+$/,"").split("/").pop();if(!handle||seen.has(handle))return;seen.add(handle);const idHost=a.closest("[data-product-id]")||a.querySelector("[data-product-id]"),label=a.getAttribute("aria-label")||"";products.push({product_url:url,product_id:a.getAttribute("data-product-id")||idHost&&idHost.getAttribute("data-product-id")||null,product_name:label.replace(/^\s*View product:\s*/i,"")||null})}),products}function parseRecommendedProducts(html){if(!html)return[];try{const tmp=document.createElement("div");tmp.innerHTML=html;const node=tmp.querySelector(RECO_SELECTOR);if(node){const parsed=JSON.parse(node.textContent);if(parsed&&Array.isArray(parsed.products)&&parsed.products.length)return parsed.products}return extractProductsFromHtml(tmp)}catch(err){return console.error("[FeaturedCollectionsNosto] parse failed:",err),[]}}function extractHandle(url){const parts=String(url).split("?")[0].replace(/\/+$/,"").split("/");return parts[parts.length-1]}async function fetchCard(product){try{const handle=extractHandle(product.product_url);if(!handle||/^\d+$/.test(handle))return null;const url=(window.Shopify&&Shopify.routes&&Shopify.routes.root||"/")+"products/"+encodeURIComponent(handle)+"?section_id="+SECTION_NAME,resp=await fetch(url,{credentials:"same-origin"});if(!resp.ok)return null;const html=await resp.text();if(/^<!doctype/i.test(html.trim()))return null;const tmp=document.createElement("div");tmp.innerHTML=html;const card=tmp.querySelector(".card-wrapper")||tmp.querySelector(".product-card-wrapper");if(!card)return null;if(!product.product_id){const idEl=card.matches("[data-product-id]")?card:card.querySelector("[data-product-id]");idEl&&(product.product_id=idEl.getAttribute("data-product-id"))}return{product,cardEl:card}}catch{return null}}function requestPlacement(placement){if(placementCache.has(placement))return placementCache.get(placement);const core=(async function(){await waitForNosto();const reco=await new Promise(function(resolve){window.nostojs(function(api){api.createRecommendationRequest({includeTagging:!0}).setElements([placement]).load({skipEvents:!0}).then(function(response){resolve(response&&response.recommendations&&response.recommendations[placement])}).catch(function(err){console.error("[FeaturedCollectionsNosto] recommendation request failed:",err),resolve(null)})})});return reco?{products:parseRecommendedProducts(reco.html),resultId:reco.result_id||null}:{products:[],resultId:null}})(),guarded=Promise.race([core.catch(function(err){return console.error("[FeaturedCollectionsNosto] placement error \u2192 fallback classique:",err),{products:[],resultId:null}}),new Promise(function(resolve){setTimeout(function(){resolve({products:[],resultId:null,timedOut:!0})},FALLBACK_TIMEOUT_MS)})]);return placementCache.set(placement,guarded),guarded}function findSwiperInstance(el){return new Promise(function(resolve){let spent=0;const tick=function(){if(el.swiperInstance)return resolve(el.swiperInstance);if(spent>=SWIPER_TIMEOUT_MS)return resolve(null);spent+=SWIPER_POLL_MS,setTimeout(tick,SWIPER_POLL_MS)};tick()})}function bindTracking(slide,productId,placement){!productId||slide.__nostoTrackingBound||(slide.__nostoTrackingBound=!0,slide.querySelectorAll("a").forEach(function(link){link.addEventListener("click",function(){window.nostojs(function(api){api.createRecommendationRequest().setProducts([{product_id:productId}],placement).load().catch(function(){})})})}))}
1function tabHasSlides(wrapper,index){return wrapper.querySelectorAll('.swiper-slide[data-index="'+index+'"]').length>0}function isTabActive(featuredEl,index){const heading=featuredEl.querySelector('.featured-collections__heading[data-index="'+index+'"]');return!!(heading&&heading.classList.contains("visible"))}function loadTab(featuredEl,heading){const index=heading.dataset.index,placement=heading.dataset.nostoPlacement;if(!index||!placement)return Promise.resolve();const loads=featuredEl.__nostoTabLoads||(featuredEl.__nostoTabLoads={});return loads[index]||(loads[index]=loadTabImpl(featuredEl,heading,index,placement)),loads[index]}function removeSkeletonSlides(wrapper,index){wrapper.querySelectorAll('.swiper-slide.nosto-fc__skeleton-slide[data-index="'+index+'"]').forEach(function(s){s.remove()})}async function refreshSwiper(featuredEl,active){const swiper=await findSwiperInstance(featuredEl);swiper&&typeof swiper.update=="function"&&(swiper.update(),active&&typeof swiper.slideTo=="function"&&swiper.slideTo(0,0))}async function fallbackToClassic(featuredEl,heading,wrapper,index,tabState,active){const sectionId=featuredEl.dataset.sectionId;let classic=[];if(sectionId)try{const url=window.location.pathname+"?section_id="+encodeURIComponent(sectionId)+"&collection_index="+index,html=await fetch(url,{credentials:"same-origin"}).then(function(r){return r.ok?r.text():""}),tmp=document.createElement("div");tmp.innerHTML=html,classic=Array.from(tmp.querySelectorAll('.nosto-fc__fallback-slide[data-index="'+index+'"]'))}catch(e){console.error("[FeaturedCollectionsNosto] fetch fallback classique \xE9chou\xE9:",e)}const activeNow=isTabActive(featuredEl,index);if(removeSkeletonSlides(wrapper,index),!classic.length){hideEmptyTab(featuredEl,heading,wrapper,index,tabState);return}classic.forEach(function(slide){slide.classList.remove("nosto-fc__fallback-slide"),activeNow?slide.classList.add("visible"):slide.classList.remove("visible"),wrapper.appendChild(slide)}),tabState[index]="fallback",await refreshSwiper(featuredEl,activeNow),document.dispatchEvent(new CustomEvent("reactivateLazyObserver")),typeof window.refreshJudgemeWidgets=="function"&&window.refreshJudgemeWidgets()}async function loadTabImpl(featuredEl,heading,index,placement){const tabState=featuredEl.__nostoTabs||(featuredEl.__nostoTabs={});tabState[index]="loading";const wrapper=featuredEl.querySelector(".swiper-wrapper");if(!wrapper){tabState[index]="idle";return}const productsToShow=parseInt(heading.dataset.nostoProductsToShow,10)||8,active=isTabActive(featuredEl,index),result=await requestPlacement(placement),products=(result.products||[]).slice(0,productsToShow);if(products.length===0){fallbackToClassic(featuredEl,heading,wrapper,index,tabState,active);return}const valid=(await Promise.all(products.map(fetchCard))).filter(Boolean);if(valid.length===0){fallbackToClassic(featuredEl,heading,wrapper,index,tabState,active);return}const activeNow=isTabActive(featuredEl,index);removeSkeletonSlides(wrapper,index);const sliderId=(wrapper.closest('[id^="Swiper-"]')||{}).id||"Swiper-nosto",revealAnim=featuredEl.dataset.revealAnim==="true";valid.forEach(function(entry,i){const slide=document.createElement("div");slide.className="swiper-slide grid__item",revealAnim&&(slide.classList.add("scroll-trigger","animate--slide-in"),slide.setAttribute("data-cascade",""),slide.style.setProperty("--animation-order",i+1)),activeNow&&slide.classList.add("visible","active"),slide.id=sliderId+"-nosto-"+index+"-"+(i+1),slide.dataset.index=index,slide.dataset.nostoProductId=entry.product.product_id,slide.dataset.nostoTrackingUrl=entry.product.product_url,slide.appendChild(entry.cardEl),bindTracking(slide,entry.product.product_id,result.resultId||placement),wrapper.appendChild(slide)}),tabState[index]="done",await refreshSwiper(featuredEl,activeNow),document.dispatchEvent(new CustomEvent("reactivateLazyObserver")),typeof window.refreshJudgemeWidgets=="function"&&window.refreshJudgemeWidgets()}function recenterHeadings(featuredEl){const all=Array.from(featuredEl.querySelectorAll(".featured-collections__heading"));if(!all.length)return;all.forEach(function(h){h.style.marginLeft="",h.style.marginRight=""});const visible=all.filter(function(h){return h.style.display!=="none"&&getComputedStyle(h).display!=="none"});visible.length&&(visible[0].style.marginLeft="auto",visible[visible.length-1].style.marginRight="auto")}function hideEmptyTab(featuredEl,heading,wrapper,index,tabState){tabState[index]="empty";const wasActive=heading.classList.contains("visible");heading.style.display="none",heading.classList.remove("visible"),wrapper&&wrapper.querySelectorAll('.swiper-slide[data-index="'+index+'"]').forEach(function(s){s.remove()}),featuredEl.querySelectorAll('.featured-collections__btn[data-index="'+index+'"]').forEach(function(btn
1){btn.style.display="none",btn.classList.remove("active")}),recenterHeadings(featuredEl),wasActive&&promoteFallbackTab(featuredEl,index)}async function promoteFallbackTab(featuredEl,emptyIndex){const next=Array.from(featuredEl.querySelectorAll(".featured-collections__heading")).find(function(h){return h.style.display!=="none"&&h.dataset.index!==emptyIndex});if(!next)return;const wrapper=featuredEl.querySelector(".swiper-wrapper");next.dataset.nostoPlacement&&wrapper&&!tabHasSlides(wrapper,next.dataset.index)&&(await loadTab(featuredEl,next),next.style.display==="none")||next.click()}function schedulePreload(fn){typeof window.requestIdleCallback=="function"?window.requestIdleCallback(fn,{timeout:2500}):setTimeout(fn,1500)}function initFeaturedCollection(featuredEl){const headings=Array.from(featuredEl.querySelectorAll(".featured-collections__heading[data-nosto-placement]"));headings.length&&headings.forEach(function(heading){const wrapper=featuredEl.querySelector(".swiper-wrapper"),index=heading.dataset.index;heading.classList.contains("visible")?loadTab(featuredEl,heading):(!wrapper||!tabHasSlides(wrapper,index))&&schedulePreload(function(){loadTab(featuredEl,heading)}),heading.addEventListener("click",function(){loadTab(featuredEl,heading)})})}function init(){const elements=document.querySelectorAll(".featured-collections featured-collection");elements.length&&elements.forEach(function(el){el.querySelector(".featured-collections__heading[data-nosto-placement]")&&initFeaturedCollection(el)})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",init,{once:!0}):init()})();
2//# sourceMappingURL=/cdn/shop/t/258/assets/featured-collections-nosto.js.map?v=134117741856776280771790931185

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.