1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Make Palette search Case InSeNsItIve

fix to close #496
This commit is contained in:
Dave C-J 2014-12-09 14:37:32 +00:00
parent 8c5fab61e6
commit 6fc3aab907

View File

@ -45,12 +45,12 @@ RED.palette = (function() {
var portHeight = 10; var portHeight = 10;
var words = label.split(" "); var words = label.split(" ");
var displayLines = []; var displayLines = [];
var currentLine = words[0]; var currentLine = words[0];
var currentLineWidth = RED.view.calculateTextWidth(currentLine, "palette_label", 0); var currentLineWidth = RED.view.calculateTextWidth(currentLine, "palette_label", 0);
for (var i=1;i<words.length;i++) { for (var i=1;i<words.length;i++) {
var newWidth = RED.view.calculateTextWidth(currentLine+" "+words[i], "palette_label", 0); var newWidth = RED.view.calculateTextWidth(currentLine+" "+words[i], "palette_label", 0);
if (newWidth < nodeWidth) { if (newWidth < nodeWidth) {
@ -63,16 +63,16 @@ RED.palette = (function() {
} }
} }
displayLines.push(currentLine); displayLines.push(currentLine);
var lines = displayLines.join("<br/>"); var lines = displayLines.join("<br/>");
var multiLineNodeHeight = 8+(lineHeight*displayLines.length); var multiLineNodeHeight = 8+(lineHeight*displayLines.length);
el.css({height:multiLineNodeHeight+"px"}); el.css({height:multiLineNodeHeight+"px"});
var labelElement = el.find(".palette_label"); var labelElement = el.find(".palette_label");
labelElement.html(lines); labelElement.html(lines);
el.find(".palette_port").css({top:(multiLineNodeHeight/2-5)+"px"}); el.find(".palette_port").css({top:(multiLineNodeHeight/2-5)+"px"});
var popOverContent; var popOverContent;
try { try {
var l = "<p><b>"+label+"</b></p>"; var l = "<p><b>"+label+"</b></p>";
@ -87,16 +87,16 @@ RED.palette = (function() {
popOverContent = "<p><b>"+label+"</b></p><p>no information available</p>"; popOverContent = "<p><b>"+label+"</b></p><p>no information available</p>";
} }
el.data('popover').options.content = popOverContent; el.data('popover').options.content = popOverContent;
} }
function escapeNodeType(nt) { function escapeNodeType(nt) {
return nt.replace(" ","_").replace(".","_").replace(":","_"); return nt.replace(" ","_").replace(".","_").replace(":","_");
} }
function addNodeType(nt,def) { function addNodeType(nt,def) {
var nodeTypeId = escapeNodeType(nt); var nodeTypeId = escapeNodeType(nt);
if ($("#palette_node_"+nodeTypeId).length) { if ($("#palette_node_"+nodeTypeId).length) {
return; return;
@ -120,7 +120,7 @@ RED.palette = (function() {
} }
d.innerHTML = '<div class="palette_label"></div>'; d.innerHTML = '<div class="palette_label"></div>';
d.className="palette_node"; d.className="palette_node";
if (def.icon) { if (def.icon) {
d.style.backgroundImage = "url(icons/"+def.icon+")"; d.style.backgroundImage = "url(icons/"+def.icon+")";
@ -175,7 +175,7 @@ RED.palette = (function() {
revert: true, revert: true,
revertDuration: 50 revertDuration: 50
}); });
setLabel(nt,$(d),label); setLabel(nt,$(d),label);
} }
} }
@ -193,13 +193,13 @@ RED.palette = (function() {
var nodeTypeId = escapeNodeType(nt); var nodeTypeId = escapeNodeType(nt);
$("#palette_node_"+nodeTypeId).show(); $("#palette_node_"+nodeTypeId).show();
} }
function refreshNodeTypes() { function refreshNodeTypes() {
RED.nodes.eachSubflow(function(sf) { RED.nodes.eachSubflow(function(sf) {
var paletteNode = $("#palette_node_subflow_"+sf.id.replace(".","_")); var paletteNode = $("#palette_node_subflow_"+sf.id.replace(".","_"));
var portInput = paletteNode.find(".palette_port_input"); var portInput = paletteNode.find(".palette_port_input");
var portOutput = paletteNode.find(".palette_port_output"); var portOutput = paletteNode.find(".palette_port_output");
if (portInput.length === 0 && sf.in.length > 0) { if (portInput.length === 0 && sf.in.length > 0) {
var portIn = document.createElement("div"); var portIn = document.createElement("div");
portIn.className = "palette_port palette_port_input"; portIn.className = "palette_port palette_port_input";
@ -207,18 +207,18 @@ RED.palette = (function() {
} else if (portInput.length !== 0 && sf.in.length === 0) { } else if (portInput.length !== 0 && sf.in.length === 0) {
portInput.remove(); portInput.remove();
} }
if (portOutput.length === 0 && sf.out.length > 0) { if (portOutput.length === 0 && sf.out.length > 0) {
var portOut = document.createElement("div"); var portOut = document.createElement("div");
portOut.className = "palette_port palette_port_output"; portOut.className = "palette_port palette_port_output";
paletteNode.append(portOut); paletteNode.append(portOut);
} else if (portOutput.length !== 0 && sf.out.length === 0) { } else if (portOutput.length !== 0 && sf.out.length === 0) {
portOutput.remove(); portOutput.remove();
} }
setLabel(sf.type+":"+sf.id,paletteNode,sf.name); setLabel(sf.type+":"+sf.id,paletteNode,sf.name);
}); });
} }
function filterChange() { function filterChange() {
var val = $("#palette-search-input").val(); var val = $("#palette-search-input").val();
if (val === "") { if (val === "") {
@ -227,7 +227,7 @@ RED.palette = (function() {
$("#palette-search-clear").show(); $("#palette-search-clear").show();
} }
var re = new RegExp(val); var re = new RegExp(val,'i');
$(".palette_node").each(function(i,el) { $(".palette_node").each(function(i,el) {
if (val === "" || re.test(el.id)) { if (val === "" || re.test(el.id)) {
$(this).show(); $(this).show();