From d4213a5f143babd6efe94d1df62df5097d65a0e5 Mon Sep 17 00:00:00 2001 From: Huong Nguyen Date: Tue, 25 Jun 2024 10:41:32 +0100 Subject: [PATCH] revert Signed-off-by: Huong Nguyen --- .../theme/kedro-sphinx-theme/layout.html | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/kedro_sphinx_theme/theme/kedro-sphinx-theme/layout.html b/src/kedro_sphinx_theme/theme/kedro-sphinx-theme/layout.html index 7ae2524..a04d4c6 100644 --- a/src/kedro_sphinx_theme/theme/kedro-sphinx-theme/layout.html +++ b/src/kedro_sphinx_theme/theme/kedro-sphinx-theme/layout.html @@ -66,19 +66,29 @@ openBtn.classList.add('wy-nav-top-open'); document.querySelector('.wy-nav-top').prepend(openBtn); - // Get the current URL - const currentUrl = window.location.href; // Select all navigation links within the .wy-main-nav container var navLinks = document.querySelectorAll('.wy-main-nav .wy-main-nav-link'); - // Iterate over each link + // Function to remove 'active' class from all links + function removeActiveClass() { + navLinks.forEach(function(link) { + link.classList.remove('active'); + }); + } + + // Add click event listener to each link navLinks.forEach(function(link) { - // Check if the link's href matches the current URL - if (link.href === currentUrl) { - // Add the 'active' class to the matching link - link.classList.add('active'); - } + link.addEventListener('click', function(event) { + // Prevent the default link action + event.preventDefault(); + + // Remove 'active' class from all links + removeActiveClass(); + + // Add 'active' class to the clicked link + event.target.classList.add('active'); + }); }); });