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
a93f7506
Commit
a93f7506
authored
May 30, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring button classes.
parent
c0c6c9d9
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
73 deletions
+28
-73
Button.php
framework/yii/bootstrap/Button.php
+2
-8
ButtonDropdown.php
framework/yii/bootstrap/ButtonDropdown.php
+8
-17
ButtonGroup.php
framework/yii/bootstrap/ButtonGroup.php
+18
-48
No files found.
framework/yii/bootstrap/Button.php
View file @
a93f7506
...
...
@@ -6,7 +6,6 @@
*/
namespace
yii\bootstrap
;
use
yii\base\InvalidConfigException
;
use
yii\helpers\Html
;
...
...
@@ -35,7 +34,7 @@ class Button extends Widget
/**
* @var string the button label
*/
public
$label
;
public
$label
=
'Button'
;
/**
* @var boolean whether the label should be HTML-encoded.
*/
...
...
@@ -45,17 +44,12 @@ class Button extends Widget
/**
* 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
->
clientOptions
=
false
;
$this
->
addCssClass
(
$this
->
options
,
'btn'
);
$this
->
label
=
$this
->
encodeLabel
?
Html
::
encode
(
$this
->
label
)
:
$this
->
label
;
}
/**
...
...
@@ -63,7 +57,7 @@ class Button extends Widget
*/
public
function
run
()
{
echo
Html
::
tag
(
$this
->
tagName
,
$this
->
label
,
$this
->
options
)
.
"
\n
"
;
echo
Html
::
tag
(
$this
->
tagName
,
$this
->
encodeLabel
?
Html
::
encode
(
$this
->
label
)
:
$this
->
label
,
$this
->
options
)
;
$this
->
registerPlugin
(
'button'
);
}
}
framework/yii/bootstrap/ButtonDropdown.php
View file @
a93f7506
...
...
@@ -6,8 +6,6 @@
*/
namespace
yii\bootstrap
;
use
yii\base\InvalidConfigException
;
use
yii\helpers\Html
;
...
...
@@ -61,13 +59,14 @@ class ButtonDropdown extends Widget
/**
* @var string the button label
*/
public
$label
;
public
$label
=
'Button'
;
/**
* @var array the HTML attributes of the button.
*/
public
$buttonOptions
=
array
();
/**
* @var array list of menu items in the dropdown. Each array element represents a single
* @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
...
...
@@ -81,7 +80,7 @@ class ButtonDropdown extends Widget
*/
public
$items
=
array
();
/**
* @var boolean whether to display a group o
r split
styled button group.
* @var boolean whether to display a group o
f split-
styled button group.
*/
public
$split
=
false
;
/**
...
...
@@ -93,13 +92,9 @@ class ButtonDropdown extends Widget
/**
* 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'
);
}
...
...
@@ -111,7 +106,7 @@ class ButtonDropdown extends Widget
{
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
echo
$this
->
renderButton
()
.
"
\n
"
;
echo
$this
->
render
Items
()
.
"
\n
"
;
echo
$this
->
render
Dropdown
()
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
$this
->
registerPlugin
(
'button'
);
}
...
...
@@ -123,7 +118,6 @@ class ButtonDropdown extends Widget
protected
function
renderButton
()
{
$this
->
addCssClass
(
$this
->
buttonOptions
,
'btn'
);
$splitButton
=
''
;
if
(
$this
->
split
)
{
$tag
=
'button'
;
$options
=
$this
->
buttonOptions
;
...
...
@@ -133,8 +127,7 @@ class ButtonDropdown extends Widget
'label'
=>
'<span class="caret"></span>'
,
'encodeLabel'
=>
false
,
'options'
=>
$this
->
buttonOptions
,
)
);
));
}
else
{
$tag
=
'a'
;
$this
->
label
.=
' <span class="caret"></span>'
;
...
...
@@ -144,6 +137,7 @@ class ButtonDropdown extends Widget
}
$this
->
addCssClass
(
$options
,
'dropdown-toggle'
);
$options
[
'data-toggle'
]
=
'dropdown'
;
$splitButton
=
''
;
}
return
Button
::
widget
(
array
(
'tagName'
=>
$tag
,
...
...
@@ -157,11 +151,8 @@ class ButtonDropdown extends Widget
* Generates the dropdown menu as specified on [[items]].
* @return string the rendering result.
*/
protected
function
render
Items
()
protected
function
render
Dropdown
()
{
if
(
is_string
(
$this
->
items
))
{
return
$this
->
items
;
}
$config
=
array
(
'items'
=>
$this
->
items
,
'clientOptions'
=>
false
);
return
Dropdown
::
widget
(
$config
);
}
...
...
framework/yii/bootstrap/ButtonGroup.php
View file @
a93f7506
...
...
@@ -20,23 +20,18 @@ use yii\helpers\Html;
* // a button group with items configuration
* echo ButtonGroup::::widget(array(
* 'items' => array(
* array('label'
=>
'A'),
* array('label'
=>
'B'),
* array('label'
=>
'A'),
* array('label'
=>
'B'),
* )
* ));
*
* // button group with an item as a string
* echo ButtonGroup::::widget(array(
* 'items' => array(
* Button::widget(array('label'
=>
'A')),
* array('label'
=>
'B'),
* Button::widget(array('label'
=>
'A')),
* array('label'
=>
'B'),
* )
* ));
*
* // button group with body content as string
* ButtonGroup::beging();
* Button::widget(array('label'=>'A')), // you can also use plain string
* ButtonGroup::end();
* ```
* @see http://twitter.github.io/bootstrap/javascript.html#buttons
* @see http://twitter.github.io/bootstrap/components.html#buttonGroups
...
...
@@ -46,17 +41,15 @@ use yii\helpers\Html;
class
ButtonGroup
extends
Widget
{
/**
* @var array list of buttons. Each array element represents a single
*
menu with
the following structure:
* @var array list of buttons. Each array element represents a single
button
*
which can be specified as a string or an array of
the following structure:
*
* - label: string, required, the button label.
* - options: array, optional, the HTML attributes of the button.
*
* Optionally, you can also set each item as a string, or even the [[items]] attribute.
*/
public
$
item
s
=
array
();
public
$
button
s
=
array
();
/**
* @var boolean whether t
he labels for dropdown items should be HTML-encoded
.
* @var boolean whether t
o HTML-encode the button labels
.
*/
public
$encodeLabels
=
true
;
...
...
@@ -70,7 +63,6 @@ class ButtonGroup extends Widget
parent
::
init
();
$this
->
clientOptions
=
false
;
$this
->
addCssClass
(
$this
->
options
,
'btn-group'
);
echo
$this
->
renderGroupBegin
()
.
"
\n
"
;
}
/**
...
...
@@ -78,51 +70,29 @@ class ButtonGroup extends Widget
*/
public
function
run
()
{
echo
"
\n
"
.
$this
->
renderGroupEnd
(
);
echo
Html
::
tag
(
'div'
,
$this
->
renderButtons
(),
$this
->
options
);
$this
->
registerPlugin
(
'button'
);
}
/**
* Renders the opening tag of the button group.
* @return string the rendering result.
*/
protected
function
renderGroupBegin
()
{
return
Html
::
beginTag
(
'div'
,
$this
->
options
);
}
/**
* Renders the items and closing tag of the button group.
* @return string the rendering result.
*/
protected
function
renderGroupEnd
()
{
return
$this
->
renderItems
()
.
"
\n
"
.
Html
::
endTag
(
'div'
);
}
/**
* Generates the buttons that compound the group as specified on [[items]].
* @return string the rendering result.
*/
protected
function
render
Item
s
()
protected
function
render
Button
s
()
{
if
(
is_string
(
$this
->
items
))
{
return
$this
->
items
;
}
$buttons
=
array
();
foreach
(
$this
->
items
as
$item
)
{
if
(
is_string
(
$item
))
{
$buttons
[]
=
$item
;
continue
;
}
$label
=
ArrayHelper
::
getValue
(
$item
,
'label'
);
$options
=
ArrayHelper
::
getValue
(
$item
,
'options'
);
foreach
(
$this
->
buttons
as
$button
)
{
if
(
is_array
(
$button
))
{
$label
=
ArrayHelper
::
getValue
(
$button
,
'label'
);
$options
=
ArrayHelper
::
getValue
(
$button
,
'options'
);
$buttons
[]
=
Button
::
widget
(
array
(
'label'
=>
$label
,
'options'
=>
$options
,
'encodeLabel'
=>
$this
->
encodeLabels
)
);
));
}
else
{
$buttons
[]
=
$button
;
}
}
return
implode
(
"
\n
"
,
$buttons
);
}
...
...
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