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
3ea779af
Commit
3ea779af
authored
Mar 01, 2012
by
niskac
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved BootButton and BootButtonGroup
parent
2c3e692c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
24 deletions
+49
-24
BootButton.php
widgets/BootButton.php
+44
-21
BootButtonGroup.php
widgets/BootButtonGroup.php
+5
-3
No files found.
widgets/BootButton.php
View file @
3ea779af
...
@@ -12,8 +12,10 @@ Yii::import('bootstrap.widgets.BootWidget');
...
@@ -12,8 +12,10 @@ Yii::import('bootstrap.widgets.BootWidget');
class
BootButton
extends
BootWidget
class
BootButton
extends
BootWidget
{
{
const
TAG_LINK
=
'a'
;
const
METHOD_LINK
=
'link'
;
const
TAG_BUTTON
=
'button'
;
const
METHOD_BUTTON
=
'button'
;
const
METHOD_AJAXLINK
=
'ajaxLink'
;
const
METHOD_AJAXBUTTON
=
'ajaxButton'
;
const
TYPE_NORMAL
=
''
;
const
TYPE_NORMAL
=
''
;
const
TYPE_PRIMARY
=
'primary'
;
const
TYPE_PRIMARY
=
'primary'
;
...
@@ -27,17 +29,19 @@ class BootButton extends BootWidget
...
@@ -27,17 +29,19 @@ class BootButton extends BootWidget
const
SIZE_NORMAL
=
''
;
const
SIZE_NORMAL
=
''
;
const
SIZE_LARGE
=
'large'
;
const
SIZE_LARGE
=
'large'
;
public
$
tag
=
self
::
TAG
_LINK
;
public
$
method
=
self
::
METHOD
_LINK
;
public
$type
=
self
::
TYPE_NORMAL
;
public
$type
=
self
::
TYPE_NORMAL
;
public
$size
=
self
::
SIZE_NORMAL
;
public
$size
=
self
::
SIZE_NORMAL
;
public
$icon
;
public
$icon
;
public
$label
;
public
$label
;
public
$url
;
public
$url
;
public
$active
=
false
;
public
$items
;
public
$items
;
public
$toggle
;
public
$toggle
;
public
$loadingText
;
public
$loadingText
;
public
$completeText
;
public
$completeText
;
public
$encodeLabel
=
true
;
public
$encodeLabel
=
true
;
public
$ajaxOptions
=
array
();
/**
/**
* Initializes the widget.
* Initializes the widget.
...
@@ -57,11 +61,18 @@ class BootButton extends BootWidget
...
@@ -57,11 +61,18 @@ class BootButton extends BootWidget
if
(
isset
(
$this
->
size
)
&&
in_array
(
$this
->
size
,
$validSizes
))
if
(
isset
(
$this
->
size
)
&&
in_array
(
$this
->
size
,
$validSizes
))
$class
[]
=
'btn-'
.
$this
->
size
;
$class
[]
=
'btn-'
.
$this
->
size
;
if
(
$this
->
active
)
{
$class
[]
=
'active'
;
}
if
(
$this
->
encodeLabel
)
$this
->
label
=
CHtml
::
encode
(
$this
->
label
);
if
(
$this
->
hasDropdown
())
if
(
$this
->
hasDropdown
())
{
{
$class
[]
=
'dropdown-toggle'
;
$class
[]
=
'dropdown-toggle'
;
$this
->
label
.=
' <span class="caret"></span>'
;
$this
->
htmlOptions
[
'data-toggle'
]
=
'dropdown'
;
$this
->
htmlOptions
[
'data-toggle'
]
=
'dropdown'
;
Yii
::
app
()
->
bootstrap
->
registerDropdown
();
Yii
::
app
()
->
bootstrap
->
registerDropdown
();
}
}
...
@@ -72,9 +83,6 @@ class BootButton extends BootWidget
...
@@ -72,9 +83,6 @@ class BootButton extends BootWidget
else
else
$this
->
htmlOptions
[
'class'
]
=
$cssClass
;
$this
->
htmlOptions
[
'class'
]
=
$cssClass
;
if
(
$this
->
encodeLabel
)
$this
->
label
=
CHtml
::
encode
(
$this
->
label
);
if
(
isset
(
$this
->
icon
))
if
(
isset
(
$this
->
icon
))
{
{
if
(
strpos
(
$this
->
icon
,
'icon'
)
===
false
)
if
(
strpos
(
$this
->
icon
,
'icon'
)
===
false
)
...
@@ -83,9 +91,14 @@ class BootButton extends BootWidget
...
@@ -83,9 +91,14 @@ class BootButton extends BootWidget
$this
->
label
=
'<i class="'
.
$this
->
icon
.
'"></i> '
.
$this
->
label
;
$this
->
label
=
'<i class="'
.
$this
->
icon
.
'"></i> '
.
$this
->
label
;
}
}
if
(
!
isset
(
$this
->
url
))
$this
->
initHTML5Data
();
$this
->
url
=
'#'
;
}
/**
* Initializes the HTML5 data attributes used by the data-api.
*/
protected
function
initHTML5Data
()
{
if
(
isset
(
$this
->
toggle
)
||
isset
(
$this
->
loadingText
)
||
isset
(
$this
->
completeText
))
if
(
isset
(
$this
->
toggle
)
||
isset
(
$this
->
loadingText
)
||
isset
(
$this
->
completeText
))
{
{
if
(
isset
(
$this
->
toggle
))
if
(
isset
(
$this
->
toggle
))
...
@@ -106,22 +119,32 @@ class BootButton extends BootWidget
...
@@ -106,22 +119,32 @@ class BootButton extends BootWidget
*/
*/
public
function
run
()
public
function
run
()
{
{
if
(
$this
->
tag
===
self
::
TAG_LINK
)
echo
$this
->
createButton
();
$this
->
htmlOptions
[
'href'
]
=
$this
->
url
;
echo
CHtml
::
openTag
(
$this
->
tag
,
$this
->
htmlOptions
);
echo
$this
->
label
;
if
(
$this
->
hasDropdown
())
if
(
$this
->
hasDropdown
())
echo
' <span class="caret"></span>'
;
$this
->
controller
->
widget
(
'bootstrap.widgets.BootDropdown'
,
array
(
'items'
=>
$this
->
items
));
}
echo
CHtml
::
closeTag
(
$this
->
tag
);
if
(
$this
->
hasDropdown
())
/**
* Creates the button element.
* @return string the created button.
*/
protected
function
createButton
()
{
switch
(
$this
->
method
)
{
{
$this
->
controller
->
widget
(
'bootstrap.widgets.BootDropdown'
,
array
(
case
self
::
METHOD_BUTTON
:
'items'
=>
$this
->
items
,
return
CHtml
::
htmlButton
(
$this
->
label
,
$this
->
htmlOptions
);
));
case
self
::
METHOD_AJAXLINK
:
return
CHtml
::
ajaxLink
(
$this
->
label
,
$this
->
url
,
$this
->
ajaxOptions
,
$this
->
htmlOptions
);
case
self
::
METHOD_AJAXBUTTON
:
return
CHtml
::
ajaxButton
(
$this
->
label
,
$this
->
url
,
$this
->
ajaxOptions
,
$this
->
htmlOptions
);
default
:
case
self
::
METHOD_LINK
:
return
CHtml
::
link
(
$this
->
label
,
$this
->
url
,
$this
->
htmlOptions
);
}
}
}
}
...
...
widgets/BootButtonGroup.php
View file @
3ea779af
...
@@ -16,7 +16,7 @@ class BootButtonGroup extends BootWidget
...
@@ -16,7 +16,7 @@ class BootButtonGroup extends BootWidget
const
TOGGLE_CHECKBOX
=
'checkbox'
;
const
TOGGLE_CHECKBOX
=
'checkbox'
;
const
TOGGLE_RADIO
=
'radio'
;
const
TOGGLE_RADIO
=
'radio'
;
public
$
tag
=
BootButton
::
TAG
_LINK
;
public
$
method
=
BootButton
::
METHOD
_LINK
;
public
$type
=
BootButton
::
TYPE_NORMAL
;
public
$type
=
BootButton
::
TYPE_NORMAL
;
public
$size
=
BootButton
::
SIZE_NORMAL
;
public
$size
=
BootButton
::
SIZE_NORMAL
;
public
$encodeLabel
=
true
;
public
$encodeLabel
=
true
;
...
@@ -47,13 +47,15 @@ class BootButtonGroup extends BootWidget
...
@@ -47,13 +47,15 @@ class BootButtonGroup extends BootWidget
foreach
(
$this
->
buttons
as
$button
)
foreach
(
$this
->
buttons
as
$button
)
{
{
$this
->
controller
->
widget
(
'bootstrap.widgets.BootButton'
,
array
(
$this
->
controller
->
widget
(
'bootstrap.widgets.BootButton'
,
array
(
'
tag'
=>
isset
(
$button
[
'tag'
])
?
$button
[
'tag'
]
:
$this
->
tag
,
'
method'
=>
isset
(
$button
[
'method'
])
?
$button
[
'method'
]
:
$this
->
method
,
'type'
=>
$this
->
type
,
'type'
=>
isset
(
$button
[
'type'
])
?
$button
[
'type'
]
:
$this
->
type
,
'size'
=>
$this
->
size
,
'size'
=>
$this
->
size
,
'icon'
=>
isset
(
$button
[
'icon'
])
?
$button
[
'icon'
]
:
null
,
'icon'
=>
isset
(
$button
[
'icon'
])
?
$button
[
'icon'
]
:
null
,
'label'
=>
isset
(
$button
[
'label'
])
?
$button
[
'label'
]
:
null
,
'label'
=>
isset
(
$button
[
'label'
])
?
$button
[
'label'
]
:
null
,
'url'
=>
isset
(
$button
[
'url'
])
?
$button
[
'url'
]
:
null
,
'url'
=>
isset
(
$button
[
'url'
])
?
$button
[
'url'
]
:
null
,
'active'
=>
isset
(
$button
[
'active'
])
?
$button
[
'active'
]
:
false
,
'items'
=>
isset
(
$button
[
'items'
])
?
$button
[
'items'
]
:
array
(),
'items'
=>
isset
(
$button
[
'items'
])
?
$button
[
'items'
]
:
array
(),
'ajaxOptions'
=>
isset
(
$button
[
'ajaxOptions'
])
?
$button
[
'ajaxOptions'
]
:
array
(),
'htmlOptions'
=>
isset
(
$button
[
'htmlOptions'
])
?
$button
[
'htmlOptions'
]
:
array
(),
'htmlOptions'
=>
isset
(
$button
[
'htmlOptions'
])
?
$button
[
'htmlOptions'
]
:
array
(),
'encodeLabel'
=>
isset
(
$button
[
'encodeLabel'
])
?
$button
[
'encodeLabel'
]
:
$this
->
encodeLabel
,
'encodeLabel'
=>
isset
(
$button
[
'encodeLabel'
])
?
$button
[
'encodeLabel'
]
:
$this
->
encodeLabel
,
));
));
...
...
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