Tabs
Tabs are generally used to break content into multiple sections that can be swapped to save space, much like an accordion. By default a tab widget will swap between tabbed sections onClick, but the events can be changed to onHover through an option. Tab content can be loaded via Ajax by setting an href on a tab.
Demo
Source Code
<div id="myTabs" control="jquery_tabs"> <div id="tab0" title="Tab 0"> Less Filling! </div> <div id="tab1" title="Tab 1"> Tastes Great! </div> </div>
In this sample, a tabs widget with the name of 'myTabs' is created with the initial option - “properties” suplied. The function argument of createControl is called when the widget renders, and an object containing all the data necessary to create some tabs is passed to the render object.
Script Example
Create the control, and add some tabs immediately…
App.createControl( 'myTabs', 'jquery_tabs', { property: "rows" }, function() { this.render({ rows: [{ id:"zero", title: "First Section", content: "someStringData" }, { id:"one", title: "Second Section", url: "myFile1.html" }, { id:"two", title: "Third Section", url: "myFile2.html" } ] }); } );
Get the handle to an instance of the control, and set the on attribute and perform an action when a message is received (see Entourage MQ and Entourage Expressions for more information about what the callback function is doing here)…
App.getControl('myTabs2', 'jquery_tabs', function() { this.on("l:buildTabs then render"); });
Options
The accordion control is made up of a container div and a single level of divs within that container which will constitute it's rows when it is rendered. The control tag on the div indicates what kind of widget the div will become. The widget identity can accept the following initial parameters…
Initial options supported by the widget.
| Option | Description | Default | Type |
|---|---|---|---|
| selected | Zero-based index of the tab to be selected on initialization. To set all tabs to unselected set this option to null. | 0 | Int |
| unselect | Allows a currently selected tab to become unselected upon clicking. | false | Bool |
| event | The type of event to be used for selecting a tab. | “click” | String |
| disabled | An array containing the position of the tabs (zero-based index) that should be disabled on initialization. | [] | Array |
| cookie | Store the latest active (clicked) tab in a cookie. The cookie is used to determine the active tab on the next page load. Requires cookie plugin. The object needs to have key/value pairs of the form the cookie plugin expects as options. Available options: { expires: 7, path: '/', domain: 'jquery.com', secure: true } | null | Object |
| spinner | The HTML content of this string is shown in a tab title while remote content is loading. Pass in empty string to deactivate that behavior. | “Loading…” | String |
| cache | Wether or not to cache remote tabs content, e.g. load only once or with every click. Cached content is being lazy loaded, e.g once and only once for the first click. Note that to prevent the actual Ajax requests from being cached by the browser you need to provide an extra cache: false flag to ajaxOptions. | false | Bool |
| ajaxOptions | Additional Ajax options to consider when loading tab content | {} | Object |
| idPrefix | If the remote tab, its anchor element that is, has no title attribute to generate an id from, an id/fragment identifier is created from this prefix and a unique id returned by $.data(el), for example 'ui-tabs-54'. | “ui-tabs-” | String |
| fx | Enable animations for hiding and showing tab panels. The duration option can be a string representing one of the three predefined speeds ('slow', 'normal', 'fast') or the duration in milliseconds to run an animation (default is 'normal'). | null | String |
| tabTemplate | HTML template from which a new tab is created and added. The placeholders #{href} and #{label} are replaced with the url and tab label that are passed as arguments to the add method. | ”<li><a href='#{href}'> <span>#{label}</span> </a></li>” | String |
| panelTemplate | HTML template from which a new tab panel is created in case of adding a tab with the add method or when creating a panel for a remote tab on the fly. | ”<div></div>” | String |
| select | Function that gets called when clicking a tab. | null | Function |
| load | Function that gets called when clicking a tab. | null | Function |
| show | Function that gets called when a tab is shown. | null | Function |
| add | Function that gets called when a tab was added. | null | Function |
| remove | Function that gets called when a tab was removed. | null | Function |
| enable | Function that gets called when a tab was enabled. | null | Function |
| disable | Function that gets called when a tab was disabled. | null | Function |
Actions/JavaScript API
Functions either accept a single argument such as an integer or a string, otherwise they accept a one dimensional object literal. Any function that can be called as an action accepts the same parameters but in the action parameter format. For example…
this.reload({ index: 1, url: "myFile.html" });
is equivalent to…
<div control="jquery_tabs" id="myTabs" on="l:loadMe then reload[index=1, url='myFile.html']"> </div>
| Function | Action | Description |
|---|---|---|
| add(obj) | add[] | Add a new tab to an instance of a tab widget. The function accepts an object literal with three members; “index” (int), “url” (string) and “label” (string). The action accepts the three parameters with the same names and types. |
| enable(int) | enable[] | Enable a tab based on its index. |
| disable(int) | disable[] | Disable a tab based on its index. |
| remove(int) | remove[] | Remove a tab absed on its index. |
| load(int) | Load the data from the url that is currently associated with the tab at index N. | |
| url(obj) | Change the url that is currently associated with the tab at index N. The function accepts an object literal with two members; “index” (int) and “url” (string). The action accepts the two parameters with the same names and types. | |
| reload(obj) | reload[] | The function accepts an object literal with two members; “index” (int) and “url” (string). The action accepts the two parameters with the same names and types. |
| length() | Returns a count of how many tabs currently exist in the instance of the widget. | |
| render() | render | Renders the widget with data from the data payload contained in a Entourage Message. |