aboutsummaryrefslogtreecommitdiffhomepage
path: root/ui/static/js/touch_handler.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/static/js/touch_handler.js')
-rw-r--r--ui/static/js/touch_handler.js34
1 files changed, 33 insertions, 1 deletions
diff --git a/ui/static/js/touch_handler.js b/ui/static/js/touch_handler.js
index d7ec359..9e4b7bc 100644
--- a/ui/static/js/touch_handler.js
+++ b/ui/static/js/touch_handler.js
@@ -1,5 +1,6 @@
class TouchHandler {
- constructor() {
+ constructor(navHandler) {
+ this.navHandler = navHandler;
this.reset();
}
@@ -93,5 +94,36 @@ class TouchHandler {
element.addEventListener("touchend", (e) => this.onTouchEnd(e), hasPassiveOption ? { passive: true } : false);
element.addEventListener("touchcancel", () => this.reset(), hasPassiveOption ? { passive: true } : false);
});
+
+ let entryContentElement = document.querySelector(".entry-content");
+ if (entryContentElement) {
+ let doubleTapTimers = {
+ previous: null,
+ next: null
+ };
+
+ const detectDoubleTap = (doubleTapTimer, event) => {
+ const timer = doubleTapTimers[doubleTapTimer];
+ if (timer === null) {
+ doubleTapTimers[doubleTapTimer] = setTimeout(() => {
+ doubleTapTimers[doubleTapTimer] = null;
+ }, 200);
+ } else {
+ event.preventDefault();
+ this.navHandler.goToPage(doubleTapTimer);
+ }
+ };
+
+ entryContentElement.addEventListener("touchend", (e) => {
+ if (e.changedTouches[0].clientX >= (entryContentElement.offsetWidth / 2)) {
+ detectDoubleTap("next", e);
+ } else {
+ detectDoubleTap("previous", e);
+ }
+ }, hasPassiveOption ? { passive: false } : false);
+ entryContentElement.addEventListener("touchmove", (e) => {
+ Object.keys(doubleTapTimers).forEach(timer => doubleTapTimers[timer] = null);
+ });
+ }
}
}