(function ($) { const burgerMenuOpen = document.querySelector('.main-navigation .menu-toggle'); const btnClose = document.querySelector('.popup-menu .box-close button'); const menuMobileTotal = document.querySelectorAll('.popup-menu .box-menu ul#primary-menu > li > a').length; const menuFirstLine = document.querySelectorAll('.popup-menu .box-menu ul#primary-menu > li > a')[menuMobileTotal - 1]; // Open Popup Menu Mobile $('#site-navigation .menu-toggle').click(function () { $('html').addClass('popup-active'); $('.popup-menu').fadeIn(100); }); // Close Popup Menu Mobile $('.popup-menu .box-close button').click(function () { $('html').removeClass('popup-active'); $('.popup-menu').fadeOut(100); }); // Sub Menu Mobile .menu-item-has-children $('.menu-item-has-children .dropdown-toggle').click(function () { const status = $(this).attr('aria-expanded'); if (status == 'false') { $(this).attr('aria-expanded', 'true'); $(this).next().show(); } if (status == 'true') { $(this).attr('aria-expanded', 'false'); $(this).next().hide(); } }); // Sub Menu Mobile .page_item_has_children $('.page_item_has_children .dropdown-toggle').click(function () { const status = $(this).attr('aria-expanded'); if (status == 'false') { $(this).attr('aria-expanded', 'true'); $(this).next().show(); } if (status == 'true') { $(this).attr('aria-expanded', 'false'); $(this).next().hide(); } }); // Autofocus function solace_popup_menu_focus() { // Burger burgerMenuOpen.addEventListener("click", function () { btnClose.focus(); const firstFocus = btnClose; const lastFocus = menuFirstLine; document.addEventListener("keydown", function (e) { let isTabPressed = e.key === "Tab" || e.keyCode === 9; if (!isTabPressed) { return; } // if shift key pressed for shift + tab combination if (e.shiftKey) { if (document.activeElement === firstFocus) { lastFocus.focus(); e.preventDefault(); // alert(1); } } else { if (document.activeElement === lastFocus) { firstFocus.focus(); e.preventDefault(); // alert(2); } } }); }); // Close btnClose.addEventListener("click", function () { burgerMenuOpen.focus(); }); } solace_popup_menu_focus(); }(jQuery));