@tencentcloud/roomkit-web-vue3
Version:
<h1 align="center"> TUIRoomKit</h1> Conference (TUIRoomKit) is a product suitable for multi-person audio and video conversation scenarios such as business meetings, webinars, and online education. By integrating this product, you can add room management,
68 lines (57 loc) • 1.62 kB
text/typescript
const touchEventMap = new Map();
const clickEventMap = new Map();
const TIME_OUT = 300;
class DblTouch {
public dom: HTMLElement;
public callback: (event?: Event | TouchEvent) => void;
constructor(el: HTMLElement, binding: any) {
this.dom = el;
this.callback = binding.value;
// Compatible iphone 11 chrome browser tap twice trigger once touchend and twice click event problem
el?.addEventListener('click', (event: Event) => {
if (binding.modifiers.stop) {
event.stopPropagation();
}
this.click(event);
});
el?.addEventListener('touchend', (event: TouchEvent) => {
if (binding.modifiers.stop) {
event.stopPropagation();
}
this.touchend(event);
});
}
executeCallback(event: Event | TouchEvent) {
clickEventMap.delete(this.dom);
touchEventMap.delete(this.dom);
this.callback && this.callback(event);
}
click(event: Event) {
const lastEvent = clickEventMap.get(this.dom);
if (lastEvent) {
this.executeCallback(event);
} else {
clickEventMap.set(this.dom, event);
setTimeout(() => {
clickEventMap.delete(this.dom);
}, TIME_OUT);
}
}
touchend(event: TouchEvent) {
const lastEvent = touchEventMap.get(this.dom);
if (lastEvent) {
this.executeCallback(event);
} else {
touchEventMap.set(this.dom, event);
setTimeout(() => {
touchEventMap.delete(this.dom);
}, TIME_OUT);
}
}
}
const vDblTouch = {
mounted(el: HTMLElement, binding: any) {
return new DblTouch(el, binding);
},
};
export default vDblTouch;