Overview

Packages

  • bootstrap
    • behaviors
    • components
    • form
    • gii
    • helpers
    • widgets

Classes

  • TbActiveForm
  • TbAffix
  • TbAlert
  • TbBreadcrumb
  • TbButtonColumn
  • TbCollapse
  • TbDataColumn
  • TbDetailView
  • TbGridView
  • TbHeroUnit
  • TbListView
  • TbModal
  • TbNav
  • TbNavbar
  • TbPager
  • TbScrollspy
  • TbTabs
  • TbThumbnails
  • TbTypeAhead
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * TbNavbar class file.
  4:  * @author Christoffer Niska <christoffer.niska@gmail.com>
  5:  * @copyright Copyright &copy; Christoffer Niska 2013-
  6:  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  7:  * @package bootstrap.widgets
  8:  */
  9: 
 10: Yii::import('bootstrap.helpers.TbHtml');
 11: 
 12: /**
 13:  * Bootstrap navbar widget.
 14:  * @see http://twitter.github.com/bootstrap/components.html#navbar
 15:  */
 16: class TbNavbar extends CWidget
 17: {
 18:     /**
 19:      * @var string the navbar color.
 20:      */
 21:     public $color;
 22:     /**
 23:      * @var string the brand label text.
 24:      */
 25:     public $brandLabel;
 26:     /**
 27:      * @var mixed the brand url.
 28:      */
 29:     public $brandUrl;
 30:     /**
 31:      * @var array the HTML attributes for the brand link.
 32:      */
 33:     public $brandOptions = array();
 34:     /**
 35:      * @var string nanvbar display type.
 36:      */
 37:     public $display = TbHtml::NAVBAR_DISPLAY_FIXEDTOP;
 38:     /**
 39:      * @var boolean whether the navbar spans over the whole page.
 40:      */
 41:     public $fluid = false;
 42:     /**
 43:      * @var boolean whether to enable collapsing of the navbar on narrow screens.
 44:      */
 45:     public $collapse = false;
 46:     /**
 47:      * @var array additional HTML attributes for the collapse widget.
 48:      */
 49:     public $collapseOptions = array();
 50:     /**
 51:      * @var array list of navbar item.
 52:      */
 53:     public $items = array();
 54:     /**
 55:      * @var array the HTML attributes for the navbar.
 56:      */
 57:     public $htmlOptions = array();
 58: 
 59:     /**
 60:      * Initializes the widget.
 61:      */
 62:     public function init()
 63:     {
 64:         if ($this->brandLabel !== false) {
 65:             if (!isset($this->brandLabel)) {
 66:                 $this->brandLabel = CHtml::encode(Yii::app()->name);
 67:             }
 68: 
 69:             if (!isset($this->brandUrl)) {
 70:                 $this->brandUrl = Yii::app()->homeUrl;
 71:             }
 72:         }
 73:         if (isset($this->color)) {
 74:             TbArray::defaultValue('color', $this->color, $this->htmlOptions);
 75:         }
 76:         if (isset($this->display) && $this->display !== TbHtml::NAVBAR_DISPLAY_NONE) {
 77:             TbArray::defaultValue('display', $this->display, $this->htmlOptions);
 78:         }
 79:     }
 80: 
 81:     /**
 82:      * Runs the widget.
 83:      */
 84:     public function run()
 85:     {
 86:         $brand = $this->brandLabel !== false
 87:             ? TbHtml::navbarBrandLink($this->brandLabel, $this->brandUrl, $this->brandOptions)
 88:             : '';
 89:         ob_start();
 90:         foreach ($this->items as $item) {
 91:             if (is_string($item)) {
 92:                 echo $item;
 93:             } else {
 94:                 $widgetClassName = TbArray::popValue('class', $item);
 95:                 if ($widgetClassName !== null) {
 96:                     $this->controller->widget($widgetClassName, $item);
 97:                 }
 98:             }
 99:         }
100:         $items = ob_get_clean();
101:         ob_start();
102:         if ($this->collapse !== false) {
103:             TbHtml::addCssClass('nav-collapse', $this->collapseOptions);
104:             ob_start();
105:             /* @var TbCollapse $collapseWidget */
106:             $collapseWidget = $this->controller->widget(
107:                 'bootstrap.widgets.TbCollapse',
108:                 array(
109:                     'toggle' => false, // navbars are collapsed by default
110:                     'content' => $items,
111:                     'htmlOptions' => $this->collapseOptions,
112:                 )
113:             );
114:             $collapseContent = ob_get_clean();
115:             echo TbHtml::navbarCollapseLink('#' . $collapseWidget->getId());
116:             echo $brand . $collapseContent;
117: 
118:         } else {
119:             echo $brand . $items;
120:         }
121:         $containerContent = ob_get_clean();
122:         $containerOptions = TbArray::popValue('containerOptions', $this->htmlOptions, array());
123:         TbHtml::addCssClass($this->fluid ? 'container-fluid' : 'container', $containerOptions);
124:         ob_start();
125:         echo TbHtml::openTag('div', $containerOptions);
126:         echo $containerContent;
127:         echo '</div>';
128:         $content = ob_get_clean();
129:         echo TbHtml::navbar($content, $this->htmlOptions);
130:     }
131: }
Yiistrap API documentation generated by ApiGen 2.8.0