var CrucialHome = (function () { var $fixedTopMenu = $('.fixed-top-menu'); // var $fixedTopMenu = $('.fixed-under-menu'); var $content = $('.content'); var emailInputId; let subMenuOpen = false; let _hideTimer; function bind() { window.addEventListener('scroll', handleScroll); handleScroll(); $('#btn-signup-footer, #btn-signup-products').on('click', handleSignupClick); $('#btn-signup-front-main').on('click', processFrontSignup); $('#btn-signup-main').on('click', processSignup); $('.modal-close').on('click', hideModal); $('.hamburger .icon').on('click', toggleDropMenu); $('.dropmenu-container .item').on('click', toggleAccordion); $('#video-intro-banner').on('click', showVideoIntro); $('.main-menu-item').on('mouseenter', handleMouseEnter); $('.main-menu-item').on('mouseleave', handleMouseLeave); $('.fixed-sub-menu').on('mouseenter', handleSubMenuMouseEnter); $('.fixed-sub-menu').on('mouseleave', handleSubMenuMouseLeave); document.body.addEventListener('mousedown', handleBodyClick); let currentDate = new Date(); document.getElementById('footer-year').innerText = currentDate.getFullYear(); } function handleScroll(e) { if (!document.getElementById('underlayment')) { return; } var scroll = window.scrollY; if(scroll >= 10) { $fixedTopMenu.css('display', 'flex'); $('.hamburger .icon').css('color', '#3366CC'); } else { $fixedTopMenu.css('display', 'none'); $('.hamburger .icon').css('color', '#5DADE2'); } } function handleBodyClick(e) { if (e.target.classList.contains('main-menu-item')) { return; } if (subMenuOpen && !e.target.closest('.fixed-sub-menu') ) { hideSubMenu(); } } function handleSubMenuMouseEnter(e) { clearTimeout(_hideTimer); } function handleSubMenuMouseLeave(e) { _hideTimer = setTimeout(hideSubMenu, 500); } function handleMouseEnter(e) { clearTimeout(_hideTimer); showSubMenu(e); } function handleMouseLeave(e) { _hideTimer = setTimeout(hideSubMenu, 500); } function showSubMenu(e) { if (subMenuOpen) { hideSubMenu(); } const id = e.currentTarget.id.split('-')[2]; $('#fixed-sub-menu-' + id).show(); $('#fixed-sub-menu-' + id).css('top', e.currentTarget.offsetParent.offsetTop + e.currentTarget.offsetHeight + 10 + 'px'); $('#fixed-sub-menu-' + id).css('left', e.currentTarget.offsetLeft + 'px'); // $('#fixed-sub-menu').css('left', e.currentTarget.offsetParent.offsetLeft - (e.currentTarget.offsetWidth / 2) + 'px'); subMenuOpen = true; } function hideSubMenu(e) { $('.fixed-sub-menu').hide(); subMenuOpen = false; } function toggleDropMenu() { $('.dropmenu-container').toggle(200, function() { if ($('.dropmenu-container').is(':visible')) { document.querySelector('.hamburger .icon').classList.remove('fa-bars'); document.querySelector('.hamburger .icon').classList.add('fa-times'); document.body.style.overflow = 'hidden'; } else { document.querySelector('.hamburger .icon').classList.add('fa-bars'); document.querySelector('.hamburger .icon').classList.remove('fa-times'); document.body.style.overflow = 'auto'; } }); } function toggleAccordion() { } function hideModal() { $('.overlay, .modal').hide(); $('#modal-content').html(''); } function emailIsValid(email) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); } function showVideoIntro() { $('.overlay, .modal').show(); $('.modal-close').show(); $('#modal-content').html(''); } function processFrontSignup(e) { var emailInputId = ''; var target = e.currentTarget; if (target.id === 'btn-signup-front-main') { emailInputId = 'email-front-main'; } var dom = document.getElementById(emailInputId); if (!emailIsValid(dom.value)) { if (emailInputId === 'email-front-main') { $('#signup-front-main-error').css('visibility', 'visible'); } document.getElementById(emailInputId).focus(); return; } showModal('