You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					109 lines
				
				2.9 KiB
			
		
		
			
		
	
	
					109 lines
				
				2.9 KiB
			| 
											13 years ago
										 | <?php
 | ||
|  | /**
 | ||
|  |  * @link http://www.yiiframework.com/
 | ||
|  |  * @copyright Copyright (c) 2008 Yii Software LLC
 | ||
|  |  * @license http://www.yiiframework.com/license/
 | ||
|  |  */
 | ||
|  | 
 | ||
|  | namespace yii\bootstrap;
 | ||
|  | 
 | ||
|  | use yii\helpers\Html;
 | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * NavBar renders a navbar HTML component.
 | ||
|  |  *
 | ||
| 
											12 years ago
										 |  * Any content enclosed between the [[begin()]] and [[end()]] calls of NavBar
 | ||
|  |  * is treated as the content of the navbar. You may use widgets such as [[Nav]]
 | ||
|  |  * or [[\yii\widgets\Menu]] to build up such content. For example,
 | ||
| 
											13 years ago
										 |  *
 | ||
|  |  * ```php
 | ||
| 
											12 years ago
										 |  * use yii\bootstrap\NavBar;
 | ||
|  |  * use yii\widgets\Menu;
 | ||
|  |  *
 | ||
| 
											12 years ago
										 |  * NavBar::begin(['brandLabel' => 'NavBar Test']);
 | ||
|  |  * echo Nav::widget([
 | ||
|  |  *     'items' => [
 | ||
|  |  *         ['label' => 'Home', 'url' => ['/site/index']],
 | ||
|  |  *         ['label' => 'About', 'url' => ['/site/about']],
 | ||
|  |  *     ],
 | ||
|  |  * ]);
 | ||
| 
											12 years ago
										 |  * NavBar::end();
 | ||
| 
											13 years ago
										 |  * ```
 | ||
|  |  *
 | ||
|  |  * @see http://twitter.github.io/bootstrap/components.html#navbar
 | ||
|  |  * @author Antonio Ramirez <amigo.cobos@gmail.com>
 | ||
|  |  * @since 2.0
 | ||
|  |  */
 | ||
|  | class NavBar extends Widget
 | ||
|  | {
 | ||
| 
											13 years ago
										 | 	/**
 | ||
| 
											12 years ago
										 | 	 * @var string the text of the brand. Note that this is not HTML-encoded.
 | ||
| 
											13 years ago
										 | 	 * @see http://twitter.github.io/bootstrap/components.html#navbar
 | ||
|  | 	 */
 | ||
|  | 	public $brandLabel;
 | ||
|  | 	/**
 | ||
|  | 	 * @param array|string $url the URL for the brand's hyperlink tag. This parameter will be processed by [[Html::url()]]
 | ||
|  | 	 * and will be used for the "href" attribute of the brand link. Defaults to site root.
 | ||
|  | 	 */
 | ||
| 
											13 years ago
										 | 	public $brandUrl = '/';
 | ||
| 
											13 years ago
										 | 	/**
 | ||
|  | 	 * @var array the HTML attributes of the brand link.
 | ||
|  | 	 */
 | ||
| 
											12 years ago
										 | 	public $brandOptions = [];
 | ||
| 
											13 years ago
										 | 
 | ||
| 
											12 years ago
										 | 	public $screenReaderToggleText = 'Toggle navigation';
 | ||
| 
											13 years ago
										 | 
 | ||
|  | 	/**
 | ||
|  | 	 * Initializes the widget.
 | ||
|  | 	 */
 | ||
|  | 	public function init()
 | ||
|  | 	{
 | ||
|  | 		parent::init();
 | ||
| 
											13 years ago
										 | 		$this->clientOptions = false;
 | ||
| 
											12 years ago
										 | 		Html::addCssClass($this->options, 'navbar navbar-default');
 | ||
| 
											12 years ago
										 | 		Html::addCssClass($this->brandOptions, 'navbar-brand');
 | ||
| 
											12 years ago
										 | 		if (empty($this->options['role'])) {
 | ||
|  | 			$this->options['role'] = 'navigation';
 | ||
|  | 		}
 | ||
| 
											13 years ago
										 | 
 | ||
| 
											12 years ago
										 | 		echo Html::beginTag('nav', $this->options);
 | ||
| 
											12 years ago
										 | 		echo Html::beginTag('div', ['class' => 'container']);
 | ||
| 
											12 years ago
										 | 
 | ||
| 
											12 years ago
										 | 		echo Html::beginTag('div', ['class' => 'navbar-header']);
 | ||
| 
											12 years ago
										 | 		echo $this->renderToggleButton();
 | ||
| 
											12 years ago
										 | 		if ($this->brandLabel !== null) {
 | ||
|  | 			echo Html::a($this->brandLabel, $this->brandUrl, $this->brandOptions);
 | ||
| 
											13 years ago
										 | 		}
 | ||
| 
											12 years ago
										 | 		echo Html::endTag('div');
 | ||
|  | 
 | ||
| 
											12 years ago
										 | 		echo Html::beginTag('div', ['class' => 'collapse navbar-collapse navbar-ex1-collapse']);
 | ||
| 
											13 years ago
										 | 	}
 | ||
|  | 
 | ||
|  | 	/**
 | ||
| 
											12 years ago
										 | 	 * Renders the widget.
 | ||
| 
											13 years ago
										 | 	 */
 | ||
| 
											12 years ago
										 | 	public function run()
 | ||
| 
											13 years ago
										 | 	{
 | ||
| 
											12 years ago
										 | 
 | ||
|  | 		echo Html::endTag('div');
 | ||
|  | 		echo Html::endTag('div');
 | ||
| 
											12 years ago
										 | 		echo Html::endTag('nav');
 | ||
| 
											12 years ago
										 | 		BootstrapPluginAsset::register($this->getView());
 | ||
| 
											13 years ago
										 | 	}
 | ||
|  | 
 | ||
|  | 	/**
 | ||
|  | 	 * Renders collapsible toggle button.
 | ||
|  | 	 * @return string the rendering toggle button.
 | ||
|  | 	 */
 | ||
|  | 	protected function renderToggleButton()
 | ||
|  | 	{
 | ||
| 
											12 years ago
										 | 		$bar = Html::tag('span', '', ['class' => 'icon-bar']);
 | ||
| 
											12 years ago
										 | 		$screenReader = '<span class="sr-only">'.$this->screenReaderToggleText.'</span>';
 | ||
| 
											12 years ago
										 | 		return Html::button("{$screenReader}\n{$bar}\n{$bar}\n{$bar}", [
 | ||
| 
											12 years ago
										 | 			'class' => 'navbar-toggle',
 | ||
| 
											13 years ago
										 | 			'data-toggle' => 'collapse',
 | ||
| 
											12 years ago
										 | 			'data-target' => '.navbar-ex1-collapse',
 | ||
| 
											12 years ago
										 | 		]);
 | ||
| 
											13 years ago
										 | 	}
 | ||
| 
											13 years ago
										 | }
 |