/**
* Add javascript support for Bootstrap alerts
*
* @param string $selector Common class for the alerts
*
* @return void
*
* @throws \Exception
*
* @since 3.0
*/
public static function alert($selector = '') : void
{
// Only load once
if (!empty(static::$loaded[__METHOD__][$selector])) {
return;
}
$doc = Factory::getDocument();
if ($selector !== '') {
$scriptOptions = $doc->getScriptOptions('bootstrap.alert');
$options = [$selector];
if (is_array($scriptOptions)) {
$options = array_merge($scriptOptions, $options);
}
$doc->addScriptOptions('bootstrap.alert', $options, false);
}
// Include the Bootstrap component
Factory::getApplication()->getDocument()->getWebAssetManager()->useScript('bootstrap.alert');
static::$loaded[__METHOD__][$selector] = true;
}