Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add continuous navigation when arrow key is held down #2353

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 45 additions & 20 deletions lncrawl/assets/web/script.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
// Handle key events
let keyPressTimer = null;
let navigationInterval = null;

function goToHref(el) {
if (!el) return;
const href = el.getAttribute("href");
if (href === "#") return;
window.location.href = href;
}

window.addEventListener("keyup", function (evt) {
function goToHref(el) {
if (!el) return;
const href = el.getAttribute("href");
if (href === "#") return;
window.location.href = href;
clearInterval(keyPressTimer);
clearInterval(navigationInterval);
switch (evt.key) {
case "ArrowLeft":
goToHref(document.querySelector("a.prev-button"));
break;
case "ArrowRight":
goToHref(document.querySelector("a.next-button"));
break;
default:
break;
}
});


switch (evt.key) {
case "ArrowLeft":
goToHref(document.querySelector("a.prev-button"));
break;
case "ArrowRight":
goToHref(document.querySelector("a.next-button"));
break;
default:
break;
}
});
window.addEventListener("keydown", function (evt) {
clearInterval(keyPressTimer);
clearInterval(navigationInterval);
switch (evt.key) {
case "ArrowLeft":
keyPressTimer = setTimeout(() => {
navigationInterval = setInterval(() => {
goToHref(document.querySelector("a.prev-button"));
}, 50);
}, 450);
break;
case "ArrowRight":
keyPressTimer = setTimeout(() => {
navigationInterval = setInterval(() => {
goToHref(document.querySelector("a.next-button"));
}, 50);
}, 450);
break;
default:
break;
}
});

// Handle next TOC select
function addTocSelectListener() {
Expand All @@ -38,10 +64,9 @@ function debouncedUpdate(evt) {
var height = document.body.scrollHeight - window.innerHeight + 10;
var percent = Math.round((100.0 * scroll) / height);
document.getElementById("readpos").innerText = percent + "%";
}, 100); // 100ms delay
}, 100); // 100ms delay
}


window.addEventListener("scroll", debouncedUpdate);

window.addEventListener("load", function (evt) {
Expand Down