Current Path : /var/www/www-root/data/www/monolith-realty.ru/local/templates/monolitsochi/js/ |
Current File : /var/www/www-root/data/www/monolith-realty.ru/local/templates/monolitsochi/js/phones.js |
$(document).ready(function () { $(".phones__inner").hover(function (e) { var target = $(this)[0]; var target2 = $(this).find('.phones__dropdown'); var targetPosition = target.getBoundingClientRect().right, windowPosition = document.documentElement.clientWidth; if ( (targetPosition - 19) + (target2.width()) > windowPosition ) { $(".header .phones__dropdown").addClass("position_block"); } else { $(".header .phones__dropdown").removeClass("position_block"); } }); }); // LazarovStudio - Валидация номера по странам document.addEventListener('DOMContentLoaded', function() { setTimeout(function() { validatePhoneInputs(); enabledBtn(); }, 2000); var btnPopupForm = document.querySelectorAll('.btn.btn-default'); if (btnPopupForm) { btnPopupForm.forEach(function(button) { button.addEventListener('click', function(event) { setTimeout(function() { validatePhoneInputs(); enabledBtn(); }, 400); }); }); } function enabledBtn(allFilled = true){ var btnSubmit = document.querySelectorAll('[type="submit"]'); btnSubmit.forEach(btn => { btn.disabled = allFilled; }); } function validatePhoneInputs(){ var telInputs = document.querySelectorAll('input[type="tel"]'); telInputs.forEach(function(input) { if (input) { input.placeholder = ' '; input.setAttribute('maxlength', '18'); input.insertAdjacentHTML('afterend', '<span id="valid-msg" class="hide">✓ Valid</span>'); input.insertAdjacentHTML('afterend', '<span id="error-msg" class="hide"></span>'); const errorMsg = document.querySelector("#error-msg"); const validMsg = document.querySelector("#valid-msg"); // here, the index maps to the error code returned from getValidationError - see readme const errorMap = ["Неверный номер", "Неверный код страны", "Номер короткий", "Номер длинный", "Неверное число"]; // initialise plugin const iti = window.intlTelInput(input, { utilsScript: "https://cdn.jsdelivr.net/npm/intl-tel-input@18.1.1/build/js/utils.js", initialCountry: 'ru', }); const reset = () => { input.classList.remove("error"); errorMsg.innerHTML = ""; errorMsg.classList.add("hide"); validMsg.classList.add("hide"); }; // on blur: validate input.addEventListener('blur', () => { reset(); if (input.value.trim()) { if (iti.isValidNumber()) { validMsg.classList.remove("hide"); enabledBtn(false); } else { input.classList.add("error"); const errorCode = iti.getValidationError(); errorMsg.innerHTML = errorMap[errorCode]; errorMsg.classList.remove("hide"); } } }); input.addEventListener('focus', () => { $(input).parent().parent().find('.b24-form-control-label').css({ 'top': '8px', '-webkit-transform': 'translateY(0)', '-ms-transform': 'translateY(0)', 'transform': 'translateY(0)', 'font-size': '13px' }); }); input.addEventListener('focusout', () => { if (input.value === '') { $(input).parent().parent().find('.b24-form-control-label').css({ 'top': '50%', '-webkit-transform': 'translateY(-50%)', '-ms-transform': 'translateY(-50%)', 'transform': 'translateY(-50%)', 'font-size': '16px', }); } }); // on keyup / change flag: reset input.addEventListener('change', reset); input.addEventListener('keyup', reset); } }); } });