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
79aaf1fb
Commit
79aaf1fb
authored
May 30, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored ButtonDropdown and Dropdown.
parent
2f790f77
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
59 deletions
+18
-59
ButtonDropdown.php
framework/yii/bootstrap/ButtonDropdown.php
+6
-37
Dropdown.php
framework/yii/bootstrap/Dropdown.php
+12
-22
No files found.
framework/yii/bootstrap/ButtonDropdown.php
View file @
79aaf1fb
...
...
@@ -18,8 +18,7 @@ use yii\helpers\Html;
* // a button group using Dropdown widget
* echo ButtonDropdown::widget(array(
* 'label' => 'Action',
* 'items' => Dropdown::widget(array(
* 'clientOptions' => false,
* 'dropdown' => array(
* 'items' => array(
* array(
* 'label' => 'DropdownA',
...
...
@@ -30,22 +29,6 @@ use yii\helpers\Html;
* 'url' => '#',
* ),
* ),
* )),
* ));
*
* // split button dropdown using `items` configuration
* echo ButtonDropdown::widget(array(
* 'label' => 'Action',
* 'split' => true,
* 'items' => array(
* array(
* 'label' => 'DropdownA',
* 'url' => '/',
* ),
* array(
* 'label' => 'DropdownB',
* 'url' => '#',
* ),
* ),
* ));
* ```
...
...
@@ -65,28 +48,13 @@ class ButtonDropdown extends Widget
*/
public
$buttonOptions
=
array
();
/**
* @var array list of menu items in the dropdown. This will be used to
* set the [[Dropdown::items]] property. Each array element represents a single
* menu with the following structure:
*
* - label: string, required, the label of the item link
* - url: string, optional, the url of the item link. Defaults to "#".
* - linkOptions: array, optional, the HTML attributes of the item link.
* - options: array, optional, the HTML attributes of the item.
* - items: array, optional, the dropdown items configuration array.
*
* @see https://github.com/twitter/bootstrap/issues/5050#issuecomment-11741727
* @see [[Dropdown]]
* @var array the configuration array for [[Dropdown]].
*/
public
$
items
=
array
();
public
$
dropdown
=
array
();
/**
* @var boolean whether to display a group of split-styled button group.
*/
public
$split
=
false
;
/**
* @var boolean whether the labels for dropdown items should be HTML-encoded.
*/
public
$encodeLabels
=
true
;
/**
...
...
@@ -148,12 +116,13 @@ class ButtonDropdown extends Widget
}
/**
* Generates the dropdown menu
as specified on [[items]]
.
* Generates the dropdown menu.
* @return string the rendering result.
*/
protected
function
renderDropdown
()
{
$config
=
array
(
'items'
=>
$this
->
items
,
'clientOptions'
=>
false
);
$config
=
$this
->
dropdown
;
$config
[
'clientOptions'
]
=
false
;
return
Dropdown
::
widget
(
$config
);
}
}
framework/yii/bootstrap/Dropdown.php
View file @
79aaf1fb
...
...
@@ -13,7 +13,7 @@ use yii\helpers\Html;
/**
* Dropdown renders a
Tab bootstrap javascript
component.
* Dropdown renders a
Bootstrap dropdown menu
component.
*
* @see http://twitter.github.io/bootstrap/javascript.html#dropdowns
* @author Antonio Ramirez <amigo.cobos@gmail.com>
...
...
@@ -55,21 +55,22 @@ class Dropdown extends Widget
*/
public
function
run
()
{
echo
$this
->
renderItems
(
)
.
"
\n
"
;
echo
$this
->
renderItems
(
$this
->
items
)
;
$this
->
registerPlugin
(
'dropdown'
);
}
/**
* Renders dropdown items as specified on [[items]].
* Renders menu items.
* @param array $items the menu items to be rendered
* @return string the rendering result.
* @throws InvalidConfigException
* @throws InvalidConfigException
if the label option is not specified in one of the items.
*/
protected
function
renderItems
()
protected
function
renderItems
(
$items
)
{
$
item
s
=
array
();
foreach
(
$
this
->
items
as
$item
)
{
$
line
s
=
array
();
foreach
(
$items
as
$item
)
{
if
(
is_string
(
$item
))
{
$
item
s
[]
=
$item
;
$
line
s
[]
=
$item
;
continue
;
}
if
(
!
isset
(
$item
[
'label'
]))
{
...
...
@@ -82,24 +83,13 @@ class Dropdown extends Widget
if
(
isset
(
$item
[
'items'
]))
{
$this
->
addCssClass
(
$options
,
'dropdown-submenu'
);
$content
=
Html
::
a
(
$label
,
'#'
,
$linkOptions
)
.
$this
->
dropdown
(
$item
[
'items'
]);
$content
=
Html
::
a
(
$label
,
'#'
,
$linkOptions
)
.
$this
->
renderItems
(
$item
[
'items'
]);
}
else
{
$content
=
Html
::
a
(
$label
,
ArrayHelper
::
getValue
(
$item
,
'url'
,
'#'
),
$linkOptions
);
}
$
items
[]
=
Html
::
tag
(
'li'
,
$content
,
$options
);
$
lines
[]
=
Html
::
tag
(
'li'
,
$content
,
$options
);
}
return
Html
::
tag
(
'ul'
,
implode
(
"
\n
"
,
$items
),
$this
->
options
);
}
/**
* Generates a dropdown menu.
* @param array $items the configuration of the dropdown items. See [[items]].
* @return string the generated dropdown menu
* @see items
*/
protected
function
dropdown
(
$items
)
{
return
static
::
widget
(
array
(
'items'
=>
$items
,
'clientOptions'
=>
false
));
return
Html
::
tag
(
'ul'
,
implode
(
"
\n
"
,
$lines
),
$this
->
options
);
}
}
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