From d42cfd6ff15821846f357f9f284c9e63290b3bdc Mon Sep 17 00:00:00 2001 From: Antonio Ramirez Date: Wed, 22 May 2013 22:53:57 +0200 Subject: [PATCH] some other fixes --- framework/yii/bootstrap/Carousel.php | 38 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/framework/yii/bootstrap/Carousel.php b/framework/yii/bootstrap/Carousel.php index 0b9fb2d..21fc5ff 100644 --- a/framework/yii/bootstrap/Carousel.php +++ b/framework/yii/bootstrap/Carousel.php @@ -21,12 +21,12 @@ use yii\helpers\Html; * ```php * echo Carousel::widget(array( * 'items' => array( - * 'http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-01.jpg', + * '', * array( - * 'content' => 'http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-02.jpg', + * 'content' => '', * ), * array( - * 'content' => 'http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-03.jpg', + * 'content' => '', * 'options' => array(...) * 'caption' => '

This is title

This is the caption text

' * ), @@ -114,7 +114,7 @@ class Carousel extends Widget 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); + $this->renderItem($this->items[$i], $i); } echo Html::endTag('div') . "\n"; return ob_get_clean(); @@ -127,22 +127,27 @@ class Carousel extends Widget */ 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'); if ($index === 0) { $this->addCssClass($itemOptions, 'active'); } echo Html::beginTag('div', $itemOptions) . "\n"; - echo is_string($item) - ? $item - : $item['content']; // if not string, must be array, force required key - - if (ArrayHelper::getValue($item, 'caption')) { - echo ArrayHelper::getValue($item, 'caption'); - } - + echo $itemContent . "\n"; + echo $itemCaption . "\n"; echo Html::endTag('div') . "\n"; - } /** @@ -150,7 +155,7 @@ class Carousel extends Widget */ public function renderPreviousAndNext() { - if ($this->controls === false) { + if ($this->controls === false || !(isset($this->controls['left']) && isset($this->controls['left']))) { return; } echo Html::a($this->controls['left'], '#' . $this->options['id'], array( @@ -161,7 +166,6 @@ class Carousel extends Widget Html::a($this->controls['right'], '#' . $this->options['id'], array( 'class' => 'right carousel-control', 'data-slide' => 'next' - )) . - "\n"; + )); } } \ No newline at end of file