Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yii2bootstrap
Project
Project
Details
Activity
Releases
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
夏彬
yii2bootstrap
Commits
5cc2dc8d
Commit
5cc2dc8d
authored
Mar 16, 2014
by
SonicGD
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reformat code te be PSR-2 compatible
parent
99928844
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
1347 additions
and
1343 deletions
+1347
-1343
Alert.php
Alert.php
+90
-90
BootstrapAsset.php
BootstrapAsset.php
+4
-4
BootstrapPluginAsset.php
BootstrapPluginAsset.php
+8
-8
BootstrapThemeAsset.php
BootstrapThemeAsset.php
+7
-7
Button.php
Button.php
+30
-31
ButtonDropdown.php
ButtonDropdown.php
+84
-83
ButtonGroup.php
ButtonGroup.php
+52
-52
Carousel.php
Carousel.php
+120
-119
Collapse.php
Collapse.php
+80
-81
Dropdown.php
Dropdown.php
+70
-70
Modal.php
Modal.php
+198
-197
Nav.php
Nav.php
+165
-164
NavBar.php
NavBar.php
+114
-113
Progress.php
Progress.php
+96
-95
Tabs.php
Tabs.php
+176
-175
Widget.php
Widget.php
+53
-54
No files found.
Alert.php
View file @
5cc2dc8d
...
...
@@ -46,105 +46,105 @@ use yii\helpers\Html;
*/
class
Alert
extends
Widget
{
/**
* @var string the body content in the alert component. Note that anything between
* the [[begin()]] and [[end()]] calls of the Alert widget will also be treated
* as the body content, and will be rendered before this.
*/
public
$body
;
/**
* @var array the options for rendering the close button tag.
* The close button is displayed in the header of the modal window. Clicking
* on the button will hide the modal window. If this is null, no close button will be rendered.
*
* The following special options are supported:
*
* - tag: string, the tag name of the button. Defaults to 'button'.
* - label: string, the label of the button. Defaults to '×'.
*
* The rest of the options will be rendered as the HTML attributes of the button tag.
* Please refer to the [Alert documentation](http://getbootstrap.com/components/#alerts)
* for the supported HTML attributes.
*/
public
$closeButton
=
[];
/**
* @var string the body content in the alert component. Note that anything between
* the [[begin()]] and [[end()]] calls of the Alert widget will also be treated
* as the body content, and will be rendered before this.
*/
public
$body
;
/**
* @var array the options for rendering the close button tag.
* The close button is displayed in the header of the modal window. Clicking
* on the button will hide the modal window. If this is null, no close button will be rendered.
*
* The following special options are supported:
*
* - tag: string, the tag name of the button. Defaults to 'button'.
* - label: string, the label of the button. Defaults to '×'.
*
* The rest of the options will be rendered as the HTML attributes of the button tag.
* Please refer to the [Alert documentation](http://getbootstrap.com/components/#alerts)
* for the supported HTML attributes.
*/
public
$closeButton
=
[];
/**
* Initializes the widget.
*/
public
function
init
()
{
parent
::
init
();
/**
* Initializes the widget.
*/
public
function
init
()
{
parent
::
init
();
$this
->
initOptions
();
$this
->
initOptions
();
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
echo
$this
->
renderBodyBegin
()
.
"
\n
"
;
}
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
echo
$this
->
renderBodyBegin
()
.
"
\n
"
;
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
"
\n
"
.
$this
->
renderBodyEnd
();
echo
"
\n
"
.
Html
::
endTag
(
'div'
);
/**
* Renders the widget.
*/
public
function
run
()
{
echo
"
\n
"
.
$this
->
renderBodyEnd
();
echo
"
\n
"
.
Html
::
endTag
(
'div'
);
$this
->
registerPlugin
(
'alert'
);
}
$this
->
registerPlugin
(
'alert'
);
}
/**
* Renders the close button if any before rendering the content.
* @return string the rendering result
*/
protected
function
renderBodyBegin
()
{
return
$this
->
renderCloseButton
();
}
/**
* Renders the close button if any before rendering the content
.
* @return string the rendering result
*/
protected
function
renderBodyBegin
()
{
return
$this
->
renderCloseButton
()
;
}
/**
* Renders the alert body (if any)
.
* @return string the rendering result
*/
protected
function
renderBodyEnd
()
{
return
$this
->
body
.
"
\n
"
;
}
/**
* Renders the alert body (if any).
* @return string the rendering result
*/
protected
function
renderBodyEnd
()
{
return
$this
->
body
.
"
\n
"
;
}
/**
* Renders the close button.
* @return string the rendering result
*/
protected
function
renderCloseButton
()
{
if
(
$this
->
closeButton
!==
null
)
{
$tag
=
ArrayHelper
::
remove
(
$this
->
closeButton
,
'tag'
,
'button'
);
$label
=
ArrayHelper
::
remove
(
$this
->
closeButton
,
'label'
,
'×'
);
if
(
$tag
===
'button'
&&
!
isset
(
$this
->
closeButton
[
'type'
]))
{
$this
->
closeButton
[
'type'
]
=
'button'
;
}
/**
* Renders the close button.
* @return string the rendering result
*/
protected
function
renderCloseButton
()
{
if
(
$this
->
closeButton
!==
null
)
{
$tag
=
ArrayHelper
::
remove
(
$this
->
closeButton
,
'tag'
,
'button'
);
$label
=
ArrayHelper
::
remove
(
$this
->
closeButton
,
'label'
,
'×'
);
if
(
$tag
===
'button'
&&
!
isset
(
$this
->
closeButton
[
'type'
]))
{
$this
->
closeButton
[
'type'
]
=
'button'
;
}
return
Html
::
tag
(
$tag
,
$label
,
$this
->
closeButton
);
}
else
{
return
null
;
}
}
return
Html
::
tag
(
$tag
,
$label
,
$this
->
closeButton
);
}
else
{
return
null
;
}
}
/**
* Initializes the widget options.
* This method sets the default values for various options.
*/
protected
function
initOptions
()
{
Html
::
addCssClass
(
$this
->
options
,
'alert'
);
Html
::
addCssClass
(
$this
->
options
,
'fade'
);
Html
::
addCssClass
(
$this
->
options
,
'in'
);
/**
* Initializes the widget options.
* This method sets the default values for various options.
*/
protected
function
initOptions
()
{
Html
::
addCssClass
(
$this
->
options
,
'alert'
);
Html
::
addCssClass
(
$this
->
options
,
'fade'
);
Html
::
addCssClass
(
$this
->
options
,
'in'
);
if
(
$this
->
closeButton
!==
null
)
{
$this
->
closeButton
=
array_merge
([
'data-dismiss'
=>
'alert'
,
'aria-hidden'
=>
'true'
,
'class'
=>
'close'
,
],
$this
->
closeButton
);
}
}
if
(
$this
->
closeButton
!==
null
)
{
$this
->
closeButton
=
array_merge
([
'data-dismiss'
=>
'alert'
,
'aria-hidden'
=>
'true'
,
'class'
=>
'close'
,
],
$this
->
closeButton
);
}
}
}
BootstrapAsset.php
View file @
5cc2dc8d
...
...
@@ -17,8 +17,8 @@ use yii\web\AssetBundle;
*/
class
BootstrapAsset
extends
AssetBundle
{
public
$sourcePath
=
'@vendor/twbs/bootstrap/dist'
;
public
$css
=
[
'css/bootstrap.css'
,
];
public
$sourcePath
=
'@vendor/twbs/bootstrap/dist'
;
public
$css
=
[
'css/bootstrap.css'
,
];
}
BootstrapPluginAsset.php
View file @
5cc2dc8d
...
...
@@ -17,12 +17,12 @@ use yii\web\AssetBundle;
*/
class
BootstrapPluginAsset
extends
AssetBundle
{
public
$sourcePath
=
'@vendor/twbs/bootstrap/dist'
;
public
$js
=
[
'js/bootstrap.js'
,
];
public
$depends
=
[
'yii\web\JqueryAsset'
,
'yii\bootstrap\BootstrapAsset'
,
];
public
$sourcePath
=
'@vendor/twbs/bootstrap/dist'
;
public
$js
=
[
'js/bootstrap.js'
,
];
public
$depends
=
[
'yii\web\JqueryAsset'
,
'yii\bootstrap\BootstrapAsset'
,
];
}
BootstrapThemeAsset.php
View file @
5cc2dc8d
...
...
@@ -17,11 +17,11 @@ use yii\web\AssetBundle;
*/
class
BootstrapThemeAsset
extends
AssetBundle
{
public
$sourcePath
=
'@vendor/twbs/bootstrap/dist'
;
public
$css
=
[
'css/bootstrap-theme.css'
,
];
public
$depends
=
[
'yii\bootstrap\BootstrapAsset'
,
];
public
$sourcePath
=
'@vendor/twbs/bootstrap/dist'
;
public
$css
=
[
'css/bootstrap-theme.css'
,
];
public
$depends
=
[
'yii\bootstrap\BootstrapAsset'
,
];
}
Button.php
View file @
5cc2dc8d
...
...
@@ -26,37 +26,36 @@ use yii\helpers\Html;
*/
class
Button
extends
Widget
{
/**
* @var string the tag to use to render the button
*/
public
$tagName
=
'button'
;
/**
* @var string the button label
*/
public
$label
=
'Button'
;
/**
* @var boolean whether the label should be HTML-encoded.
*/
public
$encodeLabel
=
true
;
/**
* @var string the tag to use to render the button
*/
public
$tagName
=
'button'
;
/**
* @var string the button label
*/
public
$label
=
'Button'
;
/**
* @var boolean whether the label should be HTML-encoded.
*/
public
$encodeLabel
=
true
;
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public
function
init
()
{
parent
::
init
();
$this
->
clientOptions
=
false
;
Html
::
addCssClass
(
$this
->
options
,
'btn'
);
}
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public
function
init
()
{
parent
::
init
();
$this
->
clientOptions
=
false
;
Html
::
addCssClass
(
$this
->
options
,
'btn'
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
Html
::
tag
(
$this
->
tagName
,
$this
->
encodeLabel
?
Html
::
encode
(
$this
->
label
)
:
$this
->
label
,
$this
->
options
);
$this
->
registerPlugin
(
'button'
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
Html
::
tag
(
$this
->
tagName
,
$this
->
encodeLabel
?
Html
::
encode
(
$this
->
label
)
:
$this
->
label
,
$this
->
options
);
$this
->
registerPlugin
(
'button'
);
}
}
ButtonDropdown.php
View file @
5cc2dc8d
...
...
@@ -33,91 +33,92 @@ use yii\helpers\Html;
*/
class
ButtonDropdown
extends
Widget
{
/**
* @var string the button label
*/
public
$label
=
'Button'
;
/**
* @var array the HTML attributes of the button.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$options
=
[];
/**
* @var array the configuration array for [[Dropdown]].
*/
public
$dropdown
=
[];
/**
* @var boolean whether to display a group of split-styled button group.
*/
public
$split
=
false
;
/**
* @var string the tag to use to render the button
*/
public
$tagName
=
'button'
;
/**
* @var boolean whether the label should be HTML-encoded.
*/
public
$encodeLabel
=
true
;
/**
* @var string the button label
*/
public
$label
=
'Button'
;
/**
* @var array the HTML attributes of the button.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$options
=
[];
/**
* @var array the configuration array for [[Dropdown]].
*/
public
$dropdown
=
[];
/**
* @var boolean whether to display a group of split-styled button group.
*/
public
$split
=
false
;
/**
* @var string the tag to use to render the button
*/
public
$tagName
=
'button'
;
/**
* @var boolean whether the label should be HTML-encoded.
*/
public
$encodeLabel
=
true
;
/**
* Renders the widget.
*/
public
function
run
()
{
echo
$this
->
renderButton
()
.
"
\n
"
.
$this
->
renderDropdown
();
$this
->
registerPlugin
(
'button'
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
$this
->
renderButton
()
.
"
\n
"
.
$this
->
renderDropdown
();
$this
->
registerPlugin
(
'button'
);
}
/**
* Generates the button dropdown.
* @return string the rendering result.
*/
protected
function
renderButton
()
{
Html
::
addCssClass
(
$this
->
options
,
'btn'
);
$label
=
$this
->
label
;
if
(
$this
->
encodeLabel
)
{
$label
=
Html
::
encode
(
$label
);
}
if
(
$this
->
split
)
{
$options
=
$this
->
options
;
$this
->
options
[
'data-toggle'
]
=
'dropdown'
;
Html
::
addCssClass
(
$this
->
options
,
'dropdown-toggle'
);
$splitButton
=
Button
::
widget
([
'label'
=>
'<span class="caret"></span>'
,
'encodeLabel'
=>
false
,
'options'
=>
$this
->
options
,
'view'
=>
$this
->
getView
(),
]);
}
else
{
$label
.=
' <span class="caret"></span>'
;
$options
=
$this
->
options
;
if
(
!
isset
(
$options
[
'href'
]))
{
$options
[
'href'
]
=
'#'
;
}
Html
::
addCssClass
(
$options
,
'dropdown-toggle'
);
$options
[
'data-toggle'
]
=
'dropdown'
;
$splitButton
=
''
;
}
/**
* Generates the button dropdown.
* @return string the rendering result.
*/
protected
function
renderButton
()
{
Html
::
addCssClass
(
$this
->
options
,
'btn'
);
$label
=
$this
->
label
;
if
(
$this
->
encodeLabel
)
{
$label
=
Html
::
encode
(
$label
);
}
if
(
$this
->
split
)
{
$options
=
$this
->
options
;
$this
->
options
[
'data-toggle'
]
=
'dropdown'
;
Html
::
addCssClass
(
$this
->
options
,
'dropdown-toggle'
);
$splitButton
=
Button
::
widget
([
'label'
=>
'<span class="caret"></span>'
,
'encodeLabel'
=>
false
,
'options'
=>
$this
->
options
,
'view'
=>
$this
->
getView
(),
]);
}
else
{
$label
.=
' <span class="caret"></span>'
;
$options
=
$this
->
options
;
if
(
!
isset
(
$options
[
'href'
]))
{
$options
[
'href'
]
=
'#'
;
}
Html
::
addCssClass
(
$options
,
'dropdown-toggle'
);
$options
[
'data-toggle'
]
=
'dropdown'
;
$splitButton
=
''
;
}
return
Button
::
widget
([
'tagName'
=>
$this
->
tagName
,
'label'
=>
$label
,
'options'
=>
$options
,
'encodeLabel'
=>
false
,
'view'
=>
$this
->
getView
(),
])
.
"
\n
"
.
$splitButton
;
}
return
Button
::
widget
([
'tagName'
=>
$this
->
tagName
,
'label'
=>
$label
,
'options'
=>
$options
,
'encodeLabel'
=>
false
,
'view'
=>
$this
->
getView
(),
])
.
"
\n
"
.
$splitButton
;
}
/**
* Generates the dropdown menu.
* @return string the rendering result.
*/
protected
function
renderDropdown
()
{
$config
=
$this
->
dropdown
;
$config
[
'clientOptions'
]
=
false
;
$config
[
'view'
]
=
$this
->
getView
();
return
Dropdown
::
widget
(
$config
);
}
/**
* Generates the dropdown menu.
* @return string the rendering result.
*/
protected
function
renderDropdown
()
{
$config
=
$this
->
dropdown
;
$config
[
'clientOptions'
]
=
false
;
$config
[
'view'
]
=
$this
->
getView
();
return
Dropdown
::
widget
(
$config
);
}
}
ButtonGroup.php
View file @
5cc2dc8d
...
...
@@ -39,60 +39,60 @@ use yii\helpers\Html;
*/
class
ButtonGroup
extends
Widget
{
/**
* @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.
*/
public
$buttons
=
[];
/**
* @var boolean whether to HTML-encode the button labels.
*/
public
$encodeLabels
=
true
;
/**
* @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.
*/
public
$buttons
=
[];
/**
* @var boolean whether to HTML-encode the button labels.
*/
public
$encodeLabels
=
true
;
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public
function
init
()
{
parent
::
init
();
Html
::
addCssClass
(
$this
->
options
,
'btn-group'
);
}
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public
function
init
()
{
parent
::
init
();
Html
::
addCssClass
(
$this
->
options
,
'btn-group'
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
Html
::
tag
(
'div'
,
$this
->
renderButtons
(),
$this
->
options
);
BootstrapAsset
::
register
(
$this
->
getView
());
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
Html
::
tag
(
'div'
,
$this
->
renderButtons
(),
$this
->
options
);
BootstrapAsset
::
register
(
$this
->
getView
());
}
/**
* Generates the buttons that compound the group as specified on [[items]].
* @return string the rendering result.
*/
protected
function
renderButtons
()
{
$buttons
=
[];
foreach
(
$this
->
buttons
as
$button
)
{
if
(
is_array
(
$button
))
{
$label
=
ArrayHelper
::
getValue
(
$button
,
'label'
);
$options
=
ArrayHelper
::
getValue
(
$button
,
'options'
);
$buttons
[]
=
Button
::
widget
([
'label'
=>
$label
,
'options'
=>
$options
,
'encodeLabel'
=>
$this
->
encodeLabels
,
'view'
=>
$this
->
getView
()
]);
}
else
{
$buttons
[]
=
$button
;
}
}
/**
* Generates the buttons that compound the group as specified on [[items]].
* @return string the rendering result.
*/
protected
function
renderButtons
()
{
$buttons
=
[];
foreach
(
$this
->
buttons
as
$button
)
{
if
(
is_array
(
$button
))
{
$label
=
ArrayHelper
::
getValue
(
$button
,
'label'
);
$options
=
ArrayHelper
::
getValue
(
$button
,
'options'
);
$buttons
[]
=
Button
::
widget
([
'label'
=>
$label
,
'options'
=>
$options
,
'encodeLabel'
=>
$this
->
encodeLabels
,
'view'
=>
$this
->
getView
()
]);
}
else
{
$buttons
[]
=
$button
;
}
}
return
implode
(
"
\n
"
,
$buttons
);
}
return
implode
(
"
\n
"
,
$buttons
);
}
}
Carousel.php
View file @
5cc2dc8d
...
...
@@ -39,132 +39,133 @@ use yii\helpers\Html;
*/
class
Carousel
extends
Widget
{
/**
* @var array|boolean the labels for the previous and the next control buttons.
* If false, it means the previous and the next control buttons should not be displayed.
*/
public
$controls
=
[
'‹'
,
'›'
];
/**
* @var array list of slides in the carousel. Each array element represents a single
* slide with the following structure:
*
* ```php
* [
* // required, slide content (HTML), such as an image tag
* 'content' => '<img src="http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-01.jpg"/>',
* // optional, the caption (HTML) of the slide
* 'caption' => '<h4>This is title</h4><p>This is the caption text</p>',
* // optional the HTML attributes of the slide container
* 'options' => [],
* ]
* ```
*/
public
$items
=
[];
/**
* @var array|boolean the labels for the previous and the next control buttons.
* If false, it means the previous and the next control buttons should not be displayed.
*/
public
$controls
=
[
'‹'
,
'›'
];
/**
* @var array list of slides in the carousel. Each array element represents a single
* slide with the following structure:
*
* ```php
* [
* // required, slide content (HTML), such as an image tag
* 'content' => '<img src="http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-01.jpg"/>',
* // optional, the caption (HTML) of the slide
* 'caption' => '<h4>This is title</h4><p>This is the caption text</p>',
* // optional the HTML attributes of the slide container
* 'options' => [],
* ]
* ```
*/
public
$items
=
[];
/**
* Initializes the widget.
*/
public
function
init
()
{
parent
::
init
();
Html
::
addCssClass
(
$this
->
options
,
'carousel'
);
}
/**
* Initializes the widget.
*/
public
function
init
()
{
parent
::
init
();
Html
::
addCssClass
(
$this
->
options
,
'carousel'
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
echo
$this
->
renderIndicators
()
.
"
\n
"
;
echo
$this
->
renderItems
()
.
"
\n
"
;
echo
$this
->
renderControls
()
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
$this
->
registerPlugin
(
'carousel'
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
echo
$this
->
renderIndicators
()
.
"
\n
"
;
echo
$this
->
renderItems
()
.
"
\n
"
;
echo
$this
->
renderControls
()
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
$this
->
registerPlugin
(
'carousel'
);
}
/**
* Renders carousel indicators.
* @return string the rendering result
*/
public
function
renderIndicators
()
{
$indicators
=
[];
for
(
$i
=
0
,
$count
=
count
(
$this
->
items
);
$i
<
$count
;
$i
++
)
{
$options
=
[
'data-target'
=>
'#'
.
$this
->
options
[
'id'
],
'data-slide-to'
=>
$i
];
if
(
$i
===
0
)
{
Html
::
addCssClass
(
$options
,
'active'
);
}
$indicators
[]
=
Html
::
tag
(
'li'
,
''
,
$options
);
}
/**
* Renders carousel indicators.
* @return string the rendering result
*/
public
function
renderIndicators
()
{
$indicators
=
[];
for
(
$i
=
0
,
$count
=
count
(
$this
->
items
);
$i
<
$count
;
$i
++
)
{
$options
=
[
'data-target'
=>
'#'
.
$this
->
options
[
'id'
],
'data-slide-to'
=>
$i
];
if
(
$i
===
0
)
{
Html
::
addCssClass
(
$options
,
'active'
);
}
$indicators
[]
=
Html
::
tag
(
'li'
,
''
,
$options
);
}
return
Html
::
tag
(
'ol'
,
implode
(
"
\n
"
,
$indicators
),
[
'class'
=>
'carousel-indicators'
]);
}
return
Html
::
tag
(
'ol'
,
implode
(
"
\n
"
,
$indicators
),
[
'class'
=>
'carousel-indicators'
]);
}
/**
* Renders carousel items as specified on [[items]].
* @return string the rendering result
*/
public
function
renderItems
()
{
$items
=
[];
for
(
$i
=
0
,
$count
=
count
(
$this
->
items
);
$i
<
$count
;
$i
++
)
{
$items
[]
=
$this
->
renderItem
(
$this
->
items
[
$i
],
$i
);
}
return
Html
::
tag
(
'div'
,
implode
(
"
\n
"
,
$items
),
[
'class'
=>
'carousel-inner'
]);
}
/**
* Renders carousel items as specified on [[items]].
* @return string the rendering result
*/
public
function
renderItems
()
{
$items
=
[];
for
(
$i
=
0
,
$count
=
count
(
$this
->
items
);
$i
<
$count
;
$i
++
)
{
$items
[]
=
$this
->
renderItem
(
$this
->
items
[
$i
],
$i
);
}
/**
* Renders a single carousel item
* @param string|array $item a single item from [[items]]
* @param integer $index the item index as the first item should be set to `active`
* @return string the rendering result
* @throws InvalidConfigException if the item is invalid
*/
public
function
renderItem
(
$item
,
$index
)
{
if
(
is_string
(
$item
))
{
$content
=
$item
;
$caption
=
null
;
$options
=
[];
}
elseif
(
isset
(
$item
[
'content'
]))
{
$content
=
$item
[
'content'
];
$caption
=
ArrayHelper
::
getValue
(
$item
,
'caption'
);
if
(
$caption
!==
null
)
{
$caption
=
Html
::
tag
(
'div'
,
$caption
,
[
'class'
=>
'carousel-caption'
]);
}
$options
=
ArrayHelper
::
getValue
(
$item
,
'options'
,
[]);
}
else
{
throw
new
InvalidConfigException
(
'The "content" option is required.'
);
}
return
Html
::
tag
(
'div'
,
implode
(
"
\n
"
,
$items
),
[
'class'
=>
'carousel-inner'
]);
}
Html
::
addCssClass
(
$options
,
'item'
);
if
(
$index
===
0
)
{
Html
::
addCssClass
(
$options
,
'active'
);
}
/**
* Renders a single carousel item
* @param string|array $item a single item from [[items]]
* @param integer $index the item index as the first item should be set to `active`
* @return string the rendering result
* @throws InvalidConfigException if the item is invalid
*/
public
function
renderItem
(
$item
,
$index
)
{
if
(
is_string
(
$item
))
{
$content
=
$item
;
$caption
=
null
;
$options
=
[];
}
elseif
(
isset
(
$item
[
'content'
]))
{
$content
=
$item
[
'content'
];
$caption
=
ArrayHelper
::
getValue
(
$item
,
'caption'
);
if
(
$caption
!==
null
)
{
$caption
=
Html
::
tag
(
'div'
,
$caption
,
[
'class'
=>
'carousel-caption'
]);
}
$options
=
ArrayHelper
::
getValue
(
$item
,
'options'
,
[]);
}
else
{
throw
new
InvalidConfigException
(
'The "content" option is required.'
);
}
return
Html
::
tag
(
'div'
,
$content
.
"
\n
"
.
$caption
,
$options
);
}
Html
::
addCssClass
(
$options
,
'item'
);
if
(
$index
===
0
)
{
Html
::
addCssClass
(
$options
,
'active'
);
}
/**
* Renders previous and next control buttons.
* @throws InvalidConfigException if [[controls]] is invalid.
*/
public
function
renderControls
()
{
if
(
isset
(
$this
->
controls
[
0
],
$this
->
controls
[
1
]))
{
return
Html
::
a
(
$this
->
controls
[
0
],
'#'
.
$this
->
options
[
'id'
],
[
'class'
=>
'left carousel-control'
,
'data-slide'
=>
'prev'
,
])
.
"
\n
"
.
Html
::
a
(
$this
->
controls
[
1
],
'#'
.
$this
->
options
[
'id'
],
[
'class'
=>
'right carousel-control'
,
'data-slide'
=>
'next'
,
]);
}
elseif
(
$this
->
controls
===
false
)
{
return
''
;
}
else
{
throw
new
InvalidConfigException
(
'The "controls" property must be either false or an array of two elements.'
);
}
}
return
Html
::
tag
(
'div'
,
$content
.
"
\n
"
.
$caption
,
$options
);
}
/**
* Renders previous and next control buttons.
* @throws InvalidConfigException if [[controls]] is invalid.
*/
public
function
renderControls
()
{
if
(
isset
(
$this
->
controls
[
0
],
$this
->
controls
[
1
]))
{
return
Html
::
a
(
$this
->
controls
[
0
],
'#'
.
$this
->
options
[
'id'
],
[
'class'
=>
'left carousel-control'
,
'data-slide'
=>
'prev'
,
])
.
"
\n
"
.
Html
::
a
(
$this
->
controls
[
1
],
'#'
.
$this
->
options
[
'id'
],
[
'class'
=>
'right carousel-control'
,
'data-slide'
=>
'next'
,
]);
}
elseif
(
$this
->
controls
===
false
)
{
return
''
;
}
else
{
throw
new
InvalidConfigException
(
'The "controls" property must be either false or an array of two elements.'
);
}
}
}
Collapse.php
View file @
5cc2dc8d
...
...
@@ -41,95 +41,94 @@ use yii\helpers\Html;
*/
class
Collapse
extends
Widget
{
/**
* @var array list of groups in the collapse widget. Each array element represents a single
* group with the following structure:
*
* ```php
* // item key is the actual group header
* 'Collapsible Group Item #1' => [
* // required, the content (HTML) of the group
* 'content' => 'Anim pariatur cliche...',
* // optional the HTML attributes of the content group
* 'contentOptions' => [],
* // optional the HTML attributes of the group
* 'options' => [],
* ]
* ```
*/
public
$items
=
[];
/**
* @var array list of groups in the collapse widget. Each array element represents a single
* group with the following structure:
*
* ```php
* // item key is the actual group header
* 'Collapsible Group Item #1' => [
* // required, the content (HTML) of the group
* 'content' => 'Anim pariatur cliche...',
* // optional the HTML attributes of the content group
* 'contentOptions' => [],
* // optional the HTML attributes of the group
* 'options' => [],
* ]
* ```
*/
public
$items
=
[];
/**
* Initializes the widget.
*/
public
function
init
()
{
parent
::
init
();
Html
::
addCssClass
(
$this
->
options
,
'panel-group'
);
}
/**
* Initializes the widget.
*/
public
function
init
()
{
parent
::
init
();
Html
::
addCssClass
(
$this
->
options
,
'panel-group'
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
echo
$this
->
renderItems
()
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
$this
->
registerPlugin
(
'collapse'
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
echo
$this
->
renderItems
()
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
$this
->
registerPlugin
(
'collapse'
);
}
/**
* Renders collapsible items as specified on [[items]].
* @return string the rendering result
*/
public
function
renderItems
()
{
$items
=
[];
$index
=
0
;
foreach
(
$this
->
items
as
$header
=>
$item
)
{
$options
=
ArrayHelper
::
getValue
(
$item
,
'options'
,
[]);
Html
::
addCssClass
(
$options
,
'panel panel-default'
);
$items
[]
=
Html
::
tag
(
'div'
,
$this
->
renderItem
(
$header
,
$item
,
++
$index
),
$options
);
}
/**
* Renders collapsible items as specified on [[items]].
* @return string the rendering result
*/
public
function
renderItems
()
{
$items
=
[];
$index
=
0
;
foreach
(
$this
->
items
as
$header
=>
$item
)
{
$options
=
ArrayHelper
::
getValue
(
$item
,
'options'
,
[]);
Html
::
addCssClass
(
$options
,
'panel panel-default'
);
$items
[]
=
Html
::
tag
(
'div'
,
$this
->
renderItem
(
$header
,
$item
,
++
$index
),
$options
);
}
return
implode
(
"
\n
"
,
$items
);
}
return
implode
(
"
\n
"
,
$items
);
}
/**
* Renders a single collapsible item group
* @param string $header a label of the item group [[items]]
* @param array $item a single item from [[items]]
* @param integer $index the item index as each item group content must have an id
* @return string the rendering result
* @throws InvalidConfigException
*/
public
function
renderItem
(
$header
,
$item
,
$index
)
{
if
(
isset
(
$item
[
'content'
]))
{
$id
=
$this
->
options
[
'id'
]
.
'-collapse'
.
$index
;
$options
=
ArrayHelper
::
getValue
(
$item
,
'contentOptions'
,
[]);
$options
[
'id'
]
=
$id
;
Html
::
addCssClass
(
$options
,
'panel-collapse collapse'
);
/**
* Renders a single collapsible item group
* @param string $header a label of the item group [[items]]
* @param array $item a single item from [[items]]
* @param integer $index the item index as each item group content must have an id
* @return string the rendering result
* @throws InvalidConfigException
*/
public
function
renderItem
(
$header
,
$item
,
$index
)
{
if
(
isset
(
$item
[
'content'
]))
{
$id
=
$this
->
options
[
'id'
]
.
'-collapse'
.
$index
;
$options
=
ArrayHelper
::
getValue
(
$item
,
'contentOptions'
,
[]);
$options
[
'id'
]
=
$id
;
Html
::
addCssClass
(
$options
,
'panel-collapse collapse'
);
$headerToggle
=
Html
::
a
(
$header
,
'#'
.
$id
,
[
'class'
=>
'collapse-toggle'
,
'data-toggle'
=>
'collapse'
,
'data-parent'
=>
'#'
.
$this
->
options
[
'id'
]
])
.
"
\n
"
;
$headerToggle
=
Html
::
a
(
$header
,
'#'
.
$id
,
[
'class'
=>
'collapse-toggle'
,
'data-toggle'
=>
'collapse'
,
'data-parent'
=>
'#'
.
$this
->
options
[
'id'
]
])
.
"
\n
"
;
$header
=
Html
::
tag
(
'h4'
,
$headerToggle
,
[
'class'
=>
'panel-title'
]);
$header
=
Html
::
tag
(
'h4'
,
$headerToggle
,
[
'class'
=>
'panel-title'
]);
$content
=
Html
::
tag
(
'div'
,
$item
[
'content'
],
[
'class'
=>
'panel-body'
])
.
"
\n
"
;
}
else
{
throw
new
InvalidConfigException
(
'The "content" option is required.'
);
}
$group
=
[];
$content
=
Html
::
tag
(
'div'
,
$item
[
'content'
],
[
'class'
=>
'panel-body'
])
.
"
\n
"
;
}
else
{
throw
new
InvalidConfigException
(
'The "content" option is required.'
);
}
$group
=
[];
$group
[]
=
Html
::
tag
(
'div'
,
$header
,
[
'class'
=>
'panel-heading'
]);
$group
[]
=
Html
::
tag
(
'div'
,
$content
,
$options
);
$group
[]
=
Html
::
tag
(
'div'
,
$header
,
[
'class'
=>
'panel-heading'
]);
$group
[]
=
Html
::
tag
(
'div'
,
$content
,
$options
);
return
implode
(
"
\n
"
,
$group
);
}
return
implode
(
"
\n
"
,
$group
);
}
}
Dropdown.php
View file @
5cc2dc8d
...
...
@@ -20,79 +20,79 @@ use yii\helpers\Html;
*/
class
Dropdown
extends
Widget
{
/**
* @var array list of menu items in the dropdown. Each array element can be either an HTML string,
* or an array representing 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 "#".
* - visible: boolean, optional, whether this menu item is visible. Defaults to true.
* - linkOptions: array, optional, the HTML attributes of the item link.
* - options: array, optional, the HTML attributes of the item.
* - items: array, optional, the submenu items. The structure is the same as this property.
* Note that Bootstrap doesn't support dropdown submenu. You have to add your own CSS styles to support it.
*
* To insert divider use `<li role="presentation" class="divider"></li>`.
*/
public
$items
=
[];
/**
* @var boolean whether the labels for header items should be HTML-encoded.
*/
public
$encodeLabels
=
true
;
/**
* @var array list of menu items in the dropdown. Each array element can be either an HTML string,
* or an array representing 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 "#".
* - visible: boolean, optional, whether this menu item is visible. Defaults to true.
* - linkOptions: array, optional, the HTML attributes of the item link.
* - options: array, optional, the HTML attributes of the item.
* - items: array, optional, the submenu items. The structure is the same as this property.
* Note that Bootstrap doesn't support dropdown submenu. You have to add your own CSS styles to support it.
*
* To insert divider use `<li role="presentation" class="divider"></li>`.
*/
public
$items
=
[];
/**
* @var boolean whether the labels for header items should be HTML-encoded.
*/
public
$encodeLabels
=
true
;
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public
function
init
()
{
parent
::
init
();
Html
::
addCssClass
(
$this
->
options
,
'dropdown-menu'
);
}
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public
function
init
()
{
parent
::
init
();
Html
::
addCssClass
(
$this
->
options
,
'dropdown-menu'
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
$this
->
renderItems
(
$this
->
items
);
$this
->
registerPlugin
(
'dropdown'
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
$this
->
renderItems
(
$this
->
items
);
$this
->
registerPlugin
(
'dropdown'
);
}
/**
* Renders menu items.
* @param array
$items the menu items to be rendered
* @return string
the rendering result.
* @throws InvalidConfigException if the label option is not specified in one of the items.
*/
protected
function
renderItems
(
$items
)
{
$lines
=
[];
foreach
(
$items
as
$i
=>
$item
)
{
if
(
isset
(
$item
[
'visible'
])
&&
!
$item
[
'visible'
])
{
unset
(
$items
[
$i
]);
continue
;
}
if
(
is_string
(
$item
))
{
$lines
[]
=
$item
;
continue
;
}
if
(
!
isset
(
$item
[
'label'
]))
{
throw
new
InvalidConfigException
(
"The 'label' option is required."
);
}
$label
=
$this
->
encodeLabels
?
Html
::
encode
(
$item
[
'label'
])
:
$item
[
'label'
];
$options
=
ArrayHelper
::
getValue
(
$item
,
'options'
,
[]);
$linkOptions
=
ArrayHelper
::
getValue
(
$item
,
'linkOptions'
,
[]);
$linkOptions
[
'tabindex'
]
=
'-1'
;
$content
=
Html
::
a
(
$label
,
ArrayHelper
::
getValue
(
$item
,
'url'
,
'#'
),
$linkOptions
);
if
(
!
empty
(
$item
[
'items'
]))
{
$content
.=
$this
->
renderItems
(
$item
[
'items'
]);
Html
::
addCssClass
(
$options
,
'dropdown-submenu'
);
}
$lines
[]
=
Html
::
tag
(
'li'
,
$content
,
$options
);
}
/**
* Renders menu items.
* @param array
$items the menu items to be rendered
* @return string
the rendering result.
* @throws InvalidConfigException if the label option is not specified in one of the items.
*/
protected
function
renderItems
(
$items
)
{
$lines
=
[];
foreach
(
$items
as
$i
=>
$item
)
{
if
(
isset
(
$item
[
'visible'
])
&&
!
$item
[
'visible'
])
{
unset
(
$items
[
$i
]);
continue
;
}
if
(
is_string
(
$item
))
{
$lines
[]
=
$item
;
continue
;
}
if
(
!
isset
(
$item
[
'label'
]))
{
throw
new
InvalidConfigException
(
"The 'label' option is required."
);
}
$label
=
$this
->
encodeLabels
?
Html
::
encode
(
$item
[
'label'
])
:
$item
[
'label'
];
$options
=
ArrayHelper
::
getValue
(
$item
,
'options'
,
[]);
$linkOptions
=
ArrayHelper
::
getValue
(
$item
,
'linkOptions'
,
[]);
$linkOptions
[
'tabindex'
]
=
'-1'
;
$content
=
Html
::
a
(
$label
,
ArrayHelper
::
getValue
(
$item
,
'url'
,
'#'
),
$linkOptions
);
if
(
!
empty
(
$item
[
'items'
]))
{
$content
.=
$this
->
renderItems
(
$item
[
'items'
]);
Html
::
addCssClass
(
$options
,
'dropdown-submenu'
);
}
$lines
[]
=
Html
::
tag
(
'li'
,
$content
,
$options
);
}
return
Html
::
tag
(
'ul'
,
implode
(
"
\n
"
,
$lines
),
$this
->
options
);
}
return
Html
::
tag
(
'ul'
,
implode
(
"
\n
"
,
$lines
),
$this
->
options
);
}
}
Modal.php
View file @
5cc2dc8d
This diff is collapsed.
Click to expand it.
Nav.php
View file @
5cc2dc8d
This diff is collapsed.
Click to expand it.
NavBar.php
View file @
5cc2dc8d
...
...
@@ -39,120 +39,121 @@ use yii\helpers\Html;
*/
class
NavBar
extends
Widget
{
/**
* @var array the HTML attributes for the widget container tag. The following special options are recognized:
*
* - tag: string, defaults to "nav", the name of the container tag.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$options
=
[];
/**
* @var array the HTML attributes for the container tag. The following special options are recognized:
*
* - tag: string, defaults to "div", the name of the container tag.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$containerOptions
=
[];
/**
* @var string the text of the brand. Note that this is not HTML-encoded.
* @see http://getbootstrap.com/components/#navbar
*/
public
$brandLabel
;
/**
* @param array|string $url the URL for the brand's hyperlink tag. This parameter will be processed by [[Url::to()]]
*
and will be used for the "href" attribute of the brand link. If not set, [[\yii\web\Application::homeUrl]] will be used.
*/
public
$brandUrl
;
/**
* @var array the HTML attributes of the brand link.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$brandOptions
=
[];
/**
* @var string text to show for screen readers for the button to toggle the navbar.
*/
public
$screenReaderToggleText
=
'Toggle navigation'
;
/**
* @var boolean whether the navbar content should be included in an inner div container which by default
* adds left and right padding. Set this to false for a 100% width navbar.
*/
public
$renderInnerContainer
=
true
;
/**
* @var array the HTML attributes of the inner container.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$innerContainerOptions
=
[];
/**
* @var array the HTML attributes for the widget container tag. The following special options are recognized:
*
* - tag: string, defaults to "nav", the name of the container tag.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$options
=
[];
/**
* @var array the HTML attributes for the container tag. The following special options are recognized:
*
* - tag: string, defaults to "div", the name of the container tag.
*
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$containerOptions
=
[];
/**
* @var string the text of the brand. Note that this is not HTML-encoded.
* @see http://getbootstrap.com/components/#navbar
*/
public
$brandLabel
;
/**
* @param array|string $url the URL for the brand's hyperlink tag. This parameter will be processed by [[Url::to()]]
*
and will be used for the "href" attribute of the brand link. If not set, [[\yii\web\Application::homeUrl]] will be used.
*/
public
$brandUrl
;
/**
* @var array the HTML attributes of the brand link.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$brandOptions
=
[];
/**
* @var string text to show for screen readers for the button to toggle the navbar.
*/
public
$screenReaderToggleText
=
'Toggle navigation'
;
/**
* @var boolean whether the navbar content should be included in an inner div container which by default
* adds left and right padding. Set this to false for a 100% width navbar.
*/
public
$renderInnerContainer
=
true
;
/**
* @var array the HTML attributes of the inner container.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$innerContainerOptions
=
[];
/**
* Initializes the widget.
*/
public
function
init
()
{
parent
::
init
();
$this
->
clientOptions
=
false
;
Html
::
addCssClass
(
$this
->
options
,
'navbar'
);
if
(
$this
->
options
[
'class'
]
===
'navbar'
)
{
Html
::
addCssClass
(
$this
->
options
,
'navbar-default'
);
}
Html
::
addCssClass
(
$this
->
brandOptions
,
'navbar-brand'
);
if
(
empty
(
$this
->
options
[
'role'
]))
{
$this
->
options
[
'role'
]
=
'navigation'
;
}
$options
=
$this
->
options
;
$tag
=
ArrayHelper
::
remove
(
$options
,
'tag'
,
'nav'
);
echo
Html
::
beginTag
(
$tag
,
$options
);
if
(
$this
->
renderInnerContainer
)
{
if
(
!
isset
(
$this
->
innerContainerOptions
[
'class'
]))
{
Html
::
addCssClass
(
$this
->
innerContainerOptions
,
'container'
);
}
echo
Html
::
beginTag
(
'div'
,
$this
->
innerContainerOptions
);
}
echo
Html
::
beginTag
(
'div'
,
[
'class'
=>
'navbar-header'
]);
if
(
!
isset
(
$this
->
containerOptions
[
'id'
]))
{
$this
->
containerOptions
[
'id'
]
=
"
{
$this
->
options
[
'id'
]
}
-collapse"
;
}
echo
$this
->
renderToggleButton
();
if
(
$this
->
brandLabel
!==
null
)
{
Html
::
addCssClass
(
$this
->
brandOptions
,
'navbar-brand'
);
echo
Html
::
a
(
$this
->
brandLabel
,
$this
->
brandUrl
===
null
?
Yii
::
$app
->
homeUrl
:
$this
->
brandUrl
,
$this
->
brandOptions
);
}
echo
Html
::
endTag
(
'div'
);
Html
::
addCssClass
(
$this
->
containerOptions
,
'collapse'
);
Html
::
addCssClass
(
$this
->
containerOptions
,
'navbar-collapse'
);
$options
=
$this
->
containerOptions
;
$tag
=
ArrayHelper
::
remove
(
$options
,
'tag'
,
'div'
);
echo
Html
::
beginTag
(
$tag
,
$options
);
}
/**
* Initializes the widget.
*/
public
function
init
()
{
parent
::
init
();
$this
->
clientOptions
=
false
;
Html
::
addCssClass
(
$this
->
options
,
'navbar'
);
if
(
$this
->
options
[
'class'
]
===
'navbar'
)
{
Html
::
addCssClass
(
$this
->
options
,
'navbar-default'
);
}
Html
::
addCssClass
(
$this
->
brandOptions
,
'navbar-brand'
);
if
(
empty
(
$this
->
options
[
'role'
]))
{
$this
->
options
[
'role'
]
=
'navigation'
;
}
$options
=
$this
->
options
;
$tag
=
ArrayHelper
::
remove
(
$options
,
'tag'
,
'nav'
);
echo
Html
::
beginTag
(
$tag
,
$options
);
if
(
$this
->
renderInnerContainer
)
{
if
(
!
isset
(
$this
->
innerContainerOptions
[
'class'
]))
{
Html
::
addCssClass
(
$this
->
innerContainerOptions
,
'container'
);
}
echo
Html
::
beginTag
(
'div'
,
$this
->
innerContainerOptions
);
}
echo
Html
::
beginTag
(
'div'
,
[
'class'
=>
'navbar-header'
]);
if
(
!
isset
(
$this
->
containerOptions
[
'id'
]))
{
$this
->
containerOptions
[
'id'
]
=
"
{
$this
->
options
[
'id'
]
}
-collapse"
;
}
echo
$this
->
renderToggleButton
();
if
(
$this
->
brandLabel
!==
null
)
{
Html
::
addCssClass
(
$this
->
brandOptions
,
'navbar-brand'
);
echo
Html
::
a
(
$this
->
brandLabel
,
$this
->
brandUrl
===
null
?
Yii
::
$app
->
homeUrl
:
$this
->
brandUrl
,
$this
->
brandOptions
);
}
echo
Html
::
endTag
(
'div'
);
Html
::
addCssClass
(
$this
->
containerOptions
,
'collapse'
);
Html
::
addCssClass
(
$this
->
containerOptions
,
'navbar-collapse'
);
$options
=
$this
->
containerOptions
;
$tag
=
ArrayHelper
::
remove
(
$options
,
'tag'
,
'div'
);
echo
Html
::
beginTag
(
$tag
,
$options
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
$tag
=
ArrayHelper
::
remove
(
$this
->
containerOptions
,
'tag'
,
'div'
);
echo
Html
::
endTag
(
$tag
);
if
(
$this
->
renderInnerContainer
)
{
echo
Html
::
endTag
(
'div'
);
}
$tag
=
ArrayHelper
::
remove
(
$this
->
options
,
'tag'
,
'nav'
);
echo
Html
::
endTag
(
$tag
,
$this
->
options
);
BootstrapPluginAsset
::
register
(
$this
->
getView
());
}
/**
* Renders the widget.
*/
public
function
run
()
{
$tag
=
ArrayHelper
::
remove
(
$this
->
containerOptions
,
'tag'
,
'div'
);
echo
Html
::
endTag
(
$tag
);
if
(
$this
->
renderInnerContainer
)
{
echo
Html
::
endTag
(
'div'
);
}
$tag
=
ArrayHelper
::
remove
(
$this
->
options
,
'tag'
,
'nav'
);
echo
Html
::
endTag
(
$tag
,
$this
->
options
);
BootstrapPluginAsset
::
register
(
$this
->
getView
());
}
/**
* Renders collapsible toggle button.
* @return string the rendering toggle button.
*/
protected
function
renderToggleButton
()
{
$bar
=
Html
::
tag
(
'span'
,
''
,
[
'class'
=>
'icon-bar'
]);
$screenReader
=
"<span class=
\"
sr-only
\"
>
{
$this
->
screenReaderToggleText
}
</span>"
;
return
Html
::
button
(
"
{
$screenReader
}
\n
{
$bar
}
\n
{
$bar
}
\n
{
$bar
}
"
,
[
'class'
=>
'navbar-toggle'
,
'data-toggle'
=>
'collapse'
,
'data-target'
=>
"#
{
$this
->
containerOptions
[
'id'
]
}
"
,
]);
}
/**
* Renders collapsible toggle button.
* @return string the rendering toggle button.
*/
protected
function
renderToggleButton
()
{
$bar
=
Html
::
tag
(
'span'
,
''
,
[
'class'
=>
'icon-bar'
]);
$screenReader
=
"<span class=
\"
sr-only
\"
>
{
$this
->
screenReaderToggleText
}
</span>"
;
return
Html
::
button
(
"
{
$screenReader
}
\n
{
$bar
}
\n
{
$bar
}
\n
{
$bar
}
"
,
[
'class'
=>
'navbar-toggle'
,
'data-toggle'
=>
'collapse'
,
'data-target'
=>
"#
{
$this
->
containerOptions
[
'id'
]
}
"
,
]);
}
}
Progress.php
View file @
5cc2dc8d
...
...
@@ -59,105 +59,106 @@ use yii\helpers\Html;
*/
class
Progress
extends
Widget
{
/**
* @var string the button label.
*/
public
$label
;
/**
* @var integer the amount of progress as a percentage.
*/
public
$percent
=
0
;
/**
* @var array the HTML attributes of the bar.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$barOptions
=
[];
/**
* @var array a set of bars that are stacked together to form a single progress bar.
* Each bar is an array of the following structure:
*
* ```php
* [
* // required, the amount of progress as a percentage.
* 'percent' => 30,
* // optional, the label to be displayed on the bar
* 'label' => '30%',
* // optional, array, additional HTML attributes for the bar tag
* 'options' => [],
* ]
* ```
*/
public
$bars
;
/**
* @var string the button label.
*/
public
$label
;
/**
* @var integer the amount of progress as a percentage.
*/
public
$percent
=
0
;
/**
* @var array the HTML attributes of the bar.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$barOptions
=
[];
/**
* @var array a set of bars that are stacked together to form a single progress bar.
* Each bar is an array of the following structure:
*
* ```php
* [
* // required, the amount of progress as a percentage.
* 'percent' => 30,
* // optional, the label to be displayed on the bar
* 'label' => '30%',
* // optional, array, additional HTML attributes for the bar tag
* 'options' => [],
* ]
* ```
*/
public
$bars
;
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public
function
init
()
{
parent
::
init
();
Html
::
addCssClass
(
$this
->
options
,
'progress'
);
}
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public
function
init
()
{
parent
::
init
();
Html
::
addCssClass
(
$this
->
options
,
'progress'
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
echo
$this
->
renderProgress
()
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
BootstrapAsset
::
register
(
$this
->
getView
());
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
echo
$this
->
renderProgress
()
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
BootstrapAsset
::
register
(
$this
->
getView
());
}
/**
* Renders the progress.
* @return string the rendering result.
* @throws InvalidConfigException if the "percent" option is not set in a stacked progress bar.
*/
protected
function
renderProgress
()
{
if
(
empty
(
$this
->
bars
))
{
return
$this
->
renderBar
(
$this
->
percent
,
$this
->
label
,
$this
->
barOptions
);
}
$bars
=
[];
foreach
(
$this
->
bars
as
$bar
)
{
$label
=
ArrayHelper
::
getValue
(
$bar
,
'label'
,
''
);
if
(
!
isset
(
$bar
[
'percent'
]))
{
throw
new
InvalidConfigException
(
"The 'percent' option is required."
);
}
$options
=
ArrayHelper
::
getValue
(
$bar
,
'options'
,
[]);
$bars
[]
=
$this
->
renderBar
(
$bar
[
'percent'
],
$label
,
$options
);
}
/**
* Renders the progress.
* @return string the rendering result.
* @throws InvalidConfigException if the "percent" option is not set in a stacked progress bar.
*/
protected
function
renderProgress
()
{
if
(
empty
(
$this
->
bars
))
{
return
$this
->
renderBar
(
$this
->
percent
,
$this
->
label
,
$this
->
barOptions
);
}
$bars
=
[];
foreach
(
$this
->
bars
as
$bar
)
{
$label
=
ArrayHelper
::
getValue
(
$bar
,
'label'
,
''
);
if
(
!
isset
(
$bar
[
'percent'
]))
{
throw
new
InvalidConfigException
(
"The 'percent' option is required."
);
}
$options
=
ArrayHelper
::
getValue
(
$bar
,
'options'
,
[]);
$bars
[]
=
$this
->
renderBar
(
$bar
[
'percent'
],
$label
,
$options
);
}
return
implode
(
"
\n
"
,
$bars
);
}
return
implode
(
"
\n
"
,
$bars
);
}
/**
* Generates a bar
* @param
integer $percent the percentage of the bar
* @param string $label,
optional, the label to display at the bar
* @param array
$options the HTML attributes of the bar
* @return string
the rendering result.
*/
protected
function
renderBar
(
$percent
,
$label
=
''
,
$options
=
[])
{
$defaultOptions
=
[
'role'
=>
'progressbar'
,
'aria-valuenow'
=>
$percent
,
'aria-valuemin'
=>
0
,
'aria-valuemax'
=>
100
,
'style'
=>
"width:
{
$percent
}
%"
,
];
$options
=
array_merge
(
$defaultOptions
,
$options
);
Html
::
addCssClass
(
$options
,
'progress-bar'
);
/**
* Generates a bar
* @param
integer $percent the percentage of the bar
* @param string $label,
optional, the label to display at the bar
* @param array
$options the HTML attributes of the bar
* @return string
the rendering result.
*/
protected
function
renderBar
(
$percent
,
$label
=
''
,
$options
=
[])
{
$defaultOptions
=
[
'role'
=>
'progressbar'
,
'aria-valuenow'
=>
$percent
,
'aria-valuemin'
=>
0
,
'aria-valuemax'
=>
100
,
'style'
=>
"width:
{
$percent
}
%"
,
];
$options
=
array_merge
(
$defaultOptions
,
$options
);
Html
::
addCssClass
(
$options
,
'progress-bar'
);
$out
=
Html
::
beginTag
(
'div'
,
$options
);
$out
.=
$label
;
$out
.=
Html
::
tag
(
'span'
,
\Yii
::
t
(
'yii'
,
'{percent}% Complete'
,
[
'percent'
=>
$percent
]),
[
'class'
=>
'sr-only'
]);
$out
.=
Html
::
endTag
(
'div'
);
return
$out
;
}
$out
=
Html
::
beginTag
(
'div'
,
$options
);
$out
.=
$label
;
$out
.=
Html
::
tag
(
'span'
,
\Yii
::
t
(
'yii'
,
'{percent}% Complete'
,
[
'percent'
=>
$percent
]),
[
'class'
=>
'sr-only'
]);
$out
.=
Html
::
endTag
(
'div'
);
return
$out
;
}
}
Tabs.php
View file @
5cc2dc8d
This diff is collapsed.
Click to expand it.
Widget.php
View file @
5cc2dc8d
...
...
@@ -19,64 +19,63 @@ use yii\helpers\Json;
*/
class
Widget
extends
\yii\base\Widget
{
/**
* @var array the HTML attributes for the widget container tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$options
=
[];
/**
* @var array the options for the underlying Bootstrap JS plugin.
* Please refer to the corresponding Bootstrap plugin Web page for possible options.
* For example, [this page](http://getbootstrap.com/javascript/#modals) shows
* how to use the "Modal" plugin and the supported options (e.g. "remote").
*/
public
$clientOptions
=
[];
/**
* @var array the event handlers for the underlying Bootstrap JS plugin.
* Please refer to the corresponding Bootstrap plugin Web page for possible events.
* For example, [this page](http://getbootstrap.com/javascript/#modals) shows
* how to use the "Modal" plugin and the supported events (e.g. "shown").
*/
public
$clientEvents
=
[];
/**
* @var array the HTML attributes for the widget container tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public
$options
=
[];
/**
* @var array the options for the underlying Bootstrap JS plugin.
* Please refer to the corresponding Bootstrap plugin Web page for possible options.
* For example, [this page](http://getbootstrap.com/javascript/#modals) shows
* how to use the "Modal" plugin and the supported options (e.g. "remote").
*/
public
$clientOptions
=
[];
/**
* @var array the event handlers for the underlying Bootstrap JS plugin.
* Please refer to the corresponding Bootstrap plugin Web page for possible events.
* For example, [this page](http://getbootstrap.com/javascript/#modals) shows
* how to use the "Modal" plugin and the supported events (e.g. "shown").
*/
public
$clientEvents
=
[];
/**
* Initializes the widget.
* This method will register the bootstrap asset bundle. If you override this method,
* make sure you call the parent implementation first.
*/
public
function
init
()
{
parent
::
init
();
if
(
!
isset
(
$this
->
options
[
'id'
]))
{
$this
->
options
[
'id'
]
=
$this
->
getId
();
}
}
/**
* Initializes the widget.
* This method will register the bootstrap asset bundle. If you override this method,
* make sure you call the parent implementation first.
*/
public
function
init
()
{
parent
::
init
();
if
(
!
isset
(
$this
->
options
[
'id'
]))
{
$this
->
options
[
'id'
]
=
$this
->
getId
();
}
}
/**
* Registers a specific Bootstrap plugin and the related events
* @param string $name the name of the Bootstrap plugin
*/
protected
function
registerPlugin
(
$name
)
{
$view
=
$this
->
getView
();
/**
* Registers a specific Bootstrap plugin and the related events
* @param string $name the name of the Bootstrap plugin
*/
protected
function
registerPlugin
(
$name
)
{
$view
=
$this
->
getView
();
BootstrapPluginAsset
::
register
(
$view
);
BootstrapPluginAsset
::
register
(
$view
)
;
$id
=
$this
->
options
[
'id'
]
;
$id
=
$this
->
options
[
'id'
];
if
(
$this
->
clientOptions
!==
false
)
{
$options
=
empty
(
$this
->
clientOptions
)
?
''
:
Json
::
encode
(
$this
->
clientOptions
);
$js
=
"jQuery('#
$id
').
$name
(
$options
);"
;
$view
->
registerJs
(
$js
);
}
if
(
$this
->
clientOptions
!==
false
)
{
$options
=
empty
(
$this
->
clientOptions
)
?
''
:
Json
::
encode
(
$this
->
clientOptions
);
$js
=
"jQuery('#
$id
').
$name
(
$options
);"
;
$view
->
registerJs
(
$js
);
}
if
(
!
empty
(
$this
->
clientEvents
))
{
$js
=
[];
foreach
(
$this
->
clientEvents
as
$event
=>
$handler
)
{
$js
[]
=
"jQuery('#
$id
').on('
$event
',
$handler
);"
;
}
$view
->
registerJs
(
implode
(
"
\n
"
,
$js
));
}
}
if
(
!
empty
(
$this
->
clientEvents
))
{
$js
=
[];
foreach
(
$this
->
clientEvents
as
$event
=>
$handler
)
{
$js
[]
=
"jQuery('#
$id
').on('
$event
',
$handler
);"
;
}
$view
->
registerJs
(
implode
(
"
\n
"
,
$js
));
}
}
}
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