/**
* Add javascript support for Bootstrap toasts
*
* @param string $selector Common class for the toasts
* @param array $options Options for the toasts
*
* @return void
*
* @throws \Exception
*
* @since 4.0.0
*/
public static function toast($selector = '', $options = []) : void
{
// Only load once
if (!empty(static::$loaded[__METHOD__][$selector])) {
return;
}
if ($selector !== '') {
// Setup options object
$opt['animation'] = isset($options['animation']) ? (string) $options['animation'] : null;
$opt['autohide'] = isset($options['autohide']) ? (bool) $options['autohide'] : true;
$opt['delay'] = isset($options['delay']) ? (int) $options['delay'] : 5000;
Factory::getDocument()->addScriptOptions('bootstrap.toast', [$selector => (object) array_filter((array) $opt)]);
}
// Include the Bootstrap component
Factory::getApplication()->getDocument()->getWebAssetManager()->useScript('bootstrap.toast');
static::$loaded[__METHOD__][$selector] = true;
}