This commit is contained in:
kakkokari-gtyih 2024-10-25 02:16:45 +09:00
parent 1106af8d2d
commit d704f69975

View file

@ -27,12 +27,12 @@ export const vUserPreview: ObjectDirective<HTMLElement, string | null | undefine
}; };
class UserPreview { class UserPreview {
private el; private el: HTMLElement;
private user; private user: string;
private showTimer; private showTimer: number | null = null;
private hideTimer; private hideTimer: number | null = null;
private checkTimer; private checkTimer: number | null = null;
private promise; private promise: { cancel: () => void } | null = null;
constructor(el, user) { constructor(el, user) {
this.el = el; this.el = el;
@ -61,10 +61,10 @@ class UserPreview {
source: this.el, source: this.el,
}, { }, {
mouseover: () => { mouseover: () => {
window.clearTimeout(this.hideTimer); if (this.hideTimer != null) window.clearTimeout(this.hideTimer);
}, },
mouseleave: () => { mouseleave: () => {
window.clearTimeout(this.showTimer); if (this.showTimer != null) window.clearTimeout(this.showTimer);
this.hideTimer = window.setTimeout(this.close, 500); this.hideTimer = window.setTimeout(this.close, 500);
}, },
closed: () => dispose(), closed: () => dispose(),
@ -78,8 +78,8 @@ class UserPreview {
this.checkTimer = window.setInterval(() => { this.checkTimer = window.setInterval(() => {
if (!document.body.contains(this.el)) { if (!document.body.contains(this.el)) {
window.clearTimeout(this.showTimer); if (this.showTimer != null) window.clearTimeout(this.showTimer);
window.clearTimeout(this.hideTimer); if (this.hideTimer != null) window.clearTimeout(this.hideTimer);
this.close(); this.close();
} }
}, 1000); }, 1000);
@ -87,26 +87,26 @@ class UserPreview {
private close() { private close() {
if (this.promise) { if (this.promise) {
window.clearInterval(this.checkTimer); if (this.checkTimer != null) window.clearInterval(this.checkTimer);
this.promise.cancel(); this.promise.cancel();
this.promise = null; this.promise = null;
} }
} }
private onMouseover() { private onMouseover() {
window.clearTimeout(this.showTimer); if (this.showTimer != null) window.clearTimeout(this.showTimer);
window.clearTimeout(this.hideTimer); if (this.hideTimer != null) window.clearTimeout(this.hideTimer);
this.showTimer = window.setTimeout(this.show, 500); this.showTimer = window.setTimeout(this.show, 500);
} }
private onMouseleave() { private onMouseleave() {
window.clearTimeout(this.showTimer); if (this.showTimer != null) window.clearTimeout(this.showTimer);
window.clearTimeout(this.hideTimer); if (this.hideTimer != null) window.clearTimeout(this.hideTimer);
this.hideTimer = window.setTimeout(this.close, 500); this.hideTimer = window.setTimeout(this.close, 500);
} }
private onClick() { private onClick() {
window.clearTimeout(this.showTimer); if (this.showTimer != null) window.clearTimeout(this.showTimer);
this.close(); this.close();
} }