-
-
Notifications
You must be signed in to change notification settings - Fork 381
feat(docs): page through the guide with left/right arrow keys #2984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
AnayGarodia
wants to merge
7
commits into
maplibre:main
from
AnayGarodia:feat/2788-arrow-key-page-nav
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bfc584d
docs: page through the guide with Left/Right arrow keys
pratyushsinghal7 a20a851
chore(fmt): apply pre-commit formatting fixes
pre-commit-ci[bot] 1fdb360
docs: de-vibe comments
pratyushsinghal7 deaab7c
chore(fmt): apply pre-commit formatting fixes
pre-commit-ci[bot] d5efbdb
Apply suggestion from @CommanderStorm
CommanderStorm 1ecef38
simplify some comments
CommanderStorm 426d6c9
fix(docs): don't hijack arrow keys while search is open
AnayGarodia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | ||
| } | ||
|
|
||
| // 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(); | ||
| } | ||
| }); | ||
| })(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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