blob: b5a6c3c1196d8df8e5b1a28fd9a00b76fb8d999d (
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
|
import { mk } from './util';
// Some elements have custom right click context menus
// If there's a custom context menu active, this will be it
var context_menu = null;
// Create a right click context menu
export function context(e, entries) {
if (context_menu)
context_menu.remove();
context_menu = mk(document.body, 'ul', 'context');
context_menu.onmousedown = (e) => {
e.stopPropagation();
}
context_menu.onclick = (_e) => {
context_menu.remove();
context_menu = null;
}
context_menu.style.left = e.clientX + "px";
context_menu.style.top = e.clientY + "px";
for (const e of entries) {
const li = document.createElement('li');
li.innerText = e[0];
li.onclick = e[1];
context_menu.appendChild(li);
}
}
// When we click anywhere, remove the context menu
// The context menu itself has a onmousedown that prevents propagation so we can click its elements
document.body.onmousedown = (_e) => {
if (context_menu) {
context_menu.remove();
context_menu = null;
}
}
export function oncontextmenu_hook(_e) {
if (context_menu) {
context_menu.remove();
context_menu = null;
}
}
|