From c5a6bbc749bdaa5c8deb2840f77678e405577acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 13 Aug 2022 01:24:02 +0200 Subject: [PATCH] Open treeview links in a new tab with a right click on a node. --- assets/controllers/elements/tree_controller.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/assets/controllers/elements/tree_controller.js b/assets/controllers/elements/tree_controller.js index 770a6da7..6fbc3ed9 100644 --- a/assets/controllers/elements/tree_controller.js +++ b/assets/controllers/elements/tree_controller.js @@ -84,11 +84,24 @@ export default class extends Controller { }, [BS5Theme, FAIconTheme]); this.treeTarget.addEventListener(EVENT_INITIALIZED, (event) => { + /** @type {BSTreeView} */ const treeView = event.detail.treeView; treeView.revealNode(treeView.getSelected()); + + //Add contextmenu event listener to the tree, which allows us to open the links in a new tab with a right click + treeView.getTreeElement().addEventListener("contextmenu", this._onContextMenu.bind(this)); }); + } + _onContextMenu(event) + { + //Find the node that was clicked and open link in new tab + const node = this._tree._domToNode(event.target); + if(node && node.href) { + event.preventDefault(); + window.open(node.href, '_blank'); + } } collapseAll() {