public function carousel()
{
css('.carousel { max-width: 870px; }');
return _class('html')->carousel([
[
'img' => '//twbs.github.io/bootstrap/2.3.2/assets/img/bootstrap-mdo-sfmoma-01.jpg',
'desc' => '<h4>First Thumbnail label</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>',
],
[
'img' => '//twbs.github.io/bootstrap/2.3.2/assets/img/bootstrap-mdo-sfmoma-02.jpg',
'desc' => '<h4>Second Thumbnail label</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>',
],
[
'img' => '//twbs.github.io/bootstrap/2.3.2/assets/img/bootstrap-mdo-sfmoma-03.jpg',
'desc' => '<h4>Third Thumbnail label</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>',
],
'//twbs.github.io/bootstrap/2.3.2/assets/img/bootstrap-mdo-sfmoma-01.jpg',
'//twbs.github.io/bootstrap/2.3.2/assets/img/bootstrap-mdo-sfmoma-02.jpg',
'//twbs.github.io/bootstrap/2.3.2/assets/img/bootstrap-mdo-sfmoma-03.jpg',
]);
}
public function carousel($data = [], $extra = [])
{
$extra['id'] = $extra['id'] ?: __FUNCTION__ . '_' . ++$this->_ids[__FUNCTION__];
$items = [];
$headers = [];
foreach ((array) $data as $k => $v) {
if ( ! is_array($v)) {
$img_src = $v;
$v = [];
} else {
$img_src = $v['img'];
}
$desc = $v['desc'];
$alt = $v['alt'] ?: strip_tags($desc);
$id = $v['id'] ?: 'carousel_item_' . $k;
if (isset($extra['selected'])) {
$is_active = ($extra['selected'] == $k);
} else {
$is_active = (++$i == 1);
}
$class_head = $v['class_head'] ?: $extra['class_head'];
$class_body = $v['class_body'] ?: $extra['class_body'];
$headers[] = '<li data-target="#' . $extra['id'] . '" data-slide-to="' . ($i - 1) . '" class="' . ($is_active ? 'active' : '') . ($class_head ? ' ' . $class_head : '') . '"></li>';
$items[] =
'<div class="item' . ($is_active ? ' active' : '') . ($class_body ? ' ' . $class_body : '') . '">
<img src="' . $img_src . '" alt="' . $alt . '">
' . ($desc ? '<div class="carousel-caption">' . $desc . '</div>' : '') . '
</div>';
}
$controls = '
<a class="left carousel-control" href="#' . $extra['id'] . '" data-slide="prev"><span class="icon icon-chevron-left fa fa-chevron-left"></span></a>
<a class="right carousel-control" href="#' . $extra['id'] . '" data-slide="next"><span class="icon icon-chevron-right fa fa-chevron-right"></span></a>
';
return '<div id="' . $extra['id'] . '" class="carousel slide' . ($extra['class'] ? ' ' . $extra['class'] : '') . '" data-ride="carousel">
<ol class="carousel-indicators">' . implode(PHP_EOL, $headers) . '</ol>
<div class="carousel-inner">' . implode(PHP_EOL, $items) . '</div>
' . ( ! $extra['no_controls'] ? $controls : '') . '
</div>';
}