https://www.mariechantal.com/cdn/shop/t/121/assets/cart-page-recom…?v=126134143850785909001778665648
1export class CartPageRecommendations extends window.BAO.CustomElement(){connectedCallback(){super.connectedCallback(),this.init()}async init(){this.initializeState(),await this.fetchInitialCartState(),this.scheduleRender()}disconnectedCallback(){super.disconnectedCallback(),this.resetState()}setupListeners(){super.setupListeners(),this.onCartChanged=this.handleCartChange.bind(this),window.BAO.eventBus.addEventListener(window.BAO.EVENTS.PUSH_CART.CHANGED,this.onCartChanged)}initializeState(){this.isRendering=!1,this._expanded=!1,this.renderTimeoutId=null,this.cartState=null,this.lastRecommendationProductId=null}resetState(){this.expanded=!1,this.isRendering=!1,this.cartState=null,this.lastRecommendationProductId=null,this.clearRenderTimeout()}clearRenderTimeout(){this.renderTimeoutId&&(window.clearTimeout(this.renderTimeoutId),this.renderTimeoutId=null)}get expanded(){return this._expanded}set expanded(expanded){this._expanded=expanded;const aside=document.querySelector('dialog[key="cart"] .drw-Drawer_Aside'),recs=document.querySelectorAll("cart-page-recommendations");this.updateExpandedState(aside,recs,expanded)}async fetchInitialCartState(){try{const cartState=await(await fetch("/cart.js")).json();this.cartState=cartState,this.lastRecommendationProductId=null}catch(error){console.error("Failed to fetch initial cart state:",error)}}getLastAddedItem(cartState){return this.hasCartItems(cartState)?[...cartState.items].sort((a,b)=>b.key-a.key)[0]:null}hasCartItems(cartState){return cartState?.items&&cartState.items.length>0}hasValidCartData(){return this.hasCartItems(this.cartState)}shouldUpdateRecommendations(cartState){const currentProductId=this.getLastAddedItem(cartState)?.product_id,shouldUpdate=currentProductId&¤tProductId!==this.lastRecommendationProductId;return shouldUpdate&&(this.lastRecommendationProductId=currentProductId),shouldUpdate}buildRecommendationUrl(productId,intent){const baseUrl=this.dataset.url;if(!baseUrl||!productId)return null;const url=new URL(baseUrl,window.location.origin);return url.searchParams.set("product_id",productId),intent&&url.searchParams.set("intent",intent),url.toString()}async fetchRecommendationHtml(url){return(await fetch(url)).text()}parseRecommendationHtml(htmlString){const html=document.createElement("div");return html.innerHTML=htmlString,html}hasRecommendationItems(htmlElement){return htmlElement.querySelectorAll("[data-rec-item]").length>0}extractRecommendationContent(htmlElement){const recommendationElement=htmlElement.querySelector("cart-page-recommendations");return recommendationElement?recommendationElement.innerHTML:""}async fetchRecommendationsWithFallback(productId){try{const complementaryContent=await this.tryFetchRecommendations(productId,"complementary");return complementaryContent||await this.tryFetchRecommendations(productId,"related")||""}catch(error){return console.error("Recommendation fetch error:",error),""}}async tryFetchRecommendations(productId,intent){const url=this.buildRecommendationUrl(productId,intent);if(!url)return null;const html=await this.fetchRecommendationHtml(url),element=this.parseRecommendationHtml(html);return this.hasRecommendationItems(element)?this.extractRecommendationContent(element):null}scheduleRender(){this.clearRenderTimeout(),this.isRendering||(this.renderTimeoutId=window.setTimeout(()=>{this.renderTimeoutId=null,this.render()},500))}async render(){if(!this.isRendering){this.isRendering=!0;try{if(!this.canRenderRecommendations()){this.expanded=!1;return}const lastAddedItem=this.getLastAddedItem(this.cartState),content=await this.fetchRecommendationsWithFallback(lastAddedItem.product_id);this.updateRecommendationsDisplay(content)}catch(error){console.error("Render error:",error),this.expanded=!1}finally{this.isRendering=!1}}}canRenderRecommendations(){return this.hasValidCartData()?this.getLastAddedItem(this.cartState)?.product_id:!1}updateRecommendationsDisplay(content){content?(this.updateRecommendationContainers(content),this.externalEls?.container?.element.classList.remove("crt-Recommendations-hidden"),this.expanded=!0):this.expanded=!1}updateRecommendationContainers(content){document.querySelectorAll("cart-page-recommendations").forEach(container=>{container.innerHTML=content})}updateExpandedState(aside,recs,expanded){aside?.setAttribute("aria-expanded",expanded),recs?.forEach(rec=>{rec.setAttribute("loaded",expanded)})}handleCartChange(event){const{state}=event.detail;state&&(this.cartState=state,this.shouldUpdateRecommendations(state)&&this.scheduleRender())}}customElements.get("cart-page-recommendations")||customElements.define("cart-page-recommendations",CartPageRecommendations);const{setInitialised,useArrows}=window.BAO.Carousel.plugins;class CartPageRecommendationsCarousel extends window.BAO.CustomElement(){connectedCallback(){super.connectedCallback(),window.setTimeout(()=>this.render(),500)}render(){this.els?.slide?.exists&&(this.carousel=this.setupCarousel())}setupCarousel(){return new window.KeenSlider(this.els.slides.element,{selector:this.els.slide.selector,loop:!1,mode:"snap",slides:{perView:2,spacing:20},breakpoints:{"(min-width: 768px)":{slides:{perView:4,spacing:5}}}},[setInitialised(),useArrows({next:this.els.next.element,previous:this.els.prev.element})])}}customElements.get("cart-page-recommendations-carousel")||customElements.define("cart-page-recommendations-carousel",CartPageRecommendationsCarousel); 2//# sourceMappingURL=/cdn/shop/t/121/assets/cart-page-recommendations.js.map?v=126134143850785909001778665648
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.