1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
*## TbDropdown class file. |
4
|
|
|
* |
5
|
|
|
* |
6
|
|
|
* @author Christoffer Niska <[email protected]> |
7
|
|
|
* @copyright Copyright © Christoffer Niska 2012- |
8
|
|
|
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
Yii::import('booster.widgets.TbBaseMenu'); |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
*## Bootstrap dropdown menu. |
15
|
|
|
* |
16
|
|
|
* @see http://twitter.github.com/bootstrap/javascript.html#dropdowns |
17
|
|
|
* |
18
|
|
|
* @package booster.widgets.navigation |
19
|
|
|
*/ |
20
|
|
|
class TbDropdown extends TbBaseMenu { |
21
|
|
|
/** |
22
|
|
|
*### .init() |
23
|
|
|
* |
24
|
|
|
* Initializes the widget. |
25
|
|
|
*/ |
26
|
|
|
public function init() { |
27
|
|
|
|
28
|
|
|
parent::init(); |
29
|
|
|
|
30
|
|
|
if (isset($this->htmlOptions['class'])) { |
31
|
|
|
$this->htmlOptions['class'] .= ' dropdown-menu'; |
32
|
|
|
} else { |
33
|
|
|
$this->htmlOptions['class'] = 'dropdown-menu'; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
*### .renderMenuItem() |
39
|
|
|
* |
40
|
|
|
* Renders the content of a menu item. |
41
|
|
|
* Note that the container and the sub-menus are not rendered here. |
42
|
|
|
* |
43
|
|
|
* @param array $item the menu item to be rendered. Please see {@link items} on what data might be in the item. |
44
|
|
|
* |
45
|
|
|
* @return string the rendered item |
46
|
|
|
*/ |
47
|
|
|
protected function renderMenuItem($item) { |
48
|
|
|
|
49
|
|
|
if (isset($item['icon'])) { |
50
|
|
|
if (strpos($item['icon'], 'icon') === false && strpos($item['icon'], 'fa') === false) { |
51
|
|
|
$item['icon'] = 'icon-' . implode(' icon-', explode(' ', $item['icon'])); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$item['label'] = '<i class="' . $item['icon'] . '"></i> ' . $item['label']; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if (!isset($item['linkOptions'])) { |
58
|
|
|
$item['linkOptions'] = array(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// TODO: Bootstrap 3 does not support submenu |
62
|
|
|
// http://stackoverflow.com/questions/18023493/bootstrap-3-dropdown-sub-menu-missing |
63
|
|
|
// we may use this to support it |
64
|
|
|
/* if (isset($item['items']) && !empty($item['items']) && empty($item['url'])) { |
65
|
|
|
$item['url'] = '#'; |
66
|
|
|
} */ |
67
|
|
|
|
68
|
|
|
$item['linkOptions']['tabindex'] = -1; |
69
|
|
|
|
70
|
|
|
if (isset($item['url'])) { |
71
|
|
|
return CHtml::link($item['label'], $item['url'], $item['linkOptions']); |
72
|
|
|
} else { |
73
|
|
|
return CHtml::link($item['label'], '#', array()); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
*### .getDividerCssClass() |
79
|
|
|
* |
80
|
|
|
* Returns the divider CSS class. |
81
|
|
|
* @return string the class name |
82
|
|
|
*/ |
83
|
|
|
public function getDividerCssClass() |
84
|
|
|
{ |
85
|
|
|
return 'divider'; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
*### .getDropdownCssClass() |
90
|
|
|
* |
91
|
|
|
* Returns the dropdown css class. |
92
|
|
|
* @return string the class name |
93
|
|
|
*/ |
94
|
|
|
public function getDropdownCssClass() |
95
|
|
|
{ |
96
|
|
|
return 'dropdown-submenu'; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
*### .isVertical() |
101
|
|
|
* |
102
|
|
|
* Returns whether this is a vertical menu. |
103
|
|
|
* @return boolean the result |
104
|
|
|
*/ |
105
|
|
|
public function isVertical() |
106
|
|
|
{ |
107
|
|
|
return true; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|