-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move click/tap events to onClick handler to fix bug with double tappi…
…ng on mobile chrome.
- Loading branch information
Showing
2 changed files
with
17 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
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(); | ||
if (swiper.params.preventClicksPropagation && swiper.animating) { | ||
e.stopPropagation(); | ||
e.stopImmediatePropagation(); | ||
} | ||
} else { | ||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters