From 367a1b232918f86338238e2b79fa2c3ac651926b Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Thu, 29 Oct 2020 23:33:26 +0100 Subject: [PATCH] Check if event is cancelable before preventDefault (#54) This recovers the initial wanted behavior of opening the post mention preview dropdown instead of directly going to the post on touchscreens. --- .../mentions/js/src/forum/addPostMentionPreviews.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/extensions/mentions/js/src/forum/addPostMentionPreviews.js b/extensions/mentions/js/src/forum/addPostMentionPreviews.js index dfe78afb2..76e4400da 100644 --- a/extensions/mentions/js/src/forum/addPostMentionPreviews.js +++ b/extensions/mentions/js/src/forum/addPostMentionPreviews.js @@ -103,7 +103,14 @@ export default function addPostMentionPreviews() { } }; - $this.on('touchstart', e => e.preventDefault()); + // On a touch (mobile) device we cannot hover the link to reveal the preview. + // Instead we cancel the navigation so that a click reveals the preview. + // Users can then click on the preview to go to the post if desired. + $this.on('touchend', e => { + if (e.cancelable) { + e.preventDefault(); + } + }); $this.add($preview).hover( () => {