From 75414b95d244015e0ea7a646e99748451b3b82f8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 04:54:36 +0000 Subject: [PATCH 1/2] Initial plan From a8c22a94c6fa42fe50e15ff7bf7ef88b0b93f189 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 04:59:51 +0000 Subject: [PATCH 2/2] refactor: extract menu dropdown code to shared js/menu.js Co-authored-by: arjun7965 <15646612+arjun7965@users.noreply.github.com> --- books.html | 23 +---------------------- index.html | 23 +---------------------- js/menu.js | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 44 deletions(-) create mode 100644 js/menu.js diff --git a/books.html b/books.html index 9eaf5f8..2be2658 100644 --- a/books.html +++ b/books.html @@ -195,29 +195,8 @@ tryLoadCover(img); }); }); - - // Menu dropdown toggle - 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'); - } - - // Close dropdown when clicking outside - 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'); - } - } - }); + diff --git a/index.html b/index.html index b4a86a0..9b92ccd 100644 --- a/index.html +++ b/index.html @@ -98,29 +98,8 @@ const icon = document.querySelector('.theme-toggle-slider i'); icon.className = theme === 'light' ? 'fas fa-moon' : 'fas fa-sun'; }); - - // Menu dropdown toggle - 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'); - } - - // Close dropdown when clicking outside - 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'); - } - } - }); + diff --git a/js/menu.js b/js/menu.js new file mode 100644 index 0000000..eedb89a --- /dev/null +++ b/js/menu.js @@ -0,0 +1,21 @@ +// Menu dropdown toggle +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'); +} + +// Close dropdown when clicking outside +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'); + } + } +});