From 57cd3fe19b677869fe73c4f8cb7c04352b8ba1f9 Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Sat, 19 Jul 2025 21:49:44 -0600 Subject: [PATCH] Moved JS from baseof --- layouts/_default/baseof.html | 52 +------------------- layouts/index.html | 66 +------------------------- layouts/partials/homepage-scripts.html | 65 +++++++++++++++++++++++++ static/js/mobile-menu.js | 50 +++++++++++++++++++ 4 files changed, 117 insertions(+), 116 deletions(-) create mode 100644 layouts/partials/homepage-scripts.html create mode 100644 static/js/mobile-menu.js diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 41bf648..d08042d 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -75,56 +75,6 @@ - + diff --git a/layouts/index.html b/layouts/index.html index 8e0cd10..e91e30b 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -152,69 +152,5 @@ } - +{{ partial "homepage-scripts.html" . }} {{ end }} \ No newline at end of file diff --git a/layouts/partials/homepage-scripts.html b/layouts/partials/homepage-scripts.html new file mode 100644 index 0000000..edd9d00 --- /dev/null +++ b/layouts/partials/homepage-scripts.html @@ -0,0 +1,65 @@ + \ No newline at end of file diff --git a/static/js/mobile-menu.js b/static/js/mobile-menu.js new file mode 100644 index 0000000..3cb55d2 --- /dev/null +++ b/static/js/mobile-menu.js @@ -0,0 +1,50 @@ +// Mobile Menu Functionality +document.addEventListener('DOMContentLoaded', function() { + const mobileMenuToggle = document.querySelector('.mobile-menu-toggle'); + const navLinks = document.querySelector('.nav-links'); + const overlay = document.querySelector('.mobile-menu-overlay'); + const body = document.body; + + function toggleMenu() { + const isActive = mobileMenuToggle.classList.contains('active'); + + if (isActive) { + mobileMenuToggle.classList.remove('active'); + navLinks.classList.remove('active'); + overlay.classList.remove('active'); + body.classList.remove('menu-open'); + } else { + mobileMenuToggle.classList.add('active'); + navLinks.classList.add('active'); + overlay.classList.add('active'); + body.classList.add('menu-open'); + } + } + + function closeMenu() { + mobileMenuToggle.classList.remove('active'); + navLinks.classList.remove('active'); + overlay.classList.remove('active'); + body.classList.remove('menu-open'); + } + + if (mobileMenuToggle && navLinks && overlay) { + mobileMenuToggle.addEventListener('click', toggleMenu); + + // Close menu when clicking on overlay + overlay.addEventListener('click', closeMenu); + + // Close menu when clicking on a link + const navLinksItems = navLinks.querySelectorAll('a'); + navLinksItems.forEach(link => { + link.addEventListener('click', closeMenu); + }); + + // Close menu on escape key + document.addEventListener('keydown', function(event) { + if (event.key === 'Escape') { + closeMenu(); + } + }); + } +}); \ No newline at end of file