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-contrib-jshint');
grunt.registerTask('default', ['jshint:core','jshint:tests','simplemocha:core','simplemocha:nodes']);
grunt.registerTask('all', ['jshint:core','jshint:nodes','jshint:editor','default']);
grunt.registerTask('default', ['jshint:core','jshint:tests','jshint:editor','simplemocha:core','simplemocha:nodes']);
};

View File

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

View File

@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
RED.history = function() {
RED.history = (function() {
var undo_history = [];
return {
//TODO: this function is a placeholder until there is a 'save' event that can be listened to
markAllDirty: function() {
for (var i in undo_history) {
for (var i=0;i<undo_history.length;i++) {
undo_history[i].dirty = true;
}
},
@ -31,42 +31,45 @@ RED.history = function() {
},
pop: function() {
var ev = undo_history.pop();
var i;
if (ev) {
if (ev.t == 'add') {
for (var i in ev.nodes) {
for (i=0;i<ev.nodes.length;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]);
}
for (var i in ev.workspaces) {
for (i=0;i<ev.workspaces.length;i++) {
RED.nodes.removeWorkspace(ev.workspaces[i].id);
RED.view.removeWorkspace(ev.workspaces[i]);
}
} 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.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]);
}
for (var i in ev.links) {
for (i=0;i<ev.links.length;i++) {
RED.nodes.addLink(ev.links[i]);
}
} else if (ev.t == "move") {
for (var i in ev.nodes) {
for (i=0;i<ev.nodes.length;i++) {
var n = ev.nodes[i];
n.n.x = n.ox;
n.n.y = n.oy;
n.n.dirty = true;
}
} else if (ev.t == "edit") {
for (var i in ev.changes) {
ev.node[i] = ev.changes[i];
for (i in ev.changes) {
if (ev.changes.hasOwnProperty(i)) {
ev.node[i] = ev.changes[i];
}
}
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.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
* limitations under the License.
**/
var RED = function() {
var RED = (function() {
$('#btn-keyboard-shortcuts').click(function(){showHelp();});
@ -177,8 +177,9 @@ var RED = function() {
}
});
RED.comms.subscribe("node/#",function(topic,msg) {
var i;
if (topic == "node/added") {
for (var i=0;i<msg.length;i++) {
for (i=0;i<msg.length;i++) {
var m = msg[i];
var id = m.id;
$.get('nodes/'+id, function(data) {
@ -189,7 +190,7 @@ var RED = function() {
}
} else if (topic == "node/removed") {
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]);
}
var typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>";
@ -235,4 +236,4 @@ var RED = function() {
return {
};
}();
})();

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
RED.nodes = function() {
RED.nodes = (function() {
var node_defs = {};
var nodes = [];
@ -45,14 +45,16 @@ RED.nodes = function() {
nodes.push(n);
var updatedConfigNode = false;
for (var d in n._def.defaults) {
var property = n._def.defaults[d];
if (property.type) {
var type = getType(property.type)
if (type && type.category == "config") {
var configNode = configNodes[n[d]];
if (configNode) {
updatedConfigNode = true;
configNode.users.push(n);
if (n._def.defaults.hasOwnProperty(d)) {
var property = n._def.defaults[d];
if (property.type) {
var type = getType(property.type)
if (type && type.category == "config") {
var configNode = configNodes[n[d]];
if (configNode) {
updatedConfigNode = true;
configNode.users.push(n);
}
}
}
}
@ -96,15 +98,17 @@ RED.nodes = function() {
}
var updatedConfigNode = false;
for (var d in node._def.defaults) {
var property = node._def.defaults[d];
if (property.type) {
var type = getType(property.type)
if (type && type.category == "config") {
var configNode = configNodes[node[d]];
if (configNode) {
updatedConfigNode = true;
var users = configNode.users;
users.splice(users.indexOf(node),1);
if (node._def.defaults.hasOwnProperty(d)) {
var property = node._def.defaults[d];
if (property.type) {
var type = getType(property.type)
if (type && type.category == "config") {
var configNode = configNodes[node[d]];
if (configNode) {
updatedConfigNode = true;
var users = configNode.users;
users.splice(users.indexOf(node),1);
}
}
}
}
@ -124,7 +128,7 @@ RED.nodes = function() {
}
function refreshValidation() {
for (var n in nodes) {
for (var n=0;n<nodes.length;n++) {
RED.editor.validateNode(nodes[n]);
}
}
@ -139,13 +143,14 @@ RED.nodes = function() {
delete workspaces[id];
var removedNodes = [];
var removedLinks = [];
for (var n in nodes) {
var n;
for (n=0;n<nodes.length;n++) {
var node = nodes[n];
if (node.z == id) {
removedNodes.push(node);
}
}
for (var n in removedNodes) {
for (n=0;n<removedNodes.length;n++) {
var rmlinks = removeNode(removedNodes[n].id);
removedLinks = removedLinks.concat(rmlinks);
}
@ -157,10 +162,10 @@ RED.nodes = function() {
visited[node.id] = true;
var nns = [node];
var stack = [node];
while(stack.length != 0) {
while(stack.length !== 0) {
var n = stack.shift();
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;
if (!visited[child.id]) {
visited[child.id] = true;
@ -181,7 +186,9 @@ RED.nodes = function() {
node.id = n.id;
node.type = n.type;
for (var d in n._def.defaults) {
node[d] = n[d];
if (n._def.defaults.hasOwnProperty(d)) {
node[d] = n[d];
}
}
if(exportCreds && n.credentials) {
node.credentials = {};
@ -202,8 +209,8 @@ RED.nodes = function() {
node.wires.push([]);
}
var wires = links.filter(function(d){return d.source === n;});
for (var i in wires) {
var w = wires[i];
for (var j=0;j<wires.length;j++) {
var w = wires[j];
node.wires[w.sourcePort].push(w.target.id);
}
}
@ -216,7 +223,7 @@ RED.nodes = function() {
function createExportableNodeSet(set) {
var nns = [];
var exportedConfigNodes = {};
for (var n in set) {
for (var n=0;n<set.length;n++) {
var node = set[n].n;
var convertedNode = RED.nodes.convertNode(node);
for (var d in node._def.defaults) {
@ -242,13 +249,18 @@ RED.nodes = function() {
//TODO: rename this (createCompleteNodeSet)
function createCompleteNodeSet() {
var nns = [];
for (var i in workspaces) {
nns.push(workspaces[i]);
var i;
for (i in workspaces) {
if (workspaces.hasOwnProperty(i)) {
nns.push(workspaces[i]);
}
}
for (var i in configNodes) {
nns.push(convertNode(configNodes[i], true));
for (i in configNodes) {
if (configNodes.hasOwnProperty(i)) {
nns.push(convertNode(configNodes[i], true));
}
}
for (var i in nodes) {
for (i=0;i<nodes.length;i++) {
var node = nodes[i];
nns.push(convertNode(node, true));
}
@ -257,9 +269,11 @@ RED.nodes = function() {
function importNodes(newNodesObj,createNewIds) {
try {
var i;
var n;
var newNodes;
if (typeof newNodesObj === "string") {
if (newNodesObj == "") {
if (newNodesObj === "") {
return;
}
newNodes = JSON.parse(newNodesObj);
@ -271,8 +285,8 @@ RED.nodes = function() {
newNodes = [newNodes];
}
var unknownTypes = [];
for (var i=0;i<newNodes.length;i++) {
var n = newNodes[i];
for (i=0;i<newNodes.length;i++) {
n = newNodes[i];
// TODO: remove workspace in next release+1
if (n.type != "workspace" && n.type != "tab" && !getType(n.type)) {
// 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");
}
for (var i in newNodes) {
var n = newNodes[i];
for (i=0;i<newNodes.length;i++) {
n = newNodes[i];
// TODO: remove workspace in next release+1
if (n.type === "workspace" || n.type === "tab") {
if (n.type === "workspace") {
@ -319,8 +333,8 @@ RED.nodes = function() {
var new_nodes = [];
var new_links = [];
for (var i in newNodes) {
var n = newNodes[i];
for (i=0;i<newNodes.length;i++) {
n = newNodes[i];
// TODO: remove workspace in next release+1
if (n.type !== "workspace" && n.type !== "tab") {
var def = getType(n.type);
@ -328,7 +342,9 @@ RED.nodes = function() {
if (!RED.nodes.node(n.id)) {
var configNode = {id:n.id,type:n.type,users:[]};
for (var d in def.defaults) {
configNode[d] = n[d];
if (def.defaults.hasOwnProperty(d)) {
configNode[d] = n[d];
}
}
configNode.label = def.label;
configNode._def = def;
@ -358,8 +374,10 @@ RED.nodes = function() {
}
node.outputs = n.outputs||node._def.outputs;
for (var d in node._def.defaults) {
node[d] = n[d];
for (var d2 in node._def.defaults) {
if (node._def.defaults.hasOwnProperty(d2)) {
node[d2] = n[d2];
}
}
addNode(node);
@ -369,11 +387,11 @@ RED.nodes = function() {
}
}
}
for (var i in new_nodes) {
var n = new_nodes[i];
for (var w1 in n.wires) {
for (i=0;i<new_nodes.length;i++) {
n = new_nodes[i];
for (var w1=0;w1<n.wires.length;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) {
var link = {source:n,sourcePort:w1,target:node_map[wires[w2]]};
addLink(link);
@ -404,18 +422,20 @@ RED.nodes = function() {
removeWorkspace: removeWorkspace,
workspace: getWorkspace,
eachNode: function(cb) {
for (var n in nodes) {
for (var n=0;n<nodes.length;n++) {
cb(nodes[n]);
}
},
eachLink: function(cb) {
for (var l in links) {
for (var l=0;l<links.length;l++) {
cb(links[l]);
}
},
eachConfig: function(cb) {
for (var id in configNodes) {
cb(configNodes[id]);
if (configNodes.hasOwnProperty(id)) {
cb(configNodes[id]);
}
}
},
node: getNode,
@ -428,4 +448,4 @@ RED.nodes = function() {
nodes: nodes, // 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
* limitations under the License.
**/
RED.editor = function() {
RED.editor = (function() {
var editing_node = null;
// TODO: should IMPORT/EXPORT get their own dialogs?
@ -97,13 +97,12 @@ RED.editor = function() {
while (node.outputs < node.ports.length) {
node.ports.pop();
}
var removedLinks = [];
RED.nodes.eachLink(function(l) {
if (l.source === node && l.sourcePort >= node.outputs) {
removedLinks.push(l);
}
});
for (var l in removedLinks) {
for (var l=0;l<removedLinks.length;l++) {
RED.nodes.removeLink(removedLinks[l]);
}
} else if (node.outputs > node.ports.length) {
@ -129,15 +128,17 @@ RED.editor = function() {
var changes = {};
var changed = false;
var wasDirty = RED.view.dirty();
var d;
if (editing_node._def.oneditsave) {
var oldValues = {};
for (var d in editing_node._def.defaults) {
if (typeof editing_node[d] === "string" || typeof editing_node[d] === "number") {
oldValues[d] = editing_node[d];
} else {
oldValues[d] = $.extend(true,{},{v:editing_node[d]}).v;
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") {
oldValues[d] = editing_node[d];
} else {
oldValues[d] = $.extend(true,{},{v:editing_node[d]}).v;
}
}
}
var rc = editing_node._def.oneditsave.call(editing_node);
@ -145,16 +146,18 @@ RED.editor = function() {
changed = true;
}
for (var d in editing_node._def.defaults) {
if (oldValues[d] === null || typeof oldValues[d] === "string" || typeof oldValues[d] === "number") {
if (oldValues[d] !== editing_node[d]) {
changes[d] = oldValues[d];
changed = true;
}
} else {
if (JSON.stringify(oldValues[d]) !== JSON.stringify(editing_node[d])) {
changes[d] = oldValues[d];
changed = true;
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] !== editing_node[d]) {
changes[d] = oldValues[d];
changed = true;
}
} else {
if (JSON.stringify(oldValues[d]) !== JSON.stringify(editing_node[d])) {
changes[d] = oldValues[d];
changed = true;
}
}
}
}
@ -163,35 +166,37 @@ RED.editor = function() {
}
if (editing_node._def.defaults) {
for (var d in editing_node._def.defaults) {
var input = $("#node-input-"+d);
var newValue;
if (input.attr('type') === "checkbox") {
newValue = input.prop('checked');
} else {
newValue = input.val();
}
if (newValue != null) {
if (editing_node[d] != newValue) {
if (editing_node._def.defaults[d].type) {
if (newValue == "_ADD_") {
newValue = "";
}
// Change to a related config node
var configNode = RED.nodes.node(editing_node[d]);
if (configNode) {
var users = configNode.users;
users.splice(users.indexOf(editing_node),1);
}
var configNode = RED.nodes.node(newValue);
if (configNode) {
configNode.users.push(editing_node);
for (d in editing_node._def.defaults) {
if (editing_node._def.defaults.hasOwnProperty(d)) {
var input = $("#node-input-"+d);
var newValue;
if (input.attr('type') === "checkbox") {
newValue = input.prop('checked');
} else {
newValue = input.val();
}
if (newValue != null) {
if (editing_node[d] != newValue) {
if (editing_node._def.defaults[d].type) {
if (newValue == "_ADD_") {
newValue = "";
}
// Change to a related config node
var configNode = RED.nodes.node(editing_node[d]);
if (configNode) {
var users = configNode.users;
users.splice(users.indexOf(editing_node),1);
}
configNode = RED.nodes.node(newValue);
if (configNode) {
configNode.users.push(editing_node);
}
}
changes[d] = editing_node[d];
editing_node[d] = newValue;
changed = true;
}
changes[d] = editing_node[d];
editing_node[d] = newValue;
changed = true;
}
}
}
@ -224,7 +229,7 @@ RED.editor = function() {
RED.notify("Saved nodes","success");
});
}
};
}
} else if (RED.view.state() == RED.state.IMPORT) {
RED.view.importNodes($("#node-input-import").val());
}
@ -343,7 +348,8 @@ RED.editor = function() {
* @param prefix
*/
function populateCredentialsInputs(node, credDef, credData, prefix) {
for (var cred in credDef) {
var cred;
for (cred in credDef) {
if (credDef.hasOwnProperty(cred)) {
if (credDef[cred].type == 'password') {
if (credData[cred]) {
@ -360,7 +366,7 @@ RED.editor = function() {
attachPropertyChangeHandler(node, credDef, cred, prefix);
}
}
for (var cred in credDef) {
for (cred in credDef) {
if (credDef.hasOwnProperty(cred)) {
$("#" + prefix + "-" + cred).change();
}
@ -385,7 +391,7 @@ RED.editor = function() {
var input = $("#" + prefix + '-' + cred);
var value = input.val();
if (credDefinition[cred].type == 'password') {
node.credentials['has_' + cred] = (value != "");
node.credentials['has_' + cred] = (value !== "");
if (value == '__PWRD__') {
continue;
}
@ -409,19 +415,23 @@ RED.editor = function() {
*/
function prepareEditDialog(node,definition,prefix) {
for (var d in definition.defaults) {
if (definition.defaults[d].type) {
prepareConfigNodeSelect(node,d,definition.defaults[d].type);
} else {
preparePropertyEditor(node,d,prefix);
if (definition.defaults.hasOwnProperty(d)) {
if (definition.defaults[d].type) {
prepareConfigNodeSelect(node,d,definition.defaults[d].type);
} else {
preparePropertyEditor(node,d,prefix);
}
attachPropertyChangeHandler(node,definition.defaults,d,prefix);
}
attachPropertyChangeHandler(node,definition.defaults,d,prefix);
}
var completePrepare = function() {
if (definition.oneditprepare) {
definition.oneditprepare.call(node);
}
for (var d in definition.defaults) {
$("#"+prefix+"-"+d).change();
if (definition.defaults.hasOwnProperty(d)) {
$("#"+prefix+"-"+d).change();
}
}
}
@ -494,10 +504,10 @@ RED.editor = function() {
configTypeDef.ondelete.call(RED.nodes.node(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];
for (var d in user._def.defaults) {
if (user[d] == configId) {
if (user._def.defaults.hasOwnProperty(d) && user[d] == configId) {
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);
}
@ -559,12 +569,14 @@ RED.editor = function() {
var configAdding = $(this).dialog('option','node-adding');
var configTypeDef = RED.nodes.getType(configType);
var configNode;
var d;
if (configAdding) {
configNode = {type:configType,id:configId,users:[]};
for (var d in configTypeDef.defaults) {
var input = $("#node-config-input-"+d);
configNode[d] = input.val();
for (d in configTypeDef.defaults) {
if (configTypeDef.defaults.hasOwnProperty(d)) {
configNode[d] = $("#node-config-input-"+d).val();
}
}
configNode.label = configTypeDef.label;
configNode._def = configTypeDef;
@ -572,9 +584,10 @@ RED.editor = function() {
updateConfigNodeSelect(configProperty,configType,configNode.id);
} else {
configNode = RED.nodes.node(configId);
for (var d in configTypeDef.defaults) {
var input = $("#node-config-input-"+d);
configNode[d] = input.val();
for (d in configTypeDef.defaults) {
if (configTypeDef.defaults.hasOwnProperty(d)) {
configNode[d] = $("#node-config-input-"+d).val();
}
}
updateConfigNodeSelect(configProperty,configType,configId);
}
@ -637,4 +650,4 @@ RED.editor = function() {
validateNode: validateNode,
updateNodeProperties: updateNodeProperties // TODO: only exposed for edit-undo
}
}();
})();

View File

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

View File

@ -13,35 +13,41 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
RED.library = function() {
RED.library = (function() {
function loadFlowLibrary() {
$.getJSON("library/flows",function(data) {
//console.log(data);
//console.log(data);
var buildMenu = function(data,root) {
var ul = document.createElement("ul");
ul.className = "dropdown-menu";
if (data.d) {
for (var i in data.d) {
var li = document.createElement("li");
var buildMenu = function(data,root) {
var i;
var li;
var a;
var ul = document.createElement("ul");
ul.className = "dropdown-menu";
if (data.d) {
for (i in data.d) {
if (data.d.hasOwnProperty(i)) {
li = document.createElement("li");
li.className = "dropdown-submenu pull-left";
var a = document.createElement("a");
a = document.createElement("a");
a.href="#";
a.innerHTML = i;
li.appendChild(a);
li.appendChild(buildMenu(data.d[i],root+(root!=""?"/":"")+i));
li.appendChild(buildMenu(data.d[i],root+(root!==""?"/":"")+i));
ul.appendChild(li);
}
}
if (data.f) {
for (var i in data.f) {
var li = document.createElement("li");
var a = document.createElement("a");
}
if (data.f) {
for (i in data.f) {
if (data.f.hasOwnProperty(i)) {
li = document.createElement("li");
a = document.createElement("a");
a.href="#";
a.innerHTML = data.f[i];
a.flowName = root+(root!=""?"/":"")+data.f[i];
a.flowName = root+(root!==""?"/":"")+data.f[i];
a.onclick = function() {
$.get('library/flows/'+this.flowName, function(data) {
RED.view.importNodes(data);
@ -51,10 +57,11 @@ RED.library = function() {
ul.appendChild(li);
}
}
return ul;
};
var menu = buildMenu(data,"");
$("#flow-menu-parent>ul").replaceWith(menu);
}
return ul;
};
var menu = buildMenu(data,"");
$("#flow-menu-parent>ul").replaceWith(menu);
});
}
loadFlowLibrary();
@ -75,22 +82,22 @@ RED.library = function() {
function buildFileList(root,data) {
var ul = document.createElement("ul");
for (var i in data) {
var li;
for (var i=0;i<data.length;i++) {
var v = data[i];
if (typeof v === "string") {
// directory
var li = buildFileListItem(v);
li.onclick = function () {
li = buildFileListItem(v);
li.onclick = (function () {
var dirName = v;
return function(e) {
var bcli = $('<li class="active"><span class="divider">/</span> <a href="#">'+dirName+'</a></li>');
$("a",bcli).click(function(e) {
$(this).parent().nextAll().remove();
$.getJSON("library/"+options.url+root+dirName,function(data) {
$("#node-select-library").children().first().replaceWith(buildFileList(root+dirName+"/",data));
});
e.stopPropagation();
$(this).parent().nextAll().remove();
$.getJSON("library/"+options.url+root+dirName,function(data) {
$("#node-select-library").children().first().replaceWith(buildFileList(root+dirName+"/",data));
});
e.stopPropagation();
});
var bc = $("#node-dialog-library-breadcrumbs");
$(".active",bc).removeClass("active");
@ -99,14 +106,14 @@ RED.library = function() {
$("#node-select-library").children().first().replaceWith(buildFileList(root+dirName+"/",data));
});
}
}();
})();
li.innerHTML = '<i class="icon-folder-close"></i> '+v+"</i>";
ul.appendChild(li);
} else {
// file
var li = buildFileListItem(v);
li = buildFileListItem(v);
li.innerHTML = v.name;
li.onclick = function() {
li.onclick = (function() {
var item = v;
return function(e) {
$(".list-selected",ul).removeClass("list-selected");
@ -117,7 +124,7 @@ RED.library = function() {
libraryEditor.setText(data);
});
}
}();
})();
ul.appendChild(li);
}
}
@ -136,132 +143,131 @@ RED.library = function() {
$('#node-input-'+options.type+'-menu-open-library').click(function(e) {
$("#node-select-library").children().remove();
var bc = $("#node-dialog-library-breadcrumbs");
bc.children().first().nextAll().remove();
libraryEditor.setText('');
$.getJSON("library/"+options.url,function(data) {
$("#node-select-library").append(buildFileList("/",data));
$("#node-dialog-library-breadcrumbs a").click(function(e) {
$(this).parent().nextAll().remove();
$("#node-select-library").children().first().replaceWith(buildFileList("/",data));
e.stopPropagation();
});
$( "#node-dialog-library-lookup" ).dialog( "open" );
$("#node-select-library").children().remove();
var bc = $("#node-dialog-library-breadcrumbs");
bc.children().first().nextAll().remove();
libraryEditor.setText('');
$.getJSON("library/"+options.url,function(data) {
$("#node-select-library").append(buildFileList("/",data));
$("#node-dialog-library-breadcrumbs a").click(function(e) {
$(this).parent().nextAll().remove();
$("#node-select-library").children().first().replaceWith(buildFileList("/",data));
e.stopPropagation();
});
e.preventDefault();
$( "#node-dialog-library-lookup" ).dialog( "open" );
});
e.preventDefault();
});
$('#node-input-'+options.type+'-menu-save-library').click(function(e) {
//var found = false;
var name = $("#node-input-name").val().replace(/(^\s*)|(\s*$)/g,"");
//var buildPathList = function(data,root) {
// var paths = [];
// if (data.d) {
// for (var i in data.d) {
// var dn = root+(root==""?"":"/")+i;
// var d = {
// label:dn,
// files:[]
// };
// for (var f in data.d[i].f) {
// d.files.push(data.d[i].f[f].fn.split("/").slice(-1)[0]);
// }
// paths.push(d);
// paths = paths.concat(buildPathList(data.d[i],root+(root==""?"":"/")+i));
// }
// }
// return paths;
//};
$("#node-dialog-library-save-folder").attr("value","");
var filename = name.replace(/[^\w-]/g,"-");
if (filename == "") {
filename = "unnamed-"+options.type;
}
$("#node-dialog-library-save-filename").attr("value",filename+".js");
//var paths = buildPathList(libraryData,"");
//$("#node-dialog-library-save-folder").autocomplete({
// minLength: 0,
// source: paths,
// select: function( event, ui ) {
// $("#node-dialog-library-save-filename").autocomplete({
// minLength: 0,
// source: ui.item.files
// });
// }
//});
$( "#node-dialog-library-save" ).dialog( "open" );
e.preventDefault();
//var found = false;
var name = $("#node-input-name").val().replace(/(^\s*)|(\s*$)/g,"");
//var buildPathList = function(data,root) {
// var paths = [];
// if (data.d) {
// for (var i in data.d) {
// var dn = root+(root==""?"":"/")+i;
// var d = {
// label:dn,
// files:[]
// };
// for (var f in data.d[i].f) {
// d.files.push(data.d[i].f[f].fn.split("/").slice(-1)[0]);
// }
// paths.push(d);
// paths = paths.concat(buildPathList(data.d[i],root+(root==""?"":"/")+i));
// }
// }
// return paths;
//};
$("#node-dialog-library-save-folder").attr("value","");
var filename = name.replace(/[^\w-]/g,"-");
if (filename === "") {
filename = "unnamed-"+options.type;
}
$("#node-dialog-library-save-filename").attr("value",filename+".js");
//var paths = buildPathList(libraryData,"");
//$("#node-dialog-library-save-folder").autocomplete({
// minLength: 0,
// source: paths,
// select: function( event, ui ) {
// $("#node-dialog-library-save-filename").autocomplete({
// minLength: 0,
// source: ui.item.files
// });
// }
//});
$( "#node-dialog-library-save" ).dialog( "open" );
e.preventDefault();
});
require(["orion/editor/edit"], function(edit) {
libraryEditor = edit({
parent:document.getElementById('node-select-library-text'),
lang:"js",
readonly: true
});
libraryEditor = edit({
parent:document.getElementById('node-select-library-text'),
lang:"js",
readonly: true
});
});
$( "#node-dialog-library-lookup" ).dialog({
title: options.type+" library",
modal: true,
autoOpen: false,
width: 800,
height: 450,
buttons: [
{
text: "Ok",
click: function() {
if (selectedLibraryItem) {
for (var i in options.fields) {
var field = options.fields[i];
$("#node-input-"+field).val(selectedLibraryItem[field]);
};
options.editor.setText(libraryEditor.getText());
title: options.type+" library",
modal: true,
autoOpen: false,
width: 800,
height: 450,
buttons: [
{
text: "Ok",
click: function() {
if (selectedLibraryItem) {
for (var i=0;i<options.fields.length;i++) {
var field = options.fields[i];
$("#node-input-"+field).val(selectedLibraryItem[field]);
}
$( this ).dialog( "close" );
}
},
{
text: "Cancel",
click: function() {
$( this ).dialog( "close" );
options.editor.setText(libraryEditor.getText());
}
$( this ).dialog( "close" );
}
],
open: function(e) {
var form = $("form",this);
form.height(form.parent().height()-30);
$("#node-select-library-text").height("100%");
$(".form-row:last-child",form).children().height(form.height()-60);
},
resize: function(e) {
var form = $("form",this);
form.height(form.parent().height()-30);
$(".form-row:last-child",form).children().height(form.height()-60);
{
text: "Cancel",
click: function() {
$( this ).dialog( "close" );
}
}
],
open: function(e) {
var form = $("form",this);
form.height(form.parent().height()-30);
$("#node-select-library-text").height("100%");
$(".form-row:last-child",form).children().height(form.height()-60);
},
resize: function(e) {
var form = $("form",this);
form.height(form.parent().height()-30);
$(".form-row:last-child",form).children().height(form.height()-60);
}
});
function saveToLibrary(overwrite) {
var name = $("#node-input-name").val().replace(/(^\s*)|(\s*$)/g,"");
if (name == "") {
if (name === "") {
name = "Unnamed "+options.type;
}
var filename = $("#node-dialog-library-save-filename").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");
return;
}
var fullpath = pathname+(pathname==""?"":"/")+filename;
var fullpath = pathname+(pathname===""?"":"/")+filename;
if (!overwrite) {
//var pathnameParts = pathname.split("/");
//var exists = false;
@ -290,7 +296,7 @@ RED.library = function() {
//}
}
var queryArgs = [];
for (var i in options.fields) {
for (var i=0;i<options.fields.length;i++) {
var field = options.fields[i];
if (field == "name") {
queryArgs.push("name="+encodeURIComponent(name));
@ -306,48 +312,48 @@ RED.library = function() {
});
}
$( "#node-dialog-library-save-confirm" ).dialog({
title: "Save to library",
modal: true,
autoOpen: false,
width: 530,
height: 230,
buttons: [
{
text: "Ok",
click: function() {
saveToLibrary(true);
$( this ).dialog( "close" );
}
},
{
text: "Cancel",
click: function() {
$( this ).dialog( "close" );
}
title: "Save to library",
modal: true,
autoOpen: false,
width: 530,
height: 230,
buttons: [
{
text: "Ok",
click: function() {
saveToLibrary(true);
$( this ).dialog( "close" );
}
]
},
{
text: "Cancel",
click: function() {
$( this ).dialog( "close" );
}
}
]
});
$( "#node-dialog-library-save" ).dialog({
title: "Save to library",
modal: true,
autoOpen: false,
width: 530,
height: 230,
buttons: [
{
text: "Ok",
click: function() {
saveToLibrary(false);
$( this ).dialog( "close" );
}
},
{
text: "Cancel",
click: function() {
$( this ).dialog( "close" );
}
title: "Save to library",
modal: true,
autoOpen: false,
width: 530,
height: 230,
buttons: [
{
text: "Ok",
click: function() {
saveToLibrary(false);
$( this ).dialog( "close" );
}
]
},
{
text: "Cancel",
click: function() {
$( this ).dialog( "close" );
}
}
]
});
}
@ -356,6 +362,6 @@ RED.library = function() {
create: createUI,
loadFlowLibrary: loadFlowLibrary
}
}();
})();

View File

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

View File

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

View File

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

View File

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

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
RED.sidebar.info = function() {
RED.sidebar.info = (function() {
var content = document.createElement("div");
content.id = "tab-info";
@ -24,7 +24,7 @@ RED.sidebar.info = function() {
RED.sidebar.addTab("info",content);
function jsonFilter(key,value) {
if (key == "") {
if (key === "") {
return value;
}
var t = typeof value;
@ -47,31 +47,33 @@ RED.sidebar.info = function() {
table += "<tr><td>ID</td><td>&nbsp;"+node.id+"</td></tr>";
table += '<tr class="blank"><td colspan="2">&nbsp;Properties</td></tr>';
for (var n in node._def.defaults) {
var val = node[n]||"";
var type = typeof val;
if (type === "string") {
if (val.length > 30) {
val = val.substring(0,30)+" ...";
if (node._def.defaults.hasOwnProperty(n)) {
var val = node[n]||"";
var type = typeof val;
if (type === "string") {
if (val.length > 30) {
val = val.substring(0,30)+" ...";
}
val = val.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
} else if (type === "number") {
val = val.toString();
} else if ($.isArray(val)) {
val = "[<br/>";
for (var i=0;i<Math.min(node[n].length,10);i++) {
var vv = JSON.stringify(node[n][i],jsonFilter," ").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
val += "&nbsp;"+i+": "+vv+"<br/>";
}
if (node[n].length > 10) {
val += "&nbsp;... "+node[n].length+" items<br/>";
}
val += "]";
} else {
val = JSON.stringify(val,jsonFilter," ");
val = val.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
}
val = val.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
} else if (type === "number") {
val = val.toString();
} else if ($.isArray(val)) {
val = "[<br/>";
for (var i=0;i<Math.min(node[n].length,10);i++) {
var vv = JSON.stringify(node[n][i],jsonFilter," ").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
val += "&nbsp;"+i+": "+vv+"<br/>";
}
if (node[n].length > 10) {
val += "&nbsp;... "+node[n].length+" items<br/>";
}
val += "]";
} else {
val = JSON.stringify(val,jsonFilter," ");
val = val.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
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 += '<div class="node-help">'+($("script[data-help-name|='"+node.type+"']").html()||"")+"</div>";
@ -84,4 +86,4 @@ RED.sidebar.info = function() {
$("#tab-info").html("");
}
}
}();
})();

View File

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

View File

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