From 4ad02ad03ea6f6a4d2abf1574919dacc5ef08e9a Mon Sep 17 00:00:00 2001 From: snuffster Date: Tue, 22 Oct 2024 20:44:00 -0700 Subject: [PATCH] disable swipe gesture to navigate posts --- client/js/util/touch.js | 91 ------------------------------- client/js/views/post_main_view.js | 15 ----- 2 files changed, 106 deletions(-) delete mode 100644 client/js/util/touch.js diff --git a/client/js/util/touch.js b/client/js/util/touch.js deleted file mode 100644 index 64bd00a..0000000 --- a/client/js/util/touch.js +++ /dev/null @@ -1,91 +0,0 @@ -"use strict"; - -const direction = { - NONE: null, - LEFT: "left", - RIGHT: "right", - DOWN: "down", - UP: "up", -}; - -function handleTouchStart(handler, evt) { - const touchEvent = evt.touches[0]; - handler._xStart = touchEvent.clientX; - handler._yStart = touchEvent.clientY; -} - -function handleTouchMove(handler, evt) { - if (!handler._xStart || !handler._yStart) { - return; - } - - const xDirection = handler._xStart - evt.touches[0].clientX; - const yDirection = handler._yStart - evt.touches[0].clientY; - - if (Math.abs(xDirection) > Math.abs(yDirection)) { - if (xDirection > 0) { - handler._direction = direction.LEFT; - } else { - handler._direction = direction.RIGHT; - } - } else if (yDirection > 0) { - handler._direction = direction.DOWN; - } else { - handler._direction = direction.UP; - } -} - -function handleTouchEnd(handler) { - switch (handler._direction) { - case direction.NONE: - return; - case direction.LEFT: - handler._swipeLeftTask(); - break; - case direction.RIGHT: - handler._swipeRightTask(); - break; - case direction.DOWN: - handler._swipeDownTask(); - break; - case direction.UP: - handler._swipeUpTask(); - // no default - } - - handler._xStart = null; - handler._yStart = null; -} - -class Touch { - constructor( - target, - swipeLeft = () => {}, - swipeRight = () => {}, - swipeUp = () => {}, - swipeDown = () => {} - ) { - this._target = target; - - this._swipeLeftTask = swipeLeft; - this._swipeRightTask = swipeRight; - this._swipeUpTask = swipeUp; - this._swipeDownTask = swipeDown; - - this._xStart = null; - this._yStart = null; - this._direction = direction.NONE; - - this._target.addEventListener("touchstart", (evt) => { - handleTouchStart(this, evt); - }); - this._target.addEventListener("touchmove", (evt) => { - handleTouchMove(this, evt); - }); - this._target.addEventListener("touchend", () => { - handleTouchEnd(this); - }); - } -} - -module.exports = Touch; diff --git a/client/js/views/post_main_view.js b/client/js/views/post_main_view.js index 5ef7f61..e8d0066 100644 --- a/client/js/views/post_main_view.js +++ b/client/js/views/post_main_view.js @@ -5,7 +5,6 @@ const router = require("../router.js"); const views = require("../util/views.js"); const uri = require("../util/uri.js"); const keyboard = require("../util/keyboard.js"); -const Touch = require("../util/touch.js"); const PostContentControl = require("../controls/post_content_control.js"); const PostNotesOverlayControl = require("../controls/post_notes_overlay_control.js"); const PostReadonlySidebarControl = require("../controls/post_readonly_sidebar_control.js"); @@ -100,20 +99,6 @@ class PostMainView { this.sidebarControl._evtDeleteClick(e); } }); - - new Touch( - postContainerNode, - () => { - if (!ctx.editMode) { - showPreviousImage(); - } - }, - () => { - if (!ctx.editMode) { - showNextImage(); - } - } - ); } _installSidebar(ctx) {