forked from lapo-luchini/asn1js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.js
53 lines (46 loc) · 1.6 KB
/
context.js
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
const
id = (elem) => document.getElementById(elem),
contextMenu = id('contextmenu'),
btnCopyHex = id('btnCopyHex'),
btnCopyB64 = id('btnCopyB64'),
btnCopyTree = id('btnCopyTree'),
btnCopyValue = id('btnCopyValue');
export function bindContextMenu(node) {
const type = node.asn1.typeName();
const valueEnabled = type != 'SET' && type != 'SEQUENCE';
node.onclick = function (event) {
// do not show the menu in case of clicking the icon
if (event.srcElement.nodeName != 'SPAN') return;
contextMenu.style.left = event.pageX + 'px';
contextMenu.style.top = event.pageY + 'px';
contextMenu.style.visibility = 'visible';
contextMenu.node = this;
btnCopyValue.style.display = valueEnabled ? 'block' : 'none';
event.preventDefault();
event.stopPropagation();
};
}
function close(event) {
contextMenu.style.visibility = 'hidden';
event.stopPropagation();
}
contextMenu.onmouseleave = close;
btnCopyHex.onclick = function (event) {
navigator.clipboard.writeText(contextMenu.node.asn1.toHexString('byte'));
close(event);
};
btnCopyB64.onclick = function (event) {
event.stopPropagation();
navigator.clipboard.writeText(contextMenu.node.asn1.toB64String());
close(event);
};
btnCopyTree.onclick = function (event) {
event.stopPropagation();
navigator.clipboard.writeText(contextMenu.node.asn1.toPrettyString());
close(event);
};
btnCopyValue.onclick = function (event) {
event.stopPropagation();
navigator.clipboard.writeText(contextMenu.node.asn1.content());
close(event);
};