From 435396f0fea91635fe0681dd669a3a73409d4e33 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Wed, 19 Jun 2024 07:23:06 -0700 Subject: [PATCH] chore: simplify logic --- package-lock.json | 4 ++-- package.json | 2 +- src/assets/scripts/menu.js | 22 ++++++---------------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index a14c0b82..127df9d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "coryd.dev", - "version": "19.5.5", + "version": "19.5.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coryd.dev", - "version": "19.5.5", + "version": "19.5.6", "license": "MIT", "dependencies": { "@cdransf/api-text": "^1.4.0", diff --git a/package.json b/package.json index 589635af..eafca847 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "19.5.5", + "version": "19.5.6", "description": "The source for my personal site. Built using 11ty.", "type": "module", "scripts": { diff --git a/src/assets/scripts/menu.js b/src/assets/scripts/menu.js index 019b45c7..fe6bf6a4 100644 --- a/src/assets/scripts/menu.js +++ b/src/assets/scripts/menu.js @@ -3,6 +3,7 @@ window.addEventListener('load', () => { const menuButtonContainer = document.querySelector('.menu-button-container') const menuItems = document.querySelectorAll('.menu-primary li[role="menu-item"]') const isMobile = () => window.innerWidth <= 768 + const updateTabIndex = () => { const isExpanded = menuInput.checked menuButtonContainer.setAttribute('aria-expanded', isExpanded) @@ -12,17 +13,16 @@ window.addEventListener('load', () => { if (link) link.setAttribute('tabindex', isMobile() && !isExpanded ? '-1' : '0') }) } - const handleMenuChange = () => updateTabIndex() updateTabIndex() - menuInput.addEventListener('change', handleMenuChange) + menuInput.addEventListener('change', updateTabIndex) menuButtonContainer.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault() menuInput.checked = !menuInput.checked - handleMenuChange() + updateTabIndex() } }) @@ -36,19 +36,9 @@ window.addEventListener('load', () => { }) document.addEventListener('keydown', e => { - if (e.key === 'Escape') { - if (isMobile() && menuInput.checked) { - menuInput.checked = false - handleMenuChange() - } - } - }) - - window.addEventListener('resize', () => { - updateTabIndex() - if (!isMobile() && menuInput.checked) { + if (e.key === 'Escape' && isMobile() && menuInput.checked) { menuInput.checked = false - handleMenuChange() + updateTabIndex() } }) -}) +}) \ No newline at end of file