1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Tidy editor code to pass jshint

This commit is contained in:
Nick O'Leary 2014-08-08 00:01:35 +01:00
parent fb2f307a26
commit 972e6fc6b3
16 changed files with 514 additions and 448 deletions

View File

@ -86,7 +86,6 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-simple-mocha'); grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('default', ['jshint:core','jshint:tests','simplemocha:core','simplemocha:nodes']); grunt.registerTask('default', ['jshint:core','jshint:tests','jshint:editor','simplemocha:core','simplemocha:nodes']);
grunt.registerTask('all', ['jshint:core','jshint:nodes','jshint:editor','default']);
}; };

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
RED.comms = function() { RED.comms = (function() {
var errornotification = null; var errornotification = null;
var subscriptions = {}; var subscriptions = {};
@ -30,13 +30,16 @@ RED.comms = function() {
errornotification = null; errornotification = null;
} }
for (var t in subscriptions) { for (var t in subscriptions) {
if (subscriptions.hasOwnProperty(t)) {
ws.send(JSON.stringify({subscribe:t})); ws.send(JSON.stringify({subscribe:t}));
} }
} }
}
ws.onmessage = function(event) { ws.onmessage = function(event) {
var msg = JSON.parse(event.data); var msg = JSON.parse(event.data);
if (msg.topic) { if (msg.topic) {
for (var t in subscriptions) { for (var t in subscriptions) {
if (subscriptions.hasOwnProperty(t)) {
var re = new RegExp("^"+t.replace(/([\[\]\?\(\)\\\\$\^\*\.|])/g,"\\$1").replace(/\+/g,"[^/]+").replace(/\/#$/,"(\/.*)?")+"$"); var re = new RegExp("^"+t.replace(/([\[\]\?\(\)\\\\$\^\*\.|])/g,"\\$1").replace(/\+/g,"[^/]+").replace(/\/#$/,"(\/.*)?")+"$");
if (re.test(msg.topic)) { if (re.test(msg.topic)) {
var subscribers = subscriptions[t]; var subscribers = subscriptions[t];
@ -48,6 +51,7 @@ RED.comms = function() {
} }
} }
} }
}
}; };
ws.onclose = function() { ws.onclose = function() {
if (errornotification == null) { if (errornotification == null) {
@ -72,4 +76,4 @@ RED.comms = function() {
connect: connectWS, connect: connectWS,
subscribe: subscribe subscribe: subscribe
} }
}(); })();

View File

@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
RED.history = function() { RED.history = (function() {
var undo_history = []; var undo_history = [];
return { return {
//TODO: this function is a placeholder until there is a 'save' event that can be listened to //TODO: this function is a placeholder until there is a 'save' event that can be listened to
markAllDirty: function() { markAllDirty: function() {
for (var i in undo_history) { for (var i=0;i<undo_history.length;i++) {
undo_history[i].dirty = true; undo_history[i].dirty = true;
} }
}, },
@ -31,42 +31,45 @@ RED.history = function() {
}, },
pop: function() { pop: function() {
var ev = undo_history.pop(); var ev = undo_history.pop();
var i;
if (ev) { if (ev) {
if (ev.t == 'add') { if (ev.t == 'add') {
for (var i in ev.nodes) { for (i=0;i<ev.nodes.length;i++) {
RED.nodes.remove(ev.nodes[i]); RED.nodes.remove(ev.nodes[i]);
} }
for (var i in ev.links) { for (i=0;i<ev.links.length;i++) {
RED.nodes.removeLink(ev.links[i]); RED.nodes.removeLink(ev.links[i]);
} }
for (var i in ev.workspaces) { for (i=0;i<ev.workspaces.length;i++) {
RED.nodes.removeWorkspace(ev.workspaces[i].id); RED.nodes.removeWorkspace(ev.workspaces[i].id);
RED.view.removeWorkspace(ev.workspaces[i]); RED.view.removeWorkspace(ev.workspaces[i]);
} }
} else if (ev.t == "delete") { } else if (ev.t == "delete") {
for (var i in ev.workspaces) { for (i=0;i<ev.workspaces.length;i++) {
RED.nodes.addWorkspace(ev.workspaces[i]); RED.nodes.addWorkspace(ev.workspaces[i]);
RED.view.addWorkspace(ev.workspaces[i]); RED.view.addWorkspace(ev.workspaces[i]);
} }
for (var i in ev.nodes) { for (i=0;i<ev.nodes.length;i++) {
RED.nodes.add(ev.nodes[i]); RED.nodes.add(ev.nodes[i]);
} }
for (var i in ev.links) { for (i=0;i<ev.links.length;i++) {
RED.nodes.addLink(ev.links[i]); RED.nodes.addLink(ev.links[i]);
} }
} else if (ev.t == "move") { } else if (ev.t == "move") {
for (var i in ev.nodes) { for (i=0;i<ev.nodes.length;i++) {
var n = ev.nodes[i]; var n = ev.nodes[i];
n.n.x = n.ox; n.n.x = n.ox;
n.n.y = n.oy; n.n.y = n.oy;
n.n.dirty = true; n.n.dirty = true;
} }
} else if (ev.t == "edit") { } else if (ev.t == "edit") {
for (var i in ev.changes) { for (i in ev.changes) {
if (ev.changes.hasOwnProperty(i)) {
ev.node[i] = ev.changes[i]; ev.node[i] = ev.changes[i];
} }
}
RED.editor.updateNodeProperties(ev.node); RED.editor.updateNodeProperties(ev.node);
for (var i in ev.links) { for (i=0;i<ev.links.length;i++) {
RED.nodes.addLink(ev.links[i]); RED.nodes.addLink(ev.links[i]);
} }
RED.editor.validateNode(ev.node); RED.editor.validateNode(ev.node);
@ -79,4 +82,4 @@ RED.history = function() {
} }
} }
}(); })();

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
var RED = function() { var RED = (function() {
$('#btn-keyboard-shortcuts').click(function(){showHelp();}); $('#btn-keyboard-shortcuts').click(function(){showHelp();});
@ -177,8 +177,9 @@ var RED = function() {
} }
}); });
RED.comms.subscribe("node/#",function(topic,msg) { RED.comms.subscribe("node/#",function(topic,msg) {
var i;
if (topic == "node/added") { if (topic == "node/added") {
for (var i=0;i<msg.length;i++) { for (i=0;i<msg.length;i++) {
var m = msg[i]; var m = msg[i];
var id = m.id; var id = m.id;
$.get('nodes/'+id, function(data) { $.get('nodes/'+id, function(data) {
@ -189,7 +190,7 @@ var RED = function() {
} }
} else if (topic == "node/removed") { } else if (topic == "node/removed") {
if (msg.types) { if (msg.types) {
for (var i=0;i<msg.types.length;i++) { for (i=0;i<msg.types.length;i++) {
RED.palette.remove(msg.types[i]); RED.palette.remove(msg.types[i]);
} }
var typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>"; var typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>";
@ -235,4 +236,4 @@ var RED = function() {
return { return {
}; };
}(); })();

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
RED.nodes = function() { RED.nodes = (function() {
var node_defs = {}; var node_defs = {};
var nodes = []; var nodes = [];
@ -45,6 +45,7 @@ RED.nodes = function() {
nodes.push(n); nodes.push(n);
var updatedConfigNode = false; var updatedConfigNode = false;
for (var d in n._def.defaults) { for (var d in n._def.defaults) {
if (n._def.defaults.hasOwnProperty(d)) {
var property = n._def.defaults[d]; var property = n._def.defaults[d];
if (property.type) { if (property.type) {
var type = getType(property.type) var type = getType(property.type)
@ -57,6 +58,7 @@ RED.nodes = function() {
} }
} }
} }
}
if (updatedConfigNode) { if (updatedConfigNode) {
RED.sidebar.config.refresh(); RED.sidebar.config.refresh();
} }
@ -96,6 +98,7 @@ RED.nodes = function() {
} }
var updatedConfigNode = false; var updatedConfigNode = false;
for (var d in node._def.defaults) { for (var d in node._def.defaults) {
if (node._def.defaults.hasOwnProperty(d)) {
var property = node._def.defaults[d]; var property = node._def.defaults[d];
if (property.type) { if (property.type) {
var type = getType(property.type) var type = getType(property.type)
@ -109,6 +112,7 @@ RED.nodes = function() {
} }
} }
} }
}
if (updatedConfigNode) { if (updatedConfigNode) {
RED.sidebar.config.refresh(); RED.sidebar.config.refresh();
} }
@ -124,7 +128,7 @@ RED.nodes = function() {
} }
function refreshValidation() { function refreshValidation() {
for (var n in nodes) { for (var n=0;n<nodes.length;n++) {
RED.editor.validateNode(nodes[n]); RED.editor.validateNode(nodes[n]);
} }
} }
@ -139,13 +143,14 @@ RED.nodes = function() {
delete workspaces[id]; delete workspaces[id];
var removedNodes = []; var removedNodes = [];
var removedLinks = []; var removedLinks = [];
for (var n in nodes) { var n;
for (n=0;n<nodes.length;n++) {
var node = nodes[n]; var node = nodes[n];
if (node.z == id) { if (node.z == id) {
removedNodes.push(node); removedNodes.push(node);
} }
} }
for (var n in removedNodes) { for (n=0;n<removedNodes.length;n++) {
var rmlinks = removeNode(removedNodes[n].id); var rmlinks = removeNode(removedNodes[n].id);
removedLinks = removedLinks.concat(rmlinks); removedLinks = removedLinks.concat(rmlinks);
} }
@ -157,10 +162,10 @@ RED.nodes = function() {
visited[node.id] = true; visited[node.id] = true;
var nns = [node]; var nns = [node];
var stack = [node]; var stack = [node];
while(stack.length != 0) { while(stack.length !== 0) {
var n = stack.shift(); var n = stack.shift();
var childLinks = links.filter(function(d) { return (d.source === n) || (d.target === n);}); var childLinks = links.filter(function(d) { return (d.source === n) || (d.target === n);});
for (var i in childLinks) { for (var i=0;i<childLinks.length;i++) {
var child = (childLinks[i].source === n)?childLinks[i].target:childLinks[i].source; var child = (childLinks[i].source === n)?childLinks[i].target:childLinks[i].source;
if (!visited[child.id]) { if (!visited[child.id]) {
visited[child.id] = true; visited[child.id] = true;
@ -181,8 +186,10 @@ RED.nodes = function() {
node.id = n.id; node.id = n.id;
node.type = n.type; node.type = n.type;
for (var d in n._def.defaults) { for (var d in n._def.defaults) {
if (n._def.defaults.hasOwnProperty(d)) {
node[d] = n[d]; node[d] = n[d];
} }
}
if(exportCreds && n.credentials) { if(exportCreds && n.credentials) {
node.credentials = {}; node.credentials = {};
for (var cred in n._def.credentials) { for (var cred in n._def.credentials) {
@ -202,8 +209,8 @@ RED.nodes = function() {
node.wires.push([]); node.wires.push([]);
} }
var wires = links.filter(function(d){return d.source === n;}); var wires = links.filter(function(d){return d.source === n;});
for (var i in wires) { for (var j=0;j<wires.length;j++) {
var w = wires[i]; var w = wires[j];
node.wires[w.sourcePort].push(w.target.id); node.wires[w.sourcePort].push(w.target.id);
} }
} }
@ -216,7 +223,7 @@ RED.nodes = function() {
function createExportableNodeSet(set) { function createExportableNodeSet(set) {
var nns = []; var nns = [];
var exportedConfigNodes = {}; var exportedConfigNodes = {};
for (var n in set) { for (var n=0;n<set.length;n++) {
var node = set[n].n; var node = set[n].n;
var convertedNode = RED.nodes.convertNode(node); var convertedNode = RED.nodes.convertNode(node);
for (var d in node._def.defaults) { for (var d in node._def.defaults) {
@ -242,13 +249,18 @@ RED.nodes = function() {
//TODO: rename this (createCompleteNodeSet) //TODO: rename this (createCompleteNodeSet)
function createCompleteNodeSet() { function createCompleteNodeSet() {
var nns = []; var nns = [];
for (var i in workspaces) { var i;
for (i in workspaces) {
if (workspaces.hasOwnProperty(i)) {
nns.push(workspaces[i]); nns.push(workspaces[i]);
} }
for (var i in configNodes) { }
for (i in configNodes) {
if (configNodes.hasOwnProperty(i)) {
nns.push(convertNode(configNodes[i], true)); nns.push(convertNode(configNodes[i], true));
} }
for (var i in nodes) { }
for (i=0;i<nodes.length;i++) {
var node = nodes[i]; var node = nodes[i];
nns.push(convertNode(node, true)); nns.push(convertNode(node, true));
} }
@ -257,9 +269,11 @@ RED.nodes = function() {
function importNodes(newNodesObj,createNewIds) { function importNodes(newNodesObj,createNewIds) {
try { try {
var i;
var n;
var newNodes; var newNodes;
if (typeof newNodesObj === "string") { if (typeof newNodesObj === "string") {
if (newNodesObj == "") { if (newNodesObj === "") {
return; return;
} }
newNodes = JSON.parse(newNodesObj); newNodes = JSON.parse(newNodesObj);
@ -271,8 +285,8 @@ RED.nodes = function() {
newNodes = [newNodes]; newNodes = [newNodes];
} }
var unknownTypes = []; var unknownTypes = [];
for (var i=0;i<newNodes.length;i++) { for (i=0;i<newNodes.length;i++) {
var n = newNodes[i]; n = newNodes[i];
// TODO: remove workspace in next release+1 // TODO: remove workspace in next release+1
if (n.type != "workspace" && n.type != "tab" && !getType(n.type)) { if (n.type != "workspace" && n.type != "tab" && !getType(n.type)) {
// TODO: get this UI thing out of here! (see below as well) // TODO: get this UI thing out of here! (see below as well)
@ -295,8 +309,8 @@ RED.nodes = function() {
//"DO NOT DEPLOY while in this state.<br/>Either, add missing types to Node-RED, restart and then reload page,<br/>or delete unknown "+n.name+", rewire as required, and then deploy.","error"); //"DO NOT DEPLOY while in this state.<br/>Either, add missing types to Node-RED, restart and then reload page,<br/>or delete unknown "+n.name+", rewire as required, and then deploy.","error");
} }
for (var i in newNodes) { for (i=0;i<newNodes.length;i++) {
var n = newNodes[i]; n = newNodes[i];
// TODO: remove workspace in next release+1 // TODO: remove workspace in next release+1
if (n.type === "workspace" || n.type === "tab") { if (n.type === "workspace" || n.type === "tab") {
if (n.type === "workspace") { if (n.type === "workspace") {
@ -319,8 +333,8 @@ RED.nodes = function() {
var new_nodes = []; var new_nodes = [];
var new_links = []; var new_links = [];
for (var i in newNodes) { for (i=0;i<newNodes.length;i++) {
var n = newNodes[i]; n = newNodes[i];
// TODO: remove workspace in next release+1 // TODO: remove workspace in next release+1
if (n.type !== "workspace" && n.type !== "tab") { if (n.type !== "workspace" && n.type !== "tab") {
var def = getType(n.type); var def = getType(n.type);
@ -328,8 +342,10 @@ RED.nodes = function() {
if (!RED.nodes.node(n.id)) { if (!RED.nodes.node(n.id)) {
var configNode = {id:n.id,type:n.type,users:[]}; var configNode = {id:n.id,type:n.type,users:[]};
for (var d in def.defaults) { for (var d in def.defaults) {
if (def.defaults.hasOwnProperty(d)) {
configNode[d] = n[d]; configNode[d] = n[d];
} }
}
configNode.label = def.label; configNode.label = def.label;
configNode._def = def; configNode._def = def;
RED.nodes.add(configNode); RED.nodes.add(configNode);
@ -358,8 +374,10 @@ RED.nodes = function() {
} }
node.outputs = n.outputs||node._def.outputs; node.outputs = n.outputs||node._def.outputs;
for (var d in node._def.defaults) { for (var d2 in node._def.defaults) {
node[d] = n[d]; if (node._def.defaults.hasOwnProperty(d2)) {
node[d2] = n[d2];
}
} }
addNode(node); addNode(node);
@ -369,11 +387,11 @@ RED.nodes = function() {
} }
} }
} }
for (var i in new_nodes) { for (i=0;i<new_nodes.length;i++) {
var n = new_nodes[i]; n = new_nodes[i];
for (var w1 in n.wires) { for (var w1=0;w1<n.wires.length;w1++) {
var wires = (n.wires[w1] instanceof Array)?n.wires[w1]:[n.wires[w1]]; var wires = (n.wires[w1] instanceof Array)?n.wires[w1]:[n.wires[w1]];
for (var w2 in wires) { for (var w2=0;w2<wires.length;w2++) {
if (wires[w2] in node_map) { if (wires[w2] in node_map) {
var link = {source:n,sourcePort:w1,target:node_map[wires[w2]]}; var link = {source:n,sourcePort:w1,target:node_map[wires[w2]]};
addLink(link); addLink(link);
@ -404,19 +422,21 @@ RED.nodes = function() {
removeWorkspace: removeWorkspace, removeWorkspace: removeWorkspace,
workspace: getWorkspace, workspace: getWorkspace,
eachNode: function(cb) { eachNode: function(cb) {
for (var n in nodes) { for (var n=0;n<nodes.length;n++) {
cb(nodes[n]); cb(nodes[n]);
} }
}, },
eachLink: function(cb) { eachLink: function(cb) {
for (var l in links) { for (var l=0;l<links.length;l++) {
cb(links[l]); cb(links[l]);
} }
}, },
eachConfig: function(cb) { eachConfig: function(cb) {
for (var id in configNodes) { for (var id in configNodes) {
if (configNodes.hasOwnProperty(id)) {
cb(configNodes[id]); cb(configNodes[id]);
} }
}
}, },
node: getNode, node: getNode,
import: importNodes, import: importNodes,
@ -428,4 +448,4 @@ RED.nodes = function() {
nodes: nodes, // TODO: exposed for d3 vis nodes: nodes, // TODO: exposed for d3 vis
links: links // TODO: exposed for d3 vis links: links // TODO: exposed for d3 vis
}; };
}(); })();

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
RED.editor = function() { RED.editor = (function() {
var editing_node = null; var editing_node = null;
// TODO: should IMPORT/EXPORT get their own dialogs? // TODO: should IMPORT/EXPORT get their own dialogs?
@ -97,13 +97,12 @@ RED.editor = function() {
while (node.outputs < node.ports.length) { while (node.outputs < node.ports.length) {
node.ports.pop(); node.ports.pop();
} }
var removedLinks = [];
RED.nodes.eachLink(function(l) { RED.nodes.eachLink(function(l) {
if (l.source === node && l.sourcePort >= node.outputs) { if (l.source === node && l.sourcePort >= node.outputs) {
removedLinks.push(l); removedLinks.push(l);
} }
}); });
for (var l in removedLinks) { for (var l=0;l<removedLinks.length;l++) {
RED.nodes.removeLink(removedLinks[l]); RED.nodes.removeLink(removedLinks[l]);
} }
} else if (node.outputs > node.ports.length) { } else if (node.outputs > node.ports.length) {
@ -129,23 +128,26 @@ RED.editor = function() {
var changes = {}; var changes = {};
var changed = false; var changed = false;
var wasDirty = RED.view.dirty(); var wasDirty = RED.view.dirty();
var d;
if (editing_node._def.oneditsave) { if (editing_node._def.oneditsave) {
var oldValues = {}; var oldValues = {};
for (var d in editing_node._def.defaults) { for (d in editing_node._def.defaults) {
if (editing_node._def.defaults.hasOwnProperty(d)) {
if (typeof editing_node[d] === "string" || typeof editing_node[d] === "number") { if (typeof editing_node[d] === "string" || typeof editing_node[d] === "number") {
oldValues[d] = editing_node[d]; oldValues[d] = editing_node[d];
} else { } else {
oldValues[d] = $.extend(true,{},{v:editing_node[d]}).v; oldValues[d] = $.extend(true,{},{v:editing_node[d]}).v;
} }
} }
}
var rc = editing_node._def.oneditsave.call(editing_node); var rc = editing_node._def.oneditsave.call(editing_node);
if (rc === true) { if (rc === true) {
changed = true; changed = true;
} }
for (var d in editing_node._def.defaults) { for (d in editing_node._def.defaults) {
if (editing_node._def.defaults.hasOwnProperty(d)) {
if (oldValues[d] === null || typeof oldValues[d] === "string" || typeof oldValues[d] === "number") { if (oldValues[d] === null || typeof oldValues[d] === "string" || typeof oldValues[d] === "number") {
if (oldValues[d] !== editing_node[d]) { if (oldValues[d] !== editing_node[d]) {
changes[d] = oldValues[d]; changes[d] = oldValues[d];
@ -158,12 +160,14 @@ RED.editor = function() {
} }
} }
} }
}
} }
if (editing_node._def.defaults) { if (editing_node._def.defaults) {
for (var d in editing_node._def.defaults) { for (d in editing_node._def.defaults) {
if (editing_node._def.defaults.hasOwnProperty(d)) {
var input = $("#node-input-"+d); var input = $("#node-input-"+d);
var newValue; var newValue;
if (input.attr('type') === "checkbox") { if (input.attr('type') === "checkbox") {
@ -183,7 +187,7 @@ RED.editor = function() {
var users = configNode.users; var users = configNode.users;
users.splice(users.indexOf(editing_node),1); users.splice(users.indexOf(editing_node),1);
} }
var configNode = RED.nodes.node(newValue); configNode = RED.nodes.node(newValue);
if (configNode) { if (configNode) {
configNode.users.push(editing_node); configNode.users.push(editing_node);
} }
@ -196,6 +200,7 @@ RED.editor = function() {
} }
} }
} }
}
if (editing_node._def.credentials) { if (editing_node._def.credentials) {
var prefix = 'node-input'; var prefix = 'node-input';
var credDefinition = editing_node._def.credentials; var credDefinition = editing_node._def.credentials;
@ -224,7 +229,7 @@ RED.editor = function() {
RED.notify("Saved nodes","success"); RED.notify("Saved nodes","success");
}); });
} }
}; }
} else if (RED.view.state() == RED.state.IMPORT) { } else if (RED.view.state() == RED.state.IMPORT) {
RED.view.importNodes($("#node-input-import").val()); RED.view.importNodes($("#node-input-import").val());
} }
@ -343,7 +348,8 @@ RED.editor = function() {
* @param prefix * @param prefix
*/ */
function populateCredentialsInputs(node, credDef, credData, prefix) { function populateCredentialsInputs(node, credDef, credData, prefix) {
for (var cred in credDef) { var cred;
for (cred in credDef) {
if (credDef.hasOwnProperty(cred)) { if (credDef.hasOwnProperty(cred)) {
if (credDef[cred].type == 'password') { if (credDef[cred].type == 'password') {
if (credData[cred]) { if (credData[cred]) {
@ -360,7 +366,7 @@ RED.editor = function() {
attachPropertyChangeHandler(node, credDef, cred, prefix); attachPropertyChangeHandler(node, credDef, cred, prefix);
} }
} }
for (var cred in credDef) { for (cred in credDef) {
if (credDef.hasOwnProperty(cred)) { if (credDef.hasOwnProperty(cred)) {
$("#" + prefix + "-" + cred).change(); $("#" + prefix + "-" + cred).change();
} }
@ -385,7 +391,7 @@ RED.editor = function() {
var input = $("#" + prefix + '-' + cred); var input = $("#" + prefix + '-' + cred);
var value = input.val(); var value = input.val();
if (credDefinition[cred].type == 'password') { if (credDefinition[cred].type == 'password') {
node.credentials['has_' + cred] = (value != ""); node.credentials['has_' + cred] = (value !== "");
if (value == '__PWRD__') { if (value == '__PWRD__') {
continue; continue;
} }
@ -409,6 +415,7 @@ RED.editor = function() {
*/ */
function prepareEditDialog(node,definition,prefix) { function prepareEditDialog(node,definition,prefix) {
for (var d in definition.defaults) { for (var d in definition.defaults) {
if (definition.defaults.hasOwnProperty(d)) {
if (definition.defaults[d].type) { if (definition.defaults[d].type) {
prepareConfigNodeSelect(node,d,definition.defaults[d].type); prepareConfigNodeSelect(node,d,definition.defaults[d].type);
} else { } else {
@ -416,14 +423,17 @@ RED.editor = function() {
} }
attachPropertyChangeHandler(node,definition.defaults,d,prefix); attachPropertyChangeHandler(node,definition.defaults,d,prefix);
} }
}
var completePrepare = function() { var completePrepare = function() {
if (definition.oneditprepare) { if (definition.oneditprepare) {
definition.oneditprepare.call(node); definition.oneditprepare.call(node);
} }
for (var d in definition.defaults) { for (var d in definition.defaults) {
if (definition.defaults.hasOwnProperty(d)) {
$("#"+prefix+"-"+d).change(); $("#"+prefix+"-"+d).change();
} }
} }
}
if (definition.credentials) { if (definition.credentials) {
if (node.credentials) { if (node.credentials) {
@ -494,10 +504,10 @@ RED.editor = function() {
configTypeDef.ondelete.call(RED.nodes.node(configId)); configTypeDef.ondelete.call(RED.nodes.node(configId));
} }
RED.nodes.remove(configId); RED.nodes.remove(configId);
for (var i in configNode.users) { for (var i=0;i<configNode.users.length;i++) {
var user = configNode.users[i]; var user = configNode.users[i];
for (var d in user._def.defaults) { for (var d in user._def.defaults) {
if (user[d] == configId) { if (user._def.defaults.hasOwnProperty(d) && user[d] == configId) {
user[d] = ""; user[d] = "";
} }
} }
@ -540,7 +550,7 @@ RED.editor = function() {
} }
}); });
select.append('<option value="_ADD_"'+(value==""?" selected":"")+'>Add new '+type+'...</option>'); select.append('<option value="_ADD_"'+(value===""?" selected":"")+'>Add new '+type+'...</option>');
window.setTimeout(function() { select.change();},50); window.setTimeout(function() { select.change();},50);
} }
@ -559,12 +569,14 @@ RED.editor = function() {
var configAdding = $(this).dialog('option','node-adding'); var configAdding = $(this).dialog('option','node-adding');
var configTypeDef = RED.nodes.getType(configType); var configTypeDef = RED.nodes.getType(configType);
var configNode; var configNode;
var d;
if (configAdding) { if (configAdding) {
configNode = {type:configType,id:configId,users:[]}; configNode = {type:configType,id:configId,users:[]};
for (var d in configTypeDef.defaults) { for (d in configTypeDef.defaults) {
var input = $("#node-config-input-"+d); if (configTypeDef.defaults.hasOwnProperty(d)) {
configNode[d] = input.val(); configNode[d] = $("#node-config-input-"+d).val();
}
} }
configNode.label = configTypeDef.label; configNode.label = configTypeDef.label;
configNode._def = configTypeDef; configNode._def = configTypeDef;
@ -572,9 +584,10 @@ RED.editor = function() {
updateConfigNodeSelect(configProperty,configType,configNode.id); updateConfigNodeSelect(configProperty,configType,configNode.id);
} else { } else {
configNode = RED.nodes.node(configId); configNode = RED.nodes.node(configId);
for (var d in configTypeDef.defaults) { for (d in configTypeDef.defaults) {
var input = $("#node-config-input-"+d); if (configTypeDef.defaults.hasOwnProperty(d)) {
configNode[d] = input.val(); configNode[d] = $("#node-config-input-"+d).val();
}
} }
updateConfigNodeSelect(configProperty,configType,configId); updateConfigNodeSelect(configProperty,configType,configId);
} }
@ -637,4 +650,4 @@ RED.editor = function() {
validateNode: validateNode, validateNode: validateNode,
updateNodeProperties: updateNodeProperties // TODO: only exposed for edit-undo updateNodeProperties: updateNodeProperties // TODO: only exposed for edit-undo
} }
}(); })();

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
RED.keyboard = function() { RED.keyboard = (function() {
var active = true; var active = true;
var handlers = {}; var handlers = {};
@ -65,4 +65,4 @@ RED.keyboard = function() {
enable: function(){ active = true; } enable: function(){ active = true; }
} }
}(); })();

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
RED.library = function() { RED.library = (function() {
function loadFlowLibrary() { function loadFlowLibrary() {
@ -21,27 +21,33 @@ RED.library = function() {
//console.log(data); //console.log(data);
var buildMenu = function(data,root) { var buildMenu = function(data,root) {
var i;
var li;
var a;
var ul = document.createElement("ul"); var ul = document.createElement("ul");
ul.className = "dropdown-menu"; ul.className = "dropdown-menu";
if (data.d) { if (data.d) {
for (var i in data.d) { for (i in data.d) {
var li = document.createElement("li"); if (data.d.hasOwnProperty(i)) {
li = document.createElement("li");
li.className = "dropdown-submenu pull-left"; li.className = "dropdown-submenu pull-left";
var a = document.createElement("a"); a = document.createElement("a");
a.href="#"; a.href="#";
a.innerHTML = i; a.innerHTML = i;
li.appendChild(a); li.appendChild(a);
li.appendChild(buildMenu(data.d[i],root+(root!=""?"/":"")+i)); li.appendChild(buildMenu(data.d[i],root+(root!==""?"/":"")+i));
ul.appendChild(li); ul.appendChild(li);
} }
} }
}
if (data.f) { if (data.f) {
for (var i in data.f) { for (i in data.f) {
var li = document.createElement("li"); if (data.f.hasOwnProperty(i)) {
var a = document.createElement("a"); li = document.createElement("li");
a = document.createElement("a");
a.href="#"; a.href="#";
a.innerHTML = data.f[i]; a.innerHTML = data.f[i];
a.flowName = root+(root!=""?"/":"")+data.f[i]; a.flowName = root+(root!==""?"/":"")+data.f[i];
a.onclick = function() { a.onclick = function() {
$.get('library/flows/'+this.flowName, function(data) { $.get('library/flows/'+this.flowName, function(data) {
RED.view.importNodes(data); RED.view.importNodes(data);
@ -51,6 +57,7 @@ RED.library = function() {
ul.appendChild(li); ul.appendChild(li);
} }
} }
}
return ul; return ul;
}; };
var menu = buildMenu(data,""); var menu = buildMenu(data,"");
@ -75,13 +82,13 @@ RED.library = function() {
function buildFileList(root,data) { function buildFileList(root,data) {
var ul = document.createElement("ul"); var ul = document.createElement("ul");
var li;
for (var i in data) { for (var i=0;i<data.length;i++) {
var v = data[i]; var v = data[i];
if (typeof v === "string") { if (typeof v === "string") {
// directory // directory
var li = buildFileListItem(v); li = buildFileListItem(v);
li.onclick = function () { li.onclick = (function () {
var dirName = v; var dirName = v;
return function(e) { return function(e) {
var bcli = $('<li class="active"><span class="divider">/</span> <a href="#">'+dirName+'</a></li>'); var bcli = $('<li class="active"><span class="divider">/</span> <a href="#">'+dirName+'</a></li>');
@ -99,14 +106,14 @@ RED.library = function() {
$("#node-select-library").children().first().replaceWith(buildFileList(root+dirName+"/",data)); $("#node-select-library").children().first().replaceWith(buildFileList(root+dirName+"/",data));
}); });
} }
}(); })();
li.innerHTML = '<i class="icon-folder-close"></i> '+v+"</i>"; li.innerHTML = '<i class="icon-folder-close"></i> '+v+"</i>";
ul.appendChild(li); ul.appendChild(li);
} else { } else {
// file // file
var li = buildFileListItem(v); li = buildFileListItem(v);
li.innerHTML = v.name; li.innerHTML = v.name;
li.onclick = function() { li.onclick = (function() {
var item = v; var item = v;
return function(e) { return function(e) {
$(".list-selected",ul).removeClass("list-selected"); $(".list-selected",ul).removeClass("list-selected");
@ -117,7 +124,7 @@ RED.library = function() {
libraryEditor.setText(data); libraryEditor.setText(data);
}); });
} }
}(); })();
ul.appendChild(li); ul.appendChild(li);
} }
} }
@ -136,7 +143,6 @@ RED.library = function() {
$('#node-input-'+options.type+'-menu-open-library').click(function(e) { $('#node-input-'+options.type+'-menu-open-library').click(function(e) {
$("#node-select-library").children().remove(); $("#node-select-library").children().remove();
var bc = $("#node-dialog-library-breadcrumbs"); var bc = $("#node-dialog-library-breadcrumbs");
bc.children().first().nextAll().remove(); bc.children().first().nextAll().remove();
@ -180,7 +186,7 @@ RED.library = function() {
$("#node-dialog-library-save-folder").attr("value",""); $("#node-dialog-library-save-folder").attr("value","");
var filename = name.replace(/[^\w-]/g,"-"); var filename = name.replace(/[^\w-]/g,"-");
if (filename == "") { if (filename === "") {
filename = "unnamed-"+options.type; filename = "unnamed-"+options.type;
} }
$("#node-dialog-library-save-filename").attr("value",filename+".js"); $("#node-dialog-library-save-filename").attr("value",filename+".js");
@ -221,10 +227,10 @@ RED.library = function() {
text: "Ok", text: "Ok",
click: function() { click: function() {
if (selectedLibraryItem) { if (selectedLibraryItem) {
for (var i in options.fields) { for (var i=0;i<options.fields.length;i++) {
var field = options.fields[i]; var field = options.fields[i];
$("#node-input-"+field).val(selectedLibraryItem[field]); $("#node-input-"+field).val(selectedLibraryItem[field]);
}; }
options.editor.setText(libraryEditor.getText()); options.editor.setText(libraryEditor.getText());
} }
$( this ).dialog( "close" ); $( this ).dialog( "close" );
@ -252,16 +258,16 @@ RED.library = function() {
function saveToLibrary(overwrite) { function saveToLibrary(overwrite) {
var name = $("#node-input-name").val().replace(/(^\s*)|(\s*$)/g,""); var name = $("#node-input-name").val().replace(/(^\s*)|(\s*$)/g,"");
if (name == "") { if (name === "") {
name = "Unnamed "+options.type; name = "Unnamed "+options.type;
} }
var filename = $("#node-dialog-library-save-filename").val().replace(/(^\s*)|(\s*$)/g,""); var filename = $("#node-dialog-library-save-filename").val().replace(/(^\s*)|(\s*$)/g,"");
var pathname = $("#node-dialog-library-save-folder").val().replace(/(^\s*)|(\s*$)/g,""); var pathname = $("#node-dialog-library-save-folder").val().replace(/(^\s*)|(\s*$)/g,"");
if (filename == "" || !/.+\.js$/.test(filename)) { if (filename === "" || !/.+\.js$/.test(filename)) {
RED.notify("Invalid filename","warning"); RED.notify("Invalid filename","warning");
return; return;
} }
var fullpath = pathname+(pathname==""?"":"/")+filename; var fullpath = pathname+(pathname===""?"":"/")+filename;
if (!overwrite) { if (!overwrite) {
//var pathnameParts = pathname.split("/"); //var pathnameParts = pathname.split("/");
//var exists = false; //var exists = false;
@ -290,7 +296,7 @@ RED.library = function() {
//} //}
} }
var queryArgs = []; var queryArgs = [];
for (var i in options.fields) { for (var i=0;i<options.fields.length;i++) {
var field = options.fields[i]; var field = options.fields[i];
if (field == "name") { if (field == "name") {
queryArgs.push("name="+encodeURIComponent(name)); queryArgs.push("name="+encodeURIComponent(name));
@ -356,6 +362,6 @@ RED.library = function() {
create: createUI, create: createUI,
loadFlowLibrary: loadFlowLibrary loadFlowLibrary: loadFlowLibrary
} }
}(); })();

View File

@ -13,17 +13,17 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
RED.notify = function() { RED.notify = (function() {
var currentNotifications = []; var currentNotifications = [];
var c = 0; var c = 0;
return function(msg,type,fixed,timeout) { return function(msg,type,fixed,timeout) {
if (currentNotifications.length > 4) { if (currentNotifications.length > 4) {
var ll = currentNotifications.length; var ll = currentNotifications.length;
for (var i = 0;ll > 4 && i<currentNotifications.length;i+=1) { for (var i = 0;ll > 4 && i<currentNotifications.length;i+=1) {
var n = currentNotifications[i]; var notifiction = currentNotifications[i];
if (!n.fixed) { if (!notifiction.fixed) {
window.clearTimeout(n.timeoutid); window.clearTimeout(notifiction.timeoutid);
n.close(); notifiction.close();
ll -= 1; ll -= 1;
} }
} }
@ -39,7 +39,7 @@ RED.notify = function() {
n.innerHTML = msg; n.innerHTML = msg;
$("#notifications").append(n); $("#notifications").append(n);
$(n).slideDown(300); $(n).slideDown(300);
n.close = function() { n.close = (function() {
var nn = n; var nn = n;
return function() { return function() {
currentNotifications.splice(currentNotifications.indexOf(nn),1); currentNotifications.splice(currentNotifications.indexOf(nn),1);
@ -47,7 +47,7 @@ RED.notify = function() {
nn.parentNode.removeChild(nn); nn.parentNode.removeChild(nn);
}); });
}; };
}(); })();
if (!fixed) { if (!fixed) {
n.timeoutid = window.setTimeout(n.close,timeout||3000); n.timeoutid = window.setTimeout(n.close,timeout||3000);
} }
@ -55,5 +55,5 @@ RED.notify = function() {
c+=1; c+=1;
return n; return n;
} }
}(); })();

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
**/ **/
RED.palette = function() { RED.palette = (function() {
var exclusion = ['config','unknown','deprecated']; var exclusion = ['config','unknown','deprecated'];
var core = ['input', 'output', 'function', 'social', 'storage', 'analysis', 'advanced']; var core = ['input', 'output', 'function', 'social', 'storage', 'analysis', 'advanced'];
@ -64,22 +64,22 @@ RED.palette = function() {
d.style.backgroundColor = def.color; d.style.backgroundColor = def.color;
if (def.outputs > 0) { if (def.outputs > 0) {
var port = document.createElement("div"); var portOut = document.createElement("div");
port.className = "palette_port palette_port_output"; portOut.className = "palette_port palette_port_output";
d.appendChild(port); d.appendChild(portOut);
} }
if (def.inputs > 0) { if (def.inputs > 0) {
var port = document.createElement("div"); var portIn = document.createElement("div");
port.className = "palette_port"; portIn.className = "palette_port";
d.appendChild(port); d.appendChild(portIn);
} }
if ($("#palette-base-category-"+category[0]).length == 0){ if ($("#palette-base-category-"+category[0]).length === 0){
createCategoryContainer(category[0]); createCategoryContainer(category[0]);
} }
if ($("#palette-"+def.category).length == 0) { if ($("#palette-"+def.category).length === 0) {
$("#palette-base-category-"+category[0]).append('<div id="palette-'+def.category+'"></div>'); $("#palette-base-category-"+category[0]).append('<div id="palette-'+def.category+'"></div>');
} }
@ -120,7 +120,7 @@ RED.palette = function() {
function filterChange() { function filterChange() {
var val = $("#palette-search-input").val(); var val = $("#palette-search-input").val();
if (val == "") { if (val === "") {
$("#palette-search-clear").hide(); $("#palette-search-clear").hide();
} else { } else {
$("#palette-search-clear").show(); $("#palette-search-clear").show();
@ -128,7 +128,7 @@ RED.palette = function() {
var re = new RegExp(val); var re = new RegExp(val);
$(".palette_node").each(function(i,el) { $(".palette_node").each(function(i,el) {
if (val == "" || re.test(el.id)) { if (val === "" || re.test(el.id)) {
$(this).show(); $(this).show();
} else { } else {
$(this).hide(); $(this).hide();
@ -165,4 +165,4 @@ RED.palette = function() {
add:addNodeType, add:addNodeType,
remove:removeNodeType remove:removeNodeType
}; };
}(); })();

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
RED.sidebar = function() { RED.sidebar = (function() {
//$('#sidebar').tabs(); //$('#sidebar').tabs();
var sidebar_tabs = RED.tabs.create({ var sidebar_tabs = RED.tabs.create({
@ -150,4 +150,4 @@ RED.sidebar = function() {
containsTab: containsTab containsTab: containsTab
} }
}(); })();

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
RED.sidebar.config = function() { RED.sidebar.config = (function() {
var content = document.createElement("div"); var content = document.createElement("div");
content.id = "tab-config"; content.id = "tab-config";
@ -35,7 +35,7 @@ RED.sidebar.config = function() {
list.empty(); list.empty();
RED.nodes.eachConfig(function(node) { RED.nodes.eachConfig(function(node) {
var li = list.find("#tab-config-list-type-"+node.type); var li = list.find("#tab-config-list-type-"+node.type);
if (li.length == 0) { if (li.length === 0) {
li = $("<li>",{id:"tab-config-list-type-"+node.type}).appendTo(list); li = $("<li>",{id:"tab-config-list-type-"+node.type}).appendTo(list);
$('<div class="tab-config-list-type">'+node.type+'</div>').appendTo(li); $('<div class="tab-config-list-type">'+node.type+'</div>').appendTo(li);
} }
@ -80,4 +80,4 @@ RED.sidebar.config = function() {
return { return {
refresh:refresh refresh:refresh
} }
}(); })();

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
RED.sidebar.info = function() { RED.sidebar.info = (function() {
var content = document.createElement("div"); var content = document.createElement("div");
content.id = "tab-info"; content.id = "tab-info";
@ -24,7 +24,7 @@ RED.sidebar.info = function() {
RED.sidebar.addTab("info",content); RED.sidebar.addTab("info",content);
function jsonFilter(key,value) { function jsonFilter(key,value) {
if (key == "") { if (key === "") {
return value; return value;
} }
var t = typeof value; var t = typeof value;
@ -47,6 +47,7 @@ RED.sidebar.info = function() {
table += "<tr><td>ID</td><td>&nbsp;"+node.id+"</td></tr>"; table += "<tr><td>ID</td><td>&nbsp;"+node.id+"</td></tr>";
table += '<tr class="blank"><td colspan="2">&nbsp;Properties</td></tr>'; table += '<tr class="blank"><td colspan="2">&nbsp;Properties</td></tr>';
for (var n in node._def.defaults) { for (var n in node._def.defaults) {
if (node._def.defaults.hasOwnProperty(n)) {
var val = node[n]||""; var val = node[n]||"";
var type = typeof val; var type = typeof val;
if (type === "string") { if (type === "string") {
@ -73,6 +74,7 @@ RED.sidebar.info = function() {
table += "<tr><td>&nbsp;"+n+"</td><td>"+val+"</td></tr>"; table += "<tr><td>&nbsp;"+n+"</td><td>"+val+"</td></tr>";
} }
}
table += "</tbody></table><br/>"; table += "</tbody></table><br/>";
table += '<div class="node-help">'+($("script[data-help-name|='"+node.type+"']").html()||"")+"</div>"; table += '<div class="node-help">'+($("script[data-help-name|='"+node.type+"']").html()||"")+"</div>";
$("#tab-info").html(table); $("#tab-info").html(table);
@ -84,4 +86,4 @@ RED.sidebar.info = function() {
$("#tab-info").html(""); $("#tab-info").html("");
} }
} }
}(); })();

View File

@ -16,7 +16,7 @@
RED.tabs = function() { RED.tabs = (function() {
function createTabs(options) { function createTabs(options) {
@ -69,7 +69,7 @@ RED.tabs = function() {
var li = ul.find("a[href='#"+id+"']").parent(); var li = ul.find("a[href='#"+id+"']").parent();
if (li.hasClass("active")) { if (li.hasClass("active")) {
var tab = li.prev(); var tab = li.prev();
if (tab.size() == 0) { if (tab.size() === 0) {
tab = li.next(); tab = li.next();
} }
activateTab(tab.find("a")); activateTab(tab.find("a"));
@ -124,4 +124,4 @@ RED.tabs = function() {
return { return {
create: createTabs create: createTabs
} }
}(); })();

View File

@ -15,7 +15,7 @@
**/ **/
RED.touch = RED.touch||{}; RED.touch = RED.touch||{};
RED.touch.radialMenu = function() { RED.touch.radialMenu = (function() {
var touchMenu = null; var touchMenu = null;
@ -60,7 +60,7 @@ RED.touch.radialMenu = function() {
}); });
var menuOpts = []; var menuOpts = [];
function createMenuOpt(x,y,opt) { var createMenuOpt = function(x,y,opt) {
opt.el = menu.append("div") opt.el = menu.append("div")
.style({ .style({
position: "absolute", position: "absolute",
@ -112,7 +112,7 @@ RED.touch.radialMenu = function() {
} }
function hide() { var hide = function() {
isActive = false; isActive = false;
activeOption = null; activeOption = null;
touchMenu.remove(); touchMenu.remove();
@ -182,5 +182,5 @@ RED.touch.radialMenu = function() {
} }
} }
}(); })();

View File

@ -15,7 +15,7 @@
**/ **/
RED.view = function() { RED.view = (function() {
var space_width = 5000, var space_width = 5000,
space_height = 5000, space_height = 5000,
lineCurveScale = 0.75, lineCurveScale = 0.75,
@ -88,11 +88,12 @@ RED.view = function() {
}) })
.on("touchcancel", canvasMouseUp) .on("touchcancel", canvasMouseUp)
.on("touchstart", function() { .on("touchstart", function() {
var touch0;
if (d3.event.touches.length>1) { if (d3.event.touches.length>1) {
clearTimeout(touchStartTime); clearTimeout(touchStartTime);
touchStartTime = null; touchStartTime = null;
d3.event.preventDefault(); d3.event.preventDefault();
var touch0 = d3.event.touches.item(0); touch0 = d3.event.touches.item(0);
var touch1 = d3.event.touches.item(1); var touch1 = d3.event.touches.item(1);
var a = touch0['pageY']-touch1['pageY']; var a = touch0['pageY']-touch1['pageY'];
var b = touch0['pageX']-touch1['pageX']; var b = touch0['pageX']-touch1['pageX'];
@ -110,7 +111,7 @@ RED.view = function() {
startTouchDistance = Math.sqrt((a*a)+(b*b)); startTouchDistance = Math.sqrt((a*a)+(b*b));
} else { } else {
var obj = d3.select(document.body); var obj = d3.select(document.body);
var touch0 = d3.event.touches.item(0); touch0 = d3.event.touches.item(0);
var pos = [touch0.pageX,touch0.pageY]; var pos = [touch0.pageX,touch0.pageY];
startTouchCenter = [touch0.pageX,touch0.pageY]; startTouchCenter = [touch0.pageX,touch0.pageY];
startTouchDistance = 0; startTouchDistance = 0;
@ -137,9 +138,10 @@ RED.view = function() {
d3.event.preventDefault(); d3.event.preventDefault();
return; return;
} }
var touch0;
if (d3.event.touches.length<2) { if (d3.event.touches.length<2) {
if (touchStartTime) { if (touchStartTime) {
var touch0 = d3.event.touches.item(0); touch0 = d3.event.touches.item(0);
var dx = (touch0.pageX-startTouchCenter[0]); var dx = (touch0.pageX-startTouchCenter[0]);
var dy = (touch0.pageY-startTouchCenter[1]); var dy = (touch0.pageY-startTouchCenter[1]);
var d = Math.abs(dx*dx+dy*dy); var d = Math.abs(dx*dx+dy*dy);
@ -152,7 +154,7 @@ RED.view = function() {
} }
canvasMouseMove.call(this); canvasMouseMove.call(this);
} else { } else {
var touch0 = d3.event.touches.item(0); touch0 = d3.event.touches.item(0);
var touch1 = d3.event.touches.item(1); var touch1 = d3.event.touches.item(1);
var a = touch0['pageY']-touch1['pageY']; var a = touch0['pageY']-touch1['pageY'];
var b = touch0['pageX']-touch1['pageX']; var b = touch0['pageX']-touch1['pageX'];
@ -232,7 +234,7 @@ RED.view = function() {
$("#workspace-toolbar").hide(); $("#workspace-toolbar").hide();
} }
var chart = $("#chart"); var chart = $("#chart");
if (activeWorkspace != 0) { if (activeWorkspace !== 0) {
workspaceScrollPositions[activeWorkspace] = { workspaceScrollPositions[activeWorkspace] = {
left:chart.scrollLeft(), left:chart.scrollLeft(),
top:chart.scrollTop() top:chart.scrollTop()
@ -298,7 +300,7 @@ RED.view = function() {
var tabId = RED.nodes.id(); var tabId = RED.nodes.id();
do { do {
workspaceIndex += 1; workspaceIndex += 1;
} while($("#workspace-tabs a[title='Sheet "+workspaceIndex+"']").size() != 0); } while($("#workspace-tabs a[title='Sheet "+workspaceIndex+"']").size() !== 0);
var ws = {type:"tab",id:tabId,label:"Sheet "+workspaceIndex}; var ws = {type:"tab",id:tabId,label:"Sheet "+workspaceIndex};
RED.nodes.addWorkspace(ws); RED.nodes.addWorkspace(ws);
@ -331,7 +333,7 @@ RED.view = function() {
selected_link = null; selected_link = null;
updateSelection(); updateSelection();
} }
if (mouse_mode == 0) { if (mouse_mode === 0) {
if (lasso) { if (lasso) {
lasso.remove(); lasso.remove();
lasso = null; lasso = null;
@ -372,6 +374,8 @@ RED.view = function() {
var oy = parseInt(lasso.attr("oy")); var oy = parseInt(lasso.attr("oy"));
var x = parseInt(lasso.attr("x")); var x = parseInt(lasso.attr("x"));
var y = parseInt(lasso.attr("y")); var y = parseInt(lasso.attr("y"));
var w;
var h;
if (mouse_position[0] < ox) { if (mouse_position[0] < ox) {
x = mouse_position[0]; x = mouse_position[0];
w = ox-x; w = ox-x;
@ -393,19 +397,22 @@ RED.view = function() {
return; return;
} }
if (mouse_mode != RED.state.IMPORT_DRAGGING && !mousedown_node && selected_link == null) return; if (mouse_mode != RED.state.IMPORT_DRAGGING && !mousedown_node && selected_link == null) {
return;
}
var mousePos;
if (mouse_mode == RED.state.JOINING) { if (mouse_mode == RED.state.JOINING) {
// update drag line // update drag line
drag_line.attr("class", "drag_line"); drag_line.attr("class", "drag_line");
var mousePos = mouse_position; mousePos = mouse_position;
var numOutputs = (mousedown_port_type == 0)?(mousedown_node.outputs || 1):1; var numOutputs = (mousedown_port_type === 0)?(mousedown_node.outputs || 1):1;
var sourcePort = mousedown_port_index; var sourcePort = mousedown_port_index;
var y = -((numOutputs-1)/2)*13 +13*sourcePort; var portY = -((numOutputs-1)/2)*13 +13*sourcePort;
var sc = (mousedown_port_type == 0)?1:-1; var sc = (mousedown_port_type === 0)?1:-1;
var dy = mousePos[1]-(mousedown_node.y+y); var dy = mousePos[1]-(mousedown_node.y+portY);
var dx = mousePos[0]-(mousedown_node.x+sc*mousedown_node.w/2); var dx = mousePos[0]-(mousedown_node.x+sc*mousedown_node.w/2);
var delta = Math.sqrt(dy*dy+dx*dx); var delta = Math.sqrt(dy*dy+dx*dx);
var scale = lineCurveScale; var scale = lineCurveScale;
@ -422,25 +429,27 @@ RED.view = function() {
} }
drag_line.attr("d", drag_line.attr("d",
"M "+(mousedown_node.x+sc*mousedown_node.w/2)+" "+(mousedown_node.y+y)+ "M "+(mousedown_node.x+sc*mousedown_node.w/2)+" "+(mousedown_node.y+portY)+
" C "+(mousedown_node.x+sc*(mousedown_node.w/2+node_width*scale))+" "+(mousedown_node.y+y+scaleY*node_height)+" "+ " C "+(mousedown_node.x+sc*(mousedown_node.w/2+node_width*scale))+" "+(mousedown_node.y+portY+scaleY*node_height)+" "+
(mousePos[0]-sc*(scale)*node_width)+" "+(mousePos[1]-scaleY*node_height)+" "+ (mousePos[0]-sc*(scale)*node_width)+" "+(mousePos[1]-scaleY*node_height)+" "+
mousePos[0]+" "+mousePos[1] mousePos[0]+" "+mousePos[1]
); );
d3.event.preventDefault(); d3.event.preventDefault();
} else if (mouse_mode == RED.state.MOVING) { } else if (mouse_mode == RED.state.MOVING) {
var m = mouse_position; mousePos = mouse_position;
var d = (mouse_offset[0]-m[0])*(mouse_offset[0]-m[0]) + (mouse_offset[1]-m[1])*(mouse_offset[1]-m[1]); var d = (mouse_offset[0]-mousePos[0])*(mouse_offset[0]-mousePos[0]) + (mouse_offset[1]-mousePos[1])*(mouse_offset[1]-mousePos[1]);
if (d > 2) { if (d > 2) {
mouse_mode = RED.state.MOVING_ACTIVE; mouse_mode = RED.state.MOVING_ACTIVE;
clickElapsed = 0; clickElapsed = 0;
} }
} else if (mouse_mode == RED.state.MOVING_ACTIVE || mouse_mode == RED.state.IMPORT_DRAGGING) { } else if (mouse_mode == RED.state.MOVING_ACTIVE || mouse_mode == RED.state.IMPORT_DRAGGING) {
var mousePos = mouse_position; mousePos = mouse_position;
var node;
var i;
var minX = 0; var minX = 0;
var minY = 0; var minY = 0;
for (var n = 0; n<moving_set.length; n++) { for (var n = 0; n<moving_set.length; n++) {
var node = moving_set[n]; node = moving_set[n];
if (d3.event.shiftKey) { if (d3.event.shiftKey) {
node.n.ox = node.n.x; node.n.ox = node.n.x;
node.n.oy = node.n.y; node.n.oy = node.n.y;
@ -451,21 +460,21 @@ RED.view = function() {
minX = Math.min(node.n.x-node.n.w/2-5,minX); minX = Math.min(node.n.x-node.n.w/2-5,minX);
minY = Math.min(node.n.y-node.n.h/2-5,minY); minY = Math.min(node.n.y-node.n.h/2-5,minY);
} }
if (minX != 0 || minY != 0) { if (minX !== 0 || minY !== 0) {
for (var n = 0; n<moving_set.length; n++) { for (i = 0; i<moving_set.length; i++) {
var node = moving_set[n]; node = moving_set[i];
node.n.x -= minX; node.n.x -= minX;
node.n.y -= minY; node.n.y -= minY;
} }
} }
if (d3.event.shiftKey && moving_set.length > 0) { if (d3.event.shiftKey && moving_set.length > 0) {
var gridOffset = [0,0]; var gridOffset = [0,0];
var node = moving_set[0]; node = moving_set[0];
gridOffset[0] = node.n.x-(20*Math.floor((node.n.x-node.n.w/2)/20)+node.n.w/2); gridOffset[0] = node.n.x-(20*Math.floor((node.n.x-node.n.w/2)/20)+node.n.w/2);
gridOffset[1] = node.n.y-(20*Math.floor(node.n.y/20)); gridOffset[1] = node.n.y-(20*Math.floor(node.n.y/20));
if (gridOffset[0] != 0 || gridOffset[1] != 0) { if (gridOffset[0] !== 0 || gridOffset[1] !== 0) {
for (var n = 0; n<moving_set.length; n++) { for (i = 0; i<moving_set.length; i++) {
var node = moving_set[n]; node = moving_set[i];
node.n.x -= gridOffset[0]; node.n.x -= gridOffset[0];
node.n.y -= gridOffset[1]; node.n.y -= gridOffset[1];
if (node.n.x == node.n.ox && node.n.y == node.n.oy) { if (node.n.x == node.n.ox && node.n.y == node.n.oy) {
@ -509,8 +518,8 @@ RED.view = function() {
if (mouse_mode == RED.state.MOVING_ACTIVE) { if (mouse_mode == RED.state.MOVING_ACTIVE) {
if (moving_set.length > 0) { if (moving_set.length > 0) {
var ns = []; var ns = [];
for (var i in moving_set) { for (var j=0;j<moving_set.length;j++) {
ns.push({n:moving_set[i].n,ox:moving_set[i].ox,oy:moving_set[i].oy}); ns.push({n:moving_set[j].n,ox:moving_set[j].ox,oy:moving_set[j].oy});
} }
RED.history.push({t:'move',nodes:ns,dirty:dirty}); RED.history.push({t:'move',nodes:ns,dirty:dirty});
} }
@ -561,8 +570,10 @@ RED.view = function() {
nn.changed = true; nn.changed = true;
for (var d in nn._def.defaults) { for (var d in nn._def.defaults) {
if (nn._def.defaults.hasOwnProperty(d)) {
nn[d] = nn._def.defaults[d].value; nn[d] = nn._def.defaults[d].value;
} }
}
if (nn._def.onadd) { if (nn._def.onadd) {
nn._def.onadd.call(nn); nn._def.onadd.call(nn);
@ -619,7 +630,7 @@ RED.view = function() {
} }
function clearSelection() { function clearSelection() {
for (var i in moving_set) { for (var i=0;i<moving_set.length;i++) {
var n = moving_set[i]; var n = moving_set[i];
n.n.dirty = true; n.n.dirty = true;
n.n.selected = false; n.n.selected = false;
@ -629,7 +640,7 @@ RED.view = function() {
} }
function updateSelection() { function updateSelection() {
if (moving_set.length == 0) { if (moving_set.length === 0) {
$("#li-menu-export").addClass("disabled"); $("#li-menu-export").addClass("disabled");
$("#li-menu-export-clipboard").addClass("disabled"); $("#li-menu-export-clipboard").addClass("disabled");
$("#li-menu-export-library").addClass("disabled"); $("#li-menu-export-library").addClass("disabled");
@ -638,7 +649,7 @@ RED.view = function() {
$("#li-menu-export-clipboard").removeClass("disabled"); $("#li-menu-export-clipboard").removeClass("disabled");
$("#li-menu-export-library").removeClass("disabled"); $("#li-menu-export-library").removeClass("disabled");
} }
if (moving_set.length == 0 && selected_link == null) { if (moving_set.length === 0 && selected_link == null) {
RED.keyboard.remove(/* backspace */ 8); RED.keyboard.remove(/* backspace */ 8);
RED.keyboard.remove(/* delete */ 46); RED.keyboard.remove(/* delete */ 46);
RED.keyboard.remove(/* c */ 67); RED.keyboard.remove(/* c */ 67);
@ -649,16 +660,16 @@ RED.view = function() {
RED.keyboard.add(/* c */ 67,{ctrl:true},function(){copySelection();d3.event.preventDefault();}); RED.keyboard.add(/* c */ 67,{ctrl:true},function(){copySelection();d3.event.preventDefault();});
RED.keyboard.add(/* x */ 88,{ctrl:true},function(){copySelection();deleteSelection();d3.event.preventDefault();}); RED.keyboard.add(/* x */ 88,{ctrl:true},function(){copySelection();deleteSelection();d3.event.preventDefault();});
} }
if (moving_set.length == 0) { if (moving_set.length === 0) {
RED.keyboard.remove(/* up */ 38); RED.keyboard.remove(/* up */ 38);
RED.keyboard.remove(/* down */ 40); RED.keyboard.remove(/* down */ 40);
RED.keyboard.remove(/* left */ 37); RED.keyboard.remove(/* left */ 37);
RED.keyboard.remove(/* right*/ 39); RED.keyboard.remove(/* right*/ 39);
} else { } else {
RED.keyboard.add(/* up */ 38, function() { d3.event.shiftKey?moveSelection( 0,-20):moveSelection( 0,-1);d3.event.preventDefault();},endKeyboardMove); RED.keyboard.add(/* up */ 38, function() { if(d3.event.shiftKey){moveSelection( 0,-20)}else{moveSelection( 0,-1);}d3.event.preventDefault();},endKeyboardMove);
RED.keyboard.add(/* down */ 40, function() { d3.event.shiftKey?moveSelection( 0, 20):moveSelection( 0, 1);d3.event.preventDefault();},endKeyboardMove); RED.keyboard.add(/* down */ 40, function() { if(d3.event.shiftKey){moveSelection( 0, 20)}else{moveSelection( 0, 1);}d3.event.preventDefault();},endKeyboardMove);
RED.keyboard.add(/* left */ 37, function() { d3.event.shiftKey?moveSelection(-20, 0):moveSelection(-1, 0);d3.event.preventDefault();},endKeyboardMove); RED.keyboard.add(/* left */ 37, function() { if(d3.event.shiftKey){moveSelection(-20, 0)}else{moveSelection(-1, 0);}d3.event.preventDefault();},endKeyboardMove);
RED.keyboard.add(/* right*/ 39, function() { d3.event.shiftKey?moveSelection( 20, 0):moveSelection( 1, 0);d3.event.preventDefault();},endKeyboardMove); RED.keyboard.add(/* right*/ 39, function() { if(d3.event.shiftKey){moveSelection( 20, 0)}else{moveSelection( 1, 0);}d3.event.preventDefault();},endKeyboardMove);
} }
if (moving_set.length == 1) { if (moving_set.length == 1) {
RED.sidebar.info.refresh(moving_set[0].n); RED.sidebar.info.refresh(moving_set[0].n);
@ -678,9 +689,10 @@ RED.view = function() {
function moveSelection(dx,dy) { function moveSelection(dx,dy) {
var minX = 0; var minX = 0;
var minY = 0; var minY = 0;
var node;
for (var i=0;i<moving_set.length;i++) { for (var i=0;i<moving_set.length;i++) {
var node = moving_set[i]; node = moving_set[i];
if (node.ox == null && node.oy == null) { if (node.ox == null && node.oy == null) {
node.ox = node.n.x; node.ox = node.n.x;
node.oy = node.n.y; node.oy = node.n.y;
@ -692,9 +704,9 @@ RED.view = function() {
minY = Math.min(node.n.y-node.n.h/2-5,minY); minY = Math.min(node.n.y-node.n.h/2-5,minY);
} }
if (minX != 0 || minY != 0) { if (minX !== 0 || minY !== 0) {
for (var n = 0; n<moving_set.length; n++) { for (var n = 0; n<moving_set.length; n++) {
var node = moving_set[n]; node = moving_set[n];
node.n.x -= minX; node.n.x -= minX;
node.n.y -= minY; node.n.y -= minY;
} }
@ -707,10 +719,12 @@ RED.view = function() {
var removedLinks = []; var removedLinks = [];
var startDirty = dirty; var startDirty = dirty;
if (moving_set.length > 0) { if (moving_set.length > 0) {
for (var i in moving_set) { for (var i=0;i<moving_set.length;i++) {
var node = moving_set[i].n; var node = moving_set[i].n;
node.selected = false; node.selected = false;
if (node.x < 0) {node.x = 25}; if (node.x < 0) {
node.x = 25
}
var rmlinks = RED.nodes.remove(node.id); var rmlinks = RED.nodes.remove(node.id);
removedNodes.push(node); removedNodes.push(node);
removedLinks = removedLinks.concat(rmlinks); removedLinks = removedLinks.concat(rmlinks);
@ -733,7 +747,7 @@ RED.view = function() {
function copySelection() { function copySelection() {
if (moving_set.length > 0) { if (moving_set.length > 0) {
var nns = []; var nns = [];
for (var n in moving_set) { for (var n=0;n<moving_set.length;n++) {
var node = moving_set[n].n; var node = moving_set[n].n;
nns.push(RED.nodes.convertNode(node)); nns.push(RED.nodes.convertNode(node));
} }
@ -773,7 +787,7 @@ RED.view = function() {
mousedown_port_index = portIndex || 0; mousedown_port_index = portIndex || 0;
document.body.style.cursor = "crosshair"; document.body.style.cursor = "crosshair";
d3.event.preventDefault(); d3.event.preventDefault();
}; }
function portMouseUp(d,portType,portIndex) { function portMouseUp(d,portType,portIndex) {
document.body.style.cursor = ""; document.body.style.cursor = "";
@ -800,7 +814,7 @@ RED.view = function() {
return; return;
} }
var src,dst,src_port; var src,dst,src_port;
if (mousedown_port_type == 0) { if (mousedown_port_type === 0) {
src = mousedown_node; src = mousedown_node;
src_port = mousedown_port_index; src_port = mousedown_port_index;
dst = mouseup_node; dst = mouseup_node;
@ -856,9 +870,11 @@ RED.view = function() {
dblClickPrimed = (lastClickNode == mousedown_node); dblClickPrimed = (lastClickNode == mousedown_node);
lastClickNode = mousedown_node; lastClickNode = mousedown_node;
var i;
if (d.selected && d3.event.ctrlKey) { if (d.selected && d3.event.ctrlKey) {
d.selected = false; d.selected = false;
for (var i=0;i<moving_set.length;i+=1) { for (i=0;i<moving_set.length;i+=1) {
if (moving_set[i].n === d) { if (moving_set[i].n === d) {
moving_set.splice(i,1); moving_set.splice(i,1);
break; break;
@ -868,10 +884,10 @@ RED.view = function() {
if (d3.event.shiftKey) { if (d3.event.shiftKey) {
clearSelection(); clearSelection();
var cnodes = RED.nodes.getAllFlowNodes(mousedown_node); var cnodes = RED.nodes.getAllFlowNodes(mousedown_node);
for (var i in cnodes) { for (var n=0;n<cnodes.length;n++) {
cnodes[i].selected = true; cnodes[n].selected = true;
cnodes[i].dirty = true; cnodes[n].dirty = true;
moving_set.push({n:cnodes[i]}); moving_set.push({n:cnodes[n]});
} }
} else if (!d.selected) { } else if (!d.selected) {
if (!d3.event.ctrlKey) { if (!d3.event.ctrlKey) {
@ -886,7 +902,7 @@ RED.view = function() {
var mouse = d3.touches(this)[0]||d3.mouse(this); var mouse = d3.touches(this)[0]||d3.mouse(this);
mouse[0] += d.x-d.w/2; mouse[0] += d.x-d.w/2;
mouse[1] += d.y-d.h/2; mouse[1] += d.y-d.h/2;
for (var i in moving_set) { for (i=0;i<moving_set.length;i++) {
moving_set[i].ox = moving_set[i].n.x; moving_set[i].ox = moving_set[i].n.x;
moving_set[i].oy = moving_set[i].n.y; moving_set[i].oy = moving_set[i].n.y;
moving_set[i].dx = moving_set[i].n.x-mouse[0]; moving_set[i].dx = moving_set[i].n.x-mouse[0];
@ -921,13 +937,13 @@ RED.view = function() {
function showTouchMenu(obj,pos) { function showTouchMenu(obj,pos) {
var mdn = mousedown_node; var mdn = mousedown_node;
var options = []; var options = [];
options.push({name:"delete",disabled:(moving_set.length==0),onselect:function() {deleteSelection();}}); options.push({name:"delete",disabled:(moving_set.length===0),onselect:function() {deleteSelection();}});
options.push({name:"cut",disabled:(moving_set.length==0),onselect:function() {copySelection();deleteSelection();}}); options.push({name:"cut",disabled:(moving_set.length===0),onselect:function() {copySelection();deleteSelection();}});
options.push({name:"copy",disabled:(moving_set.length==0),onselect:function() {copySelection();}}); options.push({name:"copy",disabled:(moving_set.length===0),onselect:function() {copySelection();}});
options.push({name:"paste",disabled:(clipboard.length==0),onselect:function() {importNodes(clipboard,true);}}); options.push({name:"paste",disabled:(clipboard.length===0),onselect:function() {importNodes(clipboard,true);}});
options.push({name:"edit",disabled:(moving_set.length != 1),onselect:function() { RED.editor.edit(mdn);}}); options.push({name:"edit",disabled:(moving_set.length != 1),onselect:function() { RED.editor.edit(mdn);}});
options.push({name:"select",onselect:function() {selectAll();}}); options.push({name:"select",onselect:function() {selectAll();}});
options.push({name:"undo",disabled:(RED.history.depth() == 0),onselect:function() {RED.history.pop();}}); options.push({name:"undo",disabled:(RED.history.depth() === 0),onselect:function() {RED.history.pop();}});
RED.touch.radialMenu.show(obj,pos,options); RED.touch.radialMenu.show(obj,pos,options);
resetMouseVars(); resetMouseVars();
@ -1023,7 +1039,7 @@ RED.view = function() {
nodeMouseUp.call(this,d); nodeMouseUp.call(this,d);
}) })
.on("mouseover",function(d) { .on("mouseover",function(d) {
if (mouse_mode == 0) { if (mouse_mode === 0) {
var node = d3.select(this); var node = d3.select(this);
node.classed("node_hovered",true); node.classed("node_hovered",true);
} }
@ -1172,16 +1188,16 @@ RED.view = function() {
d.ports = d.ports || d3.range(numOutputs); d.ports = d.ports || d3.range(numOutputs);
d._ports = thisNode.selectAll(".port_output").data(d.ports); d._ports = thisNode.selectAll(".port_output").data(d.ports);
d._ports.enter().append("rect").attr("class","port port_output").attr("rx",3).attr("ry",3).attr("width",10).attr("height",10) d._ports.enter().append("rect").attr("class","port port_output").attr("rx",3).attr("ry",3).attr("width",10).attr("height",10)
.on("mousedown",function(){var node = d; return function(d,i){portMouseDown(node,0,i);}}() ) .on("mousedown",(function(){var node = d; return function(d,i){portMouseDown(node,0,i);}})() )
.on("touchstart",function(){var node = d; return function(d,i){portMouseDown(node,0,i);}}() ) .on("touchstart",(function(){var node = d; return function(d,i){portMouseDown(node,0,i);}})() )
.on("mouseup",function(){var node = d; return function(d,i){portMouseUp(node,0,i);}}() ) .on("mouseup",(function(){var node = d; return function(d,i){portMouseUp(node,0,i);}})() )
.on("touchend",function(){var node = d; return function(d,i){portMouseUp(node,0,i);}}() ) .on("touchend",(function(){var node = d; return function(d,i){portMouseUp(node,0,i);}})() )
.on("mouseover",function(d,i) { var port = d3.select(this); port.classed("port_hovered",(mouse_mode!=RED.state.JOINING || mousedown_port_type != 0 ));}) .on("mouseover",function(d,i) { var port = d3.select(this); port.classed("port_hovered",(mouse_mode!=RED.state.JOINING || mousedown_port_type !== 0 ));})
.on("mouseout",function(d,i) { var port = d3.select(this); port.classed("port_hovered",false);}); .on("mouseout",function(d,i) { var port = d3.select(this); port.classed("port_hovered",false);});
d._ports.exit().remove(); d._ports.exit().remove();
if (d._ports) { if (d._ports) {
var numOutputs = d.outputs || 1; numOutputs = d.outputs || 1;
var y = (d.h/2)-((numOutputs-1)/2)*13; y = (d.h/2)-((numOutputs-1)/2)*13;
var x = d.w - 5; var x = d.w - 5;
d._ports.each(function(d,i) { d._ports.each(function(d,i) {
var port = d3.select(this); var port = d3.select(this);
@ -1404,9 +1420,11 @@ RED.view = function() {
var minX = 0; var minX = 0;
var minY = 0; var minY = 0;
var i;
var node;
for (var i in new_ms) { for (i=0;i<new_ms.length;i++) {
var node = new_ms[i]; node = new_ms[i];
node.n.selected = true; node.n.selected = true;
node.n.changed = true; node.n.changed = true;
node.n.x -= dx - mouse_position[0]; node.n.x -= dx - mouse_position[0];
@ -1416,8 +1434,8 @@ RED.view = function() {
minX = Math.min(node.n.x-node_width/2-5,minX); minX = Math.min(node.n.x-node_width/2-5,minX);
minY = Math.min(node.n.y-node_height/2-5,minY); minY = Math.min(node.n.y-node_height/2-5,minY);
} }
for (var i in new_ms) { for (i=0;i<new_ms.length;i++) {
var node = new_ms[i]; node = new_ms[i];
node.n.x -= minX; node.n.x -= minX;
node.n.y -= minY; node.n.y -= minY;
node.dx -= minX; node.dx -= minX;
@ -1622,4 +1640,4 @@ RED.view = function() {
redraw(); redraw();
} }
}; };
}(); })();