* @copyright Copyright © Christoffer Niska 2011- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @package bootstrap.widgets */ Yii::import('bootstrap.widgets.TbMenu'); /** * Bootstrap Javascript tabs widget. * @see http://twitter.github.com/bootstrap/javascript.html#tabs */ class TbTabs extends CWidget { // Tab placements. const PLACEMENT_ABOVE = 'above'; const PLACEMENT_BELOW = 'below'; const PLACEMENT_LEFT = 'left'; const PLACEMENT_RIGHT = 'right'; /** * @var string the type of tabs to display. Defaults to 'tabs'. Valid values are 'tabs' and 'pills'. * Please not that Javascript pills are not fully supported in Bootstrap yet! * @see TbMenu::$type */ public $type = TbMenu::TYPE_TABS; /** * @var string the placement of the tabs. * Valid values are 'above', 'below', 'left' and 'right'. */ public $placement; /** * @var array the tab configuration. */ public $tabs = array(); /** * @var boolean indicates whether to stack navigation items. */ public $stacked = false; /** /** * @var boolean whether to encode item labels. */ public $encodeLabel = true; /** * @var string[] the Javascript event handlers. */ public $events = array(); /** * @var array the HTML attributes for the widget container. */ public $htmlOptions = array(); /** * Initializes the widget. */ public function init() { if (!isset($this->htmlOptions['id'])) $this->htmlOptions['id'] = $this->getId(); $classes = array(); $validPlacements = array(self::PLACEMENT_ABOVE, self::PLACEMENT_BELOW, self::PLACEMENT_LEFT, self::PLACEMENT_RIGHT); if (isset($this->placement) && in_array($this->placement, $validPlacements)) $classes[] = 'tabs-'.$this->placement; if (!empty($classes)) { $classes = implode(' ', $classes); if (isset($this->htmlOptions['class'])) $this->htmlOptions['class'] .= ' '.$classes; else $this->htmlOptions['class'] = $classes; } } /** * Run this widget. */ public function run() { $id = $this->id; $content = array(); $items = $this->normalizeTabs($this->tabs, $content); ob_start(); $this->controller->widget('bootstrap.widgets.TbMenu', array( 'stacked'=>$this->stacked, 'type'=>$this->type, 'encodeLabel'=>$this->encodeLabel, 'items'=>$items, )); $tabs = ob_get_clean(); ob_start(); echo '