From 6e59bbd524fc7f6f81c444f5d9b7854c3101e88c Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 20 Aug 2021 14:58:52 -0400 Subject: [PATCH] Fixed context menu. Added feature for off-clicking. --- .../templates/panel/server_files.html | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/frontend/templates/panel/server_files.html b/app/frontend/templates/panel/server_files.html index 959b3004..b135b527 100644 --- a/app/frontend/templates/panel/server_files.html +++ b/app/frontend/templates/panel/server_files.html @@ -668,6 +668,9 @@ }else{ $('#unzip').hide();} + var clientX = event.clientX; + var clientY = event.clientY; + document.getElementById('files-tree-nav-content') @@ -676,12 +679,27 @@ .setAttribute('data-name', ctxmenuName); document.getElementById("files-tree-nav").style.display = "flex"; document.getElementById("files-tree-nav").style.position = "fixed"; - document.getElementById("files-tree-nav").style.top = event.clientY + 'px'; - document.getElementById("files-tree-nav").style.left = event.clientX + 'px'; + domRect = document.getElementById("files-tree-nav").getBoundingClientRect(); + sum = (clientY+domRect['height']) - window.innerHeight + if(domRect['height']+clientY > window.innerHeight){ + clientY = clientY - sum + } + document.getElementById("files-tree-nav").style.top = clientY + 'px'; + document.getElementById("files-tree-nav").style.left = clientX + 'px'; + console.log(domRect) + console.log(window.innerHeight) }) } } + document.addEventListener('click', function(e){ + let inside = (e.target.closest('#files-tree-nav')); + if(!inside){ + let contextMenu = document.getElementById('files-tree-nav'); + contextMenu.setAttribute('style', 'display:none'); + } +}); + function createFileE(event) { bootbox.prompt("{% raw translate('serverFiles', 'createFileQuestion') %}", function(result) {