-
Notifications
You must be signed in to change notification settings - Fork 0
/
YMetroUiNavbar.php
171 lines (145 loc) · 4.91 KB
/
YMetroUiNavbar.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
Yii::import('zii.widgets.CMenu');
/**
* ## YMetroUiMenu class file.
*
* @author Lorenzo Milesi <[email protected]>
* @copyright Copyright © Internavigare S.r.l. 2014
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
*/
class YMetroUiNavbar extends CMenu
{
// Navbar types.
const TYPE_DARK = 'dark';
const TYPE_LIGHT = 'light';
const TYPE_WHITE = 'white';
// Navbar fix locations.
const FIXED_TOP = 'top';
const FIXED_BOTTOM = 'bottom';
/**
* @var string the navbar type. Valid values are TYPE_*.
* @since 1.0.0
*/
public $type;
/**
* @var string the text for the brand.
*/
public $brand;
/**
* @var string the URL for the brand link.
*/
public $brandUrl;
/**
* @var array the HTML attributes for the brand link.
*/
public $brandOptions = array();
/**
* @var array navigation items.
* @since 0.9.8
*/
public $items = array();
/**
* @var mixed fix location of the navbar if applicable.
* Valid values are 'top' and 'bottom'. Defaults to 'top'.
* Setting the value to false will make the navbar static.
* @since 0.9.8
*/
public $fixed = false;
/**
* @var array the HTML attributes for the widget container.
*/
public $htmlOptions = array();
/**
* ### .init()
*
* Initializes the widget.
*/
public function init()
{
parent::init();
if ($this->brand !== false) {
if (!isset($this->brand)) {
$this->brand = CHtml::encode(Yii::app()->name);
}
if (!isset($this->brandUrl)) {
$this->brandUrl = Yii::app()->homeUrl;
}
if (isset($this->brandOptions['class'])) {
$this->brandOptions['class'] .= ' element';
} else {
$this->brandOptions['class'] = 'element';
}
}
$classes = array('navigation-bar');
if (isset($this->type) && in_array($this->type, array(self::TYPE_DARK, self::TYPE_LIGHT, self::TYPE_WHITE))) {
$classes[] = $this->type;
}
// add the dropdown-menu options
$this->submenuHtmlOptions = array('class' => 'dropdown-menu ' . $this->type, 'data-role' => 'dropdown');
if ($this->fixed !== false && in_array($this->fixed, array(self::FIXED_TOP, self::FIXED_BOTTOM))) {
$classes[] = 'fixed-' . $this->fixed;
}
if (!empty($classes)) {
$classes = implode(' ', $classes);
if (isset($this->htmlOptions['class'])) {
$this->htmlOptions['class'] .= ' ' . $classes;
} else {
$this->htmlOptions['class'] = $classes;
}
}
}
/**
* ### .run()
*
* Runs the widget.
*/
public function run()
{
echo CHtml::openTag('div', $this->htmlOptions);
echo CHtml::openTag('div', array('class' => 'navigation-bar-content container'));
if ($this->brand !== false) {
if ($this->brandUrl !== false) {
echo CHtml::openTag("a", $this->brandOptions);
echo CHtml::tag("span", array('class' => 'icon-grid-view'), $this->brand);
echo CHtml::closeTag("a");
} else {
echo CHtml::openTag('span', $this->brandOptions) . $this->brand . '</span>';
}
echo CHtml::tag("span", array('class' => 'element-divider'), " ");
}
$this->renderMenu($this->items);
CHtml::closeTag("div"); // navigation-bar-content container
CHtml::closeTag("div"); // main
}
/**
* @inherit
*/
protected function renderMenu($items)
{
if (count($items)) {
echo '<a class="element1 pull-menu" href="#"></a>';
echo CHtml::openTag('ul', array('class' => 'element-menu')) . "\n";
$this->renderMenuRecursive($items);
echo CHtml::closeTag('ul');
}
}
/**
* @inherit
*/
protected function renderMenuItem($item)
{
// Special case: sub items
if(isset($item['items']) && count($item['items'])) {
$item['url'] = "#";
if (isset($item['linkOptions']) && isset($item['linkOptions']['class']))
$item['linkOptions']['class'] .= " dropdown-toggle";
else
$item['linkOptions']['class'] = " dropdown-toggle";
}
if (isset($item['url'])) {
$label = $this->linkLabelWrapper === null ? $item['label'] : CHtml::tag($this->linkLabelWrapper, $this->linkLabelWrapperHtmlOptions, $item['label']);
return CHtml::link($label, $item['url'], isset($item['linkOptions']) ? $item['linkOptions'] : array());
} else
return CHtml::tag('span', isset($item['linkOptions']) ? $item['linkOptions'] : array(), $item['label']);
}
}