mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-10 23:50:38 +08:00
Merge branch 'nav-active' of github.com:Alex-Code/yii2 into Alex-Code-nav-active
Conflicts: extensions/bootstrap/CHANGELOG.md extensions/bootstrap/Nav.php
This commit is contained in:
@@ -12,11 +12,11 @@ Yii Framework 2 bootstrap extension Change Log
|
|||||||
- Enh #1601: Added support for tagName and encodeLabel parameters in ButtonDropdown (omnilight)
|
- Enh #1601: Added support for tagName and encodeLabel parameters in ButtonDropdown (omnilight)
|
||||||
- Enh #1881: Improved `yii\bootstrap\NavBar` with `containerOptions`, `innerContainerOptions` and `renderInnerContainer` (creocoder)
|
- Enh #1881: Improved `yii\bootstrap\NavBar` with `containerOptions`, `innerContainerOptions` and `renderInnerContainer` (creocoder)
|
||||||
- Enh #2425: Tabs widget now selects first tab if no active tab is specified (samdark)
|
- Enh #2425: Tabs widget now selects first tab if no active tab is specified (samdark)
|
||||||
|
- Enh #2634: Submenus will now be checked for being active (Alex-Code)
|
||||||
- Enh #2643: Add size attribute to Modal (tof06)
|
- Enh #2643: Add size attribute to Modal (tof06)
|
||||||
- Chg #1459: Update Collapse to use bootstrap 3 classes (tonydspaniard)
|
- Chg #1459: Update Collapse to use bootstrap 3 classes (tonydspaniard)
|
||||||
- Chg #1820: Update Progress to use bootstrap 3 markup (samdark)
|
- Chg #1820: Update Progress to use bootstrap 3 markup (samdark)
|
||||||
|
|
||||||
|
|
||||||
2.0.0 alpha, December 1, 2013
|
2.0.0 alpha, December 1, 2013
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,10 @@ class Nav extends Widget
|
|||||||
* @see isItemActive
|
* @see isItemActive
|
||||||
*/
|
*/
|
||||||
public $activateItems = true;
|
public $activateItems = true;
|
||||||
|
/**
|
||||||
|
* @var boolean whether to activate parent menu items when one of the corresponding child menu items is active.
|
||||||
|
*/
|
||||||
|
public $activateParents = false;
|
||||||
/**
|
/**
|
||||||
* @var string the route used to determine if a menu item is active or not.
|
* @var string the route used to determine if a menu item is active or not.
|
||||||
* If not set, it will use the route of the current request.
|
* If not set, it will use the route of the current request.
|
||||||
@@ -156,16 +160,15 @@ class Nav extends Widget
|
|||||||
$active = $this->isItemActive($item);
|
$active = $this->isItemActive($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($active) {
|
|
||||||
Html::addCssClass($options, 'active');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($items !== null) {
|
if ($items !== null) {
|
||||||
$linkOptions['data-toggle'] = 'dropdown';
|
$linkOptions['data-toggle'] = 'dropdown';
|
||||||
Html::addCssClass($options, 'dropdown');
|
Html::addCssClass($options, 'dropdown');
|
||||||
Html::addCssClass($linkOptions, 'dropdown-toggle');
|
Html::addCssClass($linkOptions, 'dropdown-toggle');
|
||||||
$label .= ' ' . Html::tag('b', '', ['class' => 'caret']);
|
$label .= ' ' . Html::tag('b', '', ['class' => 'caret']);
|
||||||
if (is_array($items)) {
|
if (is_array($items)) {
|
||||||
|
if ($this->activateItems) {
|
||||||
|
$items = $this->isChildActive($items, $active);
|
||||||
|
}
|
||||||
$items = Dropdown::widget([
|
$items = Dropdown::widget([
|
||||||
'items' => $items,
|
'items' => $items,
|
||||||
'encodeLabels' => $this->encodeLabels,
|
'encodeLabels' => $this->encodeLabels,
|
||||||
@@ -173,11 +176,33 @@ class Nav extends Widget
|
|||||||
'view' => $this->getView(),
|
'view' => $this->getView(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->activateItems && $active) {
|
||||||
|
Html::addCssClass($options, 'active');
|
||||||
}
|
}
|
||||||
|
|
||||||
return Html::tag('li', Html::a($label, $url, $linkOptions) . $items, $options);
|
return Html::tag('li', Html::a($label, $url, $linkOptions) . $items, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if a child item is active optionally activating the parent.
|
||||||
|
* @param array $items @see items
|
||||||
|
* @param boolean $active should the parent be active too
|
||||||
|
* @return array @see items
|
||||||
|
*/
|
||||||
|
protected function isChildActive($items, &$active)
|
||||||
|
{
|
||||||
|
foreach ($items as $i => $child) {
|
||||||
|
if (ArrayHelper::remove($items[$i], 'active', false) || $this->isItemActive($child)) {
|
||||||
|
Html::addCssClass($items[$i]['options'], 'active');
|
||||||
|
if ($this->activateParents) {
|
||||||
|
$active = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a menu item is active.
|
* Checks whether a menu item is active.
|
||||||
|
|||||||
Reference in New Issue
Block a user