PageSourceSearch

https://modway.com/cdn/shop/t/303/assets/swatch-add-to-cart.js?v=100408408565481942691777996187

js modway.com collected 2026-09-26 05:09:44 UTC 3,899 bytes, 2 lines download raw bytes

1import{Component}from"@theme/component";import{CartAddEvent,CartErrorEvent,ThemeEvents}from"@theme/events";import{fetchConfig}from"@theme/utilities";let inFlightCountPromise=null,cachedSwatchCount=null;async function fetchSwatchCount(){return inFlightCountPromise||(inFlightCountPromise=(async()=>{try{const response=await fetch(`${Theme.routes.cart_url}.js`,{headers:{Accept:"application/json"}});if(!response.ok)return console.warn("[swatch-add-to-cart] /cart.js fetch failed:",response.status),null;const count=(await response.json()).items.filter(item=>item.product_type==="Swatch").reduce((sum,item)=>sum+item.quantity,0);return cachedSwatchCount=count,count}catch(error){return console.error("[swatch-add-to-cart] fetch error",error),null}finally{inFlightCountPromise=null}})(),inFlightCountPromise)}class SwatchAddToCart extends Component{requiredRefs=["button"];#resetTimeout;connectedCallback(){super.connectedCallback(),this.refs.button.addEventListener("click",this.#handleClick),document.addEventListener(ThemeEvents.cartUpdate,this.#updateLimitState),this.#updateLimitState()}disconnectedCallback(){super.disconnectedCallback(),this.refs.button.removeEventListener("click",this.#handleClick),document.removeEventListener(ThemeEvents.cartUpdate,this.#updateLimitState),this.#resetTimeout&&clearTimeout(this.#resetTimeout)}#getLimit(){const attr=parseInt(this.dataset.swatchLimit||"",10);if(Number.isFinite(attr)&&attr>0)return attr;const themeLimit=Theme.swatchLimit;return typeof themeLimit=="number"&&themeLimit>0?themeLimit:null}#updateLimitState=async()=>{const limit=this.#getLimit();if(!limit)return;const count=await fetchSwatchCount();count!==null&&(count>=limit?(this.dataset.state="limit",this.refs.button.setAttribute("aria-disabled","true")):this.dataset.state==="limit"&&(delete this.dataset.state,this.refs.button.removeAttribute("aria-disabled")))};#handleClick=async event=>{event.preventDefault(),event.stopPropagation();const variantId=this.dataset.variantId;if(!variantId||this.dataset.state==="loading"||this.dataset.state==="limit")return;const limit=this.#getLimit();if(limit&&cachedSwatchCount!==null&&cachedSwatchCount>=limit){this.dataset.state="limit",this.refs.button.setAttribute("aria-disabled","true"),this.dispatchEvent(new CartErrorEvent(this.id,`Limit of ${limit} swatches per order reached.`,"",[]));return}this.dataset.state="loading",this.refs.button.setAttribute("aria-busy","true");const sectionIds=[];document.querySelectorAll("cart-items-component").forEach(item=>{item instanceof HTMLElement&&item.dataset.sectionId&&sectionIds.push(item.dataset.sectionId)});const formData=new FormData;formData.set("id",variantId),formData.set("quantity","1"),sectionIds.length&&formData.set("sections",sectionIds.join(","));const cfg=fetchConfig("javascript",{body:formData});fetch(Theme.routes.cart_add_url,{...cfg,headers:{...cfg.headers,Accept:"text/html"}}).then(response=>response.json()).then(response=>{if(this.refs.button.removeAttribute("aria-busy"),response.status){this.dataset.state="error",this.dispatchEvent(new CartErrorEvent(this.id,response.message,response.description,response.errors)),this.#scheduleReset();return}this.dataset.state="added",this.dispatchEvent(new CartAddEvent({},this.id,{source:"swatch-add-to-cart",itemCount:1,productId:this.dataset.productId,variantId,sections:response.sections})),this.#scheduleReset()}).catch(error=>{this.refs.button.removeAttribute("aria-busy"),this.dataset.state="error",this.#scheduleReset(),console.error(error)})};
1#scheduleReset(){this.#resetTimeout&&clearTimeout(this.#resetTimeout),this.#resetTimeout=window.setTimeout(()=>{this.dataset.state!=="limit"&&delete this.dataset.state},2e3)}}customElements.get("swatch-add-to-cart")||customElements.define("swatch-add-to-cart",SwatchAddToCart);
2//# sourceMappingURL=/cdn/shop/t/303/assets/swatch-add-to-cart.js.map?v=100408408565481942691777996187

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.