Commit d42cfd6f by Antonio Ramirez

some other fixes

parent 3ca4de8f
...@@ -21,12 +21,12 @@ use yii\helpers\Html; ...@@ -21,12 +21,12 @@ use yii\helpers\Html;
* ```php * ```php
* echo Carousel::widget(array( * echo Carousel::widget(array(
* 'items' => array( * 'items' => array(
* 'http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-01.jpg', * '<img src="http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-01.jpg"/>',
* array( * array(
* 'content' => 'http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-02.jpg', * 'content' => '<img src="http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-02.jpg"/>',
* ), * ),
* array( * array(
* 'content' => 'http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-03.jpg', * 'content' => '<img src="http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-03.jpg"/>',
* 'options' => array(...) * 'options' => array(...)
* 'caption' => '<h4>This is title</h5><p>This is the caption text</p>' * 'caption' => '<h4>This is title</h5><p>This is the caption text</p>'
* ), * ),
...@@ -114,7 +114,7 @@ class Carousel extends Widget ...@@ -114,7 +114,7 @@ class Carousel extends Widget
ob_start(); ob_start();
echo Html::beginTag('div', array('class' => 'carousel-inner')) . "\n"; echo Html::beginTag('div', array('class' => 'carousel-inner')) . "\n";
for ($i = 0, $ln = count($this->items); $i < $ln; $i++) { for ($i = 0, $ln = count($this->items); $i < $ln; $i++) {
echo $this->renderItem($this->items[$i], $i); $this->renderItem($this->items[$i], $i);
} }
echo Html::endTag('div') . "\n"; echo Html::endTag('div') . "\n";
return ob_get_clean(); return ob_get_clean();
...@@ -127,22 +127,27 @@ class Carousel extends Widget ...@@ -127,22 +127,27 @@ class Carousel extends Widget
*/ */
public function renderItem($item, $index) public function renderItem($item, $index)
{ {
$itemOptions = ArrayHelper::getValue($item, 'options', array()); if (is_string($item)) {
$itemOptions = array();
$itemContent = $item;
$itemCaption = '';
} else {
$itemOptions = ArrayHelper::getValue($item, 'options', array());
$itemContent = $item['content']; // if not string, must be array, force required key
$itemCaption = ArrayHelper::getValue($item, 'caption');
if ($itemCaption) {
$itemCaption = Html::tag('div', $itemCaption, array('class' => 'carousel-caption'));
}
}
$this->addCssClass($itemOptions, 'item'); $this->addCssClass($itemOptions, 'item');
if ($index === 0) { if ($index === 0) {
$this->addCssClass($itemOptions, 'active'); $this->addCssClass($itemOptions, 'active');
} }
echo Html::beginTag('div', $itemOptions) . "\n"; echo Html::beginTag('div', $itemOptions) . "\n";
echo is_string($item) echo $itemContent . "\n";
? $item echo $itemCaption . "\n";
: $item['content']; // if not string, must be array, force required key
if (ArrayHelper::getValue($item, 'caption')) {
echo ArrayHelper::getValue($item, 'caption');
}
echo Html::endTag('div') . "\n"; echo Html::endTag('div') . "\n";
} }
/** /**
...@@ -150,7 +155,7 @@ class Carousel extends Widget ...@@ -150,7 +155,7 @@ class Carousel extends Widget
*/ */
public function renderPreviousAndNext() public function renderPreviousAndNext()
{ {
if ($this->controls === false) { if ($this->controls === false || !(isset($this->controls['left']) && isset($this->controls['left']))) {
return; return;
} }
echo Html::a($this->controls['left'], '#' . $this->options['id'], array( echo Html::a($this->controls['left'], '#' . $this->options['id'], array(
...@@ -161,7 +166,6 @@ class Carousel extends Widget ...@@ -161,7 +166,6 @@ class Carousel extends Widget
Html::a($this->controls['right'], '#' . $this->options['id'], array( Html::a($this->controls['right'], '#' . $this->options['id'], array(
'class' => 'right carousel-control', 'class' => 'right carousel-control',
'data-slide' => 'next' 'data-slide' => 'next'
)) . ));
"\n";
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment