-
Notifications
You must be signed in to change notification settings - Fork 1
/
DropdownX.php
executable file
·79 lines (71 loc) · 2.46 KB
/
DropdownX.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
<?php
/**
* @Author: pangpond
* @Date: 2015-03-12 20:43:00
* @Last Modified by: pangpond
* @Last Modified time: 2015-03-27 15:17:58
*/
namespace nextensions\material;
use yii\base\InvalidConfigException;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
/**
* An extended nav menu for Bootstrap 3 - that offers
* submenu drilldown
*
*/
class DropdownX extends \yii\bootstrap\Dropdown
{
public $subMenuOptions = [];
/**
* Initializes the widget
*/
public function init()
{
Html::addCssClass($this->options, '');
}
/**
* @inherit doc
*/
protected function renderItems($items, $options = [])
{
$lines = [];
foreach ($items as $i => $item) {
if (isset($item['visible']) && !$item['visible']) {
unset($items[$i]);
continue;
}
if (is_string($item)) {
$lines[] = $item;
continue;
}
if (!isset($item['label'])) {
throw new InvalidConfigException("The 'label' option is required.");
}
$encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
$label = $encodeLabel ? Html::encode($item['label']) : $item['label'];
$itemOptions = ArrayHelper::getValue($item, 'options', []);
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
$linkOptions['tabindex'] = '-1';
$url = array_key_exists('url', $item) ? $item['url'] : null;
if (empty($item['items'])) {
if ($url === null) {
$content = $label;
Html::addCssClass($itemOptions, 'dropdown-header');
} else {
$content = Html::a($label, $url, $linkOptions);
}
} else {
Html::addCssClass($linkOptions, 'dropdown-toggle');
$linkOptions['data-toggle'] = 'dropdown';
$submenuOptions = $options;
unset($submenuOptions['id']);
$content = Html::a($label, $url === null ? '#' : $url, $linkOptions)
. $this->renderItems($item['items'], $submenuOptions);
Html::addCssClass($itemOptions, 'dropdown dropdown-submenu');
}
$lines[] = Html::tag('li', $content, $itemOptions);
}
return Html::tag('ul', implode("\n", $lines), $options);
}
}