Displaying Tabs
Advance preparation
OpenSocial has a feature that displays messages to users with tab dialogs. Use of the tabs feature must be declared with Required Elements in Gadget XML in order to use this feature.
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Hello, world!">
<Require feature="tabs" />
...
Creating a tab
First, the contents for displaying the tab must be prepared. A minimum of 1 element per TabSet and minimum of 1 element per Tab are necessary in the contents.
<div id="tabs" />
<div id="tab1">This is tab 1.</div>
<div id="tab2">This is tab 2.</div>
<div id="tab3">This is tab 3.</div>
The following is sample code for handling these contents as a tab.
var tabs = new gadgets.TabSet(__MODULE_ID__, null, document.getElementById("tabs"));
tabs.addTab("Tab 1", {
contentContainer: document.getElementById("tab1"),
callback: function() {
// ...
}
});
tabs.addTab("Tab 2", {
contentContainer: document.getElementById("tab2"),
callback: function() {
// ...
}
});
tabs.addTab("Tab 3", {
contentContainer: document.getElementById("tab3"),
callback: function() {
// ...
}
});
- Specify the ID of the DOM element for the TabSet and generate a TabSet? object with the gadgets.TabSet?() constructor.
- Add a tab to the TabSet with the addTab() method. The specifiable parameters are as follows.
- contentContainer: The DOM element that becomes the contents of the tab. A new DOM element is added by default.
- callback: The callback function called when this tab is selected.
- tooltip: The tooltip string that is displayed when the cursor is over this tab.
- index: The location where this tab is inserted. It is added to the end by default.
The method for acquiring the selected tab and explicitly calling the callback function is as follows.
var selected = tabs.getSelectedTab();
var callback = selected.getCallback
callback.call();
Revision History
- 12/2010
- Initial Release.