mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #434 from anna2130/palette-multi-line-nodes
Node expands for multi-line node names
This commit is contained in:
commit
483c4352d3
@ -34,7 +34,6 @@ RED.palette = (function() {
|
||||
$(this).next().slideToggle();
|
||||
$(this).children("i").toggleClass("expanded");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
core.forEach(createCategoryContainer);
|
||||
@ -56,12 +55,38 @@ RED.palette = (function() {
|
||||
d.id = "palette_node_"+nodeTypeId;
|
||||
d.type = nt;
|
||||
|
||||
var label = /^(.*?)([ -]in|[ -]out)?$/.exec(nt)[1];
|
||||
// calculate width of label text
|
||||
$.fn.textWidth = function(text, font) {
|
||||
if (!$.fn.textWidth.fakeEl) {
|
||||
$.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body);
|
||||
}
|
||||
$.fn.textWidth.fakeEl.text(text || this.val() || this.text()).css('font', font || this.css('font'));
|
||||
return $.fn.textWidth.fakeEl.width();
|
||||
};
|
||||
|
||||
d.innerHTML = '<div class="palette_label">'+label+"</div>";
|
||||
var label = /^(.*?)([ -]in|[ -]out)?$/.exec(nt)[1];
|
||||
var pixels = $.fn.textWidth(label, '13px helvetica');
|
||||
var nodeWidth = 90;
|
||||
var labelWidth = nodeWidth - 10;
|
||||
var numLines = Math.ceil(pixels / nodeWidth);
|
||||
var multiLine = numLines > 1;
|
||||
|
||||
// styles matching with style.css
|
||||
var nodeHeight = 25;
|
||||
var lineHeight = 16;
|
||||
var portHeight = 10;
|
||||
var multiLineNodeHeight = lineHeight * numLines + (nodeHeight - lineHeight);
|
||||
|
||||
d.innerHTML = '<div class="palette_label"'+
|
||||
(multiLine ? 'style="line-height: '+
|
||||
lineHeight + 'px; margin-top: 5px"' : '')+
|
||||
'>'+label+"</div>";
|
||||
d.className="palette_node";
|
||||
if (def.icon) {
|
||||
d.style.backgroundImage = "url(icons/"+def.icon+")";
|
||||
if (multiLine) {
|
||||
d.style.backgroundSize = "18px 27px";
|
||||
}
|
||||
if (def.align == "right") {
|
||||
d.style.backgroundPosition = "95% 50%";
|
||||
} else if (def.inputs > 0) {
|
||||
@ -70,16 +95,23 @@ RED.palette = (function() {
|
||||
}
|
||||
|
||||
d.style.backgroundColor = def.color;
|
||||
d.style.height = multiLineNodeHeight + "px";
|
||||
|
||||
if (def.outputs > 0) {
|
||||
var portOut = document.createElement("div");
|
||||
portOut.className = "palette_port palette_port_output";
|
||||
if (multiLine) {
|
||||
portOut.style.top = ((multiLineNodeHeight - portHeight) / 2) + "px";
|
||||
}
|
||||
d.appendChild(portOut);
|
||||
}
|
||||
|
||||
if (def.inputs > 0) {
|
||||
var portIn = document.createElement("div");
|
||||
portIn.className = "palette_port";
|
||||
if (multiLine) {
|
||||
portIn.style.top = ((multiLineNodeHeight - portHeight) / 2) + "px";
|
||||
}
|
||||
d.appendChild(portIn);
|
||||
}
|
||||
|
||||
@ -92,7 +124,7 @@ RED.palette = (function() {
|
||||
}
|
||||
|
||||
$("#palette-"+category).append(d);
|
||||
d.onmousedown = function(e) { e.preventDefault(); }
|
||||
d.onmousedown = function(e) { e.preventDefault(); };
|
||||
|
||||
$(d).popover({
|
||||
title:d.type,
|
||||
|
Loading…
Reference in New Issue
Block a user