/**
* Add javascript support for Bootstrap collapse
*
* @param string $selector Common class for the collapse
* @param string[] $params Additional parameters - see below
*
* @return void
*
* @throws \Exception
*
* @since 4.0.0
*
* Options for the collapse can be:
* - parent string false If parent is provided, then all collapsible elements under the specified parent will
* be closed when this collapsible item is shown.
* - toggle boolean true Toggles the collapsible element on invocation
*/
public static function collapse($selector = '', $params = []) : void
{
// Only load once
if (!empty(static::$loaded[__METHOD__][$selector])) {
return;
}
if ($selector !== '') {
// Setup options object
$opt = [];
$opt['parent'] = isset($params['parent']) ? $params['parent'] : false;
$opt['toggle'] = isset($params['toggle']) ? (bool) $params['toggle'] : true;
Factory::getDocument()->addScriptOptions('bootstrap.collapse', [$selector => (object) array_filter((array) $opt)]);
}
// Include the Bootstrap component
Factory::getApplication()->getDocument()->getWebAssetManager()->useScript('bootstrap.collapse');
static::$loaded[__METHOD__][$selector] = true;
}