function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } if (_typeof(adcValid) !== 'object') var adcValid = {}; adcValid.errorMes = { settings: { button: [], message: 'js_errorMessage' }, remove: function remove() { $('.' + this.settings.message + ', .' + this.settings.message + '2').remove(); }, mes: function mes(elem, msg) { var _t = this, style, x, y, $elem = typeof elem.attr === "function" ? elem : $(elem); if (!$elem.length) { console.error('Not an item to display an error', $elem); return false; } ; if (_t.body === _t.add) { _t.add.add("html"); x = $elem.offset().left; y = $elem.offset().top; } else { x = $elem.offset().left - _t.add.offset().left; y = $elem.offset().top - _t.add.offset().top + _t.add.scrollTop(); } _t.add.animate({ scrollTop: y - 50 }, 0, function () { style = 'left: ' + x + 'px;' + 'top: ' + (y - 36) + 'px;' + 'background-color: #e74c3c;' + 'border-radius: 5px;' + 'border: 1px dashed black;' + 'color: #fff;' + 'font-family: Arial, \'Nimbus Sans L\', Helvetica, sans-serif;' + 'font-size: 14px;' + 'margin: 3px 0 0 0px;' + 'padding: 6px 5px 5px;' + 'position: absolute;' + 'display: block;' + 'z-index: 9999'; _t.remove(); _t.add.append('
' + msg + '
'); $elem.focus(); }); }, resize: function resize() { var _t = this; _t.window.resize(function () { _t.remove(); }); }, init: function init() { var _t = this; _t.window = $(window); _t.body = $('body'); _t.add = _t.body; _t.click = $('input, textarea').add(_t.body); _t.click.on("touchend click", function (e) { var result = true; for (var i = 0; i < _t.settings.button.length; i++) { if ($(e.target).closest('.' + _t.settings.button[i]).length || e.target.classList.contains(_t.settings.button[i])) result = false; } if (result) _t.remove(); }); _t.resize(); } }; adcValid.validation = { settings: { postal_code: /^[\d]{2,6}$/i, rename: /^[^\\|\/.!@#$%^&*()=+`~'":;?,<>{}[\]\d«»„\t\n\v\f\r]+$/i, rename2: /^[^\\|\/.!@#$%^&*()=+~'":;?,<>{}[\]\d«»„\t\n\v\f\r\s]+\s[^\\|\/.!@#$%^&*()=+~'":;?,<>{}[\]\d«»„\t\n\v\f\r\s]+$/i, rephone: /^[\d\-+() ]*$/i, email: /^([a-z0-9_-]+\.)*[a-z0-9_-]+@[a-z0-9_-]+(\.[a-z0-9_-]+)*\.[a-z]{2,6}$/i }, cleaning: function cleaning(text) { return text.replace(/^\s+|\s+$/g, '').replace(/\s+/g, ' '); }, partition: function partition(input, hint, _req, _cc) { var _t = this, req = false, $input = typeof input.attr === "function" ? input : $(input), val = _t.cleaning($input.val()); mes = hint || defaults.get_locale_var('set_address'); if (!val) { if (_typeof(_req) === 'object') { if (_req[_cc] !== undefined) req = _req[_cc]; } else { req = _req; } if (req) { $input.val(''); adcValid.errorMes.mes($input, mes); return false; } } else { $input.val(val); } return true; }, init: function init(button, fullAddress) { var _t = this, errorText = { not: ['Field is required'], notName: ['Name is a required field', 'set_fio'], erName: ['Name field is entered incorrectly', 'error_fio'], notPhone: ['Phone number is a required field', 'set_phone'], erPhone: ['The phone number is entered incorrectly', 'error_phone'], erEmail: ['The email is entered incorrectly', 'error_email'], notAddress: ['Address is a required field', 'set_address'], erAddress: ['Invalid address, please, refill the form', 'error_address'], notHouse: ['House is a required field', 'set_house'], notCity: ['City is a required field', 'set_city'] }; for (var ekey in errorText) { if (_typeof(defaults) === 'object' && errorText[ekey][1]) errorText[ekey][0] = defaults.get_locale_var(errorText[ekey][1]); } _t['button'] = typeof button.attr === "function" ? button : $(button); _t['form'] = _t.button.closest('form'); if (!_t['allForm']) _t['allForm'] = $('form'); _t['input'] = { name: _t.form.find('[name="name"]'), phone: _t.form.find('[name="phone"]'), address: _t.form.find('[name="address"]'), email: _t.form.find('[name="email"]') }; if (_t.input.name.attr('data-count-length') === "2+") _t.settings.rename = _t.settings.rename2; if (!_t.cleaning(_t.input.name.val())) { adcValid.errorMes.mes(_t.input.name, errorText.notName[0]); return false; } else if (!_t.settings.rename.test(_t.cleaning(_t.input.name.val()))) { adcValid.errorMes.mes(_t.input.name, errorText.erName[0]); return false; } else if (!_t.input.phone.val() || !_t.input.phone.val().length) { adcValid.errorMes.mes(_t.input.phone, errorText.notPhone[0]); return false; } else if (!_t.settings.rephone.test(_t.input.phone.val()) || _t.input.phone.val().length < 6) { adcValid.errorMes.mes(_t.input.phone, errorText.erPhone[0]); return false; } else if (_t.input.address.length && _t.cleaning(_t.input.address.val()) === '' && _t.input.address.is(':visible')) { adcValid.errorMes.mes(_t.input.address, errorText.erAddress[0]); return false; } else if (_t.input.email.length && _t.input.email.is(':visible') && !_t.settings.email.test(_t.input.email.val())) { adcValid.errorMes.mes(_t.input.email, errorText.erEmail[0]); return false; } else { if (_typeof(fullAddress) === 'object' && !fullAddress.length) { _t['fullAddress'] = []; for (var key in fullAddress) { var el = _t.form.find('[name="' + key + '"]'), error = key === 'street' ? 'notAddress' : key === 'house' ? 'notHouse' : key === 'city' ? 'notCity' : 'not'; if (el.length) { if (fullAddress[key]) { if (!_t.cleaning(el.val()) || _t.settings[key] && !_t.settings[key].test(_t.cleaning(el.val()))) { adcValid.errorMes.mes(el, errorText[error][0]); return false; } } } else { el = _t.form.find('#' + key + '[type="checkbox"]'); if (el.length) { if (!el.prop("checked")) { adcValid.errorMes.mes(el, errorText[error][0]); return false; } } } if (el.attr('type') !== 'checkbox') _t.fullAddress.push(_t.cleaning(el.val())); } _t.allForm.find('[name="address"]').val(_t.fullAddress.join(' ')); } adcValid.errorMes.remove(); return true; } } }; $().ready(function () { adcValid.errorMes.init(); //change phone input type to tel manually $('[name="phone"]').attr('type', 'tel').addClass('only_number'); //scroll to top $('.to_top').click(function (e) { e.preventDefault(); $('html,body').animate({ scrollTop: 0 }, 400); return false; }); // autoselect local country from selector var ip_country = $('input[name=ip_country]').val(); if (ip_country) { var found = false; $('select').each(function () { if (this.id === 'country_code_selector') { $(this).change(function () { $('input[name=country_code]').val(this.value); }); $('#' + this.id + ' option').each(function () { if (this.value === ip_country) { found = true; this.parentElement.value = ip_country; } }); } }); if (found) { $('input[name="country_code"]').each(function () { this.value = ip_country; }); } else { var ip_country_name = $('input[name=ip_country_name]').val(); if (ip_country_name) { $('select').each(function () { if ($(this).attr('id') === 'country_code_selector') $(this).append($('