PageSourceSearch

https://pitstop-pro.com/cdn/shop/t/36/assets/pitstop-cart-drawer.js?v=61200255861387397951789783167

js pitstop-pro.com collected 2026-10-04 02:55:28 UTC 10,790 bytes, 2 lines download raw bytes

1(function(){"use strict";var routes=window.Theme&&window.Theme.routes||{},CART_URL=routes.cart_url||"/cart",ADD_URL=routes.cart_add_url||"/cart/add",CHANGE_URL=routes.cart_change_url||"/cart/change",SECTION_ID="cart-drawer";function $(s,r){return(r||document).querySelector(s)}function $$(s,r){return Array.prototype.slice.call((r||document).querySelectorAll(s))}var FOCUSABLE='a[href],button:not([disabled]),input:not([disabled]):not([type=hidden]),select,textarea,[tabindex]:not([tabindex="-1"])';function isCartPage(){return document.body.classList.contains("template-cart")}var Drawer={el:function(){return $("[data-cart-drawer]")},isOpen:function(){var el=Drawer.el();return!!(el&&el.classList.contains("is-open"))},open:function(opener){var el=Drawer.el();if(el){el._opener=opener||document.activeElement,el.setAttribute("aria-hidden","false"),el.classList.add("is-open"),document.body.classList.add("ps-no-scroll");var f=$$(FOCUSABLE,el).filter(function(x){return x.offsetParent!==null});if(setTimeout(function(){(f[0]||el).focus({preventScroll:!0})},60),window.affirm&&window.affirm.ui&&window.affirm.ui.refresh)try{window.affirm.ui.refresh()}catch(e){}}},close:function(){var el=Drawer.el();if(!(!el||!el.classList.contains("is-open"))&&(el.classList.remove("is-open"),el.setAttribute("aria-hidden","true"),document.body.classList.remove("ps-no-scroll"),el._opener&&el._opener.focus))try{el._opener.focus({preventScroll:!0})}catch(e){}}};function updateHeaderCount(cart){$$("[data-header-cart-count]").forEach(function(el){el.setAttribute("data-header-cart-count",cart.item_count>0?cart.item_count:""),el.classList.toggle("visible",cart.item_count>0)}),$$(".site-header-cart-button").forEach(function(btn){btn.classList.toggle("count-hidden",cart.item_count===0)})}var Cart={refresh:function(){var cur=Drawer.el();if(!cur)return Promise.resolve();var wasOpen=cur.classList.contains("is-open");return fetch(CART_URL+"?section_id="+SECTION_ID,{credentials:"same-origin"}).then(function(r){return r.text()}).then(function(html){var doc=new DOMParser().parseFromString(html,"text/html"),fresh=doc.querySelector("[data-cart-drawer]");return fresh&&(cur.innerHTML=fresh.innerHTML,wasOpen&&(cur.classList.add("is-open"),cur.setAttribute("aria-hidden","false"))),fetch(CART_URL+".js",{credentials:"same-origin"})}).then(function(r){return r.json()}).then(function(cart){if(updateHeaderCount(cart),window.affirm&&window.affirm.ui&&window.affirm.ui.refresh)try{window.affirm.ui.refresh()}catch(e){}return document.dispatchEvent(new CustomEvent("pitstop:cart:updated",{detail:cart})),cart})},add:function(body){return fetch(ADD_URL+".js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Requested-With":"XMLHttpRequest"},body:body}).then(function(r){return r.json().then(function(d){if(!r.ok)throw new Error(d.description||d.message||"Could not add to cart.");return d})}).then(function(d){return Cart.refresh().then(function(){return d})})},change:function(line,quantity){return fetch(CHANGE_URL+".js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({line:line,quantity:quantity})}).then(function(r){if(!r.ok)throw new Error("Could not update the cart.");return Cart.refresh()}).then(function(cart){return isCartPage()&&window.location.reload(),cart})}};function markBusy(line){var row=$('[data-cart-drawer] .ps-cart-line[data-line="'+line+'"]');row&&row.classList.add("is-busy")}document.addEventListener("click",function(e){var closeBtn=e.target.closest("[data-ps-drawer-close]");if(closeBtn){closeBtn.tagName!=="A"&&e.preventDefault(),Drawer.close();return}var open=e.target.closest("[data-ps-cart-open]");if(open&&!isCartPage()&&Drawer.el()){e.preventDefault(),Drawer.open(open);return}var drawer=e.target.closest("[data-cart-drawer]");if(drawer){var step=e.target.closest("[data-qty-minus],[data-qty-plus]");if(step){var input=$("[data-qty-input]",step.parentElement);if(!input)return;var next=Math.max(0,(parseInt(input.value,10)||0)+(step.hasAttribute("data-qty-plus")?1:-1));input.value=next,input.dispatchEvent(new Event("change",{bubbles:!0}));return}var rm=e.target.closest("[data-line-remove]");if(rm){e.preventDefault();var ln=parseInt(rm.getAttribute("data-line"),10);markBusy(ln),Cart.change(ln,0).catch(function(){Cart.refresh()})}}}),document.addEventListener("change",function(e){var input=e.target.closest("[data-cart-drawer] [data-qty-input][data-line]");if(input){var ln=parseInt(input.getAttribute("data-line"),10);markBusy(ln),Cart.change(ln,Math.max(0,parseInt(input.value,10)||0)).catch(function(){Cart.refresh()})}}),document.addEventListener("keydown",function(e){if(Drawer.isOpen()){if(e.key==="Escape"){Drawer.close();return}
1if(e.key==="Tab"){var box=Drawer.el(),f=$$(FOCUSABLE,box).filter(function(x){return x.offsetParent!==null});if(f.length){var first=f[0],last=f[f.length-1];e.shiftKey&&document.activeElement===first?(e.preventDefault(),last.focus()):!e.shiftKey&&document.activeElement===last&&(e.preventDefault(),first.focus())}}}}),document.addEventListener("submit",function(e){var form=e.target;if(!(!form||!form.getAttribute)){var action=form.getAttribute("action")||"";if(action.indexOf("/cart/add")!==-1&&Drawer.el()){e.preventDefault(),e.stopImmediatePropagation();var fd=new FormData(form);if(fd.get("id")){var body=new URLSearchParams;fd.forEach(function(v,k){typeof v=="string"&&body.append(k,v)});var btn=form.querySelector("[type=submit],[name=add]");btn&&(btn.disabled=!0,btn.classList.add("is-busy")),Cart.add(body.toString()).then(function(){Drawer.open(btn)}).catch(function(err){var msg=form.querySelector(".ps-atc-error");msg||(msg=document.createElement("div"),msg.className="ps-atc-error",msg.setAttribute("role","alert"),(btn?btn.parentNode:form).appendChild(msg)),msg.textContent=err.message||"Could not add to cart.",msg.style.cssText="margin-top:8px;color:#a12f18;font-size:14px"}).then(function(){btn&&(btn.disabled=!1,btn.classList.remove("is-busy"))})}}}},!0);var ownRequests=0,observeTimer=null;function observed(url,method){if(!(ownRequests>0)&&!(!url||(method||"GET").toUpperCase()==="GET")){var u=String(url),isAdd=/\/cart\/add(\.js)?(\?|$)/.test(u),isChange=/\/cart\/(change|update|clear)(\.js)?(\?|$)/.test(u);!isAdd&&!isChange||(clearTimeout(observeTimer),observeTimer=setTimeout(function(){Cart.refresh().then(function(){isAdd&&!isCartPage()&&Drawer.open()}).catch(function(){})},250))}}function wrapOwn(fn){ownRequests++;var p;try{p=fn()}catch(e){throw ownRequests--,e}return p.then(function(v){return ownRequests--,v},function(e){throw ownRequests--,e})}var _add=Cart.add,_change=Cart.change;if(Cart.add=function(b){return wrapOwn(function(){return _add(b)})},Cart.change=function(l,q){return wrapOwn(function(){return _change(l,q)})},window.fetch){var nativeFetch=window.fetch;window.fetch=function(input,init){var url=typeof input=="string"?input:input&&input.url,method=init&&init.method||input&&input.method||"GET",p=nativeFetch.apply(this,arguments);try{ownRequests===0&&p.then(function(r){r&&r.ok&&observed(url,method)},function(){})}catch(e){}return p}}if(window.XMLHttpRequest){var xo=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(method,url){try{var self=this;this.addEventListener("load",function(){self.status>=200&&self.status<300&&observed(url,method)})}catch(e){}return xo.apply(this,arguments)}}function setMsg(text,kind){var m=$("[data-ps-discount-msg]");m&&(m.textContent=text||"",m.classList.toggle("is-error",kind==="error"),m.classList.toggle("is-ok",kind==="ok"))}function currentCodes(cart){return(cart.discount_codes||[]).filter(function(d){return d.applicable}).map(function(d){return d.code})}Cart.applyDiscount=function(code){return code=(code||"").trim().toUpperCase(),code?wrapOwn(function(){return fetch(CART_URL+".js",{credentials:"same-origin"}).then(function(r){return r.json()}).then(function(cart){var codes=currentCodes(cart);return codes.indexOf(code)===-1&&codes.push(code),fetch("/cart/update.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({discount:codes.join(",")})})}).then(function(r){return r.json()}).then(function(cart){var entry=(cart.discount_codes||[]).filter(function(d){return d.code.toUpperCase()===code})[0],ok=!!(entry&&entry.applicable);if(ok)try{fetch("/discount/"+encodeURIComponent(code),{credentials:"same-origin"})}catch(e){}return Cart.refresh().then(function(){ok?setMsg("Code "+code+" applied. It will carry through to checkout.","ok"):setMsg("That code isn't valid for this cart.","error");var input=$("[data-ps-discount-input]");return input&&(input.value=ok?"":code),ok})})}):Promise.resolve()},Cart.removeDiscount=function(code){return wrapOwn(function(){return fetch(CART_URL+".js",{credentials:"same-origin"}).then(function(r){return r.json()}).then(function(cart){var codes=currentCodes(cart).filter(function(c){return c.toUpperCase()!==(code||"").toUpperCase()});return fetch("/cart/update.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({discount:codes.join(",")})})}).then(function(){return Cart.refresh()}).then(function(){setMsg("","")})})},document.addEventListener("submit",function(e){var form=e.target.closest&&e.target.closest("[data-ps-discount-form]");if(form){e.preventDefault(),e.stopPropagation();var input=form.querySelector("[data-ps-discount-input]"),btn=form.querySelector("[type=submit]");if(!input||!input.value.trim()){setMsg("Enter a discount code.","error");return}
1btn&&(btn.disabled=!0),Cart.applyDiscount(input.value).catch(function(){setMsg("Could not apply that code. Try again.","error")}).then(function(){var b=$("[data-ps-discount-form] [type=submit]");b&&(b.disabled=!1)})}},!0),document.addEventListener("click",function(e){var add=e.target.closest&&e.target.closest("[data-ps-rec-add]");if(add){e.preventDefault();var card=add.closest("[data-ps-rec]");card&&card.classList.add("is-busy"),add.disabled=!0,Cart.add("id="+encodeURIComponent(add.getAttribute("data-ps-rec-add"))+"&quantity=1").catch(function(){card&&card.classList.remove("is-busy"),add.disabled=!1});return}var rm=e.target.closest&&e.target.closest("[data-ps-discount-remove]");rm&&(e.preventDefault(),Cart.removeDiscount(rm.getAttribute("data-ps-discount-remove")).catch(function(){Cart.refresh()}))}),window.PitstopCart={open:Drawer.open,close:Drawer.close,refresh:Cart.refresh,add:Cart.add,change:Cart.change,applyDiscount:Cart.applyDiscount,removeDiscount:Cart.removeDiscount}})();
2//# sourceMappingURL=/cdn/shop/t/36/assets/pitstop-cart-drawer.js.map?v=61200255861387397951789783167

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.