diff --git a/editor/js/ui/palette.js b/editor/js/ui/palette.js index 411a39cee..d7b2a11a7 100644 --- a/editor/js/ui/palette.js +++ b/editor/js/ui/palette.js @@ -127,8 +127,9 @@ RED.palette = (function() { if (def.icon) { + var icon_url = (typeof def.icon === "function" ? def.icon.call({}) : def.icon); var iconContainer = $('
',{class:"palette_icon_container"+(def.align=="right"?" palette_icon_container_right":"")}).appendTo(d); - $('
',{class:"palette_icon",style:"background-image: url(icons/"+def.icon+")"}).appendTo(iconContainer); + $('
',{class:"palette_icon",style:"background-image: url(icons/"+icon_url+")"}).appendTo(iconContainer); } d.style.backgroundColor = def.color; diff --git a/editor/js/ui/view.js b/editor/js/ui/view.js index 3359b2a30..0ee42d6ab 100644 --- a/editor/js/ui/view.js +++ b/editor/js/ui/view.js @@ -1459,6 +1459,29 @@ RED.view = (function() { (d._def.align?' node_label_'+d._def.align:'')+ (d._def.labelStyle?' '+(typeof d._def.labelStyle == "function" ? d._def.labelStyle.call(d):d._def.labelStyle):'') ; }); + + if (d._def.icon) { + icon = thisNode.select(".node_icon"); + var current_url = icon.attr("xlink:href"); + var icon_url; + if (typeof d._def.icon == "function") { + icon_url = d._def.icon.call(d); + } else { + icon_url = d._def.icon; + } + if ("icons/"+icon_url != current_url) { + icon.attr("xlink:href","icons/"+icon_url); + var img = new Image(); + img.src = "icons/"+d._def.icon; + img.onload = function() { + icon.attr("width",Math.min(img.width,30)); + icon.attr("height",Math.min(img.height,30)); + icon.attr("x",15-Math.min(img.width,30)/2); + } + } + } + + thisNode.selectAll(".node_tools").attr("x",function(d){return d.w-35;}).attr("y",function(d){return d.h-20;}); thisNode.selectAll(".node_changed")