From 4bf4f5063f00ea8655a5e5473b3c8536bba06867 Mon Sep 17 00:00:00 2001 From: Philip Bell Date: Thu, 5 Oct 2023 09:53:03 -0500 Subject: [PATCH 1/2] prevent link from opening on swipe --- src/actions/swipeable/swipeable.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/actions/swipeable/swipeable.js b/src/actions/swipeable/swipeable.js index d4f8bf8..f3f55cf 100644 --- a/src/actions/swipeable/swipeable.js +++ b/src/actions/swipeable/swipeable.js @@ -47,6 +47,16 @@ export function swipeable(node, { thresholdProvider }) { dispatch('swipeStart', { x, y }) addMoveEventListener(window, handleMove) addEndEventListener(window, handleUp) + // Prevents link text from displaying when content is swiped. + event.preventDefault(); + } + + function checkShouldOpenLink(node) { + if (Math.abs(moved) > 10) { + node.addEventListener('click', (event) => event.preventDefault(event), { + once: true, + }); + } } function handleMove(event) { @@ -66,12 +76,14 @@ export function swipeable(node, { thresholdProvider }) { dispatch('swipeThresholdReached', { direction: moved > 0 ? PREV : NEXT }) removeEndEventListener(window, handleUp) removeMoveEventListener(window, handleMove) + checkShouldOpenLink(node); } } function handleUp(event) { removeEndEventListener(window, handleUp) removeMoveEventListener(window, handleMove) + checkShouldOpenLink(node); isTouching = false From 0ccf22e5a8a51084a356cffa829e1362038eb01c Mon Sep 17 00:00:00 2001 From: Philip Bell Date: Thu, 5 Oct 2023 09:55:26 -0500 Subject: [PATCH 2/2] make threshold a variable --- src/actions/swipeable/swipeable.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/actions/swipeable/swipeable.js b/src/actions/swipeable/swipeable.js index f3f55cf..16c2854 100644 --- a/src/actions/swipeable/swipeable.js +++ b/src/actions/swipeable/swipeable.js @@ -52,7 +52,8 @@ export function swipeable(node, { thresholdProvider }) { } function checkShouldOpenLink(node) { - if (Math.abs(moved) > 10) { + const linkOpenThreshold = 10; + if (Math.abs(moved) > linkOpenThreshold) { node.addEventListener('click', (event) => event.preventDefault(event), { once: true, });