Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
0adc6563
Commit
0adc6563
authored
Mar 05, 2014
by
Alex-Code
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sub menus didn't get checked for being active.
Based off the method in ```Menu.php``` I've updated ```Nav``` so it will check if sub menus are active or not.
parent
993963bb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
10 deletions
+30
-10
Nav.php
extensions/bootstrap/Nav.php
+30
-10
No files found.
extensions/bootstrap/Nav.php
View file @
0adc6563
...
...
@@ -75,6 +75,10 @@ class Nav extends Widget
*/
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.
* If not set, it will use the route of the current request.
* @see params
...
...
@@ -110,11 +114,37 @@ class Nav extends Widget
*/
public
function
run
()
{
$this
->
activateItems
(
$this
->
items
,
$hasActiveChild
);
echo
$this
->
renderItems
();
BootstrapAsset
::
register
(
$this
->
getView
());
}
/**
* Check for active items adding the active class if found.
* @param array $items the items to check
* @param boolean $active does an item have an active child
*/
protected
function
activateItems
(
&
$items
,
&
$active
)
{
foreach
(
$items
as
&
$item
)
{
$hasActiveChild
=
false
;
if
(
isset
(
$item
[
'items'
])
&&
is_array
(
$item
[
'items'
]))
{
$this
->
activateItems
(
$item
[
'items'
],
$hasActiveChild
);
}
if
(
!
isset
(
$item
[
'active'
]))
{
if
(
$this
->
activateParents
&&
$hasActiveChild
||
$this
->
activateItems
&&
$this
->
isItemActive
(
$item
))
{
$active
=
$item
[
'active'
]
=
true
;
}
}
elseif
(
$item
[
'active'
])
{
$active
=
true
;
}
if
(
ArrayHelper
::
remove
(
$item
,
'active'
,
false
))
{
Html
::
addCssClass
(
$item
[
'options'
],
'active'
);
}
}
}
/**
* Renders widget items.
*/
public
function
renderItems
()
...
...
@@ -151,16 +181,6 @@ class Nav extends Widget
$url
=
ArrayHelper
::
getValue
(
$item
,
'url'
,
'#'
);
$linkOptions
=
ArrayHelper
::
getValue
(
$item
,
'linkOptions'
,
[]);
if
(
isset
(
$item
[
'active'
]))
{
$active
=
ArrayHelper
::
remove
(
$item
,
'active'
,
false
);
}
else
{
$active
=
$this
->
isItemActive
(
$item
);
}
if
(
$active
)
{
Html
::
addCssClass
(
$options
,
'active'
);
}
if
(
$items
!==
null
)
{
$linkOptions
[
'data-toggle'
]
=
'dropdown'
;
Html
::
addCssClass
(
$options
,
'dropdown'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment