1"use strict";(self.webpackChunk_mvps_genesis_quickstart_theme=self.webpackChunk_mvps_genesis_quickstart_theme||[]).push([[266],{266:(e,t,s)=>{s.d(t,{default:()=>n});var o=s(1559),i=s(7889),a=s(4191);const n=class{#e;formElement;submitButtonElement;actionInputElement;processingButtonText;successMessage;stockMessageErrorSelector;missingAttributesMessage;limitedStockMessage;outOfStockMessage;otherMessage;messageContainer;submitButtonTextProperty;submitButtonText;scrollToMessage;constructor(e){let{actionInputElement:t='input[name="Action"]',limitedStockMessage:s={dynamic:!0,message:"We do not have enough of the combination you have selected.<br />Please adjust your quantity.",options:{autohide:!0,type:"warning"}},missingAttributesMessage:i={message:'All <em class="u-color-error">Required</em> options have not been selected.<br />Please review the following options: <span class="u-color-error">%missingAttributes%</span>',options:{autohide:!0,type:"warning"}},otherMessage:n={message:"Please review your selection.",options:{autohide:!0,type:"warning"}},outOfStockMessage:r={dynamic:!0,message:"The combination you have selected is out of stock.<br />Please review your options or check back later.",options:{autohide:!0,type:"warning"}},processingButtonText:c="Processing...",responseMessageElement:l=".js-add-to-cart-message",scrollToMessage:m=!1,scrollToMessageOptions:h={behavior:"smooth",block:"center"},stockMessageErrorSelector:u=".g-messages--error",submitButtonElement:g=".js-add-to-cart",successMessage:d={message:"Added to cart.",options:{autohide:!0,type:"success"}}}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.#e=new o.A(this),this.formElement=this.#e.isElement("formElement",e),this.submitButtonElement=this.#e.isElement("options.submitButtonElement",g,{container:this.formElement}),this.actionInputElement=this.#e.isElement("options.actionInputElement",t,{container:this.formElement}),this.processingButtonText=this.#e.isString("options.processingButtonText",c),this.successMessage=this.#e.isObject("options.successMessage",d),this.stockMessageErrorSelector=this.#e.isString("options.stockMessageErrorSelector",u),this.missingAttributesMessage=this.#e.isObject("options.missingAttributesMessage",i),this.limitedStockMessage=this.#e.isObject("options.limitedStockMessage",s),this.outOfStockMessage=this.#e.isObject("options.outOfStockMessage",r),this.otherMessage=this.#e.isObject("options.otherMessage",n),this.messageContainer=new a.MessageContainer({container:this.#e.isElement("options.responseMessageElement",l,{container:this.formElement})}),this.submitButtonTextProperty=this.submitButtonElement instanceof HTMLButtonElement?"textContent":"value",this.submitButtonText=this.submitButtonElement[this.submitButtonTextProperty],this.scrollToMessage={mode:this.#e.inSet("options.scrollToMessage",m,[!0,!1,"success","error"]),scrollIntoView:this.#e.isObject("options.scrollToMessageOptions",h)},this.bindEvents()}bindEvents(){this.formElement.addEventListener("submit",this.onSubmit.bind(this),!1)}async onSubmit(e){if("ADPR"!==this.actionInputElement.value)return;e.preventDefault(),e.stopImmediatePropagation(),this.submitButtonElement.dataset.action&&(this.formElement.action=this.submitButtonElement.dataset.action);const t=new FormData(this.formElement),s=new Request(this.formElement.action,{body:t,method:this.formElement.method||"POST"});let o={data:null,form:this.formElement,formData:t,message:null,request:s,success:!1};this.submitButtonElement.disabled=!0,this.submitButtonElement[this.submitButtonTextProperty]=this.processingButtonText,this.messageContainer.clear();const a=await fetch(s);if(a.ok){const e=await a.text(),t=(new DOMParser).parseFromString(e,"text/html"),s=a.headers.get("g-mm-page-code");switch(o.data=t,s){case"BASK":this.onSuccess(),o.success=!0;break;case"PATR":case"PROD":this.onMissingAttributes();break;case"PLMT":this.onLimitedStock(o);break;case"POUT":this.onOutOfStock(o);break;default:this.onOther()}o.message=this.messageContainer.currentMessage.message,this.handleScrollToMessage("BASK"===s)}else{const e=`${this.constructor.name} - The request failed with a status of: ${a.status}`;o.message=e}this.submitButtonElement.disabled=!1,this.submitButtonElement[this.submitButtonTextProperty]=this.submitButtonText,i.default.dispatchEvent("MVPS:addToCart",o)}handleScrollToMessage(e){if(!1===this.scrollToMessage.mode)return;this.#e.isBoolean("handleScrollToMessage.isSuccess",e);let t=!0===this.scrollToMessage.mode;!t&&(e&&"success"===this.scrollToMessage.mode||!e&&"error"===this.scrollToMessage.mode)&&(t=!0),t&&this.messageContainer.container.scrollIntoView(this.scrollToMessage.scrollIntoView)}onSuccess(){this.messageContainer.add(new a.Message(this.successMessage.message,this.successMessage.options)),"undefined"!=typeof attrMachCall&&window.attrMachCall.Initialize()}onMissingAttributes(){const e=this.formElement.querySelectorAll(".g-product-layout-purchase__options .is-required"),t=[];for(let s=0,o=e.length;s<o;s++)t.push(e[s].title?e[s].title:e[s].textContent);this.messageContainer.add(new a.Message(this.missingAttributesMessage.message.replace("%missingAttributes%",t.join(", ")),this.missingAttributesMessage.options))}onLimitedStock(e){let t=this.limitedStockMessage.message;if("object"==typeof e.data&&!0===this.limitedStockMessage.dynamic){const s=this.getStockMessage(e.data);""!==s&&(t=s)}this.messageContainer.add(new a.Message(t,this.limitedStockMessage.options))}onOutOfStock(e){let t=this.outOfStockMessage.message;if("object"==typeof e.data&&!0===this.outOfStockMessage.dynamic){const s=this.getStockMessage(e.data);""!==s&&(t=s)}this.messageContainer.add(new a.Message(t,this.outOfStockMessage.options))}onOther(){this.messageContainer.add(new a.Message(this.otherMessage.message,this.otherMessage.options))}getStockMessage(e){const t=e.querySelector(this.stockMessageErrorSelector);return t?t.innerHTML:""}}}}]); 2//# sourceMappingURL=266.2af9a670bd30615217bd.chunk.js.map
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.