Enable swipe and wheel navigation

This commit is contained in:
Kiyomichi Kosaka
2025-06-14 10:52:10 +02:00
parent c8d382ac8e
commit d0feb6be34
2 changed files with 42 additions and 1 deletions
+40
View File
@@ -1007,3 +1007,43 @@ document.getElementById('toggleExtended').addEventListener('click', () => {
// to ensure diff rows end up in the correct section
updateTimeBreakdown(manualMode ? manualCobiets : toCobiets(new Date()));
});
// ── Swipe & Wheel Navigation ────────────────────────────────────────────────
let swipeStartX = null;
let swipeStartY = null;
function swipeStart(e) {
const touch = e.touches ? e.touches[0] : e;
swipeStartX = touch.clientX;
swipeStartY = touch.clientY;
}
function swipeEnd(e) {
if (swipeStartX === null || swipeStartY === null) return;
const touch = e.changedTouches ? e.changedTouches[0] : e;
const dx = touch.clientX - swipeStartX;
const dy = touch.clientY - swipeStartY;
if (Math.abs(dx) > 40 && Math.abs(dx) > Math.abs(dy)) {
const direction = dx < 0 ? 1 : -1; // left → next, right → prev
navigatePeriod({
altKey: e.altKey || false,
shiftKey: e.shiftKey || false,
ctrlKey: e.ctrlKey || false
}, direction);
}
swipeStartX = swipeStartY = null;
}
document.addEventListener('touchstart', swipeStart, {passive: true});
document.addEventListener('touchend', swipeEnd);
document.addEventListener('mousedown', swipeStart);
document.addEventListener('mouseup', swipeEnd);
function wheelNavigate(e) {
if (Math.abs(e.deltaX) > Math.abs(e.deltaY) && Math.abs(e.deltaX) > 10) {
const direction = e.deltaX > 0 ? 1 : -1;
navigatePeriod(e, direction);
}
}
document.addEventListener('wheel', wheelNavigate);