record click timestamps to calculate number of clicks (#728)

* record click timestamps to calculate number of clicks

* break after each case
This commit is contained in:
WeidiDeng authored and GitHub committed 2024-03-30 11:07:25 +08:00
1 parent d982f4d3b1
commit 8038397185
1 file changed
+27 -20
+27 -20
View File
@@ -18,35 +18,42 @@ export default function clickInit(art, events) {
}
});
let clickTime = 0;
let clickTimes = [];
events.proxy($video, 'click', (event) => {
const now = Date.now();
clickTimes.push(now);
const { MOBILE_CLICK_PLAY, DBCLICK_TIME, MOBILE_DBCLICK_PLAY, DBCLICK_FULLSCREEN } = constructor;
if (now - clickTime <= DBCLICK_TIME) {
art.emit('dblclick', event);
const clicks = clickTimes.filter((t) => now - t <= DBCLICK_TIME);
switch (clicks.length) {
case 1:
art.emit('click', event);
if (isMobile) {
if (!art.isLock && MOBILE_DBCLICK_PLAY) {
if (isMobile) {
if (!art.isLock && MOBILE_CLICK_PLAY) {
art.toggle();
}
} else {
art.toggle();
}
} else {
if (DBCLICK_FULLSCREEN) {
art.fullscreen = !art.fullscreen;
}
}
} else {
art.emit('click', event);
clickTimes = clicks;
break;
case 2:
art.emit('dblclick', event);
if (isMobile) {
if (!art.isLock && MOBILE_CLICK_PLAY) {
art.toggle();
if (isMobile) {
if (!art.isLock && MOBILE_DBCLICK_PLAY) {
art.toggle();
}
} else {
if (DBCLICK_FULLSCREEN) {
art.fullscreen = !art.fullscreen;
}
}
} else {
art.toggle();
}
clickTimes = [];
break;
default:
clickTimes = [];
}
clickTime = now;
});
}