PageSourceSearch

https://twillory.com/cdn/shop/t/1072/assets/cart.js?v=99812269738581552721789034703

js twillory.com collected 2026-10-03 19:31:54 UTC 21,832 bytes, 12 lines download raw bytes

1class CartDrawer extends DrawerComponent{constructor(){super(),window.FoxKitSections=FoxTheme.utils.getSectionId(this),this.onCartRefreshListener=this.onCartRefresh.bind(this),this.getSectionToRenderListener=this.getSectionToRender.bind(this)}get requiresBodyAppended(){return!1}get sectionId(){return this.getAttribute("data-section-id")}connectedCallback(){super.connectedCallback(),document.addEventListener("cart:grouped-sections",this.getSectionToRenderListener),document.addEventListener("cart:refresh",this.onCartRefreshListener)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("cart:grouped-sections",this.getSectionToRenderListener),document.removeEventListener("cart:refresh",this.onCartRefreshListener)}getSectionToRender(event){event.detail.sections.push(FoxTheme.utils.getSectionId(this))}restoreFocus(){if(!this.open)return;const activeElement=document.activeElement;activeElement&&activeElement!==document.body&&this.contains(activeElement)||(FoxTheme.a11y.removeTrapFocus(null,this),FoxTheme.a11y.trapFocus(this,this.focusElement))}async onCartRefresh(event){const cartId=`CartDrawer-${this.sectionId}`,cartElement=document.getElementById(cartId);if(cartElement)try{const responseText=await(await fetch(`${FoxTheme.routes.root_url}?section_id=${this.sectionId}`)).text(),newCartContent=new DOMParser().parseFromString(responseText,"text/html").getElementById(cartId).innerHTML;cartElement.innerHTML=newCartContent,event.detail.open===!0?this.show():this.restoreFocus()}catch(error){console.error("Error refreshing cart:",error)}}}customElements.define("cart-drawer",CartDrawer);class CartItems extends HTMLElement{constructor(){super(),this.pendingUpdates=new Map,this.handleQuantityClick=this.handleQuantityClick.bind(this),this.handleQuantityChange=this.handleQuantityChange.bind(this),this.handleQuantityBlur=this.handleQuantityBlur.b
1ind(this),this.addEventListener("click",this.handleQuantityClick),this.addEventListener("change",this.handleQuantityChange,!0),this.addEventListener("focusout",this.handleQuantityBlur,!0),this.cartUpdateUnsubscriber=FoxTheme.pubsub.subscribe(FoxTheme.pubsub.PUB_SUB_EVENTS.cartUpdate,this.onCartUpdate.bind(this)),this.cartItemProducts=this.querySelectorAll(".cart-item__product"),this.cartItemQuantitys=this.querySelectorAll(".cart-item__quantity");const loadTemplateContent=(elements,parentSelector)=>{elements.forEach(element=>{const template=element.querySelector("template"),templateContent=template&&document.importNode(template.content,!0),parent=element.querySelector(parentSelector);if(parent&&template&&!parent.querySelector(".template-content")){const contentWrapper=document.createElement("div");contentWrapper.classList.add("template-content","w-full"),contentWrapper.appendChild(templateContent),parent.appendChild(contentWrapper)}})},removeTemplateContent=(elements,parentSelector)=>{elements.forEach(element=>{const parent=element.querySelector(parentSelector),templateContent=parent?.querySelector(".template-content");templateContent&&parent.removeChild(templateContent)})},handleTabletMatch=()=>{loadTemplateContent(this.cartItemProducts,".cart-item__product--info"),removeTemplateContent(this.cartItemQuantitys,".cart-item__quantity-wrapper")},handleTabletUnmatch=()=>{removeTemplateContent(this.cartItemProducts,".cart-item__product--info"),loadTemplateContent(this.cartItemQuantitys,".cart-item__quantity-wrapper")},mqlTablet=window.matchMedia(FoxTheme.config.mediaQueryTablet);FoxTheme.config.mqlTablet=mqlTablet.matches,FoxTheme.config.mqlTablet?handleTabletMatch():handleTabletUnmatch(),mqlTablet.onchange=event=>{event.matches?handleTabletMatch():(FoxTheme.config.mqlTablet=!1,handleTabletUnmatch())},window.FoxKitSections=FoxTheme.utils.getSectionId(this)}cartUpdateUnsubscriber=void 0;disconnectedCallback(){this.removeEventListener("click",this.handleQuantityClick),this.removeEventListener("change",this.handleQuantityChange,!0),this.removeEventListener("focusout",this.handleQuantityBlur,!0),this.cartUpdateUnsubscriber&&this.cartUpdateUnsubscriber()}handleQuantityClick(event){const button=event.target.closest(".quantity__button");if(!button)return;const input=button.closest("quantity-input")?.querySelector(".quantity__input");input&&input.dataset.cartUpdating!=="true"&&setTimeout(()=>{input.dataset.cartUpdating!=="true"&&this.validateQuantity({target:input})},0)}handleQuantityChange(event){const input=event.target.closest(".quantity__input");input&&input.dataset.cartUpdating!=="true"&&this.validateQuantity({target:input})}handleQuantityBlur(event){const input=event.target.closest(".quantity__input");if(!input||input.dataset.cartUpdating==="true")return;if(input.dataset.cartStockError==="true"){delete input.dataset.cartStockError;return}const nextFocusedElement=event.relatedTarget;nextFocusedElement&&nextFocusedElement.closest("quantity-input")===input.closest("quantity-input")||this.validateQuantity({target:input})}onChange(event){this.validateQuantity(event)}setValidity(target,message){target.setCustomValidity(message),target.reportValidity(),target.value=target.defaultValue,target.select()}validateQuantity(event){const target=event.target,inputValue=parseInt(target.value,10),index=target.getAttribute("data-index");let message="";if(!Number.isNaN(inputValue)){if(inputValue===0){target.setCustomValidity(""),target.reportValidity(),this.updateQuantity(index,0,document.activeElement?.getAttribute?.("name")||target.getAttribute("name")||"updates[]",target);return}inputValue<parseInt(target.getAttribute("data-min"),10)?message=FoxTheme.quickOrderListStrings.min_error.replace("[min]",target.getAttribute("data-min")):target.max&&inputValue>parseInt(target.max,10)?message=FoxTheme.quickOrderListStrings.max_error.replace("[max]",target.max):target.step&&inputValue%parseInt(target.step,10)!==0&&(message=FoxTheme.quickOrderListStrings.step_error.replace("[step]",target.step)),message?this.setValidity(target,message):(target.setCustomValidity(""),target.reportValidity(),this.updateQuantity(index,inputValue,document.activeElement?.getAttribute?.("name")||target.getAttribute("name")||"updates[]",target))}}onCartUpdate(event){if(this.pendingUpdates.delete(String(event.line)),this.hideLoader(event.line),event.target){const lineIndex=parseInt(event.line,10)-1,actualQuantity=event.cart.items?.[lineIndex]?.quantity;if(actualQuantity!==void 0&&(event.target.value=String(actualQuantity),event.target.defaultValue=String(actualQuantity)),event.target.readOnly=!1,typeof event.target.setSelectionRange=="function")try{event.target.setSelectionRange(0,0)}catch{}if(event.target.blur(),delete event.target.dataset.cartUpdating,window.getSelection){const selection=window.getSelection();selection&&selection.removeAllRanges&&selection.removeAllRanges()}}if(event.cart.errors){this.onCartError(event.cart.errors,event.target);return}const sectionId=FoxTheme.utils.getSectionId(this),sectionToRender=new DOMParser().parseFromString(event.cart.sections[sectionId],"text/html"),cartDrawer=document.querySelector(`#CartDrawer-${sectionId}`),cartDrawerBody=document.querySelector(`#CartDrawerBody-${sectionId}`),cartDrawerFooter=document.querySelector(`#CartDrawerFooter-${sectionId}`),cartDrawerEmpty=document.querySelector(`#CartDrawerEmpty-${sectionId}`);if(cartDrawer){const cartDrawerBodyUpdate=sectionToRender.querySelector(`#CartDrawerBody-${sectionId}`),cartDrawerFooterUpdate=sectionToRender.querySelector(`#CartDrawerFooter-${sectionId}`),cartDrawerEmptyUpdate=sectionToRender.querySelector(`#CartDrawerEmpty-${sectionId}`);cartDrawerBodyUpdate&&(cartDrawerBody.innerHTML=cartDrawerBodyUpdate.innerHTML),cartDrawerFooterUpdate&&(cartDrawerFooter.innerHTML=cartDrawerFooterUpdate.innerHTML),cartDrawerEmptyUpdate&&(cartDrawerEmpty.innerHTML=cartDrawerEmptyUpdate.innerHTML),event.cart.item_count>0?(cartDrawerBody.classList.remove("hidden"),cartDrawerFooter.classList.remove("hidden"),cartDrawerEmpty.classList.add("hidden")):(cartDrawerBody.classList.add("hidden"),cartDrawerFooter.classList.add("hidden"),cartDrawerEmpty.classList.remove("hidden")),cartDrawer.closest("cart-drawer")?.restoreFocus()}const mainCart=document.querySelector(`#MainCart-${sectionId}`);if(mainCart){const updatedElement=sectionToRender.querySelector(`#MainCart-${sectionId}`);updatedElement?mainCart.innerHTML=updatedElement.innerHTML:(mainCart.closest(".cart").classList.add("is-empty"),mainCart.remove())}document.dispatchEvent(new CustomEvent("cart:updated",{detail:{cart:event.cart}}))}onCartError(errors,target){if(target){if(this.hideLoader(target.getAttribute("data-index")),target.readOnly=!1,typeof target.setSelectionRange=="function")try{target.setSelectionRange(0,0)}catch{}if(target.blur(),delete target.dataset.cartUpdating,window.getSelection){const selection=window.getSelection();selection&&selection.removeAllRanges&&selection.removeAllRanges()}this.setValidity(target,errors),target.dataset.cartStockError="true";return}else window.location.href=FoxTheme.routes.cart_url;alert(errors)}updateQuantity(line,quantity,name,target){const lineKey=String(line),normalizedQuantity=parseInt(quantity,10);if(!(Number.isNaN(normalizedQuantity)||this.pendingUpdates.get(lineKey)===normalizedQuantity)){if(target){if(target.dataset.cartUpdating="true",target.readOnly=!0,t
1ypeof target.setSelectionRange=="function")try{target.setSelectionRange(0,0)}catch{}if(target.blur(),window.getSelection){const selection=window.getSelection();selection&&selection.removeAllRanges&&selection.removeAllRanges()}}this.pendingUpdates.set(lineKey,normalizedQuantity),this.showLoader(line),fetch(`${FoxTheme.routes.cart_url}.js`,{...FoxTheme.utils.fetchConfig("javascript")}).then(response=>response.json()).then(currentCart=>{const item=currentCart.items[line-1],hasPreOrderProperties=item&&item.properties&&Object.keys(item.properties).some(key=>key.includes("Pre-Order"));let sectionsToBundle=[];document.documentElement.dispatchEvent(new CustomEvent("cart:grouped-sections",{bubbles:!0,detail:{sections:sectionsToBundle}}));let body;hasPreOrderProperties&&normalizedQuantity>0?body=JSON.stringify({line,quantity:normalizedQuantity,properties:{[Object.keys(item.properties).find(key=>key.includes("Pre-Order"))]:normalizedQuantity.toString()},sections:sectionsToBundle}):body=JSON.stringify({line,quantity:normalizedQuantity,sections:sectionsToBundle}),fetch(`${FoxTheme.routes.cart_change_url}`,{...FoxTheme.utils.fetchConfig(),body}).then(response=>response.json()).then(parsedState=>{FoxTheme.pubsub.publish(FoxTheme.pubsub.PUB_SUB_EVENTS.cartUpdate,{sources:"cart-items",cart:parsedState,target,line,name})}).catch(error=>{if(this.pendingUpdates.delete(lineKey),target){if(target.readOnly=!1,delete target.dataset.cartUpdating,typeof target.setSelectionRange=="function")try{target.setSelectionRange(0,0)}catch{}if(target.blur(),window.getSelection){const selection=window.getSelection();selection&&selection.removeAllRanges&&selection.removeAllRanges()}}this.hideLoader(line),console.log(error)})}).catch(error=>{if(this.pendingUpdates.delete(lineKey),target){if(target.readOnly=!1,delete target.dataset.cartUpdating,typeof target.setSelectionRange=="function")try{target.setSelectionRange(0,0)}catch{}if(target.blur(),window.getSelection){const selection=window.getSelection();selection&&selection.removeAllRanges&&selection.removeAllRanges()}}this.hideLoader(line),console.log(error)})}}showLoader(line){const sectionId=FoxTheme.utils.getSectionId(this),loaders=document.querySelectorAll(`#Loader-${sectionId}-${line}`),quantityInputs=document.querySelectorAll(`#Quantity-${sectionId}-${line}`),quantityWrappers=document.querySelectorAll(`#CartItem-${line} .quantity, #CartDrawer-Item-${line} .quantity`);loaders&&loaders.forEach(loader=>{loader.classList.add("btn--loading")}),quantityInputs&&quantityInputs.forEach(input=>{input.classList.add("loading"),input.setAttribute("aria-busy","true")}),quantityWrappers&&quantityWrappers.forEach(wrapper=>{wrapper.classList.add("is-loading")})}hideLoader(line){const sectionId=FoxTheme.utils.getSectionId(this),loaders=document.querySelectorAll(`#Loader-${sectionId}-${line}`),quantityInputs=document.querySelectorAll(`#Quantity-${sectionId}-${line}`),quantityWrappers=document.querySelectorAll(`#CartItem-${line} .quantity, #CartDrawer-Item-${line} .quantity`);loaders&&loaders.forEach(loader=>{loader.classList.remove("btn--loading")}),quantityInputs&&quantityInputs.forEach(input=>{input.classList.remove("loading"),input.removeAttribute("aria-busy")}),quantityWrappers&&quantityWrappers.forEach(wrapper=>{wrapper.classList.remove("is-loading")})}setValidity(target,message){target.setCustomValidity(message),target.reportValidity(),target.value=target.defaultValue,target.select()}}customElements.define("cart-items",CartItems);class CartRemoveItem extends HTMLAnchorElement{constructor(){super(),this.addEventListener("click",event=>{event.preventDefault(),this.closest("cart-items").updateQuantity(this.dataset.index,0)})}}customElements.define("cart-remove-item",CartRemoveItem,{extends:"a"});class CartNote extends HTMLElement{constructor(){super(),this.addEventListener("change",FoxTheme.utils.debounce(this.onChange.bind(this),300)),this.button&&this.cartNoteDetailsSummary&&this.button.addEventListener("click",()=>{this.cartNoteDetailsSummary.close()})}get cartNoteDetailsSummary(){return this.closest('[is="accordion-detail
1s"]')}get button(){return this.querySelector('[type="button"]')}onChange(event){const body=JSON.stringify({note:event.target.value});fetch(`${FoxTheme.routes.cart_update_url}`,{...FoxTheme.utils.fetchConfig(),body})}}customElements.define("cart-note",CartNote);class CalculateShipping extends ModalComponent{constructor(){super(),this.countryProvince=this.querySelector("country-province"),this.isCountrySetup=!1}static get observedAttributes(){return[...super.observedAttributes,"data-show"]}show(){super.show(),this.setAttribute("data-show",!0)}hide(){super.hide(),this.setAttribute("data-show",!1)}attributeChangedCallback(name,oldValue,newValue){if(super.attributeChangedCallback(name,oldValue,newValue),name==="data-show"&&newValue==="true"&&!this.isCountrySetup&&this.countryProvince){const template=this.countryProvince.querySelector("template"),templateContent=document.importNode(template.content,!0);this.countryProvince.countryElement.appendChild(templateContent),this.countryProvince.init(),this.isCountrySetup=!0}}}customElements.define("calculate-shipping",CalculateShipping);class CountryProvinceForm extends HTMLElement{constructor(){super(),this.provinceElement=this.querySelector('[name="address[province]"]'),this.countryElement=this.querySelector('[name="address[country]"]'),this.template=this.dataset.template,this.countryElement.addEventListener("change",this.handleCountryChange.bind(this)),this.template&&this.template==="cart"&&this.init()}init(){this.getAttribute("country")!==""?(this.countryElement.selectedIndex=Math.max(0,Array.from(this.countryElement.options).findIndex(option=>option.textContent===this.dataset.country)),this.countryElement.dispatchEvent(new Event("change"))):this.handleCountryChange()}handleCountryChange(){const option=this.countryElement.options[this.countryElement.selectedIndex],provinces=JSON.parse(option.dataset.provinces);this.provinceElement.closest(".form-field").hidden=provinces.length===0,provinces.length!==0&&(this.provinceElement.innerHTML="",provinces.forEach(data=>{const selected=data[1]===this.dataset.province;this.provinceElement.options.add(new Option(data[1],data[0],selected,selected))}))}}customElements.define("country-province",CountryProvinceForm);class ShippingCalculator extends HTMLFormElement{constructor(){super(),this.submitButton=this.querySelector('[type="submit"]'),this.resultsElement=this.lastElementChild,this.submitButton.addEventListener("click",this.handleFormSubmit.bind(this))}handleFormSubmit(event){event.preventDefault();const zip=this.querySelector('[name="address[zip]"]').value,country=this.querySelector('[name="address[country]"]').value,province=this.querySelector('[name="address[province]"]').value;this.submitButton.classList.add("btn--loading");const body=JSON.stringify({shipping_address:{zip,country,province}});let sectionUrl=`${FoxTheme.routes.cart_url}/shipping_rates.json`;sectionUrl=sectionUrl.replace("//","/"),fetch(sectionUrl,{...FoxTheme.utils.fetchConfig("javascript"),body}).then(response=>response.json()).then(parsedState=>{parsedState.shipping_rates?this.formatShippingRates(parsedState.shipping_rates):this.formatError(parsedState)}).catch(e=>{console.error(e)}).finally(()=>{this.resultsElement.hidden=!1,this.submitButton.classList.remove("btn--loading")})}formatError(errors){const shippingRatesList=Object.keys(errors).map(errorKe
1y=>`<li>${errors[errorKey]}</li>`);this.resultsElement.innerHTML=`
2      <div class="alert alert--error blocks-radius grid gap-2">
3        <p class="font-body-bolder m-0">${FoxTheme.shippingCalculatorStrings.error}</p>
4        <ul class="list-disc grid gap-1 text-sm" role="list">${shippingRatesList.join("")}</ul>
5      </div>
6    `}formatShippingRates(shippingRates){const shippingRatesList=shippingRates.map(({presentment_name,currency,price})=>`<li>${presentment_name}: ${currency} ${price}</li>`);this.resultsElement.innerHTML=`
7      <div class="alert blocks-radius alert--${shippingRates.length===0?"error":"success"} grid gap-2 leading-tight">
8        <p class="font-body-bolder m-0">${shippingRates.length===0?FoxTheme.shippingCalculatorStrings.notFound:shippingRates.length===1?FoxTheme.shippingCalculatorStrings.oneResult:FoxTheme.shippingCalculatorStrings.multipleResults}</p>
9        ${shippingRatesList===""?"":`<ul class="list-disc grid gap-1 text-sm" role="list">${shippingRatesList.join("")}</ul>`}
10      </div>
11    `}}customElements.define("shipping-calculator",ShippingCalculator,{extends:"form"});class CartDrawerProductsRecommendation extends HTMLElement{constructor(){if(super(),"requestIdleCallback"in window)requestIdleCallback(this.init.bind(this),{timeout:1500});else{const userAgent=navigator.userAgent;userAgent.includes("Safari")&&!userAgent.includes("Chrome")?this.init():FoxTheme.Motion.inView(this,this.init.bind(this),{margin:"600px 0px 600px 0px"})}}get slideContainer(){return this.querySelector(".swiper")}get sliderPagination(){return this.querySelector(".swiper-pagination")}get sliderNext(){return this.querySelector(".swiper-button-next")}get sliderPrev(){return this.querySelector(".swiper-button-prev")}init(){fetch(this.dataset.url).then(response=>response.text()).then(responseText=>{const sectionInnerHTML=new DOMParser().parseFromString(responseText,"text/html").querySelector(".shopify-section");if(sectionInnerHTML===null)return;const recommendations=sectionInnerHTML.querySelector("cart-drawer-products-recommendation");if(recommendations&&recommendations.innerHTML.trim().length){const productCount=recommendations.querySelectorAll(".product-card");this.innerHTML=recommendations.innerHTML,this.initCarousel(),productCount.length>0&&this.classList.remove("hidden"),this.dispatchEvent(new CustomEvent("recommendations:loaded"))}else this.closest(".shopify-section").remove(),this.classList.add("hidden"),this.dispatchEvent(new CustomEvent("is-empty"))}).catch(e=>{console.error(e)})}initCarousel(){this.carousel=new FoxTheme.Carousel(this.slideContainer,{slidesPerView:1,spaceBetween:10,loop:!1,pagination:{el:this.sliderPagination,type:"fraction"},navigation:{nextEl:this.sliderNext,prevEl:this.sliderPrev}}),this.carousel&&this.carousel.init()}}customElements.define("cart-drawer-products-recommendation",CartDrawerProductsRecommendation);class MainCart extends HTMLElement{constructor(){super(),document.addEventListener("cart:grouped-sections",this.getSectionToRender.bind(this))}getSectionToRender(event){event.detail.sections.push(FoxTheme.utils.getSectionId(this))}}customElements.define("main-cart",MainCart);class FreeShippingGoal extends HTMLElement{constructor(){super(),this.selectors={leftToSpend:"[data-left-to-spend]"},this.goal=Number(this.dataset.minimumAmount)*Number(window.Shopify.currency.rate||1)||0,this.progress=this.querySelector("progress-bar"),this.money_format=window.FoxTheme.settings.moneyFormat}connectedCallback(){this.updateShippingGloal(Number(this.dataset.cartTotal)),document.addEventListener("cart:updated",event=>{this.updateShippingGloal(event.detail.cart.items_subtotal_price)})}updateShippingGloal(amount){if(amount>0?this.classList.remove("hidden"):this.classList.add("hidden"),this.cartTotal=amount/100,this.goalLeft=this.goal-this.cartTotal,this.goalDone=this.goalLeft<=0,this.percent=this.cartTotal*100/this.goal,this.percent>=100&&(this.percent=100),this.cartTotal>=this.goal)this.progress.style.setProperty("--percent",`${this.percent}%`),this.classList.add("free-shipping-goal--done"),this.progress.dataset.value=this.cartTotal,this.progress.dataset.max=this.goal;else{let spend=(this.goal-this.cartTotal)*100;this.querySelector(this.selectors.leftToSpend).innerHTML=FoxTheme.Currency.formatMoney(spend,this.money_format),this.classList.remove("free-shipping-goal--done"),this.progress.style.setProperty("--percent",`${this.percent}%`),this.progress.dataset.value=this.cartTotal,this.progress.dataset.max=this.goal}}}customElements.define("free-shipping-goal",FreeShippingGoal),window.FoxKitAddToCart=async payload=>{if(!payload?.properties?.["_FoxKit offer"])return;const cartJson=await(await fetch(`${FoxTheme.routes.cart_url}`,{...FoxTheme.utils.fetchConfig()}
11)).json();cartJson.sections=payload.sections,FoxTheme.pubsub.publish(FoxTheme.pubsub.PUB_SUB_EVENTS.cartUpdate,{cart:cartJson}),document.dispatchEvent(new CustomEvent("product-ajax:added",{detail:{product:payload}}))};
12//# sourceMappingURL=/cdn/shop/t/1072/assets/cart.js.map?v=99812269738581552721789034703

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.