From 3ecf57b884368fdf00d6c46ef2af5f0ad8054bff Mon Sep 17 00:00:00 2001 From: Tobias Kunze Date: Mon, 7 Apr 2025 22:47:00 +0200 Subject: [PATCH] Fix link activation --- src/servala/static/js/sidebar.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/servala/static/js/sidebar.js b/src/servala/static/js/sidebar.js index f541788..ce607c8 100644 --- a/src/servala/static/js/sidebar.js +++ b/src/servala/static/js/sidebar.js @@ -1,13 +1,12 @@ /** - * This script marks the current path as active in the sidebar. + * This script marks the current path as active in the menu. */ const markActive = (link) => { - const parentItem = link.closest('.sidebar-item'); + const parentItem = link.closest('.menu-item'); + link.classList.add('active'); if (parentItem) { parentItem.classList.add('active'); - } else { - link.classList.add('active'); } } @@ -16,13 +15,13 @@ const checkLink = (fuzzy) => { document.addEventListener('DOMContentLoaded', () => { const currentPath = window.location.pathname; - const sidebarLinks = [...document.querySelectorAll('a.sidebar-link')] + const menuLinks = [...document.querySelectorAll('a.menu-link')] - const exactMatches = sidebarLinks.filter(link => link.getAttribute('href') === currentPath) + const exactMatches = menuLinks.filter(link => link.getAttribute('href') === currentPath) if (exactMatches.length > 0) { markActive(exactMatches[0]) } else { - fuzzyMatches = sidebarLinks.filter(link => currentPath.startsWith(link.getAttribute('href'))) + fuzzyMatches = menuLinks.filter(link => currentPath.startsWith(link.getAttribute('href'))) if (fuzzyMatches.length > 0) { const longestMatch = fuzzyMatches.sort((a, b) => b.href.length - a.href.length)[0] markActive(longestMatch)