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

Tidy-up tab ui api

This commit is contained in:
Nick O'Leary 2014-02-21 09:54:50 +00:00
parent f7a72a48ea
commit 715fb6e7f4
5 changed files with 65 additions and 14 deletions

View File

@ -131,7 +131,15 @@
<ul id="workspace-tabs"></ul> <ul id="workspace-tabs"></ul>
<div id="workspace-add-tab"><a id="btn-workspace-add-tab" href="#"><i class="icon-plus"></i></a></div> <div id="workspace-add-tab"><a id="btn-workspace-add-tab" href="#"><i class="icon-plus"></i></a></div>
<div id="chart"></div> <div id="chart"></div>
<div id="workspace-toolbar">
<div class="btn-group">
<a class="btn btn-small" href="#"><i class="icon-zoom-out"></i></a>
<a class="btn btn-small" href="#"><i class="icon-th"></i></a>
<a class="btn btn-small" href="#"><i class="icon-zoom-in"></i></a>
</div> </div>
</div>
</div>
<div id="chart-zoom-controls"> <div id="chart-zoom-controls">
<div class="btn-group"> <div class="btn-group">

View File

@ -18,12 +18,12 @@ RED.sidebar = function() {
//$('#sidebar').tabs(); //$('#sidebar').tabs();
var sidebar_tabs = RED.tabs.create({ var sidebar_tabs = RED.tabs.create({
id:"sidebar-tabs", id:"sidebar-tabs",
onchange:function(id) { onchange:function(tab) {
$("#sidebar-content").children().hide(); $("#sidebar-content").children().hide();
$("#"+id).show(); $("#"+tab.id).show();
}, },
onremove: function(id) { onremove: function(tab) {
$("#"+id).remove(); $("#"+tab.id).remove();
} }
}); });
function addTab(title,content,closeable) { function addTab(title,content,closeable) {

View File

@ -20,6 +20,8 @@ RED.tabs = function() {
function createTabs(options) { function createTabs(options) {
var tabs = {};
var ul = $("#"+options.id) var ul = $("#"+options.id)
ul.addClass("red-ui-tabs"); ul.addClass("red-ui-tabs");
ul.children().first().addClass("active"); ul.children().first().addClass("active");
@ -32,7 +34,7 @@ RED.tabs = function() {
function onTabDblClick() { function onTabDblClick() {
if (options.ondblclick) { if (options.ondblclick) {
options.ondblclick($(this).attr('href').slice(1)); options.ondblclick(tabs[$(this).attr('href').slice(1)]);
} }
return false; return false;
} }
@ -45,11 +47,11 @@ RED.tabs = function() {
ul.children().removeClass("active"); ul.children().removeClass("active");
link.parent().addClass("active"); link.parent().addClass("active");
if (options.onchange) { if (options.onchange) {
options.onchange(link.attr('href').slice(1)); options.onchange(tabs[link.attr('href').slice(1)]);
}
} }
} }
}
function updateTabWidths() { function updateTabWidths() {
var tabs = ul.find("li.red-ui-tab"); var tabs = ul.find("li.red-ui-tab");
var width = ul.width(); var width = ul.width();
@ -57,8 +59,8 @@ RED.tabs = function() {
var tabWidth = (width-6-(tabCount*7))/tabCount; var tabWidth = (width-6-(tabCount*7))/tabCount;
var pct = 100*tabWidth/width; var pct = 100*tabWidth/width;
tabs.css({width:pct+"%"}); tabs.css({width:pct+"%"});
} }
ul.find("li.red-ui-tab a").on("click",onTabClick).on("dblclick",onTabDblClick); ul.find("li.red-ui-tab a").on("click",onTabClick).on("dblclick",onTabDblClick);
updateTabWidths(); updateTabWidths();
@ -74,12 +76,15 @@ RED.tabs = function() {
} }
li.remove(); li.remove();
if (options.onremove) { if (options.onremove) {
options.onremove(id); options.onremove(tabs[id]);
} }
delete tabs[id];
updateTabWidths(); updateTabWidths();
} }
return { return {
addTab: function(tab) { addTab: function(tab) {
tabs[tab.id] = tab;
var li = $("<li/>",{class:"red-ui-tab"}).appendTo(ul); var li = $("<li/>",{class:"red-ui-tab"}).appendTo(ul);
var link = $("<a/>",{href:"#"+tab.id, class:"red-ui-tab-label"}).appendTo(li); var link = $("<a/>",{href:"#"+tab.id, class:"red-ui-tab-label"}).appendTo(li);
link.html(tab.label); link.html(tab.label);

View File

@ -70,11 +70,17 @@ RED.view = function() {
var workspace_tabs = RED.tabs.create({ var workspace_tabs = RED.tabs.create({
id: "workspace-tabs", id: "workspace-tabs",
onchange: function(id) { onchange: function(tab) {
RED.view.setWorkspace(id); if (tab.type == "subflow") {
$("#workspace-toolbar").show();
} else {
$("#workspace-toolbar").hide();
}
RED.view.setWorkspace(tab.id);
}, },
ondblclick: function(id) { ondblclick: function(tab) {
showRenameWorkspaceDialog(id); showRenameWorkspaceDialog(tab.id);
}, },
onadd: function(tab) { onadd: function(tab) {
var menuli = $("<li/>"); var menuli = $("<li/>");
@ -98,6 +104,8 @@ RED.view = function() {
} else { } else {
$('#btn-workspace-delete').parent().removeClass("disabled"); $('#btn-workspace-delete').parent().removeClass("disabled");
} }
$('#workspace-menu-list a[href="#'+tab.id+'"]').parent().remove();
} }
}); });
@ -1224,7 +1232,6 @@ RED.view = function() {
}, },
removeWorkspace: function(ws) { removeWorkspace: function(ws) {
workspace_tabs.removeTab(ws.id); workspace_tabs.removeTab(ws.id);
$('#workspace-menu-list a[href="#'+ws.id+'"]').parent().remove();
}, },
getWorkspace: function() { getWorkspace: function() {
return activeWorkspace; return activeWorkspace;
@ -1272,6 +1279,12 @@ RED.view = function() {
importNodes: importNodes, importNodes: importNodes,
resize: function() { resize: function() {
workspace_tabs.resize(); workspace_tabs.resize();
},
addFlow: function() {
var ws = {type:"subflow",id:RED.nodes.id(),label:"Flow 1", closeable: true};
RED.nodes.addWorkspace(ws);
workspace_tabs.addTab(ws);
} }
}; };
}(); }();

View File

@ -36,6 +36,15 @@ body {
font-size: 40px; font-size: 40px;
color: #fff; color: #fff;
} }
div.btn-group, a.btn {
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
a.brand { a.brand {
line-height: 16px; line-height: 16px;
} }
@ -71,6 +80,17 @@ a.brand img {
left:0px; left:0px;
right:0px; right:0px;
} }
#workspace-toolbar {
display: none;
position: absolute;
top: 30px;
left:0;
right: 18px;
padding: 5px;
background: #f3f3f3;
}
#chart-zoom-controls { #chart-zoom-controls {
padding-top: 3px; padding-top: 3px;
text-align: right; text-align: right;
@ -691,6 +711,11 @@ ul.red-ui-tabs {
height: 24px; height: 24px;
border-bottom: 1px solid #999; border-bottom: 1px solid #999;
background: #e3e3e3; background: #e3e3e3;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
} }
ul.red-ui-tabs li { ul.red-ui-tabs li {