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
5fe6d991
Commit
5fe6d991
authored
May 28, 2013
by
Antonio Ramirez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added dropdown widget
parent
65feda3e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
0 deletions
+117
-0
Dropdown.php
framework/yii/bootstrap/Dropdown.php
+117
-0
No files found.
framework/yii/bootstrap/Dropdown.php
0 → 100644
View file @
5fe6d991
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\bootstrap
;
use
yii\base\InvalidConfigException
;
use
yii\helpers\base\ArrayHelper
;
use
yii\helpers\Html
;
/**
* Dropdown renders a Tab bootstrap javascript component.
*
* @see http://twitter.github.io/bootstrap/javascript.html#dropdowns
* @author Antonio Ramirez <amigo.cobos@gmail.com>
* @since 2.0
*/
class
Dropdown
extends
Widget
{
/**
* @var array list of menu items in the dropdown. Each array element represents a single
* menu with the following structure:
*
* ```php
* array(
* // required, the label of the item link
* 'label' => 'Menu label',
* // optional, url of the item link
* 'url' => '',
* // optional the HTML attributes of the item link
* 'urlOptions'=> array(...),
* // optional the HTML attributes of the item
* 'options'=> array(...),
* // optional, an array of items that configure a sub menu of the item
* // note: if `items` is set, then `url` of the parent item will be ignored and automatically set to "#"
* 'items'=> array(...)
* )
* ```
* If you wish to display a `divider`, use any string. The widget will render a bootstrap dropdown divider:
*
* ```html
* <li class="divider"></li>
* ```
*/
public
$items
=
array
();
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public
function
init
()
{
parent
::
init
();
$this
->
addCssClass
(
$this
->
options
,
'dropdown-menu'
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
Html
::
beginTag
(
'ul'
,
$this
->
options
)
.
"
\n
"
;
echo
$this
->
renderContents
()
.
"
\n
"
;
echo
Html
::
endTag
(
'ul'
)
.
"
\n
"
;
$this
->
registerPlugin
(
'dropdown'
);
}
/**
* Renders dropdown contents as specified on [[items]].
* @return string the rendering result.
* @throws InvalidConfigException
*/
protected
function
renderContents
()
{
$contents
=
array
();
foreach
(
$this
->
items
as
$item
)
{
if
(
is_string
(
$item
))
{
$contents
[]
=
Html
::
tag
(
'li'
,
''
,
array
(
'class'
=>
'divider'
));
continue
;
}
if
(
!
isset
(
$item
[
'label'
]))
{
throw
new
InvalidConfigException
(
"The 'label' option is required."
);
}
$options
=
ArrayHelper
::
getValue
(
$item
,
'options'
,
array
());
$urlOptions
=
ArrayHelper
::
getValue
(
$item
,
'urlOptions'
,
array
());
$urlOptions
[
'tabindex'
]
=
'-1'
;
if
(
isset
(
$item
[
'items'
]))
{
$this
->
addCssClass
(
$options
,
'dropdown-submenu'
);
$content
=
Html
::
a
(
$item
[
'label'
],
'#'
,
$urlOptions
)
.
$this
->
dropdown
(
$item
[
'items'
]);
}
else
{
$content
=
Html
::
a
(
$item
[
'label'
],
ArrayHelper
::
getValue
(
$item
,
'url'
,
'#'
),
$urlOptions
);
}
$contents
[]
=
Html
::
tag
(
'li'
,
$content
,
$options
);
}
return
implode
(
"
\n
"
,
$contents
);
}
/**
* 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
Dropdown
::
widget
(
array
(
'items'
=>
$items
,
'clientOptions'
=>
false
));
}
}
\ No newline at end of file
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