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,20 +557,35 @@ 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');
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) { switch (e.key) {
case 'ArrowRight': case 'ArrowRight':
e.preventDefault(); e.preventDefault();
var nextButton = document.querySelector('.nav-chapters.next'); if (html.dir == 'rtl') {
if (nextButton) { prev();
window.location.href = nextButton.href; } else {
next();
} }
break; break;
case 'ArrowLeft': case 'ArrowLeft':
e.preventDefault(); e.preventDefault();
var previousButton = document.querySelector('.nav-chapters.previous'); if (html.dir == 'rtl') {
if (previousButton) { next();
window.location.href = previousButton.href; } else {
prev();
} }
break; break;
} }