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