Make the arrow keys honor RTL.

At least to my understanding, the pages will flip in the opposite direction.
This commit is contained in:
Eric Huss 2023-09-02 16:44:47 -07:00
parent fb272d1afa
commit 802e7bffc3
1 changed files with 21 additions and 6 deletions

View File

@ -557,21 +557,36 @@ function playground_text(playground, hidden = true) {
document.addEventListener('keydown', function (e) { document.addEventListener('keydown', function (e) {
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; } if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }
if (window.search && window.search.hasFocus()) { return; } if (window.search && window.search.hasFocus()) { return; }
var html = document.querySelector('html');
switch (e.key) { function next() {
case 'ArrowRight':
e.preventDefault();
var nextButton = document.querySelector('.nav-chapters.next'); var nextButton = document.querySelector('.nav-chapters.next');
if (nextButton) { if (nextButton) {
window.location.href = nextButton.href; window.location.href = nextButton.href;
} }
break; }
case 'ArrowLeft': function prev() {
e.preventDefault();
var previousButton = document.querySelector('.nav-chapters.previous'); var previousButton = document.querySelector('.nav-chapters.previous');
if (previousButton) { if (previousButton) {
window.location.href = previousButton.href; window.location.href = previousButton.href;
} }
}
switch (e.key) {
case 'ArrowRight':
e.preventDefault();
if (html.dir == 'rtl') {
prev();
} else {
next();
}
break;
case 'ArrowLeft':
e.preventDefault();
if (html.dir == 'rtl') {
next();
} else {
prev();
}
break; break;
} }
}); });