1"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[72701],{2701:(e,t,r)=>{r.r(t),r.d(t,{default:()=>i});var s=r(4335),a=r(1088);class i extends s.A{static #e=this.options={redirectSelector:'[name="redirectTo"]',redirectParamSelector:'[data-redirect-parameters="true"]',redirectTo:"frontend.cart.offcanvas",alertTemplateSelector:".js-add-to-cart-alert-template",alertDismissDelay:3e3};init(){if(this._getForm(),!this._form)throw Error(`No form found for the plugin: ${this.constructor.name}`);this._prepareFormRedirect(),this._registerEvents()}_prepareFormRedirect(){try{let e=this._form.querySelector(this.options.redirectSelector),t=this._form.querySelector(this.options.redirectParamSelector);e.value=this.options.redirectTo,t.disabled=!0}catch(e){}}_getForm(){this.el&&"FORM"===this.el.nodeName?this._form=this.el:this._form=this.el.closest("form")}_registerEvents(){this.el.addEventListener("submit",this._formSubmit.bind(this))}_formSubmit(e){e.preventDefault();let t=this._form.getAttribute("action"),r=a.A.serialize(this._form);this.$emitter.publish("beforeFormSubmit",r),this._shouldOpenOffcanvas()?this._openOffCanvasCarts(t,r):this._addToCartWithoutOffcanvas(t,r)}_shouldOpenOffcanvas(){return"0"!==window.openOffcanvasAfterAddToCart}_addToCartWithoutOffcanvas(e,t){fetch(e,{method:"POST",body:t}).then(e=>{if(!e.ok)throw Error("Add to cart failed");window.PluginManager.getPluginInstances("CartWidget")?.forEach(e=>{e.fetch()}),this._showSuccessAlert(),this.$emitter.publish("addToCartWithoutOffcanvas")}).catch(()=>{this._openOffCanvasCarts(e,t)})}_showSuccessAlert(){let e=document.querySelector(this.options.alertTemplateSelector);if(!e||!this._form)return;let t=this._form.parentElement.querySelector(".add-to-cart-alert");t&&t.remove();let r=e.content.firstElementChild.cloneNode(!0);r.classList.add("show","add-to-cart-alert"),this._form.insertAdjacentElement("afterend",r),setTimeout(()=>{r.addEventListener("transitionend",()=>r.remove(),{once:!0}),r.classList.remove("show")},this.options.alertDismissDelay)}_openOffCanvasCarts(e,t){window.PluginManager.getPluginInstances("OffCanvasCart").forEach(r=>{this._openOffCanvasCart(r,e,t)})}_openOffCanvasCart(e,t,r){e.openOffCanvas(t,r,()=>{this.$emitter.publish("openOffCanvasCart")})}}},1088:(e,t,r)=>{r.d(t,{A:()=>s});class s{static serialize(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1];if("FORM"!==e.nodeName){if(t)throw Error("The passed element is not a form!");return{}}return new FormData(e)}static serializeJson(e){let t=!(arguments.length>1)||void 0===arguments[1]||arguments[1],r=s.serialize(e,t);if(!(r instanceof FormData)&&0===Object.keys(r).length||r instanceof FormData&&0===Array.from(r.entries()).length)return{};let a={};for(let[e,t]of r.entries())a[e]=t;return a}}}}]);
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.