{"version":3,"sources":["landingForm_A.js"],"names":["reorderBoxes","$wrapper","$","length","isTouch","window","resize","width","isMoved","detach","appendTo","show","Vendd","Scripts","load"],"mappings":"AAMA,SAAAA,eACA,IAAAC,SAAAC,EAAA,cAEA,KAAAD,SAAAE,OAAA,GAAA,CAGAC,WACAF,EAAAG,QAAAC,OAAA,WAoBAJ,EAAAG,QAAAE,QAAA,IACAC,UACAN,EAAA,mBAAAD,UAAAE,OAAA,GACAD,EAAA,mBAAAD,UAAAQ,SAAAC,SAAA,iBAAAC,OAEAT,EAAA,2BAAAD,UAAAE,OAAA,GACAD,EAAA,2BAAAD,UAAAQ,SAAAC,SAAA,iBAAAC,OACAH,SAAA,GAGAA,UACAN,EAAA,mBAAAD,UAAAE,OAAA,GACAD,EAAA,mBAAAD,UAAAQ,SAAAC,SAAA,iBAAAC,OAEAT,EAAA,2BAAAD,UAAAE,OAAA,GACAD,EAAA,2BAAAD,UAAAQ,SAAAC,SAAA,iBAAAC,OAEAH,SAAA,KAhCA,IAAAA,SAAA,EAEAN,EAAAG,QAAAE,QAAA,KACAH,YACAF,EAAA,mBAAAD,UAAAE,OAAA,GACAD,EAAA,mBAAAD,UAAAQ,SAAAC,SAAA,iBAAAC,OAEAT,EAAA,2BAAAD,UAAAE,OAAA,GACAD,EAAA,2BAAAD,UAAAQ,SAAAC,SAAA,iBAAAC,OACAH,SAAA,IA3BAI,MAAAC,QAAAC,KAAA,WAEAd","file":"Blog.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 firstname: \"\",\n lastname: \"\",\n email: \"\",\n message: \"\",\n customfield1: \"\",\n customfield2: \"\",\n phones: \"\",\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\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\n $('.js-success', $form).show();\n\n form.removeRecaptcha();\n } else {\n $('.js-error', $form).show();\n form.resetRecaptcha();\n };\n };\n\n form.onFailure = function (envelope) {\n form.loading(false);\n\n $('.js-error', $form).show();\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\n var val1 = cf.validate();\n var val2 = form.validateRecaptcha();\n\n if (!val1 || !val2)\n return;\n\n form.loading(true);\n\n Vendd.MessageBus.publishAsync(form, new Vendd.Landing.Messages.Submit(\n $form.data(\"competition\"),\n formData.email,\n formData.firstname,\n formData.lastname,\n formData.message,\n false,\n formData.address,\n formData.phones,\n formData.mobile, formData.fax, '', '',\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=\"firstname\"]', $form).val(\"\");\n $('input[name=\"lastname\"]', $form).val(\"\");\n $('input[name=\"email\"]', $form).val(\"\");\n $('input[name=\"phones\"]', $form).val(\"\");\n $('input[name=\"customfield1\"]', $form).val(\"\");\n $('input[name=\"customfield2\"]', $form).val(\"\");\n $('input[name=\"message\"]', $form).val(\"\");\n\n\n cf.reset();\n };\n\n $form.on('click', '.js-submit-button', function (e) {\n e.preventDefault();\n e.stopPropagation();\n\n if (LhApp.Context.IsConsentsEnabled) {\n form.checkConsents();\n } else {\n form.submit();\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 LandingForm: {\n checkboxRequired: 'LandingForm-required'\n }\n };\n\n $('.js-required', $form).each(function (e, el) {\n var inputName = $('input', el).attr('name'), tempOption = {};\n validationOptions[inputName] = {\n required: inputName + '-required'\n };\n if ($(this).hasClass('js-invalid-email')) {\n tempOption[inputName] = {\n isEmail: inputName + '-invalid'\n };\n $.extend(true, validationOptions, tempOption);\n }\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] = {\n checkboxRequired: consentType + '-required'\n };\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\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"]}