Skip to content

Commit

Permalink
add custom js to remove/add active class
Browse files Browse the repository at this point in the history
Signed-off-by: Huong Nguyen <huongg1409@gmail>
  • Loading branch information
Huong Nguyen committed Jun 24, 2024
1 parent d080c55 commit 8051b9b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
25 changes: 25 additions & 0 deletions docs/source/_static/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
document.addEventListener('DOMContentLoaded', function() {
// Select all navigation links within the .wy-main-nav container
var navLinks = document.querySelectorAll('.wy-main-nav .wy-main-nav-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) {
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');
});
});
});
4 changes: 4 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"sphinx_copybutton",
]

html_js_files = [
"js/custom.js",
]

templates_path = ["_templates"]

exclude_patterns = [
Expand Down
6 changes: 3 additions & 3 deletions src/kedro_sphinx_theme/theme/kedro-sphinx-theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
</div>

<div class="wy-main-nav">
<a href="/" class="active">Kedro</a>
<a href="https://docs.kedro.org/projects/kedro-viz/en/stable/">Kedro-Viz</a>
<a href="https://docs.kedro.org/projects/kedro-datasets">Kedro-Datasets</a>
<a class="wy-main-nav-link" href="/" class="active">Kedro</a>
<a class="wy-main-nav-link" href="https://docs.kedro.org/projects/kedro-viz/en/stable/">Kedro-Viz</a>
<a class="wy-main-nav-link" href="https://docs.kedro.org/projects/kedro-datasets">Kedro-Datasets</a>
</div>

{%- include "searchbox.html" %}
Expand Down

0 comments on commit 8051b9b

Please sign in to comment.