Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- document.addEventListener('DOMContentLoaded', function() {
- const menuToggle = document.getElementById('ovMenuToggle');
- const menuContainer = document.getElementById('ovMenuContainer');
- const menuItems = menuContainer.querySelectorAll('.et-menu > li');
- const allModules = menuContainer.querySelectorAll('.et_pb_module');
- const subMenus = menuContainer.querySelectorAll('ul.sub-menu');
- menuContainer.querySelectorAll('.menu-item-has-children > a').forEach(function(link) {
- if (!link.querySelector('.ov-submenu-indicator')) {
- const arrowIcon = document.createElement('span');
- arrowIcon.className = 'ov-submenu-indicator';
- arrowIcon.innerHTML = ';';
- link.appendChild(arrowIcon);
- }
- });
- menuToggle.addEventListener('click', function() {
- this.classList.toggle('ov-open');
- menuContainer.classList.toggle('ov-open');
- document.body.classList.toggle('ov-menu-open');
- if (menuContainer.classList.contains('ov-open')) {
- menuItems.forEach((item, index) => {
- setTimeout(() => {
- item.classList.add('ov-item-visible');
- }, index * 100);
- });
- allModules.forEach((item, index) => {
- setTimeout(() => {
- item.classList.add('ov-item-visible');
- }, (menuItems.length + index) * 100);
- });
- } else {
- menuItems.forEach((item) => {
- item.classList.remove('ov-item-visible');
- });
- allModules.forEach((item) => {
- item.classList.remove('ov-item-visible');
- });
- }
- });
- function toggleSubMenu(event) {
- event.preventDefault();
- event.stopPropagation();
- const menuItem = this.closest('.menu-item-has-children');
- const subMenu = menuItem.querySelector('ul.sub-menu');
- const link = menuItem.querySelector('a');
- if (subMenu) {
- menuItem.classList.toggle('toggled');
- link.classList.toggle('ov-submenu-open');
- subMenu.classList.toggle('ov-submenu-visible');
- }
- }
- const menuItemsWithChildren = menuContainer.querySelectorAll('.menu-item-has-children');
- menuItemsWithChildren.forEach(function(item) {
- const link = item.querySelector('a');
- link.addEventListener('click', toggleSubMenu);
- link.addEventListener('touchend', function(e) {
- e.preventDefault();
- toggleSubMenu.call(this, e);
- });
- });
- document.addEventListener('click', function(event) {
- if (!event.target.closest('#ovMenuContainer')) {
- subMenus.forEach(function(subMenu) {
- subMenu.classList.remove('ov-submenu-visible');
- subMenu.parentNode.classList.remove('toggled');
- const link = subMenu.parentNode.querySelector('a');
- if (link) {
- link.classList.remove('ov-submenu-open');
- }
- });
- }
- });
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement