/**
* Add javascript support for Bootstrap accordions and insert the accordion
*
* @param string $selector The ID selector for the tooltip. Expects a valid ID without the #!
* @param array $options An array of options for the tooltip.
*
* @return string HTML for the accordion
*
* @since 3.0
*
* Options for the tooltip can be:
* - parent selector If selector then all collapsible elements under the specified parent will be closed when this
* collapsible item is shown. (similar to traditional accordion behavior)
* - toggle boolean Toggles the collapsible element on invocation
* - active string Sets the active slide during load
*/
public static function startAccordion($selector = 'myAccordian', $options = []) : string
{
// Only load once
if (isset(static::$loaded[__METHOD__][$selector])) {
return '';
}
// Include Bootstrap component
Factory::getApplication()->getDocument()->getWebAssetManager()->useScript('bootstrap.collapse');
// Setup options object
$opt['parent'] = isset($options['parent']) ? $options['parent'] == true ? '#' . preg_replace('/^[\\.#]/', '', $selector) : $options['parent'] : '';
$opt['toggle'] = isset($options['toggle']) ? (bool) $options['toggle'] : !($opt['parent'] === false || isset($options['active']));
$opt['active'] = isset($options['active']) ? (string) $options['active'] : '';
// Initialise with the Joomla specifics
$opt['isJoomla'] = true;
Factory::getDocument()->addScriptOptions('bootstrap.accordion', ['#' . preg_replace('/^[\\.#]/', '', $selector) => (object) array_filter((array) $opt)]);
static::$loaded[__METHOD__][$selector] = $opt;
return '<div id="' . $selector . '" class="accordion" role="tablist">';
}