Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
e1a3ae65
Commit
e1a3ae65
authored
May 22, 2013
by
Antonio Ramirez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored and apply suggested changes
parent
5783d3a1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
64 deletions
+29
-64
Carousel.php
framework/yii/bootstrap/Carousel.php
+29
-64
No files found.
framework/yii/bootstrap/Carousel.php
View file @
e1a3ae65
...
...
@@ -21,13 +21,14 @@ use yii\helpers\Html;
* ```php
* echo Carousel::widget(array(
* 'items' => array(
* 'http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-01.jpg',
* array(
* '
src' => 'http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-01
.jpg',
* '
content' => 'http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-02
.jpg',
* ),
* array(
* '
src' => 'http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-02
.jpg',
* '
captionLabel' => 'This is the caption label',
* 'caption
Text' => 'This is the caption text
'
* '
content' => 'http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-03
.jpg',
* '
options' => array(...)
* 'caption
' => '<h4>This is title</h5><p>This is the caption text</p>
'
* ),
* )
* ));
...
...
@@ -40,21 +41,10 @@ use yii\helpers\Html;
class
Carousel
extends
Widget
{
/**
* @var string the previous button label. Defaults to '‹'.
* @var array indicates what labels should be displayed on next and previous carousel controls. If [[controls]] is
* set to `false` or they do not hold `left` and `right` keys, the controls will not be displayed.
*/
public
$previousLabel
=
'‹'
;
/**
* @var string the next button label. Defaults to '›'.
*/
public
$nextLabel
=
'›'
;
/**
* @var boolean indicates whether the carousel should slide items.
*/
public
$slide
=
true
;
/**
* @var boolean indicates whether to display the previous and next links.
*/
public
$displayPreviousAndNext
=
true
;
public
$controls
=
array
(
'left'
=>
'‹'
,
'right'
=>
'›'
);
/**
* @var array list of images to appear in the carousel. If this property is empty,
* the widget will not render anything. Each array element represents a single image in the carousel
...
...
@@ -62,13 +52,9 @@ class Carousel extends Widget
*
* ```php
* array(
* '
src
' => 'src of the image', // required
* '
content
' => 'src of the image', // required
* 'options' => ['html attributes of the item'], // optional
* 'imageOptions'=> ['html attributes of the image'] // optional
* 'captionLabel' => 'Title of the caption', // optional
* 'captionOptions' => ['html attributes of the caption'], // optional
* 'captionText' => 'Caption text, long description', // optional
* 'visible' => 'boolean', // optional, whether to display the item or not
* 'caption'=> ['html attributes of the image'] // optional
* )
* ```
*/
...
...
@@ -81,8 +67,7 @@ class Carousel extends Widget
public
function
init
()
{
parent
::
init
();
$this
->
getView
()
->
registerAssetBundle
(
'yii/bootstrap/carousel'
);
$this
->
initOptions
();
$this
->
addCssClass
(
$this
->
options
,
'carousel'
);
}
/**
...
...
@@ -95,10 +80,12 @@ class Carousel extends Widget
}
echo
Html
::
beginTag
(
'div'
,
$this
->
options
)
.
"
\n
"
;
$this
->
renderIndicators
()
.
"
\n
"
;
$this
->
renderItems
()
.
"
\n
"
;
$this
->
renderPreviousAndNext
()
.
"
\n
"
;
echo
$this
->
renderIndicators
()
.
"
\n
"
;
echo
$this
->
renderItems
()
.
"
\n
"
;
echo
$this
->
renderPreviousAndNext
()
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
$this
->
registerPlugin
(
'carousel'
);
}
/**
...
...
@@ -106,6 +93,7 @@ class Carousel extends Widget
*/
public
function
renderIndicators
()
{
ob_start
();
echo
Html
::
beginTag
(
'ol'
,
array
(
'class'
=>
'carousel-indicators'
))
.
"
\n
"
;
for
(
$i
=
0
,
$ln
=
count
(
$this
->
items
);
$i
<
$ln
;
$i
++
)
{
$options
=
array
(
'data-target'
=>
'#'
.
$this
->
options
[
'id'
],
'data-slide-to'
=>
$i
);
...
...
@@ -115,6 +103,7 @@ class Carousel extends Widget
echo
Html
::
tag
(
'li'
,
''
,
$options
)
.
"
\n
"
;
}
echo
Html
::
endTag
(
'ol'
)
.
"
\n
"
;
return
ob_get_clean
();
}
/**
...
...
@@ -122,16 +111,18 @@ class Carousel extends Widget
*/
public
function
renderItems
()
{
ob_start
();
echo
Html
::
beginTag
(
'div'
,
array
(
'class'
=>
'carousel-inner'
))
.
"
\n
"
;
for
(
$i
=
0
,
$ln
=
count
(
$this
->
items
);
$i
<
$ln
;
$i
++
)
{
echo
$this
->
renderItem
(
$this
->
items
[
$i
],
$i
);
}
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
return
ob_get_clean
();
}
/**
* Renders a single carousel item
* @param
array
$item a single item from [[items]]
* @param
mixed
$item a single item from [[items]]
* @param integer $index the item index as the first item should be set to `active`
*/
public
function
renderItem
(
$item
,
$index
)
...
...
@@ -142,10 +133,12 @@ class Carousel extends Widget
$this
->
addCssClass
(
$itemOptions
,
'active'
);
}
echo
Html
::
beginTag
(
'div'
,
$itemOptions
)
.
"
\n
"
;
echo
Html
::
img
(
$item
[
'src'
],
ArrayHelper
::
getValue
(
$item
,
'imageOptions'
,
array
()))
.
"
\n
"
;
echo
is_string
(
$item
)
?
$item
:
$item
[
'content'
];
// if not string, must be array, force required key
if
(
ArrayHelper
::
getValue
(
$item
,
'caption
Label
'
))
{
$this
->
renderCaptioN
(
$item
);
if
(
ArrayHelper
::
getValue
(
$item
,
'caption'
))
{
echo
ArrayHelper
::
getValue
(
$item
,
'caption'
);
}
echo
Html
::
endTag
(
'div'
)
.
"
\n
"
;
...
...
@@ -153,49 +146,22 @@ class Carousel extends Widget
}
/**
* Renders the caption of an item
* @param array $item a single item from [[items]]
*/
public
function
renderCaption
(
$item
)
{
$captionOptions
=
ArrayHelper
::
getValue
(
$item
,
'captionOptions'
,
array
());
$this
->
addCssClass
(
$captionOptions
,
'carousel-caption'
);
echo
Html
::
beginTag
(
'div'
,
$captionOptions
)
.
"
\n
"
;
echo
Html
::
tag
(
'h4'
,
ArrayHelper
::
getValue
(
$item
,
'captionLabel'
))
.
"
\n
"
;
echo
Html
::
tag
(
'p'
,
ArrayHelper
::
getValue
(
$item
,
'captionText'
,
''
))
.
"
\n
"
;
echo
Html
::
endTag
(
'div'
);
}
/**
* Renders previous and next button if [[displayPreviousAndNext]] is set to `true`
*/
public
function
renderPreviousAndNext
()
{
if
(
!
$this
->
displayPreviousAndNext
)
{
if
(
$this
->
controls
===
false
)
{
return
;
}
echo
Html
::
a
(
$this
->
previousLabel
,
'#'
.
$this
->
options
[
'id'
],
array
(
echo
Html
::
a
(
$this
->
controls
[
'left'
]
,
'#'
.
$this
->
options
[
'id'
],
array
(
'class'
=>
'left carousel-control'
,
'data-slide'
=>
'prev'
))
.
"
\n
"
.
Html
::
a
(
$this
->
nextLabel
,
'#'
.
$this
->
options
[
'id'
],
array
(
Html
::
a
(
$this
->
controls
[
'right'
]
,
'#'
.
$this
->
options
[
'id'
],
array
(
'class'
=>
'right carousel-control'
,
'data-slide'
=>
'next'
))
.
"
\n
"
;
}
/**
* Initializes the widget options.
* This method sets the default values for various options.
*/
public
function
initOptions
()
{
$this
->
addCssClass
(
$this
->
options
,
'carousel'
);
if
(
$this
->
slide
)
{
$this
->
addCssClass
(
$this
->
options
,
'slide'
);
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment