tabs.addTab('tabID', object);
''object'' can either be an objet defining the tab, or an array containing any number of secondary tabs, available through a built-in pull-down menu.
Sub-tabs must be added in the order you want them to appear. The first defined tab will be the one to appear when the widget loads.
// one tab
tabs.addTab('firstTab', {text: 'firstTabTitle'} );
// one tab with a secondary tab
tabs.addTab('tabGroup', [
{id: 'secondTab', text: 'secondTabTitle'},
{id: 'firstSubTab', text: 'firstSubTabTitle'}
]);
Each can use the following defined settings:
^ Info ^ Usage ^
| id | Sets the JS id for the tab |
| text | Sets the title of the tab |
| icon | Sets an icon for the tab (12*12 PNG file) |
You can also define any custom value, for later retrieval (see sample code):
tabs.addTab('firstTab',
{text: 'firstTabTitle', customValue: 'my custom value'} );
===The setContent method===
The ''setContent'' method, also defined by the TabView object, is used to fill-in your tab with content. It takes two arguments: the tab id, and the content (in the form of an HTML string).
tabs.setContent('tabID', 'Hey there!
');
var contentForTheTab = 'Hey there!
';
tabs.setContent('tabID', contentForTheTab);
Because the content is made of HTML code, you can put just about anything in a tab: text, image, Flash, Google Map, etc...
===Sample code===
var TabViewSample = {};
widget.onLoad = function() {
var tabs = new UWA.Controls.TabView();
TabViewSample.tabs = tabs;
// Create tab items
tabs.addTab("tab1", {text: "Tab One", customInfo: "custom"});
tabs.addTab("tab2", {text: "Tab Two"});
tabs.addTab("tab3", {text: "Tab Three"});
// Put some content in tabs
tabs.setContent("tab1", "Tab one
");
tabs.setContent("tab2", "Tab two
");
tabs.setContent("tab3", "Tab three
");
// Restore saved active tab
var activeTab = widget.getValue("activeTab");
if (activeTab) {
tabs.selectTab(activeTab);
}
// Register to activeTabChange event
tabs.observe('activeTabChange', TabViewSample.onActiveTabChanged);
widget.setBody('');
// Append tabview to widget body
tabs.appendTo(widget.body);
}
TabViewSample.onActiveTabChanged = function(name, data) {
var tabs = TabViewSample.tabs;
var contentHtml = tabs.getTabContent(name).innerHTML;
contentHtml += 'Tab name: '+name+', event: activeTabChange
';
if (data.customInfo) {
contentHtml += 'customInfo has value: '+ data.customInfo+'
';
}
tabs.setContent(name, contentHtml);
// Save active tab
widget.setValue("activeTab", name);
}
====Sample widget====
See the [[http://eco.netvibes.com/widgets/203214|Rugby World Cup 2007]] widget.