aboutsummaryrefslogtreecommitdiff
path: root/client/js
diff options
context:
space:
mode:
authorHunternif2019-04-11 07:34:32 +0700
committerHunternif2019-04-11 07:50:32 +0700
commit04e0f7f12c2f99f9fdebd24c6db54618f68ed139 (patch)
treebde477dd6dae9e1ef874a25be29313588e037eff /client/js
parentdd7bcdb242a44aa13388197a9c0be1c83969112d (diff)
Add swipe threshold, fix incorrect up/down detection, swipe down for random.
Diffstat (limited to 'client/js')
-rw-r--r--client/js/util/touch.js17
-rw-r--r--client/js/views/post_main_view.js12
2 files changed, 25 insertions, 4 deletions
diff --git a/client/js/util/touch.js b/client/js/util/touch.js
index 6863eb8..3a64642 100644
--- a/client/js/util/touch.js
+++ b/client/js/util/touch.js
@@ -6,6 +6,9 @@ const direction = {
UP: 'up'
};
+const thresholdX = 0.15;
+const thresholdY = 0.1;
+
function handleTouchStart(handler, evt) {
const touchEvent = evt.touches[0];
handler._xStart = touchEvent.clientX;
@@ -21,16 +24,22 @@ function handleTouchMove(handler, evt) {
const yDirection = handler._yStart - evt.touches[0].clientY;
if (Math.abs(xDirection) > Math.abs(yDirection)) {
- if (xDirection > 0) {
+ let percentSwiped = Math.abs(xDirection) / screen.width;
+ if (percentSwiped < thresholdX) {
+ return;
+ } else if (xDirection > 0) {
handler._direction = direction.LEFT;
} else {
handler._direction = direction.RIGHT;
}
} else {
- if (yDirection > 0) {
- handler._direction = direction.DOWN;
- } else {
+ let percentSwiped = Math.abs(yDirection) / screen.height;
+ if (percentSwiped < thresholdY) {
+ return;
+ } else if (yDirection > 0) {
handler._direction = direction.UP;
+ } else {
+ handler._direction = direction.DOWN;
}
}
}
diff --git a/client/js/views/post_main_view.js b/client/js/views/post_main_view.js
index 1dc0860..15e1c29 100644
--- a/client/js/views/post_main_view.js
+++ b/client/js/views/post_main_view.js
@@ -72,6 +72,12 @@ class PostMainView {
}
};
+ const showRandomImage = () => {
+ if (ctx.randomPostId) {
+ router.show(ctx.getPostUrl(ctx.randomPostId, ctx.parameters));
+ }
+ };
+
keyboard.bind('e', () => {
if (ctx.editMode) {
router.show(uri.formatClientLink('post', ctx.post.id));
@@ -98,6 +104,12 @@ class PostMainView {
if (!ctx.editMode) {
showPreviousImage()
}
+ },
+ () => {},
+ () => {
+ if (!ctx.editMode) {
+ showRandomImage()
+ }
}
)
}

© 2015 - 2026 Jakob L. Kreuze