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