diff --git a/context.js b/context.js index 4684460..2ca159f 100644 --- a/context.js +++ b/context.js @@ -1,6 +1,7 @@ const id = (elem) => document.getElementById(elem), contextMenu = id('contextmenu'), + btnHideTree = id('btnHideTree'), btnCopyHex = id('btnCopyHex'), btnCopyB64 = id('btnCopyB64'), btnCopyTree = id('btnCopyTree'), @@ -14,6 +15,8 @@ export function bindContextMenu(node) { contextMenu.style.top = event.pageY + 'px'; contextMenu.style.visibility = 'visible'; contextMenu.node = this; + btnHideTree.innerText = (node.className == 'node') ? 'Hide subtree' : 'Show subtree'; + btnHideTree.style.display = node.className.startsWith('node') ? 'block' : 'none'; btnCopyValue.style.display = valueEnabled ? 'block' : 'none'; event.stopPropagation(); }; @@ -25,6 +28,13 @@ function close() { contextMenu.onmouseleave = close; +btnHideTree.onclick = function (event) { + event.stopPropagation(); + const node = contextMenu.node; + node.className = (node.className == 'node collapsed') ? 'node' : 'node collapsed'; + close(); +}; + btnCopyHex.onclick = function (event) { event.stopPropagation(); navigator.clipboard.writeText(contextMenu.node.asn1.toHexString('byte')); diff --git a/dom.js b/dom.js index 1e8ff25..0ad6d65 100644 --- a/dom.js +++ b/dom.js @@ -143,9 +143,7 @@ export class ASN1DOM extends ASN1 { sub.appendChild(this.sub[i].toDOM(spaces)); } node.appendChild(sub); - head.onclick = function () { - node.className = (node.className == 'node collapsed') ? 'node' : 'node collapsed'; - }; + bindContextMenu(node); return node; } fakeHover(current) { @@ -202,9 +200,6 @@ export class ASN1DOM extends ASN1 { node.appendChild(skip); } } - // set the current start and end position as an attribute at the node to know the selected area - node.setAttribute('pos', this.posStart()); - node.setAttribute('end', this.posEnd()); this.toHexDOM_sub(node, 'tag', this.stream, this.posStart(), this.posLen()); this.toHexDOM_sub(node, (this.length >= 0) ? 'dlen' : 'ulen', this.stream, this.posLen(), this.posContent()); if (this.sub === null) { diff --git a/index.html b/index.html index 7602bca..05d67b7 100644 --- a/index.html +++ b/index.html @@ -9,6 +9,7 @@
+