Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter octanyum

    (@octanyum)

    after some many more hours, chatgpt came with this code that works perfectly in console mode:

    console.log('Testing script execution...');

    // Check if the menu hasn't been processed already
    if (!window.menu) {
    const menu = document.querySelector('#site-navigation');
    if (menu) {
    console.log('Menu found:', menu);

    // Find all anchor links in the menu
    const anchorLinks = menu.querySelectorAll('a[href^="#"]');
    console.log('Anchor links found:', anchorLinks);

    // Add click event listener to each anchor link
    anchorLinks.forEach(link => {
    link.addEventListener('click', function (event) {
    event.preventDefault(); // Prevent default link behavior (scrolling)
    console.log('Anchor clicked:', link.href); // Check if this fires

    // Close the entire menu (hide the dropdown or collapse it)
    const menuWrapper = document.querySelector('#site-navigation');
    if (menuWrapper) {
    // Close the menu by toggling the class that shows the menu
    // Replace 'open' with whatever class is used to control the visibility of the menu
    menuWrapper.classList.remove('open'); // If your menu uses the 'open' class for visibility

    // Alternatively, you might need to trigger a custom function if your menu is controlled by JavaScript (like closing a mobile menu)
    const menuToggleButton = document.querySelector('.menu-toggle'); // Update the selector based on your site structure
    if (menuToggleButton && menuToggleButton.getAttribute('aria-expanded') === 'true') {
    menuToggleButton.click(); // Simulate clicking the button to close the menu
    }

    console.log('Entire menu closed');
    }

    // Optional: You can add your scrolling or anchor-specific behavior here
    alert('Anchor link clicked, and the entire menu is closed!');
    });
    });

    // Find dropdown buttons
    const dropdownButtons = menu.querySelectorAll('.dropdown-toggle');
    console.log('Dropdown buttons found:', dropdownButtons);

    dropdownButtons.forEach(button => {
    button.addEventListener('click', function () {
    const parentLi = button.closest('li');
    const submenu = parentLi.querySelector('.sub-menu');
    const isExpanded = button.getAttribute('aria-expanded') === 'true';

    // Toggle submenu visibility
    if (submenu) {
    submenu.classList.toggle('toggled-on');
    button.setAttribute('aria-expanded', isExpanded ? 'false' : 'true');
    console.log('Dropdown toggled:', parentLi);

    // Log submenu state
    if (submenu.classList.contains('toggled-on')) {
    console.log('Sub-menu opened');
    } else {
    console.log('Sub-menu closed');
    }
    } else {
    console.log('No submenu found for this item');
    }
    });
    });
    } else {
    console.log('No menu found with ID #site-navigation.');
    }
    } else {
    console.log('Menu script already executed.');
    }

    how to make it now work on the website??? i injected the js code in the footer of my website, but no response…

    Thread Starter octanyum

    (@octanyum)

    after many hours working with chatgpt, we identified the elements, but no solution for actually closing the damn menu when clicking an item:

    console.log('Testing script execution...');

    // Check if the menu hasn't been processed already
    if (!window.menu) {
    const menu = document.querySelector('#site-navigation');
    if (menu) {
    console.log('Menu found:', menu);

    // Find all anchor links that are likely for the dropdowns
    const anchorLinks = menu.querySelectorAll('a[href^="#"]');
    console.log('Anchor links found:', anchorLinks);

    // Add click event listener to each anchor link
    anchorLinks.forEach(link => {
    link.addEventListener('click', function (event) {
    event.preventDefault(); // Prevent default link behavior (scrolling)
    console.log('Anchor clicked:', link.href); // Check if this fires
    alert('Anchor link clicked!');
    });
    });

    // Find dropdown buttons
    const dropdownButtons = menu.querySelectorAll('.dropdown-toggle');
    console.log('Dropdown buttons found:', dropdownButtons);

    dropdownButtons.forEach(button => {
    button.addEventListener('click', function () {
    const parentLi = button.closest('li');
    const submenu = parentLi.querySelector('.sub-menu');
    const isExpanded = button.getAttribute('aria-expanded') === 'true';

    // Toggle submenu visibility
    if (submenu) {
    submenu.classList.toggle('toggled-on');
    button.setAttribute('aria-expanded', isExpanded ? 'false' : 'true');
    console.log('Dropdown toggled:', parentLi);

    // Log whether the submenu is opened or closed
    if (submenu.classList.contains('toggled-on')) {
    console.log('Sub-menu opened');
    } else {
    console.log('Sub-menu closed');
    }
    }
    });
    });
    } else {
    console.log('No menu found with ID #site-navigation.');
    }
    } else {
    console.log('Menu script already executed.');
    }
    Thread Starter octanyum

    (@octanyum)

    hey, chouby! i’m very sorry… i simply got into panic mode… i solved it by deleting the crashed plugin, install and activate the downloading 3.3.1. zip file and all goes again smoothly now! thanks again!

    Thread Starter octanyum

    (@octanyum)

    UPDATE: i finally managed to find the conflict! when the site description is on (but the site name is empty), the menu dissappears from the secondary pages in portrait mode for ipad. so i filled in the site name anfd description, opting to not display them, and everything runs smoothly now.

Viewing 4 replies - 1 through 4 (of 4 total)