/**
* Add javascript support for Bootstrap carousels
*
* @param string $selector Common class for the carousels.
* @param array $params An array of options for the carousel.
*
* @return void
*
* @throws \Exception
*
* @since 3.0
*
* Options for the carousel can be:
* - interval number 5000 The amount of time to delay between automatically cycling an item.
* If false, carousel will not automatically cycle.
* - keyboard boolean true Whether the carousel should react to keyboard events.
* - pause string| hover Pauses the cycling of the carousel on mouseenter and resumes the cycling
* boolean of the carousel on mouseleave.
* - slide string| false Autoplays the carousel after the user manually cycles the first item.
* boolean If "carousel", autoplays the carousel on load.
*/
public static function carousel($selector = '', $params = []) : void
{
// Only load once
if (!empty(static::$loaded[__METHOD__][$selector])) {
return;
}
if ($selector !== '') {
// Setup options object
$opt['interval'] = isset($params['interval']) ? (int) $params['interval'] : 5000;
$opt['keyboard'] = isset($params['keyboard']) ? (bool) $params['keyboard'] : true;
$opt['pause'] = isset($params['pause']) ? $params['pause'] : 'hover';
$opt['slide'] = isset($params['slide']) ? (bool) $params['slide'] : false;
$opt['wrap'] = isset($params['wrap']) ? (bool) $params['wrap'] : true;
$opt['touch'] = isset($params['touch']) ? (bool) $params['touch'] : true;
Factory::getDocument()->addScriptOptions('bootstrap.carousel', [$selector => (object) array_filter((array) $opt)]);
}
// Include the Bootstrap component
Factory::getApplication()->getDocument()->getWebAssetManager()->useScript('bootstrap.carousel');
static::$loaded[__METHOD__][$selector] = true;
}