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

Keep sidebar tab menu in alphabetical order

This commit is contained in:
Nick O'Leary 2015-07-09 16:48:53 +01:00
parent fde9d40098
commit e5a0f25d94
3 changed files with 37 additions and 12 deletions

View File

@ -29,7 +29,7 @@ RED.menu = (function() {
return null; return null;
} }
} }
function setInitialState() { function setInitialState() {
var savedStateActive = isSavedStateActive(opt.id); var savedStateActive = isSavedStateActive(opt.id);
if (savedStateActive) { if (savedStateActive) {
@ -52,12 +52,16 @@ RED.menu = (function() {
item = $('<li class="divider"></li>'); item = $('<li class="divider"></li>');
} else { } else {
item = $('<li></li>'); item = $('<li></li>');
if (opt.group) {
item.addClass("menu-group-"+opt.group);
}
var linkContent = '<a '+(opt.id?'id="'+opt.id+'" ':'')+'tabindex="-1" href="#">'; var linkContent = '<a '+(opt.id?'id="'+opt.id+'" ':'')+'tabindex="-1" href="#">';
if (opt.toggle) { if (opt.toggle) {
linkContent += '<i class="fa fa-square pull-left"></i>'; linkContent += '<i class="fa fa-square pull-left"></i>';
linkContent += '<i class="fa fa-check-square pull-left"></i>'; linkContent += '<i class="fa fa-check-square pull-left"></i>';
} }
if (opt.icon !== undefined) { if (opt.icon !== undefined) {
if (/\.png/.test(opt.icon)) { if (/\.png/.test(opt.icon)) {
@ -66,16 +70,16 @@ RED.menu = (function() {
linkContent += '<i class="'+(opt.icon?opt.icon:'" style="display: inline-block;"')+'"></i> '; linkContent += '<i class="'+(opt.icon?opt.icon:'" style="display: inline-block;"')+'"></i> ';
} }
} }
if (opt.sublabel) { if (opt.sublabel) {
linkContent += '<span class="menu-label-container"><span class="menu-label">'+opt.label+'</span>'+ linkContent += '<span class="menu-label-container"><span class="menu-label">'+opt.label+'</span>'+
'<span class="menu-sublabel">'+opt.sublabel+'</span></span>' '<span class="menu-sublabel">'+opt.sublabel+'</span></span>'
} else { } else {
linkContent += '<span class="menu-label">'+opt.label+'</span>' linkContent += '<span class="menu-label">'+opt.label+'</span>'
} }
linkContent += '</a>'; linkContent += '</a>';
var link = $(linkContent).appendTo(item); var link = $(linkContent).appendTo(item);
menuItems[opt.id] = opt; menuItems[opt.id] = opt;
@ -139,7 +143,7 @@ RED.menu = (function() {
content: opt.tip content: opt.tip
}); });
} }
} }
@ -154,8 +158,8 @@ RED.menu = (function() {
// $("#"+options.id+"-submenu").show(); // $("#"+options.id+"-submenu").show();
// event.preventDefault(); // event.preventDefault();
//}); //});
var topMenu = $("<ul/>",{id:options.id+"-submenu", class:"dropdown-menu pull-right"}).insertAfter(button); var topMenu = $("<ul/>",{id:options.id+"-submenu", class:"dropdown-menu pull-right"}).insertAfter(button);
var lastAddedSeparator = false; var lastAddedSeparator = false;
@ -208,7 +212,27 @@ RED.menu = (function() {
} }
function addItem(id,opt) { function addItem(id,opt) {
createMenuItem(opt).appendTo("#"+id+"-submenu"); var item = createMenuItem(opt);
if (opt.group) {
var groupItems = $("#"+id+"-submenu").children(".menu-group-"+opt.group);
if (groupItems.length === 0) {
item.appendTo("#"+id+"-submenu");
} else {
for (var i=0;i<groupItems.length;i++) {
var groupItem = groupItems[i];
var label = $(groupItem).find(".menu-label").html();
if (opt.label < label) {
$(groupItem).before(item);
break;
}
}
if (i === groupItems.length) {
item.appendTo("#"+id+"-submenu");
}
}
} else {
item.appendTo("#"+id+"-submenu");
}
} }
function removeItem(id) { function removeItem(id) {
$("#"+id).parent().remove(); $("#"+id).parent().remove();

View File

@ -64,7 +64,8 @@ RED.sidebar = (function() {
label:options.name, label:options.name,
onselect:function() { onselect:function() {
showSidebar(options.id); showSidebar(options.id);
} },
group: "sidebar-tabs"
}); });
knownTabs[options.id] = options; knownTabs[options.id] = options;

View File

@ -178,7 +178,7 @@
}, },
"sidebar": { "sidebar": {
"info": { "info": {
"name": "Node Information", "name": "Information",
"label": "info", "label": "info",
"node": "Node", "node": "Node",
"type": "Type", "type": "Type",