Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 12, 2025

The menu dropdown initialization and click-outside handler were duplicated across index.html and books.html. Extracted to a shared module to eliminate 44 lines of duplication.

Changes

  • Created js/menu.js: Centralized toggleMenu() function and click-outside event listener
  • Updated index.html and books.html: Replaced inline implementations with <script src="js/menu.js"></script>

Implementation

// js/menu.js
function toggleMenu() {
    const dropdown = document.querySelector('.menu-dropdown');
    const btn = document.querySelector('.menu-button');
    const willShow = !dropdown.classList.contains('show');
    dropdown.classList.toggle('show');
    if (btn) btn.setAttribute('aria-expanded', willShow ? 'true' : 'false');
}

document.addEventListener('click', function(event) {
    const menuWrapper = document.querySelector('.menu-wrapper');
    if (menuWrapper && !menuWrapper.contains(event.target)) {
        const dropdown = document.querySelector('.menu-dropdown');
        if (dropdown) {
            dropdown.classList.remove('show');
            const btn = document.querySelector('.menu-button');
            if (btn) btn.setAttribute('aria-expanded', 'false');
        }
    }
});

Screenshot

Menu dropdown functionality


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: arjun7965 <15646612+arjun7965@users.noreply.github.com>
Copilot AI changed the title [WIP] Update dark mode and books page based on feedback Refactor: extract duplicated menu dropdown code to shared module Nov 12, 2025
Copilot AI requested a review from arjun7965 November 12, 2025 05:02
@arjun7965 arjun7965 marked this pull request as ready for review November 12, 2025 05:03
@arjun7965 arjun7965 merged commit 83adfbc into basic_html Nov 12, 2025
@arjun7965 arjun7965 deleted the copilot/sub-pr-1-again branch November 14, 2025 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants