From 9969d0e36f6bdc5273f5f7d4f7012804b91c3339 Mon Sep 17 00:00:00 2001 From: Helen Chong <119173961+helenclx@users.noreply.github.com> Date: Mon, 10 Jun 2024 19:35:27 +0800 Subject: [PATCH] Initiate variables for navbar class names --- src/_includes/global/navbar.njk | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/_includes/global/navbar.njk b/src/_includes/global/navbar.njk index b46cfeee..44ffd68d 100644 --- a/src/_includes/global/navbar.njk +++ b/src/_includes/global/navbar.njk @@ -91,16 +91,18 @@ {# Accessible hamburger menu navigation script based on: https://accessibleweb.dev/navigation #} const navbarToggle = document.querySelector(".navbar__toggle"); - const navbarLinks = document.querySelector(".navbar__links"); - const navbarLinkItems = document.querySelectorAll(".navbar__links li a"); + const navbarLinksClass = ".navbar__links"; + const navbarLinks = document.querySelector(navbarLinksClass); + const showNavLinksClass = "navbar__links--show"; + const navbarLinkItems = document.querySelectorAll(navbarLinksClass + " li a"); const openNavigation = () => { - navbarLinks.classList.add("navbar__links--show"); + navbarLinks.classList.add(showNavLinksClass); navbarToggle.ariaExpanded = "true"; }; const closeNavigation = () => { - navbarLinks.classList.remove("navbar__links--show"); + navbarLinks.classList.remove(showNavLinksClass); navbarToggle.ariaExpanded = "false"; }; @@ -119,7 +121,7 @@ }); const handleBlur = (event) => { - const navList = event.currentTarget.closest(".navbar__links"); + const navList = event.currentTarget.closest(navbarLinksClass); if (!event.relatedTarget || !navList.contains(event.relatedTarget)) { closeNavigation(); }