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
3647c3f1
Commit
3647c3f1
authored
May 29, 2013
by
Antonio Ramirez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added button group dropdowns
parent
9af5466b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
148 additions
and
0 deletions
+148
-0
Button.php
framework/yii/bootstrap/Button.php
+148
-0
No files found.
framework/yii/bootstrap/Button.php
0 → 100644
View file @
3647c3f1
<?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\Html
;
/**
* Button renders a group or split button dropdown bootstrap component.
*
* For example,
*
* ```php
* // a button group using Dropdown widget
* echo \yii\bootstrap\Button::widget(array(
* 'label' => 'Action',
* 'items' => Dropdown::widget(array(
* 'clientOptions' => false,
* 'items' => array(
* array(
* 'label' => 'DropdownA',
* 'url' => '/',
* ),
* array(
* 'label' => 'DropdownB',
* 'url' => '#',
* ),
* ),
* ),
* ),
* ));
*
* // split button group using `items` dropdown configuration
* echo \yii\bootstrap\Button::widget(array(
* 'label' => 'Action',
* 'split' => true,
* 'items' => array(
* array(
* 'label' => 'DropdownA',
* 'url' => '/',
* ),
* array(
* 'label' => 'DropdownB',
* 'url' => '#',
* ),
* ),
* ));
* ```
* @see http://twitter.github.io/bootstrap/javascript.html#buttons
* @see http://twitter.github.io/bootstrap/components.html#buttonDropdowns
* @author Antonio Ramirez <amigo.cobos@gmail.com>
* @since 2.0
*/
class
Button
extends
Widget
{
/**
* @var string the button label
*/
public
$label
;
/**
* @var array list of menu items in the dropdown. 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]]
*/
public
$items
=
array
();
/**
* @var boolean whether to display a group or split styled button group.
*/
public
$split
=
false
;
/**
* @var boolean whether the labels for dropdown items should be HTML-encoded.
*/
public
$encodeLabels
=
true
;
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
* @throws InvalidConfigException
*/
public
function
init
()
{
if
(
$this
->
label
===
null
)
{
throw
new
InvalidConfigException
(
"The 'label' option is required."
);
}
parent
::
init
();
$this
->
addCssClass
(
$this
->
options
,
'btn-group'
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
echo
$this
->
renderLabel
()
.
"
\n
"
;
echo
$this
->
renderItems
()
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
$this
->
registerPlugin
(
'button'
);
}
/**
* Generates the button label.
* @return string the rendering result.
*/
protected
function
renderLabel
()
{
$label
=
$this
->
encodeLabels
?
Html
::
encode
(
$this
->
label
)
:
$this
->
label
;
$options
=
array
(
'class'
=>
'btn dropdown-toggle'
,
'data-toggle'
=>
'dropdown'
);
if
(
$this
->
split
)
{
$tag
=
'button'
;
$label
.=
Html
::
tag
(
'button'
,
'<span class="caret"></span>'
,
$options
);
$options
=
array
(
'class'
=>
'btn'
);
}
else
{
$tag
=
'a'
;
$options
[
'href'
]
=
'#'
;
}
return
Html
::
tag
(
$tag
,
$label
,
$options
);
}
/**
* Generates the dropdown menu as specified on [[items]].
* @return string the rendering result.
*/
protected
function
renderItems
()
{
if
(
is_string
(
$this
->
items
))
{
return
$this
->
items
;
}
$config
=
array
(
'items'
=>
$this
->
items
,
'clientOptions'
=>
false
);
return
Dropdown
::
widget
(
$config
);
}
}
\ 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