From 592069176efb5c6df233feb4ed4910ebe08390d7 Mon Sep 17 00:00:00 2001 From: iteidrm <107106957+iteidrm@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:38:45 +0100 Subject: [PATCH 1/6] Remove the re-setting of the options Remove the re-setting of the options, as it is already done in the PHP helper as well as in the bootstrap library itself. --- .../vendor/bootstrap/js/carousel.es6.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/build/media_source/vendor/bootstrap/js/carousel.es6.js b/build/media_source/vendor/bootstrap/js/carousel.es6.js index b1b521cb1c6b5..b54b950ec6b02 100644 --- a/build/media_source/vendor/bootstrap/js/carousel.es6.js +++ b/build/media_source/vendor/bootstrap/js/carousel.es6.js @@ -4,21 +4,12 @@ window.bootstrap = window.bootstrap || {}; window.bootstrap.Carousel = Carousel; if (Joomla && Joomla.getOptions) { - // Get the elements/configurations from the PHP + // Get the elements configuration from PHP const carousels = Joomla.getOptions('bootstrap.carousel'); - // Initialise the elements + if (typeof carousels === 'object' && carousels !== null) { Object.keys(carousels).forEach((carousel) => { - const opt = carousels[carousel]; - const options = { - interval: opt.interval ? opt.interval : 5000, - keyboard: opt.keyboard ? opt.keyboard : true, - pause: opt.pause ? opt.pause : 'hover', - slide: opt.slide ? opt.slide : false, - wrap: opt.wrap ? opt.wrap : true, - touch: opt.touch ? opt.touch : true, - }; - + const options = carousels[carousel]; const elements = Array.from(document.querySelectorAll(carousel)); if (elements.length) { elements.map((el) => new window.bootstrap.Carousel(el, options)); From 5b54f9eb0b7a120780af0791250d02803abaf586 Mon Sep 17 00:00:00 2001 From: iteidrm <107106957+iteidrm@users.noreply.github.com> Date: Tue, 19 Nov 2024 14:07:50 +0100 Subject: [PATCH 2/6] Refactor parameter handling to fix unwanted filtering Refactor parameter handling to fix unwanted filtering of valid options. --- libraries/src/HTML/Helpers/Bootstrap.php | 65 +++++++++++++++++------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/libraries/src/HTML/Helpers/Bootstrap.php b/libraries/src/HTML/Helpers/Bootstrap.php index fefae6dec6ade..665b4c1f4f8c7 100644 --- a/libraries/src/HTML/Helpers/Bootstrap.php +++ b/libraries/src/HTML/Helpers/Bootstrap.php @@ -125,35 +125,66 @@ public static function button($selector = ''): void * * 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. + * - pause string| hover If set to "hover", pauses the cycling of the carousel on mouseenter and resumes the + * boolean cycling of the carousel on mouseleave. If set to false, hovering over the carousel won’t + * pause it. On touch-enabled devices, when set to "hover", cycling will pause on touchend + * (once the user finished interacting with the carousel) for two intervals, before + * automatically resuming. This is in addition to the mouse behavior. + * - ride string| false If set to true, autoplays the carousel after the user manually cycles the first item. If set + * boolean to "carousel", autoplays the carousel on load. + * - touch boolean true Whether the carousel should support left/right swipe interactions on touchscreen devices. + * - wrap boolean true Whether the carousel should cycle continuously or have hard stops. */ public static function carousel($selector = '', $params = []): void { - // Only load once if (!empty(static::$loaded[__METHOD__][$selector])) { return; } if ($selector !== '') { - // Setup options object - $opt = [ - 'interval' => (int) ($params['interval'] ?? 5000), - 'keyboard' => (bool) ($params['keyboard'] ?? true), - 'pause' => $params['pause'] ?? 'hover', - 'slide' => (bool) ($params['slide'] ?? false), - 'wrap' => (bool) ($params['wrap'] ?? true), - 'touch' => (bool) ($params['touch'] ?? true), - ]; + $opt['interval'] = 5000; + + if (isset($params['interval']) && \is_numeric($params['interval'])) { + $opt['interval'] = (int) $params['interval']; + } + + $opt['keyboard'] = true; + + if (isset($params['keyboard']) && \is_bool($params['keyboard'])) { + $opt['keyboard'] = $params['keyboard']; + } + + $opt['pause'] = 'hover'; + + if (isset($params['pause']) && \in_array($params['pause'], ['hover', false], true)) { + $opt['pause'] = $params['pause']; + } + + $opt['ride'] = false; + + if (isset($params['ride']) && \in_array($params['ride'], ['carousel', false], true)) { + $opt['ride'] = $params['ride']; + } + + $opt['touch'] = true; - Factory::getDocument()->addScriptOptions('bootstrap.carousel', [$selector => (object) array_filter($opt)]); + if (isset(touch['touch']) && \is_bool($params['touch'])) { + $opt['touch'] = $params['touch']; + } + + $opt['wrap'] = true; + + if (isset($params['wrap']) && \is_bool($params['wrap'])) { + $opt['wrap'] = $params['wrap']; + } + + Factory::getApplication()->getDocument()->addScriptOptions( + 'bootstrap.carousel', + [$selector => (object) $opt] + ); } - // Include the Bootstrap component Factory::getApplication() ->getDocument() ->getWebAssetManager() From f21beb0b8c11cafef2d09cf34d2946fe128069ed Mon Sep 17 00:00:00 2001 From: iteidrm <107106957+iteidrm@users.noreply.github.com> Date: Wed, 20 Nov 2024 09:26:17 +0100 Subject: [PATCH 3/6] Fix typo --- libraries/src/HTML/Helpers/Bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/HTML/Helpers/Bootstrap.php b/libraries/src/HTML/Helpers/Bootstrap.php index 665b4c1f4f8c7..00247ae2d5394 100644 --- a/libraries/src/HTML/Helpers/Bootstrap.php +++ b/libraries/src/HTML/Helpers/Bootstrap.php @@ -169,7 +169,7 @@ public static function carousel($selector = '', $params = []): void $opt['touch'] = true; - if (isset(touch['touch']) && \is_bool($params['touch'])) { + if (isset($params['touch']) && \is_bool($params['touch'])) { $opt['touch'] = $params['touch']; } From 38654f89b7379b456bb2700518ef1b187d88e8c5 Mon Sep 17 00:00:00 2001 From: iteidrm <107106957+iteidrm@users.noreply.github.com> Date: Wed, 20 Nov 2024 09:48:03 +0100 Subject: [PATCH 4/6] Add missing parameter to ride option The ride option can not only be set to "false" or "carousel" but also to "true". --- libraries/src/HTML/Helpers/Bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/HTML/Helpers/Bootstrap.php b/libraries/src/HTML/Helpers/Bootstrap.php index 00247ae2d5394..285a0c5d03a18 100644 --- a/libraries/src/HTML/Helpers/Bootstrap.php +++ b/libraries/src/HTML/Helpers/Bootstrap.php @@ -163,7 +163,7 @@ public static function carousel($selector = '', $params = []): void $opt['ride'] = false; - if (isset($params['ride']) && \in_array($params['ride'], ['carousel', false], true)) { + if (isset($params['ride']) && \in_array($params['ride'], ['carousel', true, false], true)) { $opt['ride'] = $params['ride']; } From d6fe622043c10608525a76f524f744cefe07b862 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Wed, 20 Nov 2024 14:42:50 +0100 Subject: [PATCH 5/6] Fix PHPCS --- libraries/src/HTML/Helpers/Bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/HTML/Helpers/Bootstrap.php b/libraries/src/HTML/Helpers/Bootstrap.php index 285a0c5d03a18..c3078b6e77731 100644 --- a/libraries/src/HTML/Helpers/Bootstrap.php +++ b/libraries/src/HTML/Helpers/Bootstrap.php @@ -145,7 +145,7 @@ public static function carousel($selector = '', $params = []): void if ($selector !== '') { $opt['interval'] = 5000; - if (isset($params['interval']) && \is_numeric($params['interval'])) { + if (isset($params['interval']) && is_numeric($params['interval'])) { $opt['interval'] = (int) $params['interval']; } From bfca2683f22ba6ec9c6818fe9886da4dcfd848dd Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Fri, 17 Jan 2025 20:10:31 +0100 Subject: [PATCH 6/6] Codestyle --- build/media_source/vendor/bootstrap/js/carousel.es6.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/media_source/vendor/bootstrap/js/carousel.es6.js b/build/media_source/vendor/bootstrap/js/carousel.es6.js index b54b950ec6b02..53e7523ee3d48 100644 --- a/build/media_source/vendor/bootstrap/js/carousel.es6.js +++ b/build/media_source/vendor/bootstrap/js/carousel.es6.js @@ -6,7 +6,7 @@ window.bootstrap.Carousel = Carousel; if (Joomla && Joomla.getOptions) { // Get the elements configuration from PHP const carousels = Joomla.getOptions('bootstrap.carousel'); - + if (typeof carousels === 'object' && carousels !== null) { Object.keys(carousels).forEach((carousel) => { const options = carousels[carousel];