diff --git a/Gruntfile.js b/Gruntfile.js index 6726842ca..62a553f78 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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']); }; diff --git a/public/red/comms.js b/public/red/comms.js index 418f65150..f2c870382 100644 --- a/public/red/comms.js +++ b/public/red/comms.js @@ -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
  • ")+"
  • "; @@ -235,4 +236,4 @@ var RED = function() { return { }; -}(); +})(); diff --git a/public/red/nodes.js b/public/red/nodes.js index 5c4fd149a..3ef208006 100644 --- a/public/red/nodes.js +++ b/public/red/nodes.js @@ -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;nEither, add missing types to Node-RED, restart and then reload page,
    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= node.outputs) { removedLinks.push(l); } }); - for (var l in removedLinks) { + for (var l=0;l 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;iAdd new '+type+'...'); + select.append(''); 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 } -}(); +})(); diff --git a/public/red/ui/keyboard.js b/public/red/ui/keyboard.js index 50a48fc7c..3bc28c4d6 100644 --- a/public/red/ui/keyboard.js +++ b/public/red/ui/keyboard.js @@ -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; } } -}(); +})(); diff --git a/public/red/ui/library.js b/public/red/ui/library.js index 5e1693c05..a2c2e2991 100644 --- a/public/red/ui/library.js +++ b/public/red/ui/library.js @@ -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/ '+dirName+''); $("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 = ' '+v+""; 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 4) { var ll = currentNotifications.length; for (var i = 0;ll > 4 && i 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('
    '); } @@ -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 }; -}(); +})(); diff --git a/public/red/ui/sidebar.js b/public/red/ui/sidebar.js index ddf813032..e788fb84e 100644 --- a/public/red/ui/sidebar.js +++ b/public/red/ui/sidebar.js @@ -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 } -}(); +})(); diff --git a/public/red/ui/tab-config.js b/public/red/ui/tab-config.js index fa5b4a185..dee966ead 100644 --- a/public/red/ui/tab-config.js +++ b/public/red/ui/tab-config.js @@ -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 = $("
  • ",{id:"tab-config-list-type-"+node.type}).appendTo(list); $('
    '+node.type+'
    ').appendTo(li); } @@ -80,4 +80,4 @@ RED.sidebar.config = function() { return { refresh:refresh } -}(); +})(); diff --git a/public/red/ui/tab-info.js b/public/red/ui/tab-info.js index c2ef60d9c..638ab4e69 100644 --- a/public/red/ui/tab-info.js +++ b/public/red/ui/tab-info.js @@ -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 += "ID "+node.id+""; table += ' Properties'; 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,"&").replace(//g,">"); + } else if (type === "number") { + val = val.toString(); + } else if ($.isArray(val)) { + val = "[
    "; + for (var i=0;i/g,">"); + val += " "+i+": "+vv+"
    "; + } + if (node[n].length > 10) { + val += " ... "+node[n].length+" items
    "; + } + val += "]"; + } else { + val = JSON.stringify(val,jsonFilter," "); + val = val.replace(/&/g,"&").replace(//g,">"); } - val = val.replace(/&/g,"&").replace(//g,">"); - } else if (type === "number") { - val = val.toString(); - } else if ($.isArray(val)) { - val = "[
    "; - for (var i=0;i/g,">"); - val += " "+i+": "+vv+"
    "; - } - if (node[n].length > 10) { - val += " ... "+node[n].length+" items
    "; - } - val += "]"; - } else { - val = JSON.stringify(val,jsonFilter," "); - val = val.replace(/&/g,"&").replace(//g,">"); + + table += " "+n+""+val+""; } - - table += " "+n+""+val+""; } table += "
    "; table += '
    '+($("script[data-help-name|='"+node.type+"']").html()||"")+"
    "; @@ -84,4 +86,4 @@ RED.sidebar.info = function() { $("#tab-info").html(""); } } -}(); +})(); diff --git a/public/red/ui/tabs.js b/public/red/ui/tabs.js index adb4cdddf..799be750a 100644 --- a/public/red/ui/tabs.js +++ b/public/red/ui/tabs.js @@ -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 } -}(); +})(); diff --git a/public/red/ui/touch/radialMenu.js b/public/red/ui/touch/radialMenu.js index 5fabf1e4d..706a89f07 100644 --- a/public/red/ui/touch/radialMenu.js +++ b/public/red/ui/touch/radialMenu.js @@ -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() { } } -}(); +})(); diff --git a/public/red/ui/view.js b/public/red/ui/view.js index 317eeffd6..1bee795af 100644 --- a/public/red/ui/view.js +++ b/public/red/ui/view.js @@ -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 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 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 0) { - for (var i in moving_set) { + for (var i=0;i 0) { var nns = []; - for (var n in moving_set) { + for (var n=0;n