{"version":3,"sources":["forms.newsletter.js"],"names":["app","newsletterForm","init","form","document","querySelector","lastNameField","emailField","csrfField","addEventListener","event","preventDefault","firstName","firstNameField","value","lastName","detail","submitButton","setAttribute","method","headers","emailAddress","fetch","body","JSON","Content-Type","json","then","data","Culture","success","uiCulture","Toast","message","stringify","pageUrl","location","pathname","reset","errorMessage","window","pushEvent","removeAttribute","catch","error","console"],"mappings":"AAIAA,IACEC,eAAA,wBA4EA,MAAO,CACLC,KA3EF,WAEE,MAAKC,EAAMC,SAAAC,cAAA,0BAEX,GAAAF,EAAA,CAEA,MAAMG,EAAaH,EAAOE,cAAJ,mBAChBE,EAAiBJ,EAACE,cAAc,iCAChCG,EAAgBL,EAACE,cAAc,gCAEhCI,EAAAA,EAAiBJ,cAAU,6BAC9BK,EAAMC,EAANN,cAAA,uCAGFF,EAAKM,iBAAiB,SAAA,SAAAC,GACpBA,EAAIA,mBADNP,EAMIS,iBAAWC,aADF,SAAAH,IAEeI,IAAxBC,EAAQC,OAAEV,QAFDW,EAAXC,aAAA,WAAA,YAOEC,EAAQ,CACRC,UAASP,EAAAC,MANTC,SAOET,EAAgBQ,MANlBO,aAOEd,EAAgBC,OAJpBc,MAAmC,4BAAA,CAQjCC,OAAMC,OARRJ,QAUQ,CAAAK,eAAuBC,mBAC5BC,eAAMC,EAASd,MACde,QAASC,KAALC,UACFC,WAAWC,KAAAA,YALfV,KAAMC,KAAKU,UAAUN,KAEpBD,KAQKQ,SAAAA,GAAAA,OAAgBC,EAASC,SAP9BV,KAMG,SAAAC,IAGS,IARXA,EAQWA,SACTI,MAAMJ,EAAKK,QAAS,UAAS,KAP7B9B,EAAKmC,QAYHC,IAAAA,UAAcX,UAAKK,yBAAAA,CAFrBE,QAAAK,OAAAJ,SAAAC,aAKwB,IAAlBT,EAAAE,SARNE,MAAMJ,EAAKK,QAAS,QAAS,KAa3BM,IAAAA,UAAcE,UAAA,wBAAA,CAFhBN,QAAAK,OAAAJ,SAAAC,SAIDE,aAAAX,EAAAK,WAE4B,MAAhBS,EAAAA,SAEdC,MAAM,iBAAW,QAAA,KAGhB1B,IAAAA,UAAayB,UAAb,wBAAA,CA3CJP,QAAAK,OAAAJ,SAAAC,SAXFE,aAAA,mBA4DKtB,EAAAyB,gBAAA,cAAPC,MAAA,SAAAC,GA7EFC,QAAAD,MAAA,SAAAA,GAsEUZ,MAAM,iBAAkB,QAAS,KAYvC/B,EAAJyC,gBAAA,oBAjFE,GAiFF1C,IAAIC,eAAeC","file":"../forms.newsletter.min.js","sourcesContent":["/* ========================================================================\r\n Newsletter form\r\n ========================================================================== */\r\n\r\napp.newsletterForm = (function () {\r\n 'use strict';\r\n\r\n function init() {\r\n const form = document.querySelector('[data-newsletter-form]');\r\n if (!form) return;\r\n\r\n const submitButton = form.querySelector('[type=\"submit\"]');\r\n const firstNameField = form.querySelector('[name=\"newsletter_firstname\"]');\r\n const lastNameField = form.querySelector('[name=\"newsletter_lastname\"]');\r\n const emailField = form.querySelector('[name=\"newsletter_email\"]');\r\n const csrfField = form.querySelector('[name=\"__RequestVerificationToken\"]');\r\n\r\n form.addEventListener('submit', (event) => {\r\n event.preventDefault();\r\n });\r\n\r\n form.addEventListener('validation', (event) => {\r\n if (event.detail.valid === false) return;\r\n\r\n submitButton.setAttribute('disabled', 'disabled');\r\n\r\n var data = {\r\n firstName: firstNameField.value,\r\n lastName: lastNameField.value,\r\n emailAddress: emailField.value,\r\n };\r\n\r\n fetch('/api/newsletter/subscribe', {\r\n method: 'POST',\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n 'X-CSRF-TOKEN': csrfField.value,\r\n Culture: util.uiCulture,\r\n HomePageId: util.homePageId,\r\n },\r\n body: JSON.stringify(data),\r\n })\r\n .then((response) => response.json())\r\n .then((data) => {\r\n if (data.success === true) {\r\n Toast(data.message, 'success', 10000);\r\n form.reset();\r\n\r\n // DATALAYER\r\n app.dataLayer.pushEvent('footerNewsletterSignup', {\r\n pageUrl: window.location.pathname,\r\n });\r\n } else if (data.success === false) {\r\n Toast(data.message, 'error', 10000);\r\n\r\n // DATALAYER\r\n app.dataLayer.pushEvent('footerNewsletterError', {\r\n pageUrl: window.location.pathname,\r\n errorMessage: data.message,\r\n });\r\n } else if (data.status === 400) {\r\n Toast('Unknown error.', 'error', 10000);\r\n\r\n // DATALAYER\r\n app.dataLayer.pushEvent('footerNewsletterError', {\r\n pageUrl: window.location.pathname,\r\n errorMessage: 'Unknown error',\r\n });\r\n }\r\n\r\n submitButton.removeAttribute('disabled');\r\n })\r\n .catch((error) => {\r\n console.error('Error:', error);\r\n Toast('Unknown error.', 'error', 10000);\r\n submitButton.removeAttribute('disabled');\r\n });\r\n });\r\n }\r\n\r\n // Expose public functions and variables\r\n return {\r\n init: init,\r\n };\r\n})();\r\n\r\napp.newsletterForm.init();\r\n"]}