2
// $Id: tabs.inc,v 1.7 2008/05/27 23:49:37 merlinofchaos Exp $
6
* Classes and theme functions for rendering javascript UI tabs.
10
* Contain a set of tabs as well as the ability to render them.
12
* There are three 'areas' of a tabset.
13
* - title: The clickable link to display the tab area. These are always visible.
14
* - body: The actual HTML body of the tab. Only one body is visible at a time.
15
* - extra: An optional decorative area around the tabs.
23
* Add a tab to the tabset.
26
* The name of the tab; this is the internal identifier and must be
27
* unique within the tabset.
29
* If given, this will be the visible title of the tab. This can also
30
* be set via $tabset->set(). This will be the link to click on to
33
* If given, this is the body of the tab itself. It will display
34
* when the tab title is clicked on.
36
function add($name, $title = '', $body = '') {
37
if (is_object($name) && is_subclass_of($name, 'views_tab')) {
38
$this->add_tab($name);
40
elseif (is_array($name)) {
41
foreach ($name as $real_tab) {
42
$this->add($real_tab);
46
$this->add_tab(new views_tab($name, $title, $body));
51
* Add a fully realized tab object to the tabset.
54
* A fully populated views_tab object.
56
function add_tab($tab) {
57
$this->tabs[$tab->name] = $tab;
61
* Set the values of a tab.
64
* The unique identifier of the tab to set.
66
* The title of the tab; this will be clickable.
68
* The HTML body of the tab.
70
function set($name, $title, $body = NULL) {
71
if (empty($this->tabs[$name])) {
72
return $this->add($name, $title, $body);
74
$this->tabs[$name]->title = $title;
76
$this->tabs[$name]->body = $body;
81
* Set the body of a tab.
83
function set_body($name, $body) {
84
if (empty($this->tabs[$name])) {
85
return $this->add($name, '', $body);
87
$this->tabs[$name]->body = $body;
91
* Add text to the 'extra' region of the tabset.
93
function add_extra($text) {
94
$this->extra .= $text;
101
* May be the name of the tab or a views_tab object.
103
function remove($tab) {
104
if (is_string($tab)) {
105
unset($this->tabs[$tab]);
108
unset($this->tabs[$tab->name]);
113
* Control which tab will be selected when it is rendered.
115
function set_selected($name) {
116
$this->selected = $name;
120
* Output the HTML for the tabs.
123
* HTML representation of the tabs.
126
views_add_js('tabs');
127
views_add_css('views-tabs');
129
if (empty($this->selected)) {
130
$keys = array_keys($this->tabs);
131
$this->selected = array_shift($keys);
134
drupal_alter('views_tabset', $this);
135
return theme('views_tabset', $this->tabs, $this->extra, $this->selected);
140
* An object to represent an individual tab within a tabset.
148
* Construct a new tab.
150
function views_tab($name, $title, $body = NULL) {
152
$this->title = $title;
157
* Generate HTML output for a tab.
160
return theme('views_tab', $this->body);
167
* @todo Turn this into a template.
169
function theme_views_tabset($tabs, $extra = NULL, $selected = NULL) {
170
$link_output = "<div class=\"views-tabs\"><ul id=\"views-tabset\">\n";
171
$tab_output = "<div class=\"views-tab-area\">\n";
173
foreach ($tabs as $name => $tab) {
174
$link_output .= '<li' . ($name == $selected ? ' class="active"': '') . '><a href="#views-tab-' . $tab->name . '" id="views-tab-title-' . $tab->name . '">' . check_plain($tab->title) . '</a></li>' . "\n";
175
$tab_output .= '<div id="views-tab-' . $tab->name . '" class="views-tab">' . $tab->render() . "</div>\n";
177
$link_output .= "</ul>\n";
180
$link_output .= "<div class=\"extra\">$extra</div>\n";
183
$link_output .= "</div>\n";
184
$tab_output .= "</div>\n";
185
return '<div class="views-tabset clear-block">' . $link_output . $tab_output . '</div>';
189
* Theme a simple tab.
191
function theme_views_tab($body) {