public function accordion()
{
$data = [
'first' => [
'body' => 'first accordion item body<br />' . PHP_EOL . 'first accordion item body',
'class_group' => 'panel-info',
'class_head' => 'alert-info',
],
'second' => [
'body' => 'second accordion item body<br />' . PHP_EOL . 'second accordion item body',
'class_group' => 'panel-danger',
'class_head' => 'alert-error',
],
'third' => 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch.
Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et.
Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo.
Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably havent heard of them accusamus labore sustainable VHS.',
'fourth' => '44444 accordion item body<br />' . PHP_EOL . 'second accordion item body',
];
return _class('html')->accordion($data, ['selected' => 'third', 'class' => 'span4 col-md-4']);
}
public function accordion($data = [], $extra = [])
{
$extra['id'] = $extra['id'] ?: __FUNCTION__ . '_' . ++$this->_ids[__FUNCTION__];
$items = [];
foreach ((array) $data as $k => $v) {
if ( ! is_array($v)) {
$content = $v;
$v = [];
} else {
$content = $v['body'];
}
$name = $v['name'] ?: $k;
$desc = $v['desc'] ?: ucfirst(str_replace('_', ' ', $name));
$id = $v['id'] ?: 'accordion_item_' . $k;
if (isset($extra['selected'])) {
$is_selected = ($extra['selected'] == $k);
} else {
$is_selected = (++$i == 1);
}
$class_group = $v['class_group'] ?: $extra['class_group'];
$class_head = $v['class_head'] ?: $extra['class_head'];
$class_body = $v['class_body'] ?: $extra['class_body'];
$badge = $v['badge'] ? ' <sup class="badge badge-' . ($v['class_badge'] ?: 'info') . '">' . $v['badge'] . '</sup>' : '';
$items[] =
'<div class="accordion-group panel panel-default' . ($class_group ? ' ' . $class_group : '') . '">
<div class="accordion-heading panel-heading' . ($class_head ? ' ' . $class_head : '') . '">
' . ($this->_is_bs3 ? '<h4 class="panel-title">' : '') . '
<a class="accordion-toggle" data-toggle="collapse" data-parent="#' . $extra['id'] . '" href="#' . $id . '">' . $desc . $badge . '</a>
' . ($this->_is_bs3 ? '</h4>' : '') . '
</div>
<div id="' . $id . '" class="accordion-body panel-collapse collapse' . ($is_selected ? ' in' : '') . ($class_body ? ' ' . $class_body : '') . '">
<div class="accordion-inner panel-body">' . $content . '</div>
</div>
</div>';
}
return '<div class="panel-group accordion' . ($extra['class'] ? ' ' . $extra['class'] : '') . '" id="' . $extra['id'] . '">' . implode(PHP_EOL, (array) $items) . '</div>';
}