Enable swipe and wheel navigation
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user