PageSourceSearch

https://www.marinelayer.com/cdn/shop/t/398/assets/main-cart.D_gvGWmp.min.js

js marinelayer.com collected 2026-10-02 06:04:05 UTC 9,106 bytes, 1 lines download raw bytes

1var e=Object.defineProperty,t=Object.defineProperties,i=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable,a=(t,i,n)=>i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[i]=n,s=(e,t)=>{for(var i in t||(t={}))r.call(t,i)&&a(e,i,t[i]);if(n)for(var i of n(t))o.call(t,i)&&a(e,i,t[i]);return e};import{A as c}from"./accordion.min.D5FYvjlc.min.js";import{f as d}from"./utils.BSlSJ0RJ.min.js";const l=".js-gift-options",h=".js-gift-wrap",u=".js-gift-option-overlay",p=".js-gift-receipt",m=".js-gift-message";class f extends HTMLElement{connectedCallback(){this.initializeGiftOptions(),this.initializeCustomizationGroupRemoval()}initializeCustomizationGroupRemoval(){this.querySelectorAll(".js-cart-remove-customization").forEach(e=>{"true"!==e.dataset.customizationBound&&(e.dataset.customizationBound="true",e.addEventListener("click",t=>{t.preventDefault(),this.handleRemoveCustomizationGroup(e)}))})}handleRemoveCustomizationGroup(e){const n=e.getAttribute("data-customization-ref"),r=e.closest("[data-customization-group]");n&&!this.loading&&(this.loading=!0,r&&r.setAttribute("aria-busy","true"),fetch("/cart.js",{headers:{Accept:"application/json"}}).then(e=>{if(!e.ok)throw new Error("Unable to read the cart");return e.json()}).then(e=>{const r={};if(e.items.filter(e=>{var t;return(null==(t=e.properties)?void 0:t._ml_customization_ref)===n}).forEach(e=>{r[e.key]=0}),0===Object.keys(r).length)throw new Error("Customization group not found");return fetch("/cart/update.js",(o=s({},this.getFetchConfig()),a={body:JSON.stringify({updates:r,sections:this.getSectionsToRender().map(e=>e.section),sections_url:window.location.pathname})},t(o,i(a))));var o,a}).then(e=>{if(!e.ok)throw new Error("Unable to update the cart");return e.json()}).then(e=>{if(e.errors)throw new Error(e.errors);this.renderCartState(e)}).catch(()=>{}).finally(()=>{this.loading=!1,r&&r.removeAttribute("aria-busy")}))}renderCartState(e){var t;"function"==typeof this.renderContents?this.renderContents(e):this.getSectionsToRender().forEach(t=>{var i;const n=document.getElementById(t.id),r=n?t.selector?n.querySelector(t.selector):n:null;r&&(r.innerHTML=this.getSectionInnerHTML(null==(i=e.sections)?void 0:i[t.section],t.selector))}),this.initializeCustomizationGroupRemoval(),null==(t=this.initializeGroupedItemRemoval)||t.call(this)}initializeGiftOptions(){this.initializeGiftOptionsDropdown(),this.initializeGiftWrap(),this.initializeGiftReceipt()}initializeGiftOptionsDropdown(){const e=this.querySelector(l),t=this.querySelector(u);if(!e||!t)return;this.giftOptionsDropdown=new c(e,{ariaEnabled:!0,openOnInit:[1],beforeOpen:()=>{t.classList.add("active")},onClose:()=>{t.classList.remove("active")}}),t.addEventListener("click",()=>{this.giftOptionsDropdown.close(0)});const i=(e,t,i)=>{e.addEventListener("keydown",e=>{"Tab"===e.key&&e.shiftKey&&this.giftOptionsDropdown.close(i)}),t.addEventListener("keydown",e=>{if("Tab"!==e.key)return;const n=t.querySelectorAll('a, button, input, textarea, select, [tabindex]:not([tabindex="-1"])');if(!n.length)return;const r=n[n.length-1];e.shiftKey||document.activeElement!==r||this.giftOptionsDropdown.close(i)})};this.querySelectorAll(`${l} .ac`).forEach((e,t)=>{setTimeout(function(){e.classList.add("fade-in")},100);const n=e.querySelector(".ac-header"),r=e.querySelector(".ac-panel");n&&r&&i(n,r,t)})}initializeGiftWrap(){const e=this.querySelector(h);if(!e)return;const t=e.getAttribute("data-product-id"),i=e.previousElementSibling;i&&e.addEventListener("click",()=>{this.loading||(i.checked?(i.checked=!1,e.setAttribute("aria-checked",!1),this.handleRemoveGiftWrap(t,i,e)):(i.checked=!0,e.setAttribute("aria-checked",!0),this.handleAddGiftWrap(t,i,e)))})}initializeGiftReceipt(){const e=this.querySelector(p),t=this.querySelector(m);if(!e||!t)return;const i=e.previousElementSibling;i&&(e.addEventListener("click",()=>{this.loading||(i.checked?(i.checked=!1,e.setAttribute("aria-checked",!1),this.handleRemoveGiftReceipt(t,i,e)):(i.checked=!0,e.setAttribute("aria-checked",!0),this.handleAddGiftReceipt(t,i,e)))}),t.addEventListener("blur",()=>{i.checked&&(""==t.value?(i.checked=!1,this.handleRemoveGiftReceipt(t,i,e)):this.handleAddGiftReceipt(t,i))}
1))}handleAddGiftWrap(e,t,i){const n={items:[{id:e,quantity:1}]},r=this.querySelectorAll("#CartDrawer-CartItems");r.length&&r.forEach(e=>{e.classList.add("loading")}),this.loading=!0,fetch(window.Shopify.routes.root+"cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}).then(()=>{fetch(window.location.pathname+"?section_id="+(this.classList.contains("js-main-cart")?"main-cart":"cart-drawer")).then(e=>e.text()).then(e=>{this.getSectionsToRender().forEach(t=>{(document.getElementById(t.id).querySelector(t.selector)||document.getElementById(t.id)).innerHTML=this.getSectionInnerHTML(e,t.selector)})}).finally(()=>{this.loading=!1})}).catch(()=>{t.checked=!1,i.setAttribute("aria-checked",!1),this.loading=!1})}handleRemoveGiftWrap(e,t,i){const n=this.querySelector(`.cart-item[data-product-id="${e}"]`);if(!n)return;const r=n.dataset.index,o=JSON.stringify({line:r,quantity:0,sections:this.getSectionsToRender().map(e=>e.section),sections_url:window.location.pathname}),a=this.querySelectorAll("#CartDrawer-CartItems");a.length&&a.forEach(e=>{e.classList.add("loading")}),this.loading=!0,fetch(`${window.routes.cart_change_url}`,s(s({},d()),{body:o})).then(e=>e.text()).then(e=>{const t=JSON.parse(e);this.getSectionsToRender().forEach(e=>{(document.getElementById(e.id).querySelector(e.selector)||document.getElementById(e.id)).innerHTML=this.getSectionInnerHTML(t.sections[e.section],e.selector)})}).catch(()=>{t.checked=!0,i.setAttribute("aria-checked",!0)}).finally(()=>{this.loading=!1})}handleRemoveGiftReceipt(e,t,i){this.loading=!0,fetch("/cart/update.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({attributes:{"gift-receipt":"no","gift-message":""}})}).then(e=>e.json()).catch(()=>{t.checked=!0,i.setAttribute("aria-checked",!0)}).finally(()=>{e.value="",this.loading=!1})}handleAddGiftReceipt(e,t,i){if(""===e.value)return;const n={"gift-receipt":"yes","gift-message":e.value};fetch("/cart/update.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({attributes:n})}).then(e=>e.json()).catch(()=>{t.checked=!1,i.setAttribute("aria-checked",!1)}).finally(()=>{this.loading=!1})}}customElements.define("main-cart",class extends f{connectedCallback(){super.connectedCallback(),this.initializeGroupedItemRemoval()}initializeGroupedItemRemoval(){this.querySelectorAll(".js-cart-remove-grouped").forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),this.handleRemoveGroupedItems(e)})})}handleRemoveGroupedItems(e){const t=e.getAttribute("data-recipe-id"),i=e.getAttribute("data-group-items");let n;try{n=JSON.parse(i)}catch(o){return}if(!t||!n||0===n.length)return;const r=n.map(e=>({line:e,quantity:0}));this.updateCartItems(r).then(()=>{setTimeout(()=>{this.refreshCartDisplay()},500)}).catch(e=>{this.removeGroupedItemsIndividually(n)})}removeGroupedItemsIndividually(e){const t=e.map(e=>this.updateCartItemQuantity(e,0));Promise.all(t).then(()=>{setTimeout(()=>{this.refreshCartDisplay()},500)}).catch(e=>{})}updateCartItemQuantity(e,t){const i=JSON.stringify({line:e,quantity:t,sections:this.getSectionsToRender().map(e=>e.section),sections_url:window.location.pathname});return fetch(`${window.routes.cart_change_url}`,s(s({},this.getFetchConfig()),{body:i})).then(e=>e.text())}updateCartItems(e){const t={};e.forEach(e=>{t[e.line]=e.quantity});const i=JSON.stringify({updates:t});return fetch("/cart/update.js",{method:"POST",headers:{"Content-Type":"application/json"},body:i}).then(e=>e.json()).then(e=>e).catch(e=>{throw e})}refreshCartDisplay(){fetch(window.location.pathname+"?section_id=main-cart").then(e=>e.text()).then(e=>{this.getSectionsToRender().forEach(t=>{(document.getElementById(t.id).querySelector(t.selector)||document.getElementById(t.id)).innerHTML=this.getSectionInnerHTML(e,t.selector)}),this.initializeGroupedItemRemoval(),this.initializeCustomizationGroupRemoval()})}getFetchConfig(){return{method:"POST",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"}}}getSectionInnerHTML(e,t=".shopify-section"){if(!e)return;const i=(new window.DOMParser).parseFromString(e,"text/html").querySelector(t);return i?i.innerHTML:""}getSectionsToRender(){return[{id:"main-cart",section:"main-cart",selector:".cart-drawer__header"},{id:"main-cart",section:"main-cart",selector:".js-cart-items"},{id:"main-cart",section:"main-cart",selector:".cart-drawer__footer"},{id:"main-cart",section:"main-cart",selector:".cart-drawer__checkout"},{id:"cart-bubble-mobile",section:"cart-icon-bubble-mobile",selector:"#cart
1-bubble-mobile"},{id:"cart-bubble-desktop",section:"cart-icon-bubble",selector:"#cart-bubble-desktop"},{id:"cart-bubble-desktop-animation",section:"cart-icon-bubble-animation",selector:"#cart-bubble-desktop-animation"}]}});export{f as Cart};

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.