{"version":3,"names":[],"mappings":"","sources":["event-registration.js"],"sourcesContent":["//Include Constant Contact inline snippet to initialize hidden email form that signs event registrants up for emails\nvar _ctct_m = \"49e1ce933c8cb01a581333911cab9156\";\n(function() {\n var ccScript = document.createElement(\"script\");\n ccScript.id = \"signupScript\";\n ccScript.setAttribute(\n \"src\",\n \"//static.ctctcdn.com/js/signup-form-widget/current/signup-form-widget.min.js\"\n );\n ccScript.setAttribute(\"async\", \"async\");\n ccScript.setAttribute(\"defer\", \"defer\");\n document.documentElement.appendChild(ccScript);\n})();\n\n(function($) {\n const page_title = document.title.split(\" | \")[0];\n const event_date = document.querySelector(\n \".post-event#content .post__meta .post__date\"\n );\n const $email_field = $(\".em-booking-form-details #user_email\");\n\n const $booking_form = $(\".em-booking-form\");\n const $booking_form_submit = $booking_form.find(\".em-booking-submit\");\n const $booking_form_email_optin = $booking_form.find(\"#cc_newsletter_signup\");\n //const event_registration_type is defined globally in the Twig template from the Events Manager post metadata (post.custom._event_location_type)\n //const stws_2021_campaigns.post_topic is defined globally in the Twig template from the Events Manager post metadata (post.tags)\n\n window.dataLayer = window.dataLayer || [];\n\n initFormEvent = () => {\n return {\n form_type: 'webinar_registration',\n topic: window.stws_2021_campaigns ? stws_2021_campaigns.post_topic : '',\n date_of_webinar: event_date.innerText.replace(/\\s/g, \" \"),\n webinar_title: page_title.split(\" - \")[0],\n user_id: btoa($email_field.val()), \n email_optin: $booking_form_email_optin.is(':checked')\n }\n }\n\n //Log AJAX errors and submit an event to the GA dataLayer\n handleAJAXError = req => {\n console.error(`Form error`);\n console.error(req);\n\n event = {\n ...initFormEvent(),\n ...{\n event: 'error',\n message: \"The registration attempt ended in an error.\",\n status: req.status,\n response: req.responseJSON ? req.responseJSON.errors : req.statusText\n }\n }\n\n //console.log(event);\n window.dataLayer.push(event);\n };\n\n //Log form actions and submit an event to the GA dataLayer\n handleFormAction = (action, msg) => {\n //console.log(`Form action: ${msg}`);\n\n event = {\n ...initFormEvent(),\n ...{\n event: action,\n message: msg\n }\n }\n\n //console.log(event);\n window.dataLayer.push(event);\n };\n\n const handleEventFormResponse = (e, req, opts) => {\n //Intercept AJAX requests\n if (opts.url.indexOf(\"admin-ajax.php\") !== -1) {\n const data = new URLSearchParams(opts.data);\n //This is a booking event\n if (data.get(\"action\") === \"booking_add\") {\n\n //Fire once per successful submit\n $(document).off('ajaxComplete', handleEventFormResponse);\n\n //The request was successful\n if (req && req.status == 200) {\n res = req.responseJSON;\n //Booking was successful\n if (res.result) {\n //console.log(\"The registration attempt completed successfully.\");\n handleFormAction(\n \"generate_lead\",\n \"User successfully completed a registration.\"\n );\n } else {\n handleAJAXError(req);\n }\n } else {\n handleAJAXError(req);\n }\n }\n }\n }\n\n //Track clicks on the booking form register button\n $booking_form_submit.on(\"click\", () => {\n handleFormAction(\"form_click\", \"User clicked the registration button.\");\n });\n\n //Track booking form submissions\n $booking_form.on(\"submit\", () => {\n handleFormAction(\"form_submit\", \"User submitted the registration form.\");\n\n $(document).on('ajaxComplete',handleEventFormResponse);\n\n //Logic for syncing event registrations and email signups on event pages\n const $email_form = $(\".register__form .ctct-form-custom\");\n const $email_flag = $booking_form.find(\"#cc_newsletter_signup\");\n const $booking_email = $booking_form.find(\"#user_email\");\n const $email_email = $email_form.find(\"#email_address_1\");\n if ($email_flag.prop(\"checked\")) {\n $email_email.val($booking_email.val());\n $email_form.submit();\n } else {\n $email_email.val(null);\n }\n });\n\n //Auto-opt-in privacy prompt\n $('.input-field-data_privacy_consent input[type=\"checkbox\"]').prop(\n \"checked\",\n true\n );\n\n //Jump-link to registration form\n $registerEl = $(\".register__register\");\n $registerElOffset = $registerEl.offset().top - 100;\n $registerInput = $registerEl\n .find(\"form input:not([type='hidden']), form select\")\n .first();\n\n $(\".post__actions .link-jump\").on(\"click\", () => {\n $(\"html,body\").animate(\n {\n scrollTop: $registerElOffset\n },\n 1000,\n () => {\n $registerInput.focus();\n }\n );\n });\n\n})(jQuery);\n"],"file":"event-registration.js"}