{"version":3,"sources":["landingForm_A.js"],"names":["Vendd","Scripts","load","$loginPage","$","length","MessageBus","publishAsync","get","Widget","Messages","BindControl","$loginB2BPage","$checkoutLoginPage"],"mappings":"AAAAA,MAAAC,QAAAC,KAAA,WACA,IAAAC,WAAAC,EAAA,eACAD,WAAAE,OAAA,GACAL,MAAAM,WAAAC,aAAAJ,WAAAK,IAAA,GAAA,IAAAR,MAAAS,OAAAC,SAAAC,YAAAR,aAEA,IAAAS,cAAAR,EAAA,mBACAQ,cAAAP,OAAA,GACAL,MAAAM,WAAAC,aAAAK,cAAAJ,IAAA,GAAA,IAAAR,MAAAS,OAAAC,SAAAC,YAAAC,gBAEA,IAAAC,mBAAAT,EAAA,wBACAS,mBAAAR,OAAA,GACAL,MAAAM,WAAAC,aAAAM,mBAAAL,IAAA,GAAA,IAAAR,MAAAS,OAAAC,SAAAC,YAAAE","file":"Login.js","sourcesContent":["Vendd.Scripts.load(function () {\n 'use strict';\n\n var $form = $('.x-landing-form'), form, formData;\n\n if ($form.length < 1)\n return;\n\n form = $form.get(0);\n\n formData = {\n competition: $form.data(\"competition\"),\n email: \"\",\n firstname: \"\",\n lastname: \"\",\n message: \"\",\n newsletter: false,\n address: \"\",\n phone: \"\",\n mobilephone: \"\",\n fax: \"\",\n gender: \"\",\n customxml: \"\",\n reCaptchaCode: \"\",\n terms: false\n };\n\n // reCAPTCHA\n var captchaId = \"landingCaptcha\";\n var captchaWidgetId;\n var $captchaElement = $form.find(\"#\" + captchaId);\n var $captchaContainer = $form.find('.recaptcha-container');\n var captchaEnabled = $captchaElement.length > 0 ? true : false;\n\n\n form.initRecaptcha = function () {\n\n if (!captchaEnabled)\n return;\n\n var sitekey = $captchaElement.data(\"sitekey\");\n if (sitekey) {\n captchaEnabled = true;\n captchaWidgetId = grecaptcha.render(captchaId, {\n 'sitekey': sitekey,\n 'callback': form.recaptchaCallback\n });\n }\n };\n\n form.recaptchaCallback = function () {\n form.validateRecaptcha();\n };\n\n form.resetRecaptcha = function () {\n // Website must only verify the user's reCAPTCHA response token (g-recaptcha-response) once. \n // If a verify attempt has been made with a particular token, it cannot be used again. \n // Call grecaptcha.reset() to ask the end user to verify with reCAPTCHA again.\n if (captchaEnabled)\n grecaptcha.reset(captchaWidgetId);\n };\n\n form.removeRecaptcha = function () {\n $captchaElement.remove();\n };\n\n form.validateRecaptcha = function () {\n if (!captchaEnabled)\n return true;\n\n formData.reCaptchaCode = $captchaElement.find('.g-recaptcha-response').val();\n\n var res = false;\n\n if (formData.reCaptchaCode) {\n $captchaContainer.find('.recaptcha-required').removeClass('error');\n res = true;\n }\n else {\n $captchaContainer.find('.recaptcha-required').addClass('error');\n }\n\n return res;\n };\n\n form.loading = function (loading) {\n if (loading) {\n $form.addClass('x-loading');\n } else {\n $form.removeClass('x-loading');\n }\n };\n\n form.onSuccess = function (envelope) {\n form.loading(false);\n\n var data = envelope.message.data;\n\n if (data.success && data.code === \"Landing_OperationSuccesful\") {\n $('.js-error', $form).hide();\n $('.js-content', $form).hide();\n $('.js-success', $form).show();\n $('html,body').animate({ scrollTop: $('.js-success', $form).offset().top - 100 }, 300);\n\n form.removeRecaptcha();\n } else {\n $('.js-error', $form).show();\n $('html,body').animate({ scrollTop: $('.js-error', $form).offset().top - 100 }, 300);\n\n form.resetRecaptcha();\n }\n };\n\n form.onFailure = function (envelope) {\n form.loading(false);\n\n $('.js-error', $form).show();\n $('html,body').animate({ scrollTop: $('.js-error', $form).offset().top - 100 }, 300);\n };\n\n form.checkConsents = function () {\n var data = [];\n\n var checkboxes = $('.form-row.consent.checkbox', form);\n $.each(checkboxes, function (e, el) {\n var chkbx = $('.checkbox-wrapper input', el);\n data.push({ type: chkbx.attr('id'), source: 'Landing Page', approved: chkbx.prop(\"checked\") });\n });\n\n if (data.length > 0) {\n window.ConsentsManager.insertConsents(data);\n } else {\n form.submit();\n }\n };\n\n form.submit = function () {\n form.loading(true);\n\n Vendd.MessageBus.publishAsync(form, new Vendd.Landing.Messages.Submit(\n formData.competition,\n formData.email,\n formData.firstname,\n formData.lastname,\n formData.message,\n formData.newsletter,\n formData.address,\n formData.phone,\n formData.mobilephone,\n formData.fax,\n formData.gender,\n formData.customxml,\n formData.reCaptchaCode,\n $('input[name=\"terms\"]:checked').length > 0\n ));\n };\n\n form.reset = function () {\n $('.js-error', $form).hide();\n $('.js-success', $form).hide();\n $('.js-content', $form).show();\n\n $('input[name=\"email\"]', $form).val(\"\");\n $('input[name=\"firstname\"]', $form).val(\"\");\n $('input[name=\"lastname\"]', $form).val(\"\");\n $('input[name=\"message\"]', $form).val(\"\");\n $('input[name=\"newsletter\"]', $form).prop('checked', false);\n $('input[name=\"address\"]', $form).val(\"\");\n $('input[name=\"phone\"]', $form).val(\"\");\n $('input[name=\"mobilephone\"]', $form).val(\"\");\n $('input[name=\"fax\"]', $form).val(\"\");\n $('input[name=\"gender\"]', $form).val(\"\");\n $('input[name=\"customxml\"]', $form).val(\"\");\n $('input[name=\"terms\"]', $form).prop('checked', false);\n\n cf.reset();\n };\n\n $form.on('click', '.js-submit-button', function (e) {\n e.preventDefault();\n e.stopPropagation();\n\n var val1 = cf.validate();\n var val2 = form.validateRecaptcha();\n\n if (val1 && val2) {\n if (LhApp.Context.IsConsentsEnabled) {\n form.checkConsents();\n } else {\n form.submit();\n }\n } else {\n if ($('.form-row.with-error', $form).length > 0) {\n $('html,body').animate({ scrollTop: $('.form-row.with-error', $form).first().offset().top - 100 }, 400);\n }\n }\n\n });\n\n $form.on('click', '.js-reset-button', function (e) {\n e.preventDefault();\n e.stopPropagation();\n\n form.reset();\n });\n\n $form.on('keyup', 'input[name], textarea[name]', function (e) {\n if (e.keyCode === 13) {\n\n if ($(this).prop(\"tagName\").toLowerCase() === \"textarea\")\n return true;\n\n e.preventDefault();\n e.stopPropagation();\n\n form.submit();\n\n return;\n }\n\n var $this = $(this);\n var fieldName = $this.attr('name');\n\n formData[fieldName] = $this.val();\n\n cf.validate(fieldName);\n });\n\n $(\".view-terms\").fancybox({\n openEffect: 'none',\n closeEffect: 'none',\n maxWidth: 940,\n helpers: {\n overlay: {\n locked: true\n }\n }\n });\n\n //init validation options\n var validationOptions = {};\n\n //add required validations\n $.each($('input[data-required], textarea[data-required], select[data-required]', $form), function (e, el) {\n var inputName = $(el).attr('name');\n validationOptions[inputName] = { required: inputName + '-required' };\n });\n\n //add email validation if exists\n if ($('input[name=\"email\"]', $form).length > 0) {\n validationOptions.email = validationOptions.email || {};\n _.extend(validationOptions.email, { isEmail: 'email-invalid' });\n }\n\n //add phone validation if exists\n if ($('input[name=\"phone\"]', $form).length > 0) {\n validationOptions.phone = validationOptions.phone || {};\n if (venddProjectConfigs.phoneLocalizationEnabled) {\n _.extend(validationOptions.phone, { isValidPhoneLocalized: { validator: 'phone-invalid', config: { type: 'phone' } } });\n } else {\n _.extend(validationOptions.phone, { isPhoneNumber: 'phone-invalid' });\n }\n }\n \n //add mobile phone validation if exists\n if ($('input[name=\"mobilephone\"]', $form).length > 0) {\n validationOptions.mobilephone = validationOptions.mobilephone || {};\n if (venddProjectConfigs.phoneLocalizationEnabled) {\n _.extend(validationOptions.mobilephone, { isValidPhoneLocalized: { validator: 'mobilephone-invalid', config: { type: 'mobile' } } });\n } else {\n _.extend(validationOptions.mobilephone, { isPhoneNumber: 'mobilephone-invalid' });\n }\n }\n\n //add consent validations\n $.each($('div.consent.checkbox[data-required]'), function (e, el) {\n var consentType = $('input', el).attr('name');\n validationOptions[consentType] = { checkboxRequired: consentType + '-required' };\n });\n\n var $consents = $('.form-row.consent input[type=\"checkbox\"]', $form);\n\n $consents.on('click', function () {\n var fieldName = $(this).attr('name');\n cf.validate(fieldName);\n });\n\n $form.validationEngine(validationOptions);\n var cf = $form.data('validationEngine');\n\n if (venddProjectConfigs.phoneLocalizationEnabled) {\n if ($('input[name=\"phone\"]', $form).length > 0) {\n $('input[name=\"phone\"]', $form).get(0).addEventListener(\"countrychange\", function () {\n formData.phone = $(this).val();\n cf = $form.data('validationEngine');\n cf.validate('phone');\n });\n }\n if ($('input[name=\"mobilephone\"]', $form).length > 0) {\n $('input[name=\"mobilephone\"]', $form).get(0).addEventListener(\"countrychange\", function () {\n formData.mobilephone = $(this).val();\n cf = $form.data('validationEngine');\n cf.validate('mobilephone');\n });\n }\n }\n\n Vendd.MessageBus.subscribe(Vendd.Landing.Messages.SubmitSuccess, form, form.onSuccess);\n Vendd.MessageBus.subscribe(Vendd.Landing.Messages.SubmitFailure, form, form.onFailure);\n Vendd.MessageBus.subscribe(Vendd.Plugins.Messages.RecaptcaLoaded, form, form.initRecaptcha);\n\n Vendd.MessageBus.subscribe(Vendd.Consents.Messages.InsertConsents, form, form.submit);\n});\n\n"]}