5
* @author Sebastian Thierer <sebathi@gmail.com>
6
* @link http://www.yiiframework.com/
7
* @copyright Copyright © 2008-2011 Yii Software LLC
8
* @license http://www.yiiframework.com/license/
11
Yii::import('zii.widgets.jui.CJuiWidget');
14
* CJuiTabs displays a tabs widget.
16
* CJuiTabs encapsulates the {@link http://jqueryui.com/demos/tabs/ JUI tabs}
19
* To use this widget, you may insert the following code in a view:
21
* $this->widget('zii.widgets.jui.CJuiTabs', array(
23
* 'StaticTab 1'=>'Content for tab 1',
24
* 'StaticTab 2'=>array('content'=>'Content for tab 2', 'id'=>'tab2'),
25
* // panel 3 contains the content rendered by a partial view
26
* 'AjaxTab'=>array('ajax'=>$ajaxUrl),
28
* // additional javascript options for the tabs plugin
30
* 'collapsible'=>true,
35
* By configuring the {@link options} property, you may specify the options
36
* that need to be passed to the JUI tabs plugin. Please refer to
37
* the {@link http://jqueryui.com/demos/tabs/ JUI tabs} documentation
38
* for possible options (name-value pairs).
40
* @author Sebastian Thierer <sebathi@gmail.com>
41
* @version $Id: CJuiTabs.php 2799 2011-01-01 19:31:13Z qiang.xue $
42
* @package zii.widgets.jui
45
class CJuiTabs extends CJuiWidget
48
* @var array list of tabs (tab title=>tab content).
49
* Note that the tab title will not be HTML-encoded.
50
* The tab content can be either a string or an array. When it is an array, it can
51
* be in one of the following two formats:
53
* array('id'=>'myTabID', 'content'=>'tab content')
54
* array('id'=>'myTabID', 'ajax'=>URL)
56
* where the 'id' element is optional. The second format allows the tab content
57
* to be dynamically fetched from the specified URL via AJAX. The URL can be either
58
* a string or an array. If an array, it will be normalized into a URL using {@link CHtml::normalizeUrl}.
62
* @var string the name of the container element that contains all panels. Defaults to 'div'.
64
public $tagName='div';
66
* @var string the template that is used to generated every panel title.
67
* The token "{title}" in the template will be replaced with the panel title and
68
* the token "{url}" will be replaced with "#TabID" or with the url of the ajax request.
70
public $headerTemplate='<li><a href="{url}">{title}</a></li>';
72
* @var string the template that is used to generated every tab content.
73
* The token "{content}" in the template will be replaced with the panel content
74
* and the token "{id}" with the tab ID.
76
public $contentTemplate='<div id="{id}">{content}</div>';
80
* This method registers necessary javascript and renders the needed HTML code.
85
if (isset($this->htmlOptions['id']))
86
$id = $this->htmlOptions['id'];
88
$this->htmlOptions['id']=$id;
90
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
96
foreach($this->tabs as $title=>$content)
98
$tabId = (is_array($content) && isset($content['id']))?$content['id']:$id.'_tab_'.$tabCount++;
100
if (!is_array($content))
102
$tabsOut .= strtr($this->headerTemplate, array('{title}'=>$title, '{url}'=>'#'.$tabId))."\n";
103
$contentOut .= strtr($this->contentTemplate, array('{content}'=>$content,'{id}'=>$tabId))."\n";
105
elseif (isset($content['content']))
107
$tabsOut .= strtr($this->headerTemplate, array('{title}'=>$title, '{url}'=>'#'.$tabId))."\n";
108
$contentOut .= strtr($this->contentTemplate, array('{content}'=>$content['content'],'{id}'=>$tabId))."\n";
111
elseif (isset($content['ajax']))
113
$tabsOut .= strtr($this->headerTemplate,array('{title}'=>$title, '{url}'=>CHtml::normalizeUrl($content['ajax'])))."\n";
116
echo "<ul>\n" . $tabsOut . "</ul>\n";
119
echo CHtml::closeTag($this->tagName)."\n";
121
$options=empty($this->options) ? '' : CJavaScript::encode($this->options);
122
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').tabs($options);");
126
* Registers the core script files.
127
* This method overrides the parent implementation by registering the cookie plugin when cookie option is used.
129
protected function registerCoreScripts()
131
parent::registerCoreScripts();
132
if(isset($this->options['cookie']))
133
Yii::app()->getClientScript()->registerCoreScript('cookie');