From 3856de4483a18bc1a39bb2edf93ca8eb5451fec3 Mon Sep 17 00:00:00 2001 From: azivner Date: Tue, 6 Nov 2018 13:45:58 +0100 Subject: [PATCH] positioning of context menu when click on elements down on the page --- src/public/javascripts/services/tree.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js index 4253dbd7b..cc759a14f 100644 --- a/src/public/javascripts/services/tree.js +++ b/src/public/javascripts/services/tree.js @@ -406,10 +406,25 @@ function initFancyTree(tree) { } } + // code below tries to detect when dropdown would overflow from page + // in such case we'll position it above click coordinates so it will fit into client + const clickPosition = e.pageY; + const clientHeight = document.documentElement.clientHeight; + const contextMenuHeight = $treeContextMenu.height(); + + let top; + + if (clickPosition + contextMenuHeight > clientHeight) { + top = clientHeight - contextMenuHeight - 10; + } + else { + top = e.pageY - 10; + } + $treeContextMenu.css({ display: "block", - top: e.pageY - 10, - left: e.pageX - 40 + top: top, + left: e.pageX - 20 }).addClass("show"); }