1const drawerSelectors={cartIcons:document.querySelectorAll(".header__icon--cart"),cartIconDesktop:document.querySelector("#cart-icon-desktop"),cartIconMobile:document.querySelector("#cart-icon-mobile")};class ajaxCart extends HTMLElement{constructor(){super(),this.openeBy=drawerSelectors.cartIcons,this.isOpen=this.classList.contains("open--drawer"),this.bindEvents(),this.setCookie(),window.globalVariables.template!="cart"?(this.addAccessibilityAttributes(this.openeBy),this.getCartData()):this.style.visibility="visible",navigator.platform==="iPhone"&&document.documentElement.style.setProperty("--viewport-height",`${window.innerHeight}px`)}static get observedAttributes(){return["updating"]}attributeChangedCallback(name,oldValue,newValue){name=="updating"&&newValue=="false"&&this.updateEvents()}addAccessibilityAttributes(openDrawerButtons){let _this=this;openDrawerButtons.forEach(element=>{element.setAttribute("role","button"),element.setAttribute("aria-expanded",!1),element.setAttribute("aria-controls",_this.id)})}onKeyUp(event){event.code.toUpperCase()==="ESCAPE"&&this.querySelector(".close-ajax--cart").dispatchEvent(new Event("click"))}setCookie(){this.getCookie("battlbox_fraud");var status="";document.cookie&&document.cookie.indexOf("battlbox_fraud")!=-1?status="Cookie is present":(status="Cookie is NOT present. It may be expired, or never set",this.createCookie("battlbox_fraud","true",5))}createCookie(name,value,minutes){var date,expires;minutes?(date=new Date,date.setTime(date.getTime()+minutes*60*1e3),expires="; expires="+date.toUTCString()):expires="",document.cookie=name+"="+value+expires+"; path=/"}getCookie(cname){let name=cname+"=",ca=decodeURIComponent(document.cookie).split(";");for(let i=0;i<ca.length;i++){let c=ca[i];for(;c.charAt(0)==" ";)c=c.substring(1);if(c.indexOf(name)==0)return c.substring(name.length,c.length)}var status="";return document.cookie&&document.cookie.indexOf("battlbox_fraud")!=-1?status="Cookie is present":status="Cookie is NOT present. It may be expired, or never set",status!="Cookie is present"&&window.globalVariables.template=="cart"&&this.fraudDetect(),""}fraudDetect(){var requestId;const APIHeaderN={Accept:"application/json","Content-Type":"application/json","X-Shop":"battlboxllc.myshopify.com"};import("https://openfpcdn.io/botd/v0.1").then(Botd=>Botd.load({publicKey:"3Hjazj3ouhErMIzokDYAMnS0"})).then(botd=>botd.detect()).then(function(result){requestId=result.requestId,fetch("https://api-manager.praella.app/api/fingerprintjs/common",{method:"POST",headers:APIHeaderN,body:JSON.stringify({url:"/verify",method:"POST",data:{requestId}})}).then(response=>response.json()).then(data=>{(data.vm.probability==1||data.bot.automationTool.probability==1||data.bot.browserSpoofing.probability==1||data.bot.searchEngine.probability==1)&&(document.querySelector("[data-redirect_checkout]").setAttribute("disabled",!0),document.querySelector("[data-redirect_checkout]").classList.add("btn-disabled"),document.querySelector("#additional-checkout")?.classList.add("d-none"),notificationEle.updateNotification("Error","There seems to be an issue with your browser. Please contact out customer support at [email protected]",{type:"error",timeout:3e3}))}).catch(error=>{console.error("Error:",error)})}).catch(error=>console.error(error))}bindEvents(){window.globalVariables.template!="cart"&&(this.openeBy.forEach(cartBtn=>cartBtn.addEventListener("click",this.openCartDrawer.bind(this))),this.addEventListener("keyup",this.onKeyUp.bind(this))),this.form=this.querySelector("[data-redirect_checkout]"),this.form&&this.form.addEventListener("click",this.getCartItems.bind(this)),this.updateEvents(),document.querySelector("#additional-checkout")&&this.expressCheckout()}getCartItems(){var isCheckOutURl=!1,cart=window.globalVariables.cart,total_price=document.querySelector("[data-total-price]").getAttribute("data-total-price"),contents=[];cart.forEach(i=>{contents.push({content_id:i.product_id,content_name:i.title,price:i.price/100,quantity:i.quantity})});var event_id="InitiateCheckout"+cart[0].key;this._checkoutEventTikTok(contents,event_id,"product_group",window.theme.currency),tiktok._tikTokCheckout(contents,window.location.href,event_id),cart.find(x=>x.properties==null)||cart.find(x=>x.properties==null)||cart.find(x=>x.properties==null)||(cart.find(x=>x.properties.shipping_interval_unit_type!=null)||cart.find(x=>x.properties.shipping_interval_unit_type!=null)||cart.find(x=>x.properties.type=="gift-recharge-immediately")||cart.find(x=>x.properties.type=="gift-recharge-email")||cart.find(x=>x.product_type=="subscription")?isCheckOutURl=!0:isCheckOutURl=!1),window.location.href="/checkout"}_redirectToCheckout=()=>{function reChargeGetCookie(name){return(document.cookie.match(`(^|; )${name}=([^;]*)`)||0)[2]}let ga_linker="";const myshopify_domain="battlboxllc.myshopify.com",token=reChargeGetCookie("cart");try{ga_linker=ga.getAll()[0].get("linkerParam")}catch{ga_linker=""}const customer_param=`customer_id=${window.theme.customersID}&customer_email=${window.theme.emailHashed}`,checkout_url=`https://checkout.battlbox.com/r/checkout?myshopify_domain=${myshopify_domain}&cart_token=${token}&${ga_linker}&${customer_param}`;window.location.href=checkout_url;const xhr=new XMLHttpRequest,data={};xhr.open("POST","/cart/update.js"),xhr.setRequestHeader("Content-Type","application/json"),xhr.onload=function(){xhr.status===200?window.console.log("done",JSON.parse(xhr.responseText)):xhr.status!==200&&window.console.log("fail",JSON.parse(xhr.responseText));const form=buildForm(data,checkout_url);document.body.appendChild(form),form.submit()},xhr.send(JSON.stringify(data));
1function buildInputs(form,obj){Object.keys(obj).forEach(key=>{const input=document.createElement("input");input.setAttribute("type","hidden"),input.setAttribute("name",key),input.setAttribute("value",typeof obj[key]=="object"?JSON.stringify(obj[key]):obj[key]),form.appendChild(input)})}function buildForm(data2,url){const form=document.createElement("form");return form.setAttribute("method","post"),form.setAttribute("action",url),form.setAttribute("id","rc_form"),form.style.display="none",buildInputs(form,data2),form}};_checkoutEventTikTok(viewContent,event_id,content_type,currency){ttq.track("InitiateCheckout",{viewContent,event_id,content_type,value:window.globalVariables.total_price/100,currency}),pintrk("track","custom")}updateEvents(){this.querySelectorAll(".close-ajax--cart").forEach(button=>button.addEventListener("click",this.closeCartDrawer.bind(this))),this.querySelectorAll("[data-itemRemove]").forEach(button=>button.addEventListener("click",this.removeItem.bind(this))),this.querySelectorAll("[data-qty-btn]").forEach(button=>button.addEventListener("click",this.manageQtyBtn.bind(this))),this.querySelectorAll("[data-qty-input]").forEach(button=>button.addEventListener("change",this.onQtyChange.bind(this)))}expressCheckout(){if(document.querySelector("#additional-checkout")){var isExpressCheckout=!1,cart=window.globalVariables.cart;cart.find(x=>x.properties==null)||cart.find(x=>x.properties==null)||cart.find(x=>x.properties==null)||(cart.find(x=>x.properties.shipping_interval_unit_type!=null)||cart.find(x=>x.properties.shipping_interval_unit_type!=null)||cart.find(x=>x.properties.type=="gift-recharge-immediately")||cart.find(x=>x.properties.type=="gift-recharge-email")||cart.find(x=>x.product_type=="subscription")?isExpressCheckout=!0:isExpressCheckout=!1),isExpressCheckout?document.querySelector("#additional-checkout")?.classList.add("d-none"):document.querySelector("#additional-checkout")?.classList.remove("d-none")}}openCartDrawer(event){if(!window.globalVariables.cart_drawer){window.location.href=window.routes.cart_fetch_url||"/cart";return}const mobileMenuDrawer=document.querySelector("#mobile-menu-drawer");window.globalVariables.templateName==="page.subscribe-2-0-google"?mobileMenuDrawer?.classList.contains("opened-drawer")&&document.querySelector(".close-mobile--navbar")?.dispatchEvent(new Event("click")):mobileMenuDrawer.classList.contains("opened-drawer")&&document.querySelector(".close-mobile--navbar")?.dispatchEvent(new Event("click")),this.classList.add("opened-drawer"),document.querySelector("body").classList.add("menu-opened"),siteOverlay.prototype.showOverlay(),Utility.forceFocus(this.querySelector(".cart-title"));let closeBtn=this.querySelector(".close-ajax--cart");Utility.trapFocus(this,closeBtn),event&&(event.preventDefault(),event.currentTarget.setAttribute("aria-expanded",!0))}closeCartDrawer(event,elementToFocus=!1){if(event!==void 0){event.preventDefault(),this.classList.remove("opened-drawer"),siteOverlay.prototype.hideOverlay(),document.querySelector("body").classList.remove("menu-opened"),event.currentTarget.setAttribute("aria-expanded",!1),Utility.removeTrapFocus(elementToFocus);let actionBtn=drawerSelectors.cartIconDesktop;window.innerWidth<1024&&(actionBtn=drawerSelectors.cartIconMobile),Utility.forceFocus(actionBtn)}}_updateCart(response,action){this.setAttribute("updating",!0);let cartHTML="";if(window.globalVariables.template!="cart"?cartHTML=response["template-ajax-cart"]:cartHTML=response["template-cart"],cartHTML==null)return;cartHTML=new DOMParser().parseFromString(cartHTML,"text/html");const cartJSON=JSON.parse(cartHTML.querySelector("[data-cartJSON]").textContent);window.globalVariables.cart=cartJSON.items;let cartElement=cartHTML.querySelector("ajax-cart");window.globalVariables.template!="cart"?this.innerHTML=cartElement.innerHTML:cartJSON.items.length>0?(this.querySelector("[data-empty-cart]").classList.add("d-none"),this.querySelectorAll("[data-has-cart]").forEach(ele=>ele.classList.remove("d-none")),this.querySelector("[data-cart-items]").innerHTML=cartElement.querySelector("[data-cart-items]").innerHTML,this.querySelector("[data-total-price]").innerHTML=cartElement.querySelector("[data-total-price]").innerHTML):(this.querySelectorAll("[data-has-cart]").forEach(ele=>ele.classList.add("d-none")),this.querySelector("[data-empty-cart]").classList.remove("d-none")),this.setAttribute("updating",!1);let cartIcon=new DOMParser().parseFromString(response.header,"text/html").getElementById("cart-icon-desktop");if(cartIcon){const newCountEl=cartIcon.querySelector("[data-cart-count], .cart
1-count");[drawerSelectors.cartIconDesktop,drawerSelectors.cartIconMobile].forEach(icon=>{if(!icon)return;icon.querySelectorAll("svg, i.icon-cart, i.icon-bag, span[data-header-cart-glyph]").forEach(el=>el.remove());const glyphs=icon.querySelectorAll("img[data-header-cart-glyph]");let desktopKept=!1,mobileKept=!1;glyphs.forEach(el=>{el.classList.contains("header-cart-glyph--desktop")?desktopKept?el.remove():desktopKept=!0:el.classList.contains("header-cart-glyph--mobile")?mobileKept?el.remove():mobileKept=!0:desktopKept&&mobileKept&&el.remove()});const countEl=icon.querySelector("[data-cart-count], .cart-count");newCountEl?countEl?countEl.innerHTML=newCountEl.innerHTML:icon.appendChild(newCountEl.cloneNode(!0)):countEl&&countEl.remove()})}window.globalVariables.cart_drawer==!0&&action=="open_drawer"&&window.globalVariables.template!="cart"&&this.openCartDrawer(),this.form=this.querySelector("[data-redirect_checkout]"),this.form&&this.form.addEventListener("click",this.getCartItems.bind(this))}getCartData(action){let fetchCart=fetch(`${routes.cart_fetch_url}?sections=template-cart,header`);window.globalVariables.template!="cart"&&(fetchCart=fetch(`${routes.cart_fetch_url}?sections=template-ajax-cart,header`)),fetchCart.then(response=>response.json()).then(response=>{this._updateCart(response,action)}).catch(e=>{console.error(e)}).finally(()=>{})}updateItemQty(line,quantity){let lineItem=document.querySelectorAll("[data-cart-item]")[line-1];lineItem&&lineItem.classList.add("updating");const body=JSON.stringify({line,quantity});fetch(`${routes.cart_change_url}`,{...fetchConfig(),body}).then(response=>(fetch("/cart.json",{method:"GET",headers:{"Content-Type":"application/json"}}).then(data=>{data.json().then(result=>{document.querySelector("[data-item_count]").innerHTML=result.items.length})}),response.text())).then(state=>{this.getCartData(),setTimeout(()=>{lineItem&&lineItem.classList.remove("updating")},1e3)}).catch(error=>{setTimeout(()=>{lineItem&&lineItem.classList.remove("updating")},1e3),console.log(error)})}removeItem(event){event.preventDefault();const _this=this;let currentTarget=event.currentTarget,itemIndex=currentTarget.dataset.index||null,pTitle=currentTarget.dataset.producttitle,pId=currentTarget.dataset.itemId,vId=currentTarget.dataset.itemVariant,vendor=currentTarget.dataset.vendor,price=currentTarget.dataset.price,connected_value=currentTarget.dataset.connect,indexesToRemove=[];if(connected_value!=null&&document.querySelectorAll(`input[data-connect="${connected_value}"]`).forEach(function(target){let itemInd=target.dataset.index||null,varId=target.dataset.itemVariant;itemInd!=null&&indexesToRemove.push(varId)}),itemIndex!=null&&indexesToRemove.push(vId),indexesToRemove.length>0){let updates={};indexesToRemove.forEach(id=>{updates[id]=0}),_this.removeUpdateCart(updates).then(()=>{dataLayer.push({ecommerce:null}),dataLayer.push({event:"remove_from_cart",ecommerce:{currency:window.theme.currency,value:`${window.globalVariables.cart.total_price/100}`,items:[{item_id:pId,item_name:pTitle,affiliation:"Google Merchandise Store",index:itemIndex,item_brand:vendor,item_variant:vId,price,quantity:0}]}})})}}removeUpdateCart(updates){let lineItem=document.querySelectorAll("[data-cart-item]");return lineItem&&lineItem.forEach(function(target){target.classList.add("updating")}),fetch("/cart/update.js",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({updates})}).then(res=>res.json()).then(()=>fetch("/cart.json",{method:"GET",headers:{"Content-Type":"application/json"}})).then(res=>res.json()).then(result=>{document.querySelector("[data-item_count]").innerHTML=result.items.length,this.getCartData(),setTimeout(()=>{lineItem&&lineItem.forEach(function(target){target.classList.remove("updating")})},1e3)}).catch(error=>{setTimeout(()=>{lineItem&&lineItem.forEach(function(target){target.classList.remove("updating")})},1e3),console.error(error)})}manageQtyBtn(event){event.preventDefault();let currentTarget=event.currentTarget,action=currentTarget.dataset.for||"increase",$qtyInput
1=currentTarget.closest("[data-qty-container]").querySelector("[data-qty-input]"),itemIndex=$qtyInput.dataset.index||1,currentQty=parseInt($qtyInput.value)||1,finalQty=1;if(action=="decrease"&¤tQty<=1)return!1;action=="decrease"?finalQty=currentQty-1:finalQty=currentQty+1,this.updateItemQty(itemIndex,finalQty)}onQtyChange(event){const $qtyInput=event.currentTarget,qtyValue=$qtyInput.value,itemIndex=$qtyInput.dataset.index||null;itemIndex&&this.updateItemQty(itemIndex,qtyValue)}}customElements.define("ajax-cart",ajaxCart); 2//# sourceMappingURL=/cdn/shop/t/484/assets/component-cart-drawer.js.map?v=136944404902275015431784873127
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.