Attach sidebar-close handler to current-page links

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
This commit is contained in:
James Addison 2024-08-12 12:50:33 +01:00
parent 7b894f5e7a
commit fc13e477f5
2 changed files with 2 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@ -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");