Skip to content

Commit

Permalink
Make the arrow keys honor RTL.
Browse files Browse the repository at this point in the history
At least to my understanding, the pages will flip in the opposite direction.
  • Loading branch information
ehuss committed Sep 2, 2023
1 parent fb272d1 commit 802e7bf
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/theme/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,20 +557,35 @@ function playground_text(playground, hidden = true) {
document.addEventListener('keydown', function (e) {
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }
if (window.search && window.search.hasFocus()) { return; }
var html = document.querySelector('html');

function next() {
var nextButton = document.querySelector('.nav-chapters.next');
if (nextButton) {
window.location.href = nextButton.href;
}
}
function prev() {
var previousButton = document.querySelector('.nav-chapters.previous');
if (previousButton) {
window.location.href = previousButton.href;
}
}
switch (e.key) {
case 'ArrowRight':
e.preventDefault();
var nextButton = document.querySelector('.nav-chapters.next');
if (nextButton) {
window.location.href = nextButton.href;
if (html.dir == 'rtl') {
prev();
} else {
next();
}
break;
case 'ArrowLeft':
e.preventDefault();
var previousButton = document.querySelector('.nav-chapters.previous');
if (previousButton) {
window.location.href = previousButton.href;
if (html.dir == 'rtl') {
next();
} else {
prev();
}
break;
}
Expand Down

0 comments on commit 802e7bf

Please sign in to comment.