1class ProductSample extends HTMLElement{constructor(){super(),this.SCROLL_DELAY=425,this.trigger=document.querySelector(".js-sample-scroll-trigger"),this.addToBags=this.querySelectorAll(".js-sample-trigger"),this.cart=document.querySelector("cart-drawer"),this.addAllToBags=this.querySelector(".js-samples-trigger"),this.addToBags.forEach(addToBag=>addToBag.addEventListener("click",()=>this.addProduct(addToBag))),this.addAllToBags.addEventListener("click",()=>this.addProducts()),this.trigger.addEventListener("click",this.scrollToSample.bind(this)),this.syncWithCart();let t;this.cart&&new MutationObserver(()=>{clearTimeout(t),t=setTimeout(()=>this.syncWithCart(),300)}).observe(this.cart,{childList:!0,subtree:!0})}syncWithCart(){fetch("/cart.js").then(r=>r.json()).then(({items})=>{const ids=items.map(i=>String(i.variant_id)),samples=this.querySelectorAll(".js-sample");let allInCart=samples.length>0;samples.forEach(sample=>{const inCart=ids.includes(String(sample.dataset.id));sample.querySelector(".js-sample-trigger").toggleAttribute("disabled",inCart),inCart||(allInCart=!1)}),this.addAllToBags.toggleAttribute("disabled",allInCart)})}addProduct(button){const sample=button.closest(".js-sample"),object=[this.createProductObj(sample)],spinner=button.querySelector(".loading-overlay__spinner");this.addToBag(button,object,spinner)}addProducts(){const samples=this.querySelectorAll(".js-sample"),objects=Array.from(samples).map(sample=>this.createProductObj(sample)),button=this.addAllToBags,spinner=button.querySelector(".loading-overlay__spinner");this.addToBag(button,objects,spinner)}addToBag(button,samples,spinner){button.setAttribute("disabled","true"),button.classList.add("loading"),spinner.classList.remove("hidden");const cart=document.querySelector("cart-drawer"),payload={items:samples};cart&&(payload.sections=cart.getSectionsToRender().map(section=>section.id),payload.sections_url=window.location.pathname,cart.setActiveElement(document.activeElement));const config=fetchConfig("javascript");config.headers["Content-Type"]="application/json",config.body=JSON.stringify(payload),fetch(`${routes.cart_add_url}`,config).then(response=>response.json()).then(response=>{if(response.status)throw new Error(response.description||response.message);cart&&cart.renderContents(response)}).then(()=>{this.syncWithCart(),cart&&cart.classList.contains("is-empty")&&cart.classList.remove("is-empty")}).catch(error=>{console.error("Error:",error),button.removeAttribute("disabled")}).finally(()=>{button.classList.remove("loading"),spinner.classList.add("hidden")})}createProductObj(sample){return{id:sample.dataset.id,quantity:1,properties:{...sample.dataset?.barcode!=null&&{_barcode:sample.dataset.barcode}}}}scrollToSample(event){event.preventDefault();const targetId=this.trigger.getAttribute("href"),targetElement=document.querySelector(targetId);targetElement&&(this.openAccordion(targetElement),setTimeout(()=>{const targetPosition=targetElement.getBoundingClientRect().top+window.scrollY,header=document.querySelector(".header"),headerHeight=header?header.offsetHeight:0,scrollOptions={top:targetPosition-headerHeight,behavior:"smooth"};window.scrollTo(scrollOptions)},this.SCROLL_DELAY))}openAccordion(accordion){accordion.closest(".accordion__item").classList.contains("accordion__item--open")||accordion.click()}}customElements.get("product-samples")||customElements.define("product-samples",ProductSample); 2//# sourceMappingURL=/cdn/shop/t/318/assets/product-sample.js.map?v=1479890412241395901788256403
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.