-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathNavBar.php
111 lines (107 loc) · 3.8 KB
/
NavBar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php namespace webmaxx\materialize;
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/**
* NavBar renders a navbar HTML component.
*
* 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,
*
* ```php
* use webmaxx\materialize\Nav;
* use webmaxx\materialize\NavBar;
*
* NavBar::begin(['brandLabel' => 'NavBar Test']);
* echo Nav::widget([
* 'items' => [
* ['label' => 'Home', 'url' => ['/site/index']],
* ['label' => 'About', 'url' => ['/site/about']],
* ],
* ]);
* NavBar::end();
* ```
* @see http://materializecss.com/navbar.html
* @author webmaxx <[email protected]>
* @since 2.0
*/
class NavBar extends Widget
{
/**
* @var array the HTML attributes for the widget container tag. The following special options are recognized:
*
* - tag: string, defaults to "nav", the name of the container tag.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $options = [];
/**
* @var string|boolean the text of the brand of false if it's not used. Note that this is not HTML-encoded.
*/
public $brandLabel = false;
/**
* @param array|string|boolean $url the URL for the brand's hyperlink tag. This parameter will be processed by [[Url::to()]]
* and will be used for the "href" attribute of the brand link. Default value is false that means
* [[\yii\web\Application::homeUrl]] will be used.
*/
public $brandUrl = false;
/**
* @var array the HTML attributes of the brand link.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $brandOptions = [];
/**
* @var boolean if true, then navbar fixed on scroll
*/
public $fixed = false;
/**
* @var array the HTML attributes of the fixed container.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $fixedContainerOptions = [];
/**
* @var array the HTML attributes of the wrapper container.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $wraperContainerOptions = [];
/**
* Initializes the widget.
*/
public function init()
{
parent::init();
$this->clientOptions = false;
if ($this->fixed) {
if (!isset($this->fixedContainerOptions['class'])) {
Html::addCssClass($this->fixedContainerOptions, 'navbar-fixed');
}
echo Html::beginTag('div', $this->fixedContainerOptions);
}
Html::addCssClass($this->brandOptions, 'brand-logo');
$options = $this->options;
$tag = ArrayHelper::remove($options, 'tag', 'nav');
echo Html::beginTag($tag, $options);
if (!isset($this->wraperContainerOptions['class'])) {
Html::addCssClass($this->wraperContainerOptions, 'nav-wrapper');
}
echo Html::beginTag('div', $this->wraperContainerOptions);
if ($this->brandLabel !== false) {
Html::addCssClass($this->brandOptions, 'brand-logo');
echo Html::a($this->brandLabel, $this->brandUrl === false ? Yii::$app->homeUrl : $this->brandUrl, $this->brandOptions);
}
}
/**
* Renders the widget.
*/
public function run()
{
//echo Html::endTag('div');
$tag = ArrayHelper::remove($this->options, 'tag', 'nav');
echo Html::endTag($tag, $this->options);
if ($this->fixed) {
echo Html::endTag('div');
}
MaterializePluginAsset::register($this->getView());
}
}