Current Path : /var/www/www-root/data/www/www.monolith-realty.ru/local/templates/landing_form/js/ |
Current File : /var/www/www-root/data/www/www.monolith-realty.ru/local/templates/landing_form/js/main.js |
window.addEventListener('DOMContentLoaded', function () { [...document.querySelectorAll('img[data-src]')].forEach(img => { if (img.dataset.src) { img.src = img.dataset.src; } }) }) document.addEventListener('DOMContentLoaded', () => { const arBtns = Array.from(document.querySelectorAll('.tab_btn')), arTabs = Array.from(document.querySelectorAll('.tab_body')); // arBtns[0].classList.add("_active"); // arTabs[0].classList.add("_active"); // let activeBtn = arBtns[0], // activeTab = arTabs[0]; arBtns.forEach((el) => { el.addEventListener('click', btnClick) }); function btnClick(e) { // e.preventDefault(); let btn = e.target.closest('.tab_btn'); changeBtn(btn); } function changeBtn(btn) { if (btn.classList.contains('_active')) { return; } let wrapperResultShow = document.querySelector('._show') let wrapperResultHide = document.querySelector('._hide') if (wrapperResultShow) { wrapperResultShow.classList.remove('_show'); } if (wrapperResultHide) { wrapperResultHide.classList.remove('_hide'); } // activeBtn.classList.remove("_active"); // btn.classList.add("_active"); // activeBtn = btn; const indexBtn = arBtns.indexOf(btn); changeTab(indexBtn); } function changeTab(index) { activeTab.classList.remove("_active"); arTabs[index].classList.add("_active"); activeTab = arTabs[index]; } //mobile_menu const mobMenuBtnClose = document.querySelector('.aside_close'); const mobMenuBtn = document.querySelector('.mob_menu_btn'); const mobMenu = document.querySelector('.aside'); const body = document.querySelector('body'); const main = document.querySelector('main'); if (mobMenuBtn) { mobMenuBtn.addEventListener('click', () => { mobMenuBtn.classList.toggle('_active'); mobMenu.classList.toggle('_active'); body.classList.toggle('lock'); main.classList.toggle('lock'); }); // close_when_click_outside document.addEventListener('click', (e) => { if (mobMenuBtn.classList.contains('_active')) { const click1 = e.composedPath().includes(mobMenuBtn); const click2 = e.composedPath().includes(mobMenu); const click3 = e.composedPath().includes(mobMenuBtnClose); if (!click1 && !click2 || click3) { mobMenuBtn.classList.remove('_active'); mobMenu.classList.remove('_active'); body.classList.remove('lock'); main.classList.remove('lock'); } } }); // mob_menu_btn_scroll } // fancybox Fancybox.bind("[data-fancybox]", { autoFocus: false, on: { done: (fancybox, ready) => { let fancyContainer = fancybox.container let btnSubmitB24 = fancyContainer.querySelector('.b24-form-btn') console.log(btnSubmitB24); btnSubmitB24.addEventListener('click', () => { setTimeout(fancyClose, 2000) }) function fancyClose() { fancybox.close() downloadCatalog() let tabBodyActive = document.querySelector('.tab_body._active') if (tabBodyActive) { let wrapper = tabBodyActive.querySelector('.tab_body__wrapper') let wrapperThanks = wrapper.nextElementSibling wrapper.classList.add('_hide') wrapperThanks.classList.add('_show') } } function downloadCatalog() { let catalogLink = document.querySelector('.brochure_link') if(catalogLink) { catalogLink.click() } } } } }); // form_result // phone_mask /*document.querySelectorAll('._phone_masked').forEach(e => IMask(e, {mask: '+{7} (000) 000-00-00'}));*/ // modal_form+validation /*let modalTabForm = document.querySelectorAll('.modal_tab_form') modalTabForm.forEach(tabForm => { let form = tabForm.querySelector('form') let formInput = form.querySelectorAll('.form__input') formInput.forEach(input => { input.addEventListener('focus', () => { labelUp(input) }) input.addEventListener('blur', () => { if (input.value === '') { labelDown(input) } }) }) function labelUp(input) { input.parentElement.classList.add('_filled') } function labelDown(input) { input.parentElement.classList.remove('_filled') } // validation let formMessageError = form.querySelector('.form_message__error') form.addEventListener('submit', formSend); function formSend(e) { e.preventDefault() let error = formValidate(form); console.log(error); if (error === 0) { if (formMessageError.classList.contains('_show')) { formMessageError.classList.remove('_show') } form.submit() } else { formMessageError.classList.add('_show') } } function formValidate(form) { let error = 0; let formReq = form.querySelectorAll('._req'); for (let index = 0; index < formReq.length; index++) { const input = formReq[index]; formRemoveError(input); if (input.classList.contains('_email')) { if (testEmail(input)) { formAddError(input); error++; } } else if (input.getAttribute('type') === 'checkbox' && input.checked === false) { formAddError(input); error++; } else { if (input.value === '') { formAddError(input); error++; } } } return error; } function formAddError(input) { input.parentElement.classList.add('_error'); input.classList.add('_error'); } function formRemoveError(input) { input.parentElement.classList.remove('_error'); input.classList.remove('_error'); } // Проверяем E-mail function testEmail(input) { return !/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,8})+$/.test(input.value); } })*/ });