diff --git a/src/core/events/onClick.mjs b/src/core/events/onClick.mjs index b042f4839..065e7f310 100644 --- a/src/core/events/onClick.mjs +++ b/src/core/events/onClick.mjs @@ -1,5 +1,9 @@ +import { now } from '../../shared/utils.mjs'; + export default function onClick(e) { const swiper = this; + const data = swiper.touchEventsData; + if (!swiper.enabled) return; if (!swiper.allowClick) { if (swiper.params.preventClicks) e.preventDefault(); @@ -7,5 +11,18 @@ export default function onClick(e) { e.stopPropagation(); e.stopImmediatePropagation(); } + return; } + + const clickTime = now(); + const pathTree = e.path || e.composedPath?.(); + + swiper.updateClickedSlide((pathTree && pathTree[0]) || e.target, pathTree); + swiper.emit('tap click', e); + + if (clickTime - data.lastClickTime < 300) { + swiper.emit('doubleTap doubleClick', e); + } + + data.lastClickTime = now(); } diff --git a/src/core/events/onTouchEnd.mjs b/src/core/events/onTouchEnd.mjs index 4c01519ce..6acfc53ff 100644 --- a/src/core/events/onTouchEnd.mjs +++ b/src/core/events/onTouchEnd.mjs @@ -1,4 +1,4 @@ -import { now, nextTick } from '../../shared/utils.mjs'; +import { nextTick } from '../../shared/utils.mjs'; export default function onTouchEnd(event) { const swiper = this; @@ -55,21 +55,6 @@ export default function onTouchEnd(event) { swiper.setGrabCursor(false); } - // Time diff - const touchEndTime = now(); - const timeDiff = touchEndTime - data.touchStartTime; - - // Tap, doubleTap, Click - if (swiper.allowClick) { - const pathTree = e.path || (e.composedPath && e.composedPath()); - swiper.updateClickedSlide((pathTree && pathTree[0]) || e.target, pathTree); - swiper.emit('tap click', e); - if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) { - swiper.emit('doubleTap doubleClick', e); - } - } - - data.lastClickTime = now(); nextTick(() => { if (!swiper.destroyed) swiper.allowClick = true; });