Skip to content

Commit

Permalink
Attach sidebar-close handler to current-page links
Browse files Browse the repository at this point in the history
This is intended primarily to resolve a problem with `singlehtml`
documentation projects when viewed on narrow (typically mobile)
displays.

Under those circumstances, the `.current` CSS selector does not
match any sidebar menu elements, because there is no logical notion
of a 'current' page in `singlehtml` -- every item is on the same
page.

Therefore this change proposes an alternative way to identify sidebar
links that are 'current' -- it checks for anchors that have an `href`
beginning with the query-string fragment identifier (`#`).

This is intended to be compatible with both `singlehtml` and `html`
project builds.  It depends upon sphinx-doc/sphinx#12551
  • Loading branch information
jayaddison committed Oct 15, 2024
1 parent 7b894f5 commit fc13e47
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sphinx_rtd_theme/static/js/theme.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function ThemeNav () {
})

// Nav menu link click operations
.on('click', ".wy-menu-vertical .current ul li a", function() {
.on('click', ".wy-menu-vertical ul li a[href^='#']", function() {
var target = $(this);
// Close menu when you click a link.
$("[data-toggle='wy-nav-shift']").removeClass("shift");
Expand Down

0 comments on commit fc13e47

Please sign in to comment.