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
3a87b8a3
Commit
3a87b8a3
authored
Mar 11, 2014
by
Alex-Code
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved check for active child items
Updated to avoid full tree traversal. Also noticed ```activateItems``` didn't do anything so that's been fixed.
parent
0adc6563
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
28 deletions
+33
-28
Nav.php
extensions/bootstrap/Nav.php
+33
-28
No files found.
extensions/bootstrap/Nav.php
View file @
3a87b8a3
...
@@ -114,37 +114,11 @@ class Nav extends Widget
...
@@ -114,37 +114,11 @@ class Nav extends Widget
*/
*/
public
function
run
()
public
function
run
()
{
{
$this
->
activateItems
(
$this
->
items
,
$hasActiveChild
);
echo
$this
->
renderItems
();
echo
$this
->
renderItems
();
BootstrapAsset
::
register
(
$this
->
getView
());
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.
* Renders widget items.
*/
*/
public
function
renderItems
()
public
function
renderItems
()
...
@@ -181,12 +155,21 @@ class Nav extends Widget
...
@@ -181,12 +155,21 @@ class Nav extends Widget
$url
=
ArrayHelper
::
getValue
(
$item
,
'url'
,
'#'
);
$url
=
ArrayHelper
::
getValue
(
$item
,
'url'
,
'#'
);
$linkOptions
=
ArrayHelper
::
getValue
(
$item
,
'linkOptions'
,
[]);
$linkOptions
=
ArrayHelper
::
getValue
(
$item
,
'linkOptions'
,
[]);
if
(
isset
(
$item
[
'active'
]))
{
$active
=
ArrayHelper
::
remove
(
$item
,
'active'
,
false
);
}
else
{
$active
=
$this
->
isItemActive
(
$item
);
}
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
,
...
@@ -195,10 +178,32 @@ class Nav extends Widget
...
@@ -195,10 +178,32 @@ class Nav extends Widget
]);
]);
}
}
}
}
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.
...
...
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