{"version":3,"file":"jwsdw-raffle.js","sources":["../../../../../../../temp/ngAnnotate/assets/jwsdw-raffle.js"],"sourcesContent":["'use strict';\r\n\r\n(function (window, $) {\r\n const $window = $(window);\r\n const $rafflePageWrapper = $('.jwsdw-raffle-wrapper');\r\n const $continueButtons = $('.jwsdw-continue-button');\r\n const $raffleForm = $('.jwsdw-raffleForm');\r\n const mobileNavbarHeight = 64;\r\n\r\n /**\r\n * @description Method to scroll to the top of an element.\r\n * @param {jQuery} element jQuery element for which offset.top defines the scroll position\r\n * @param {number} offset - Optional offset parameter.\r\n * @returns {undefined}\r\n */\r\n function scrollTo(element, offset) {\r\n offset = offset || 0;\r\n $('html, body').animate({ 'scrollTop': element.offset().top + offset });\r\n }\r\n\r\n /**\r\n * @description Function to dispatch raffle submission custom event.\r\n * @param {jQuery} $form - The raffle form that was submitted\r\n * @param {Object} data - Response data from the server.\r\n * @returns {undefined}\r\n */\r\n function afterFormSubmit($form, data) {\r\n $form.find('button[type=submit]').spinner().stop();\r\n\r\n $form[0].dispatchEvent(new CustomEvent('raffle:submitted', {\r\n 'detail': data && data.responseJSON\r\n }));\r\n }\r\n\r\n /**\r\n * @description Form submission handler.\r\n * @param {Event} e - A form submission event.\r\n * @returns {undefined}\r\n */\r\n function submitForm(e) {\r\n e.preventDefault();\r\n\r\n const $form = $(this);\r\n let payload = new FormData(e.currentTarget);\r\n if (!$form.valid()) {\r\n return;\r\n }\r\n\r\n const action = $form.prop('action');\r\n const method = $form.prop('method');\r\n payload.append(window.jwsdwSettings.csrfTokenName, window.jwsdwSettings.csrfTokenValue);\r\n payload.append('competitionId', window.jwsdwCompetitionConfigs.competitionID);\r\n\r\n $form.find('button[type=submit]').spinner().start();\r\n\r\n $.ajax({\r\n 'url': action,\r\n 'type': method,\r\n 'data': payload,\r\n 'dataType': 'json',\r\n 'processData': false,\r\n 'contentType': false,\r\n 'success': (data) => {\r\n window.dataLayer = window.dataLayer || [];\r\n\r\n window.dataLayer.push({\r\n 'event': 'ce.misc',\r\n 'eventCategory': 'misc',\r\n 'eventAction': 'raffle',\r\n 'eventLabel': data.competitionId + (data.isNewUser ? ' Non-Member' : ' Member'),\r\n 'eventValue': undefined,\r\n 'nonInteraction': false\r\n });\r\n\r\n if (data.isNewUser) {\r\n window.dataLayer.push({\r\n 'event': 'ce.misc',\r\n 'eventCategory': 'Misc',\r\n 'eventAction': 'Newsletter',\r\n 'eventLabel': 'signup',\r\n 'eventValue': undefined,\r\n 'nonInteraction': false\r\n });\r\n\r\n window.jwsdwApi.tracking.fireEvent('newsletter', {\r\n 'type': 'newsletterSubscriptionSuccessful'\r\n });\r\n }\r\n\r\n let viewport = window.jwsdwUtil.uiUtils.getViewport();\r\n if (viewport === '\\\"small\\\"' || viewport === '\\\"medium\\\"') {\r\n scrollTo($rafflePageWrapper, -mobileNavbarHeight);\r\n }\r\n $rafflePageWrapper.attr('data-state', 'registration-success');\r\n },\r\n 'complete': (data) => afterFormSubmit($form, data),\r\n 'error': (data) => {\r\n if (data.responseJSON && data.responseJSON.details && data.responseJSON.details.fieldErrors) {\r\n $form.validate().showErrors(data.responseJSON.details.fieldErrors);\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * @description Function which handles browser's back button action in order to restore the initial state of the page.\r\n * @returns {undefined}\r\n */\r\n function handleBackButton() {\r\n $rafflePageWrapper.removeAttr('data-state');\r\n }\r\n\r\n /* Initialize birthday fields validation logic */\r\n $.validator.setDefaults({\r\n 'rules': {\r\n 'email': {\r\n 'invalidvalue': true,\r\n 'customemail': true\r\n },\r\n 'dateOfBirth': {\r\n 'checkDate': '#jwsdw-raffleForm-dateOfBirth'\r\n }\r\n }\r\n });\r\n\r\n /* Handling browser back button to allow for navigation through form states */\r\n $continueButtons.on('click', function () {\r\n let state = $(this).data('setState');\r\n if (state) {\r\n let viewport = window.jwsdwUtil.uiUtils.getViewport();\r\n let scrollTarget = $(this).data('scrollTarget');\r\n history.pushState({ 'state': state }, '');\r\n\r\n requestAnimationFrame(() => {\r\n $rafflePageWrapper.attr('data-state', state);\r\n requestAnimationFrame(() => {\r\n if (viewport === '\\\"small\\\"' || viewport === '\\\"medium\\\"') {\r\n scrollTo($(scrollTarget), -mobileNavbarHeight);\r\n }\r\n });\r\n });\r\n $window.one('popstate', handleBackButton);\r\n }\r\n });\r\n\r\n /* Initializing form validation. */\r\n $raffleForm.validate();\r\n\r\n /* Handling competition form submission for new users */\r\n $raffleForm.on('submit', submitForm);\r\n}(window, jQuery));\r\n"],"names":["window","$","$window","$rafflePageWrapper","$continueButtons","$raffleForm","scrollTo","element","offset","animate","scrollTop","top","handleBackButton","removeAttr","validator","setDefaults","rules","email","invalidvalue","customemail","dateOfBirth","checkDate","on","let","state","this","data","viewport","jwsdwUtil","uiUtils","getViewport","scrollTarget","history","pushState","requestAnimationFrame","attr","one","validate","e","preventDefault","$form","action","method","payload","FormData","currentTarget","valid","prop","append","jwsdwSettings","csrfTokenName","csrfTokenValue","jwsdwCompetitionConfigs","competitionID","find","spinner","start","ajax","url","type","dataType","processData","contentType","success","dataLayer","push","event","eventCategory","eventAction","eventLabel","competitionId","isNewUser","eventValue","undefined","nonInteraction","jwsdwApi","tracking","fireEvent","complete","afterFormSubmit","stop","dispatchEvent","CustomEvent","detail","responseJSON","error","details","fieldErrors","showErrors","jQuery"],"mappings":"AAAA,aAEA,CAAC,SAAUA,EAAQC,GACf,MAAMC,EAAUD,EAAED,CAAM,EAClBG,EAAqBF,EAAE,uBAAuB,EACpD,IAAMG,EAAmBH,EAAE,wBAAwB,EAC7CI,EAAcJ,EAAE,mBAAmB,EASzC,SAASK,EAASC,EAASC,GACvBA,EAASA,GAAU,EACnBP,EAAE,YAAY,EAAEQ,QAAQ,CAAEC,UAAaH,EAAQC,OAAO,EAAEG,IAAMH,CAAO,CAAC,CAC1E,CA0FA,SAASI,IACLT,EAAmBU,WAAW,YAAY,CAC9C,CAGAZ,EAAEa,UAAUC,YAAY,CACpBC,MAAS,CACLC,MAAS,CACLC,aAAgB,CAAA,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