Make the arrow keys honor RTL.
At least to my understanding, the pages will flip in the opposite direction.
This commit is contained in:
parent
fb272d1afa
commit
802e7bffc3
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue