This repository was archived by the owner on Nov 4, 2025. It is now read-only.
Basic ranger-like keyboard navigation on website #4
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.
I was really tickled by the ranger-like website styling, so I decided to add some basic ranger-like keyboard navigation. I used Mousetrap.js to implement a few keybindings:
j/kto navigate down/up the "file listing"gg/Gto go to top/bottom of the listingl/Enterto open the linkghto go back to homepageThe logic is pretty easy to implement, so I can add more if you have requests.
Here's how it works, in brief. I have some javascript in
keyboard.jsthat finds all the html elements of classkbnav(the navigation links / "file listing") and puts them into an array. Then Mousetrap can capture keystrokes and dispatch a function to move the browser focus to the appropriate link in the array.I've been using Mousetrap on my website (also hosted with Github Pages), which you can play with for a working example.
(I also removed the line sourcing
jquery2.min.jsas it's unused -- in fact, the file itself isn't even present in the repo.)