Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions docs/content/javascripts/keyboard-nav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// left/right arrow keys page through the docs guide
(() => {
// don't hijack arrows while typing in the search box or a form control
function isTypingTarget(el) {
if (!el) {
return false;
}
if (el.isContentEditable) {
return true;
}
var tag = el.tagName;
return tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT';
}
Comment on lines +4 to +13

@CommanderStorm CommanderStorm Jul 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not seem to work seme to quite work

Recording 2026-07-10 at 02 21 01


// one document-level listener survives "instant" navigation (body swapped, no full reload)
// re-query the footer links each keypress so they track the current page
document.addEventListener('keydown', (event) => {
// leave modifier combos alone - e.g. browser back/forward shortcuts
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
return;
}
// don't hijack arrows while the search overlay is open: the user is either
// typing a query or arrowing through the results, which moves focus onto the
// result links (so an activeElement check alone doesn't cover it). `#__search`
// is the theme's search toggle checkbox, checked whenever search is open.
var searchToggle = document.getElementById('__search');
if (searchToggle && searchToggle.checked) {
return;
}
if (isTypingTarget(document.activeElement)) {
return;
}

var selector;
if (event.key === 'ArrowLeft') {
selector = 'a.md-footer__link--prev[href]';
} else if (event.key === 'ArrowRight') {
selector = 'a.md-footer__link--next[href]';
} else {
return;
}

var link = document.querySelector(selector);
if (link && link.getAttribute('href')) {
event.preventDefault();
// click() so "instant" navigation can intercept it
link.click();
}
});
})();
2 changes: 1 addition & 1 deletion zensical.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ nav = [
# The path provided should be relative to the "docs_dir".
#
# Read more: https://zensical.org/docs/customization/#additional-javascript
#extra_javascript = ["javascripts/extra.js"]
extra_javascript = ["javascripts/keyboard-nav.js"]

# ----------------------------------------------------------------------------
# Section for configuring theme options
Expand Down
Loading