2013-09-05 16:02:48 +02:00
|
|
|
/**
|
2016-01-14 16:59:45 +01:00
|
|
|
* Copyright 2013, 2016 IBM Corp.
|
2013-09-05 16:02:48 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2014-07-23 23:07:02 +02:00
|
|
|
**/
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2014-08-08 01:01:35 +02:00
|
|
|
RED.palette = (function() {
|
2014-06-30 17:31:02 +02:00
|
|
|
|
2014-07-23 23:07:02 +02:00
|
|
|
var exclusion = ['config','unknown','deprecated'];
|
2016-08-10 21:15:17 +02:00
|
|
|
var coreCategories = ['subflows', 'input', 'output', 'function', 'social', 'mobile', 'storage', 'analysis', 'advanced'];
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2015-07-14 16:59:56 +02:00
|
|
|
var categoryContainers = {};
|
|
|
|
|
2015-06-10 22:39:39 +02:00
|
|
|
function createCategoryContainer(category, label){
|
|
|
|
label = label || category.replace("_", " ");
|
2015-07-14 16:59:56 +02:00
|
|
|
var catDiv = $('<div id="palette-container-'+category+'" class="palette-category palette-close hide">'+
|
2015-07-13 12:26:29 +02:00
|
|
|
'<div id="palette-header-'+category+'" class="palette-header"><i class="expanded fa fa-angle-down"></i><span>'+label+'</span></div>'+
|
2014-08-07 14:46:03 +02:00
|
|
|
'<div class="palette-content" id="palette-base-category-'+category+'">'+
|
2014-08-19 23:58:52 +02:00
|
|
|
'<div id="palette-'+category+'-input"></div>'+
|
|
|
|
'<div id="palette-'+category+'-output"></div>'+
|
|
|
|
'<div id="palette-'+category+'-function"></div>'+
|
2014-08-07 14:46:03 +02:00
|
|
|
'</div>'+
|
2015-07-14 16:59:56 +02:00
|
|
|
'</div>').appendTo("#palette-container");
|
|
|
|
|
|
|
|
categoryContainers[category] = {
|
|
|
|
container: catDiv,
|
|
|
|
close: function() {
|
|
|
|
catDiv.removeClass("palette-open");
|
|
|
|
catDiv.addClass("palette-closed");
|
|
|
|
$("#palette-base-category-"+category).slideUp();
|
|
|
|
$("#palette-header-"+category+" i").removeClass("expanded");
|
|
|
|
},
|
|
|
|
open: function() {
|
|
|
|
catDiv.addClass("palette-open");
|
|
|
|
catDiv.removeClass("palette-closed");
|
|
|
|
$("#palette-base-category-"+category).slideDown();
|
|
|
|
$("#palette-header-"+category+" i").addClass("expanded");
|
|
|
|
},
|
|
|
|
toggle: function() {
|
|
|
|
if (catDiv.hasClass("palette-open")) {
|
|
|
|
categoryContainers[category].close();
|
|
|
|
} else {
|
|
|
|
categoryContainers[category].open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2015-02-06 14:16:19 +01:00
|
|
|
$("#palette-header-"+category).on('click', function(e) {
|
2015-07-14 16:59:56 +02:00
|
|
|
categoryContainers[category].toggle();
|
2014-08-28 01:35:07 +02:00
|
|
|
});
|
2014-07-23 23:07:02 +02:00
|
|
|
}
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2015-10-23 23:14:21 +02:00
|
|
|
function setLabel(type, el,label, info) {
|
2015-09-23 23:49:48 +02:00
|
|
|
var nodeWidth = 82;
|
2014-02-25 00:35:11 +01:00
|
|
|
var nodeHeight = 25;
|
|
|
|
var lineHeight = 20;
|
|
|
|
var portHeight = 10;
|
|
|
|
|
2016-03-12 23:41:23 +01:00
|
|
|
var words = label.split(/[ -]/);
|
2014-12-09 15:37:32 +01:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
var displayLines = [];
|
2014-12-09 15:37:32 +01:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
var currentLine = words[0];
|
|
|
|
var currentLineWidth = RED.view.calculateTextWidth(currentLine, "palette_label", 0);
|
2014-12-09 15:37:32 +01:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
for (var i=1;i<words.length;i++) {
|
|
|
|
var newWidth = RED.view.calculateTextWidth(currentLine+" "+words[i], "palette_label", 0);
|
|
|
|
if (newWidth < nodeWidth) {
|
|
|
|
currentLine += " "+words[i];
|
|
|
|
currentLineWidth = newWidth;
|
|
|
|
} else {
|
|
|
|
displayLines.push(currentLine);
|
|
|
|
currentLine = words[i];
|
|
|
|
currentLineWidth = RED.view.calculateTextWidth(currentLine, "palette_label", 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
displayLines.push(currentLine);
|
2014-12-09 15:37:32 +01:00
|
|
|
|
2016-10-18 11:26:51 +02:00
|
|
|
var tempLines = displayLines.join("^&%");
|
|
|
|
tempLines =RED.bidi.applyBidiSupport(tempLines, RED.bidi.flags.NS);
|
|
|
|
var lines = tempLines.replace("^&%", "<br/>");
|
2014-02-25 00:35:11 +01:00
|
|
|
var multiLineNodeHeight = 8+(lineHeight*displayLines.length);
|
|
|
|
el.css({height:multiLineNodeHeight+"px"});
|
|
|
|
|
|
|
|
var labelElement = el.find(".palette_label");
|
2016-10-18 11:26:51 +02:00
|
|
|
labelElement.html(lines).attr('dir', RED.bidi.resolveBaseTextDir(lines));
|
2014-12-09 15:37:32 +01:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
el.find(".palette_port").css({top:(multiLineNodeHeight/2-5)+"px"});
|
2014-12-09 15:37:32 +01:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
var popOverContent;
|
|
|
|
try {
|
2016-10-18 11:26:51 +02:00
|
|
|
var l = "<p><b>"+RED.bidi.applyBidiSupport(label,RED.bidi.flags.BTD & RED.bidi.flags.NS)+"</b></p>";
|
2014-02-25 00:35:11 +01:00
|
|
|
if (label != type) {
|
2016-10-18 11:26:51 +02:00
|
|
|
l = "<p><b>"+RED.bidi.applyBidiSupport(label,RED.bidi.flags.BTD & RED.bidi.flags.NS)+"</b><br/><i>"+type+"</i></p>";
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
2016-08-25 11:44:23 +02:00
|
|
|
popOverContent = $(l+(info?info:$("script[data-help-name$='"+type+"']").html()||"<p>"+RED._("palette.noInfo")+"</p>").trim())
|
2015-01-29 22:40:21 +01:00
|
|
|
.filter(function(n) {
|
2015-10-23 23:14:21 +02:00
|
|
|
return (this.nodeType == 1 && this.nodeName == "P") || (this.nodeType == 3 && this.textContent.trim().length > 0)
|
2015-01-29 22:40:21 +01:00
|
|
|
}).slice(0,2);
|
2014-02-25 00:35:11 +01:00
|
|
|
} catch(err) {
|
|
|
|
// Malformed HTML may cause errors. TODO: need to understand what can break
|
2015-07-01 00:42:03 +02:00
|
|
|
// NON-NLS: internal debug
|
|
|
|
console.log("Error generating pop-over label for ",type);
|
2014-02-25 00:35:11 +01:00
|
|
|
console.log(err.toString());
|
2015-05-22 01:40:27 +02:00
|
|
|
popOverContent = "<p><b>"+label+"</b></p><p>"+RED._("palette.noInfo")+"</p>";
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2015-07-18 16:33:31 +02:00
|
|
|
el.data('popover').setContent(popOverContent);
|
2014-02-25 00:35:11 +01:00
|
|
|
}
|
2014-12-09 15:37:32 +01:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
function escapeNodeType(nt) {
|
|
|
|
return nt.replace(" ","_").replace(".","_").replace(":","_");
|
|
|
|
}
|
2014-12-09 15:37:32 +01:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
function addNodeType(nt,def) {
|
|
|
|
var nodeTypeId = escapeNodeType(nt);
|
2014-08-28 01:35:07 +02:00
|
|
|
if ($("#palette_node_"+nodeTypeId).length) {
|
2014-08-07 14:46:03 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-07-23 23:07:02 +02:00
|
|
|
if (exclusion.indexOf(def.category)===-1) {
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2014-08-29 21:37:30 +02:00
|
|
|
var category = def.category.replace(" ","_");
|
|
|
|
var rootCategory = category.split("-")[0];
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2014-08-29 21:37:30 +02:00
|
|
|
var d = document.createElement("div");
|
2014-08-28 01:35:07 +02:00
|
|
|
d.id = "palette_node_"+nodeTypeId;
|
2014-08-29 21:37:30 +02:00
|
|
|
d.type = nt;
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2016-03-01 22:58:57 +01:00
|
|
|
var label = /^(.*?)([ -]in|[ -]out)?$/.exec(nt)[1];
|
|
|
|
if (typeof def.paletteLabel !== "undefined") {
|
|
|
|
try {
|
|
|
|
label = (typeof def.paletteLabel === "function" ? def.paletteLabel.call(def) : def.paletteLabel)||"";
|
|
|
|
} catch(err) {
|
|
|
|
console.log("Definition error: "+nt+".paletteLabel",err);
|
|
|
|
}
|
2014-10-08 14:54:48 +02:00
|
|
|
}
|
2014-10-09 11:05:45 +02:00
|
|
|
|
2015-03-20 12:37:47 +01:00
|
|
|
$('<div/>',{class:"palette_label"+(def.align=="right"?" palette_label_right":"")}).appendTo(d);
|
2014-12-09 15:37:32 +01:00
|
|
|
|
2014-08-29 21:37:30 +02:00
|
|
|
d.className="palette_node";
|
2015-07-01 00:42:03 +02:00
|
|
|
|
|
|
|
|
2014-08-29 21:37:30 +02:00
|
|
|
if (def.icon) {
|
2016-03-01 22:58:57 +01:00
|
|
|
var icon_url = "arrow-in.png";
|
|
|
|
try {
|
|
|
|
icon_url = (typeof def.icon === "function" ? def.icon.call({}) : def.icon);
|
|
|
|
} catch(err) {
|
|
|
|
console.log("Definition error: "+nt+".icon",err);
|
|
|
|
}
|
2015-03-20 12:37:47 +01:00
|
|
|
var iconContainer = $('<div/>',{class:"palette_icon_container"+(def.align=="right"?" palette_icon_container_right":"")}).appendTo(d);
|
2015-06-02 23:07:45 +02:00
|
|
|
$('<div/>',{class:"palette_icon",style:"background-image: url(icons/"+icon_url+")"}).appendTo(iconContainer);
|
2014-08-29 21:37:30 +02:00
|
|
|
}
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2014-08-29 21:37:30 +02:00
|
|
|
d.style.backgroundColor = def.color;
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2014-08-29 21:37:30 +02:00
|
|
|
if (def.outputs > 0) {
|
|
|
|
var portOut = document.createElement("div");
|
|
|
|
portOut.className = "palette_port palette_port_output";
|
|
|
|
d.appendChild(portOut);
|
|
|
|
}
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2014-08-29 21:37:30 +02:00
|
|
|
if (def.inputs > 0) {
|
|
|
|
var portIn = document.createElement("div");
|
2014-02-25 00:35:11 +01:00
|
|
|
portIn.className = "palette_port palette_port_input";
|
2014-08-29 21:37:30 +02:00
|
|
|
d.appendChild(portIn);
|
|
|
|
}
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2014-08-29 21:37:30 +02:00
|
|
|
if ($("#palette-base-category-"+rootCategory).length === 0) {
|
2016-08-10 21:15:17 +02:00
|
|
|
if(coreCategories.indexOf(rootCategory) !== -1){
|
2015-06-29 20:45:14 +02:00
|
|
|
createCategoryContainer(rootCategory, RED._("node-red:palette.label."+rootCategory, {defaultValue:rootCategory}));
|
2015-07-13 12:26:29 +02:00
|
|
|
} else {
|
2015-06-29 20:45:14 +02:00
|
|
|
var ns = def.set.id;
|
|
|
|
createCategoryContainer(rootCategory, RED._(ns+":palette.label."+rootCategory, {defaultValue:rootCategory}));
|
|
|
|
}
|
2014-08-29 21:37:30 +02:00
|
|
|
}
|
2015-02-06 14:16:19 +01:00
|
|
|
$("#palette-container-"+rootCategory).show();
|
2014-10-01 14:41:06 +02:00
|
|
|
|
|
|
|
if ($("#palette-"+category).length === 0) {
|
|
|
|
$("#palette-base-category-"+rootCategory).append('<div id="palette-'+category+'"></div>');
|
2014-08-29 21:37:30 +02:00
|
|
|
}
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2014-08-29 21:37:30 +02:00
|
|
|
$("#palette-"+category).append(d);
|
2014-10-01 14:41:06 +02:00
|
|
|
d.onmousedown = function(e) { e.preventDefault(); };
|
|
|
|
|
2015-07-18 16:33:31 +02:00
|
|
|
RED.popover.create({
|
|
|
|
target:$(d),
|
|
|
|
content: "hi",
|
|
|
|
delay: { show: 750, hide: 50 }
|
2014-08-29 21:37:30 +02:00
|
|
|
});
|
2015-07-18 16:33:31 +02:00
|
|
|
|
|
|
|
// $(d).popover({
|
|
|
|
// title:d.type,
|
|
|
|
// placement:"right",
|
|
|
|
// trigger: "hover",
|
|
|
|
// delay: { show: 750, hide: 50 },
|
|
|
|
// html: true,
|
|
|
|
// container:'body'
|
|
|
|
// });
|
2014-08-29 21:37:30 +02:00
|
|
|
$(d).click(function() {
|
2015-03-02 23:55:34 +01:00
|
|
|
RED.view.focus();
|
2015-10-23 23:14:21 +02:00
|
|
|
var helpText;
|
|
|
|
if (nt.indexOf("subflow:") === 0) {
|
2015-10-26 12:12:21 +01:00
|
|
|
helpText = marked(RED.nodes.subflow(nt.substring(8)).info||"");
|
2015-10-23 23:14:21 +02:00
|
|
|
} else {
|
2016-08-25 11:44:23 +02:00
|
|
|
helpText = $("script[data-help-name$='"+d.type+"']").html()||"";
|
2015-10-23 23:14:21 +02:00
|
|
|
}
|
|
|
|
var help = '<div class="node-help">'+helpText+"</div>";
|
2015-07-18 16:33:31 +02:00
|
|
|
RED.sidebar.info.set(help);
|
2014-08-29 21:37:30 +02:00
|
|
|
});
|
2016-01-08 23:34:10 +01:00
|
|
|
var chart = $("#chart");
|
|
|
|
var chartOffset = chart.offset();
|
|
|
|
var chartSVG = $("#chart>svg").get(0);
|
|
|
|
var activeSpliceLink;
|
|
|
|
var mouseX;
|
|
|
|
var mouseY;
|
|
|
|
var spliceTimer;
|
2014-08-29 21:37:30 +02:00
|
|
|
$(d).draggable({
|
|
|
|
helper: 'clone',
|
|
|
|
appendTo: 'body',
|
|
|
|
revert: true,
|
2015-03-02 23:55:34 +01:00
|
|
|
revertDuration: 50,
|
2016-10-02 23:45:49 +02:00
|
|
|
containment:'#main-container',
|
2016-01-08 15:42:05 +01:00
|
|
|
start: function() {RED.view.focus();},
|
2016-01-11 12:00:54 +01:00
|
|
|
stop: function() { d3.select('.link_splice').classed('link_splice',false); if (spliceTimer) { clearTimeout(spliceTimer); spliceTimer = null;}},
|
2016-01-08 15:42:05 +01:00
|
|
|
drag: function(e,ui) {
|
2016-10-02 23:45:49 +02:00
|
|
|
|
2016-01-08 15:42:05 +01:00
|
|
|
// TODO: this is the margin-left of palette node. Hard coding
|
|
|
|
// it here makes me sad
|
2016-04-17 22:28:56 +02:00
|
|
|
//console.log(ui.helper.position());
|
2016-01-08 15:42:05 +01:00
|
|
|
ui.position.left += 17.5;
|
2016-10-02 23:45:49 +02:00
|
|
|
|
2016-01-08 23:34:10 +01:00
|
|
|
if (def.inputs > 0 && def.outputs > 0) {
|
2016-04-17 22:28:56 +02:00
|
|
|
mouseX = ui.position.left+(ui.helper.width()/2) - chartOffset.left + chart.scrollLeft();
|
|
|
|
mouseY = ui.position.top+(ui.helper.height()/2) - chartOffset.top + chart.scrollTop();
|
|
|
|
|
2016-01-08 23:34:10 +01:00
|
|
|
if (!spliceTimer) {
|
|
|
|
spliceTimer = setTimeout(function() {
|
2016-01-10 23:25:20 +01:00
|
|
|
var nodes = [];
|
2016-01-08 23:34:10 +01:00
|
|
|
var bestDistance = Infinity;
|
|
|
|
var bestLink = null;
|
2016-01-10 23:25:20 +01:00
|
|
|
if (chartSVG.getIntersectionList) {
|
|
|
|
var svgRect = chartSVG.createSVGRect();
|
|
|
|
svgRect.x = mouseX;
|
|
|
|
svgRect.y = mouseY;
|
|
|
|
svgRect.width = 1;
|
|
|
|
svgRect.height = 1;
|
|
|
|
nodes = chartSVG.getIntersectionList(svgRect,chartSVG);
|
|
|
|
mouseX /= RED.view.scale();
|
|
|
|
mouseY /= RED.view.scale();
|
|
|
|
} else {
|
|
|
|
// Firefox doesn't do getIntersectionList and that
|
|
|
|
// makes us sad
|
|
|
|
mouseX /= RED.view.scale();
|
|
|
|
mouseY /= RED.view.scale();
|
|
|
|
nodes = RED.view.getLinksAtPoint(mouseX,mouseY);
|
|
|
|
}
|
2016-01-08 23:34:10 +01:00
|
|
|
for (var i=0;i<nodes.length;i++) {
|
|
|
|
if (d3.select(nodes[i]).classed('link_background')) {
|
|
|
|
var length = nodes[i].getTotalLength();
|
|
|
|
for (var j=0;j<length;j+=10) {
|
|
|
|
var p = nodes[i].getPointAtLength(j);
|
|
|
|
var d2 = ((p.x-mouseX)*(p.x-mouseX))+((p.y-mouseY)*(p.y-mouseY));
|
|
|
|
if (d2 < 200 && d2 < bestDistance) {
|
|
|
|
bestDistance = d2;
|
|
|
|
bestLink = nodes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (activeSpliceLink && activeSpliceLink !== bestLink) {
|
|
|
|
d3.select(activeSpliceLink.parentNode).classed('link_splice',false);
|
|
|
|
}
|
|
|
|
if (bestLink) {
|
|
|
|
d3.select(bestLink.parentNode).classed('link_splice',true)
|
|
|
|
} else {
|
|
|
|
d3.select('.link_splice').classed('link_splice',false);
|
|
|
|
}
|
|
|
|
if (activeSpliceLink !== bestLink) {
|
|
|
|
if (bestLink) {
|
|
|
|
$(ui.helper).data('splice',d3.select(bestLink).data()[0]);
|
|
|
|
} else {
|
|
|
|
$(ui.helper).removeData('splice');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
activeSpliceLink = bestLink;
|
|
|
|
spliceTimer = null;
|
|
|
|
},200);
|
|
|
|
}
|
|
|
|
}
|
2016-01-08 15:42:05 +01:00
|
|
|
}
|
2014-08-29 21:37:30 +02:00
|
|
|
});
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2015-10-23 23:14:21 +02:00
|
|
|
var nodeInfo = null;
|
2015-03-21 00:11:24 +01:00
|
|
|
if (def.category == "subflows") {
|
|
|
|
$(d).dblclick(function(e) {
|
|
|
|
RED.workspaces.show(nt.substring(8));
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2015-10-26 12:12:21 +01:00
|
|
|
nodeInfo = marked(def.info||"");
|
2015-03-21 00:11:24 +01:00
|
|
|
}
|
2015-10-23 23:14:21 +02:00
|
|
|
setLabel(nt,$(d),label,nodeInfo);
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2015-03-28 22:46:27 +01:00
|
|
|
var categoryNode = $("#palette-container-"+category);
|
|
|
|
if (categoryNode.find(".palette_node").length === 1) {
|
2015-07-14 16:59:56 +02:00
|
|
|
categoryContainers[category].open();
|
2015-03-28 22:46:27 +01:00
|
|
|
}
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2014-07-23 23:07:02 +02:00
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2014-08-28 01:35:07 +02:00
|
|
|
function removeNodeType(nt) {
|
2014-02-25 00:35:11 +01:00
|
|
|
var nodeTypeId = escapeNodeType(nt);
|
2015-03-21 00:12:52 +01:00
|
|
|
var paletteNode = $("#palette_node_"+nodeTypeId);
|
|
|
|
var categoryNode = paletteNode.closest(".palette-category");
|
|
|
|
paletteNode.remove();
|
|
|
|
if (categoryNode.find(".palette_node").length === 0) {
|
|
|
|
if (categoryNode.find("i").hasClass("expanded")) {
|
|
|
|
categoryNode.find(".palette-content").slideToggle();
|
|
|
|
categoryNode.find("i").toggleClass("expanded");
|
|
|
|
}
|
|
|
|
}
|
2014-08-28 01:35:07 +02:00
|
|
|
}
|
|
|
|
function hideNodeType(nt) {
|
2014-02-25 00:35:11 +01:00
|
|
|
var nodeTypeId = escapeNodeType(nt);
|
2014-08-28 01:35:07 +02:00
|
|
|
$("#palette_node_"+nodeTypeId).hide();
|
|
|
|
}
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2014-08-28 01:35:07 +02:00
|
|
|
function showNodeType(nt) {
|
2014-02-25 00:35:11 +01:00
|
|
|
var nodeTypeId = escapeNodeType(nt);
|
2014-08-28 01:35:07 +02:00
|
|
|
$("#palette_node_"+nodeTypeId).show();
|
2014-08-07 14:46:03 +02:00
|
|
|
}
|
2014-12-09 15:37:32 +01:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
function refreshNodeTypes() {
|
|
|
|
RED.nodes.eachSubflow(function(sf) {
|
|
|
|
var paletteNode = $("#palette_node_subflow_"+sf.id.replace(".","_"));
|
|
|
|
var portInput = paletteNode.find(".palette_port_input");
|
|
|
|
var portOutput = paletteNode.find(".palette_port_output");
|
2014-12-09 15:37:32 +01:00
|
|
|
|
2014-02-25 00:35:11 +01:00
|
|
|
if (portInput.length === 0 && sf.in.length > 0) {
|
|
|
|
var portIn = document.createElement("div");
|
|
|
|
portIn.className = "palette_port palette_port_input";
|
|
|
|
paletteNode.append(portIn);
|
|
|
|
} else if (portInput.length !== 0 && sf.in.length === 0) {
|
|
|
|
portInput.remove();
|
|
|
|
}
|
2014-12-09 15:37:32 +01:00
|
|
|
|
2014-11-07 17:12:27 +01:00
|
|
|
if (portOutput.length === 0 && sf.out.length > 0) {
|
2014-02-25 00:35:11 +01:00
|
|
|
var portOut = document.createElement("div");
|
|
|
|
portOut.className = "palette_port palette_port_output";
|
|
|
|
paletteNode.append(portOut);
|
2014-11-07 17:12:27 +01:00
|
|
|
} else if (portOutput.length !== 0 && sf.out.length === 0) {
|
2014-02-25 00:35:11 +01:00
|
|
|
portOutput.remove();
|
2014-12-09 15:37:32 +01:00
|
|
|
}
|
2015-10-26 12:12:21 +01:00
|
|
|
setLabel(sf.type+":"+sf.id,paletteNode,sf.name,marked(sf.info||""));
|
2014-02-25 00:35:11 +01:00
|
|
|
});
|
|
|
|
}
|
2014-12-09 15:37:32 +01:00
|
|
|
|
2016-08-05 17:39:41 +02:00
|
|
|
function filterChange(val) {
|
2016-05-08 21:55:13 +02:00
|
|
|
var re = new RegExp(val.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'),'i');
|
2016-01-12 18:54:53 +01:00
|
|
|
$("#palette-container .palette_node").each(function(i,el) {
|
2015-03-20 12:40:34 +01:00
|
|
|
var currentLabel = $(el).find(".palette_label").text();
|
|
|
|
if (val === "" || re.test(el.id) || re.test(currentLabel)) {
|
2014-01-19 01:01:27 +01:00
|
|
|
$(this).show();
|
|
|
|
} else {
|
|
|
|
$(this).hide();
|
|
|
|
}
|
2013-09-05 16:02:48 +02:00
|
|
|
});
|
2015-07-14 16:59:56 +02:00
|
|
|
|
|
|
|
for (var category in categoryContainers) {
|
|
|
|
if (categoryContainers.hasOwnProperty(category)) {
|
|
|
|
if (categoryContainers[category].container
|
|
|
|
.find(".palette_node")
|
|
|
|
.filter(function() { return $(this).css('display') !== 'none'}).length === 0) {
|
|
|
|
categoryContainers[category].close();
|
|
|
|
} else {
|
|
|
|
categoryContainers[category].open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-19 01:01:27 +01:00
|
|
|
}
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2014-11-11 11:15:02 +01:00
|
|
|
function init() {
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2016-08-04 17:49:36 +02:00
|
|
|
RED.events.on('registry:node-type-added', function(nodeType) {
|
|
|
|
var def = RED.nodes.getType(nodeType);
|
|
|
|
addNodeType(nodeType,def);
|
|
|
|
if (def.onpaletteadd && typeof def.onpaletteadd === "function") {
|
|
|
|
def.onpaletteadd.call(def);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
RED.events.on('registry:node-type-removed', function(nodeType) {
|
|
|
|
removeNodeType(nodeType);
|
2014-11-11 11:15:02 +01:00
|
|
|
});
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2016-08-04 17:49:36 +02:00
|
|
|
RED.events.on('registry:node-set-enabled', function(nodeSet) {
|
|
|
|
for (var j=0;j<nodeSet.types.length;j++) {
|
|
|
|
showNodeType(nodeSet.types[j]);
|
|
|
|
var def = RED.nodes.getType(nodeSet.types[j]);
|
|
|
|
if (def.onpaletteadd && typeof def.onpaletteadd === "function") {
|
|
|
|
def.onpaletteadd.call(def);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
RED.events.on('registry:node-set-disabled', function(nodeSet) {
|
|
|
|
for (var j=0;j<nodeSet.types.length;j++) {
|
|
|
|
hideNodeType(nodeSet.types[j]);
|
|
|
|
var def = RED.nodes.getType(nodeSet.types[j]);
|
|
|
|
if (def.onpaletteremove && typeof def.onpaletteremove === "function") {
|
|
|
|
def.onpaletteremove.call(def);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
RED.events.on('registry:node-set-removed', function(nodeSet) {
|
|
|
|
if (nodeSet.added) {
|
|
|
|
for (var j=0;j<nodeSet.types.length;j++) {
|
|
|
|
removeNodeType(nodeSet.types[j]);
|
|
|
|
var def = RED.nodes.getType(nodeSet.types[j]);
|
|
|
|
if (def.onpaletteremove && typeof def.onpaletteremove === "function") {
|
|
|
|
def.onpaletteremove.call(def);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-11 11:15:02 +01:00
|
|
|
});
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2016-08-04 17:49:36 +02:00
|
|
|
|
2016-08-09 11:43:03 +02:00
|
|
|
$("#palette > .palette-spinner").show();
|
|
|
|
|
|
|
|
$("#palette-search input").searchBox({
|
|
|
|
delay: 100,
|
|
|
|
change: function() {
|
|
|
|
filterChange($(this).val());
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2016-08-10 21:15:17 +02:00
|
|
|
var categoryList = coreCategories;
|
2015-02-06 14:16:19 +01:00
|
|
|
if (RED.settings.paletteCategories) {
|
2016-08-10 21:15:17 +02:00
|
|
|
categoryList = RED.settings.paletteCategories;
|
|
|
|
} else if (RED.settings.theme('palette.categories')) {
|
|
|
|
categoryList = RED.settings.theme('palette.categories');
|
|
|
|
}
|
|
|
|
if (!Array.isArray(categoryList)) {
|
|
|
|
categoryList = coreCategories
|
2015-02-06 14:16:19 +01:00
|
|
|
}
|
2016-08-10 21:15:17 +02:00
|
|
|
categoryList.forEach(function(category){
|
|
|
|
createCategoryContainer(category, RED._("palette.label."+category,{defaultValue:category}));
|
2014-01-19 01:01:27 +01:00
|
|
|
});
|
2015-07-14 16:59:56 +02:00
|
|
|
|
|
|
|
$("#palette-collapse-all").on("click", function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
for (var cat in categoryContainers) {
|
|
|
|
if (categoryContainers.hasOwnProperty(cat)) {
|
|
|
|
categoryContainers[cat].close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$("#palette-expand-all").on("click", function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
for (var cat in categoryContainers) {
|
|
|
|
if (categoryContainers.hasOwnProperty(cat)) {
|
|
|
|
categoryContainers[cat].open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-11-11 11:15:02 +01:00
|
|
|
}
|
2014-10-01 14:41:06 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
return {
|
2014-11-11 11:15:02 +01:00
|
|
|
init: init,
|
2014-08-07 14:46:03 +02:00
|
|
|
add:addNodeType,
|
2014-08-28 01:35:07 +02:00
|
|
|
remove:removeNodeType,
|
|
|
|
hide:hideNodeType,
|
2014-02-25 00:35:11 +01:00
|
|
|
show:showNodeType,
|
|
|
|
refresh:refreshNodeTypes
|
2013-09-05 16:02:48 +02:00
|
|
|
};
|
2014-08-08 01:01:35 +02:00
|
|
|
})();
|