Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
Yii Bootstrap 3
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Common
Yii Bootstrap 3
Commits
ce0f0851
Commit
ce0f0851
authored
Mar 05, 2012
by
niskac
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed dropdown item active
parent
3ea779af
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
35 deletions
+51
-35
BootBaseMenu.php
widgets/BootBaseMenu.php
+21
-11
BootDropdown.php
widgets/BootDropdown.php
+6
-0
BootMenu.php
widgets/BootMenu.php
+24
-24
No files found.
widgets/BootBaseMenu.php
View file @
ce0f0851
...
...
@@ -53,17 +53,6 @@ abstract class BootBaseMenu extends BootWidget
$item
[
'label'
]
=
'<i class="'
.
$item
[
'icon'
]
.
'"></i> '
.
$item
[
'label'
];
}
if
(
isset
(
$item
[
'items'
])
&&
!
empty
(
$item
[
'items'
]))
{
if
(
isset
(
$item
[
'linkOptions'
][
'class'
]))
$item
[
'linkOptions'
][
'class'
]
.=
' dropdown-toggle'
;
else
$item
[
'linkOptions'
][
'class'
]
=
'dropdown-toggle'
;
$item
[
'linkOptions'
][
'data-toggle'
]
=
'dropdown'
;
$item
[
'label'
]
.=
' <span class="caret"></span>'
;
}
if
(
!
isset
(
$item
[
'header'
])
&&
!
isset
(
$item
[
'url'
]))
$item
[
'url'
]
=
'#'
;
...
...
@@ -74,6 +63,27 @@ abstract class BootBaseMenu extends BootWidget
}
/**
* Checks whether a menu item is active.
* @param array $item the menu item to be checked
* @param string $route the route of the current request
* @return boolean the result
*/
protected
function
isItemActive
(
$item
,
$route
)
{
if
(
isset
(
$item
[
'url'
])
&&
is_array
(
$item
[
'url'
])
&&
!
strcasecmp
(
trim
(
$item
[
'url'
][
0
],
'/'
),
$route
))
{
if
(
count
(
$item
[
'url'
])
>
1
)
foreach
(
array_splice
(
$item
[
'url'
],
1
)
as
$name
=>
$value
)
if
(
!
isset
(
$_GET
[
$name
])
||
$_GET
[
$name
]
!=
$value
)
return
false
;
return
true
;
}
return
false
;
}
/**
* Renders the items in this menu.
* @abstract
* @param array $items the menu items
...
...
widgets/BootDropdown.php
View file @
ce0f0851
...
...
@@ -48,6 +48,9 @@ class BootDropdown extends BootBaseMenu
if
(
isset
(
$item
[
'header'
]))
$class
[]
=
'nav-header'
;
if
(
$item
[
'active'
])
$class
[]
=
'active'
;
$cssClass
=
implode
(
' '
,
$class
);
if
(
isset
(
$item
[
'itemOptions'
][
'class'
]))
$item
[
'itemOptions'
][
'class'
]
.=
$cssClass
;
...
...
@@ -95,6 +98,9 @@ class BootDropdown extends BootBaseMenu
if
((
$this
->
encodeLabel
&&
!
isset
(
$item
[
'encodeLabel'
]))
||
(
isset
(
$item
[
'encodeLabel'
])
&&
$item
[
'encodeLabel'
]
!==
false
))
$items
[
$i
][
'label'
]
=
CHtml
::
encode
(
$item
[
'label'
]);
if
(
!
isset
(
$item
[
'active'
]))
$items
[
$i
][
'active'
]
=
$this
->
isItemActive
(
$item
,
$route
);
}
return
array_values
(
$items
);
...
...
widgets/BootMenu.php
View file @
ce0f0851
...
...
@@ -94,9 +94,6 @@ class BootMenu extends BootBaseMenu
$class
=
array
();
if
(
isset
(
$item
[
'header'
]))
$class
[]
=
'nav-header'
;
if
(
$item
[
'active'
]
||
(
isset
(
$item
[
'items'
])
&&
$this
->
isChildActive
(
$item
[
'items'
])))
$class
[]
=
'active'
;
...
...
@@ -134,6 +131,30 @@ class BootMenu extends BootBaseMenu
}
/**
* Renders a single item in the menu.
* @param array $item the item configuration
* @return string the rendered item
*/
protected
function
renderItem
(
$item
)
{
if
(
!
isset
(
$item
[
'linkOptions'
]))
$item
[
'linkOptions'
]
=
array
();
if
(
isset
(
$item
[
'items'
])
&&
!
empty
(
$item
[
'items'
]))
{
if
(
isset
(
$item
[
'linkOptions'
][
'class'
]))
$item
[
'linkOptions'
][
'class'
]
.=
' dropdown-toggle'
;
else
$item
[
'linkOptions'
][
'class'
]
=
'dropdown-toggle'
;
$item
[
'linkOptions'
][
'data-toggle'
]
=
'dropdown'
;
$item
[
'label'
]
.=
' <span class="caret"></span>'
;
}
return
parent
::
renderItem
(
$item
);
}
/**
* Normalizes the items in this menu.
* @param array $items the items to be normalized
* @param string $route the route of the current request
...
...
@@ -175,27 +196,6 @@ class BootMenu extends BootBaseMenu
}
/**
* Checks whether a menu item is active.
* @param array $item the menu item to be checked
* @param string $route the route of the current request
* @return boolean the result
*/
protected
function
isItemActive
(
$item
,
$route
)
{
if
(
isset
(
$item
[
'url'
])
&&
is_array
(
$item
[
'url'
])
&&
!
strcasecmp
(
trim
(
$item
[
'url'
][
0
],
'/'
),
$route
))
{
if
(
count
(
$item
[
'url'
])
>
1
)
foreach
(
array_splice
(
$item
[
'url'
],
1
)
as
$name
=>
$value
)
if
(
!
isset
(
$_GET
[
$name
])
||
$_GET
[
$name
]
!=
$value
)
return
false
;
return
true
;
}
return
false
;
}
/**
* Returns whether a child item is active.
* @param array $items the items to check
* @return boolean the result
...
...
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