Skip to content

Commit ee4d440

Browse files
petermdBlendify
authored andcommitted
Only change current if a matching link is found (#472)
1 parent 896fe3e commit ee4d440

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

js/theme.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,15 @@ function ThemeNav () {
108108
// Try again with the closest section entry.
109109
link = $('.wy-menu-vertical')
110110
.find('[href="#' + closest_section.attr("id") + '"]');
111-
112111
}
113-
$('.wy-menu-vertical li.toctree-l1 li.current')
114-
.removeClass('current');
115-
link.closest('li.toctree-l2').addClass('current');
116-
link.closest('li.toctree-l3').addClass('current');
117-
link.closest('li.toctree-l4').addClass('current');
112+
// If we found a matching link then reset current and re-apply
113+
// otherwise retain the existing match
114+
if (link.length > 0) {
115+
$('.wy-menu-vertical li.toctree-l1 li.current').removeClass('current');
116+
link.closest('li.toctree-l2').addClass('current');
117+
link.closest('li.toctree-l3').addClass('current');
118+
link.closest('li.toctree-l4').addClass('current');
119+
}
118120
}
119121
catch (err) {
120122
console.log("Error expanding nav for anchor", err);

0 commit comments

Comments
 (0)