blob: fb596b0015e2071d910cccd3db56cf2abb8d4e50 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
export class Popup {
trigger_hov = false
content_hov = false
content?: HTMLElement
shown = false
constructor(
public trigger: HTMLElement,
public container: HTMLElement,
public new_content: () => HTMLElement
) {
trigger.onmouseenter = () => {
this.trigger_hov = true;
this.update_hov()
}
trigger.onmouseleave = () => {
this.trigger_hov = false;
this.update_hov()
}
}
set_shown(s: boolean) {
if (this.shown == s) return
if (s) {
this.content = this.new_content()
this.content.addEventListener("mouseenter", () => {
this.content_hov = true;
this.update_hov()
})
this.content.addEventListener("mouseleave", () => {
this.content_hov = false;
this.update_hov()
})
this.container.append(this.content)
} else {
this.container.removeChild(this.content!)
this.content = undefined
}
this.shown = s
}
hide_timeout?: number
update_hov() {
if (this.content_hov || this.trigger_hov) {
this.set_shown(true)
if (this.hide_timeout !== undefined) {
clearTimeout(this.hide_timeout)
this.hide_timeout = undefined
}
} else {
if (this.hide_timeout === undefined) this.hide_timeout = setTimeout(() => {
this.set_shown(false)
this.hide_timeout = undefined
}, 100)
}
}
}
|