Форма подписки

Получайте новые отзывы туристов на свой емейл!

removeTextFieldError: function(input) { input.className = 'required'; input.placeholder = ''; },

onSelectCallback: function(input) { if(typeof Widget == 'undefined' || Widget.BasicDropdown == undefined) return;

var dropdownEl = input.parentNode, instances = Widget.BasicDropdown.instances;

for(var i = 0; i < instances.length; ++i) { var instance = instances[i]; if(instance.wrapperEl == dropdownEl) { instance.onSelect = this.validate.bind(this); } } },

updateFormAfterValidation: function() { this.form.className = this.setFormClassName(); this.submit.value = this.submitButtonText(); this.submit.disabled = !this.isValid; this.submit.className = this.isValid ? 'submit' : 'disabled'; },

setFormClassName: function() { var name = this.form.className;

if(this.isValid) { return name.replace(/\s?mimi_invalid/, ''); } else { if(name.indexOf('mimi_invalid') == -1) { return name += ' mimi_invalid'; } else { return name; } } },

submitButtonText: function() { var invalidFields = document.querySelectorAll('.invalid'), text;

if(this.isValid || invalidFields == undefined) { text = this.submit.getAttribute('data-default-text'); } else { if(invalidFields.length > 1 || invalidFields[0].className.indexOf('checkgroup') == -1) { text = this.submit.getAttribute('data-invalid-text'); } else { text = this.submit.getAttribute('data-choose-list'); } } return text; },

submitForm: function() { this.formSubmitting();

var _this = this; window[this.callbackName] = function(response) { delete window[this.callbackName]; document.body.removeChild(script); _this.onSubmitCallback(response); };

var script = document.createElement('script'); script.src = this.formUrl('json'); document.body.appendChild(script); },

formUrl: function(format) { var action = this.form.action, divider = action.indexOf('?') >= 0 ? '&' : '?';

if(format == 'json') action += '.json';

return action + divider + 'callback=' + this.callbackName + '&' + serialize(this.form); },

formSubmitting: function() { this.form.className += ' mimi_submitting'; this.submit.value = this.submit.getAttribute('data-submitting-text'); this.submit.disabled = true; this.submit.className = 'disabled'; },

onSubmitCallback: function(response) { if(response.success) { this.onSubmitSuccess(response.result); } else { top.location.href = this.formUrl('html'); } },

onSubmitSuccess: function(result) { if(result.has_redirect) { top.location.href = result.redirect; } else if(result.single_opt_in || result.confirmation_html == null) { this.disableForm(); this.updateSubmitButtonText(this.submit.getAttribute('data-thanks')); } else { this.showConfirmationText(result.confirmation_html); } },

showConfirmationText: function(html) { var fields = this.form.querySelectorAll('.mimi_field');

for(var i = 0; i < fields.length; ++i) { fields[i].style['display'] = 'none'; }

(this.form.querySelectorAll('fieldset')[0] || this.form).innerHTML = html; },

disableForm: function() { var elements = this.form.elements; for(var i = 0; i < elements.length; ++i) { elements[i].disabled = true; } },

updateSubmitButtonText: function(text) { this.submit.value = text; },

revalidateOnChange: function() { var fields = this.form.querySelectorAll(".mimi_field.required");

for(var i = 0; i < fields.length; ++i) { var inputs = fields[i].getElementsByTagName('input'); for(var j = 0; j < inputs.length; ++j) { inputs[j].onchange = this.validate.bind(this); } } } });

if (document.addEventListener) { document.addEventListener("DOMContentLoaded", new Mimi.Signups.EmbedValidation); } else { window.attachEvent('onload', function() { new Mimi.Signups.EmbedValidation(); }); } })(this); // ]]>

Прочитали рассказ? Теперь можно и поиграть. Спорим, не выйграете!


Войти
Новые комментарии
© 2018