All node button to be clicked via api call

This commit is contained in:
Nick O'Leary 2020-04-27 11:03:43 +01:00
parent d9f710aa52
commit 1a9c4b7714
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
1 changed files with 45 additions and 34 deletions

View File

@ -3060,7 +3060,9 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
function nodeButtonClicked(d) { function nodeButtonClicked(d) {
if (mouse_mode === RED.state.SELECTING_NODE) { if (mouse_mode === RED.state.SELECTING_NODE) {
d3.event.stopPropagation(); if (d3.event) {
d3.event.stopPropagation();
}
return; return;
} }
var activeWorkspace = RED.workspaces.active(); var activeWorkspace = RED.workspaces.active();
@ -3087,7 +3089,9 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
RED.notify(RED._("notification.warning", {message:RED._("notification.warnings.nodeActionDisabled")}),"warning"); RED.notify(RED._("notification.warning", {message:RED._("notification.warnings.nodeActionDisabled")}),"warning");
} }
} }
d3.event.preventDefault(); if (d3.event) {
d3.event.preventDefault();
}
} }
function showTouchMenu(obj,pos) { function showTouchMenu(obj,pos) {
@ -4660,42 +4664,44 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
RED.workspaces.show(id); RED.workspaces.show(id);
} else { } else {
var node = RED.nodes.node(id); var node = RED.nodes.node(id);
if (node._def.category !== 'config' && node.z) { if (node) {
node.highlighted = true; if (node._def.category !== 'config' && node.z) {
node.dirty = true; node.highlighted = true;
RED.workspaces.show(node.z); node.dirty = true;
RED.workspaces.show(node.z);
var screenSize = [chart.width()/scaleFactor,chart.height()/scaleFactor]; var screenSize = [chart.width()/scaleFactor,chart.height()/scaleFactor];
var scrollPos = [chart.scrollLeft()/scaleFactor,chart.scrollTop()/scaleFactor]; var scrollPos = [chart.scrollLeft()/scaleFactor,chart.scrollTop()/scaleFactor];
if (node.x < scrollPos[0] || node.y < scrollPos[1] || node.x > screenSize[0]+scrollPos[0] || node.y > screenSize[1]+scrollPos[1]) { if (node.x < scrollPos[0] || node.y < scrollPos[1] || node.x > screenSize[0]+scrollPos[0] || node.y > screenSize[1]+scrollPos[1]) {
var deltaX = '-='+(((scrollPos[0] - node.x) + screenSize[0]/2)*scaleFactor); var deltaX = '-='+(((scrollPos[0] - node.x) + screenSize[0]/2)*scaleFactor);
var deltaY = '-='+(((scrollPos[1] - node.y) + screenSize[1]/2)*scaleFactor); var deltaY = '-='+(((scrollPos[1] - node.y) + screenSize[1]/2)*scaleFactor);
chart.animate({ chart.animate({
scrollLeft: deltaX, scrollLeft: deltaX,
scrollTop: deltaY scrollTop: deltaY
},200); },200);
}
if (!node._flashing) {
node._flashing = true;
var flash = 22;
var flashFunc = function() {
flash--;
node.dirty = true;
if (flash >= 0) {
node.highlighted = !node.highlighted;
setTimeout(flashFunc,100);
} else {
node.highlighted = false;
delete node._flashing;
}
RED.view.redraw();
} }
flashFunc();
if (!node._flashing) {
node._flashing = true;
var flash = 22;
var flashFunc = function() {
flash--;
node.dirty = true;
if (flash >= 0) {
node.highlighted = !node.highlighted;
setTimeout(flashFunc,100);
} else {
node.highlighted = false;
delete node._flashing;
}
RED.view.redraw();
}
flashFunc();
}
} else if (node._def.category === 'config') {
RED.sidebar.config.show(id);
} }
} else if (node._def.category === 'config') {
RED.sidebar.config.show(id);
} }
} }
}, },
@ -4776,6 +4782,11 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
scroll: function(x,y) { scroll: function(x,y) {
chart.scrollLeft(chart.scrollLeft()+x); chart.scrollLeft(chart.scrollLeft()+x);
chart.scrollTop(chart.scrollTop()+y) chart.scrollTop(chart.scrollTop()+y)
},
clickNodeButton: function(n) {
if (n._def.button) {
nodeButtonClicked(n);
}
} }
}; };
})(); })();