Allow synthetic click events.
This commit is contained in:
@@ -25,7 +25,7 @@ declare global {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ActionHandler extends HTMLElement implements ActionHandler {
|
class ActionHandler extends HTMLElement implements ActionHandler {
|
||||||
public holdTime = 400;
|
public holdTime = 500;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
public ripple: any;
|
public ripple: any;
|
||||||
@@ -66,9 +66,11 @@ class ActionHandler extends HTMLElement implements ActionHandler {
|
|||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
ev,
|
ev,
|
||||||
() => {
|
() => {
|
||||||
clearTimeout(this.timer);
|
if (this.timer) {
|
||||||
this.stopAnimation();
|
this.stopAnimation();
|
||||||
|
clearTimeout(this.timer);
|
||||||
this.timer = undefined;
|
this.timer = undefined;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{ passive: true },
|
{ passive: true },
|
||||||
);
|
);
|
||||||
@@ -95,7 +97,6 @@ class ActionHandler extends HTMLElement implements ActionHandler {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const start = (ev: Event): void => {
|
const start = (ev: Event): void => {
|
||||||
this.held = false;
|
|
||||||
let x;
|
let x;
|
||||||
let y;
|
let y;
|
||||||
if ((ev as TouchEvent).touches) {
|
if ((ev as TouchEvent).touches) {
|
||||||
@@ -106,22 +107,29 @@ class ActionHandler extends HTMLElement implements ActionHandler {
|
|||||||
y = (ev as MouseEvent).pageY;
|
y = (ev as MouseEvent).pageY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.hasHold) {
|
||||||
|
this.held = false;
|
||||||
this.timer = window.setTimeout(() => {
|
this.timer = window.setTimeout(() => {
|
||||||
this.startAnimation(x, y);
|
this.startAnimation(x, y);
|
||||||
this.held = true;
|
this.held = true;
|
||||||
}, this.holdTime);
|
}, this.holdTime);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const end = (ev: Event): void => {
|
const end = (ev: Event): void => {
|
||||||
// Prevent mouse event if touch event
|
if (['touchend', 'touchcancel'].includes(ev.type)
|
||||||
ev.preventDefault();
|
// This action handler by default relies on synthetic click events for
|
||||||
if (['touchend', 'touchcancel'].includes(ev.type) && this.timer === undefined) {
|
// touch devices, in order to ensure that embedded cards (e.g. WebRTC)
|
||||||
|
// can use stock click handlers. The exception is for hold events.
|
||||||
|
&& !(options.hasHold && this.held)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (options.hasHold) {
|
||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
this.stopAnimation();
|
this.stopAnimation();
|
||||||
this.timer = undefined;
|
this.timer = undefined;
|
||||||
if (this.held) {
|
}
|
||||||
|
if (options.hasHold && this.held) {
|
||||||
fireEvent(element, 'action', { action: 'hold' });
|
fireEvent(element, 'action', { action: 'hold' });
|
||||||
} else if (options.hasDoubleClick) {
|
} else if (options.hasDoubleClick) {
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user