Fixed context menus in web application.

This commit is contained in:
Ylian Saint-Hilaire 2019-12-23 15:46:00 -08:00
parent c022ead2ef
commit 51c6567905
3 changed files with 18 additions and 19 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "meshcentral", "name": "meshcentral",
"version": "0.4.6-k", "version": "0.4.6-l",
"keywords": [ "keywords": [
"Remote Management", "Remote Management",
"Intel AMT", "Intel AMT",

View File

@ -1840,8 +1840,6 @@ a {
/*border-radius: 4px;*/ /*border-radius: 4px;*/
display: none; display: none;
position: absolute; position: absolute;
top: 0;
left: 0;
list-style: none; list-style: none;
margin: 0; margin: 0;
padding: 5px; padding: 5px;

View File

@ -1170,7 +1170,7 @@
document.onkeyup = ondockeyup; document.onkeyup = ondockeyup;
//window.addEventListener('focus', ondocfocus, false); //window.addEventListener('focus', ondocfocus, false);
window.addEventListener('blur', ondocblur, false); window.addEventListener('blur', ondocblur, false);
window.onresize = function () { masterUpdate(512); } window.onresize = function () { hideContextMenu(); masterUpdate(512); }
setTimeout(function() { masterUpdate(512); }, 200); setTimeout(function() { masterUpdate(512); }, 200);
// Connect to the mesh server // Connect to the mesh server
@ -3691,35 +3691,26 @@
if (elem && elem != null && elem.id == 'connectbutton2' && currentNode && currentNode.agent && (currentNode.agent.id > 0) && (currentNode.agent.id < 5)) { if (elem && elem != null && elem.id == 'connectbutton2' && currentNode && currentNode.agent && (currentNode.agent.id > 0) && (currentNode.agent.id < 5)) {
contextelement = elem; contextelement = elem;
var contextmenudiv = document.getElementById('termShellContextMenu'); var contextmenudiv = document.getElementById('termShellContextMenu');
contextmenudiv.style.left = event.pageX + 'px'; showContextMenuDiv(contextmenudiv, event.pageX, event.pageY);
contextmenudiv.style.top = event.pageY + 'px';
contextmenudiv.style.display = 'block';
} else if (elem && elem != null && elem.id == 'connectbutton2' && currentNode && currentNode.agent && (currentNode.agent.id > 4)) { } else if (elem && elem != null && elem.id == 'connectbutton2' && currentNode && currentNode.agent && (currentNode.agent.id > 4)) {
contextelement = elem; contextelement = elem;
var contextmenudiv = document.getElementById('termShellContextMenuLinux'); var contextmenudiv = document.getElementById('termShellContextMenuLinux');
contextmenudiv.style.left = event.pageX + 'px'; showContextMenuDiv(contextmenudiv, event.pageX, event.pageY);
contextmenudiv.style.top = event.pageY + 'px';
contextmenudiv.style.display = 'block';
} else if (elem && elem != null && elem.id == 'MxMESH') { } else if (elem && elem != null && elem.id == 'MxMESH') {
contextelement = elem; contextelement = elem;
var contextmenudiv = document.getElementById('meshContextMenu'); var contextmenudiv = document.getElementById('meshContextMenu');
contextmenudiv.style.left = event.pageX + 'px'; showContextMenuDiv(contextmenudiv, event.pageX, event.pageY);
contextmenudiv.style.top = event.pageY + 'px';
contextmenudiv.style.display = 'block';
/*} else if (elem && elem != null && elem.classList.contains('pluginTab')) { /*} else if (elem && elem != null && elem.classList.contains('pluginTab')) {
contextelement = elem; contextelement = elem;
var contextmenudiv = document.getElementById('pluginTabContextMenu'); var contextmenudiv = document.getElementById('pluginTabContextMenu');
contextmenudiv.style.left = event.pageX + 'px'; showContextMenuDiv(contextmenudiv, event.pageX, event.pageY);
contextmenudiv.style.top = event.pageY + 'px'; */
contextmenudiv.style.display = 'block';*/
} else { } else {
while (elem && elem != null && elem.id != 'devs') { elem = elem.parentElement; } while (elem && elem != null && elem.id != 'devs') { elem = elem.parentElement; }
if (!elem || elem == null) return true; if (!elem || elem == null) return true;
contextelement = elem; contextelement = elem;
var contextmenudiv = document.getElementById('contextMenu'); var contextmenudiv = document.getElementById('contextMenu');
contextmenudiv.style.left = event.pageX + 'px'; showContextMenuDiv(contextmenudiv, event.pageX, event.pageY);
contextmenudiv.style.top = event.pageY + 'px';
contextmenudiv.style.display = 'block';
// Get the node and set the menu options // Get the node and set the menu options
var nodeid = contextelement.children[1].attributes.onclick.value; var nodeid = contextelement.children[1].attributes.onclick.value;
@ -3743,6 +3734,16 @@
return haltEvent(event); return haltEvent(event);
} }
function showContextMenuDiv(element, x, y) {
var clientRect = document.documentElement.getBoundingClientRect();
var docHeight = clientRect.height;
var docWidth = clientRect.width;
element.style.left = element.style.right = element.style.top = element.style.bottom = null;
if (x > (docWidth / 2)) { element.style.right = (docWidth - event.pageX) + 'px'; } else { element.style.left = event.pageX + 'px'; }
if (y > (docHeight / 2)) { element.style.bottom = (docHeight - event.pageY) + 'px'; } else { element.style.top = event.pageY + 'px'; }
element.style.display = 'block';
}
function cmaction(action,event) { function cmaction(action,event) {
var nodeid = contextelement.children[1].attributes.onclick.value; var nodeid = contextelement.children[1].attributes.onclick.value;
nodeid = nodeid.substring(12, nodeid.length - 18); nodeid = nodeid.substring(12, nodeid.length - 18);