var tabs = new UWA.Controls.TabView();
MyWidget.tabs = tabs;
====The addTab method====
The ''addTab'' method, defined by the TabView object, is where you define one tab. It takes two arguments: the first on is the id of the tab (or group of tabs), the second one is an object or array, used for defined or custom options.
Tabs must be added in the order you want them to appear.
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.
// one tab
tabs.addTab('firstTab', {text: 'Title for the first tab'} );
// three tabs
tabs.addTab('firstTab', {text: 'First tab'});
tabs.addTab('secondTab', {text: 'Second tab'});
tabs.addTab('thirdTab', {text: 'Third tab'});
If you need sub-tabs, note that they 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 with a secondary tab
tabs.addTab('tabGroup', [
{id: 'secondTab', text: 'secondTabTitle'},
{id: 'firstSubTab', text: 'firstSubTabTitle'}
]);
Each tab 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). This is however seldomly implemented in normal use...
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 is the equivalent of el.setHTML for a normal HTML element.
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.