Skip to content
Snippets Groups Projects
Commit febe38ed authored by Florent Torregrosa's avatar Florent Torregrosa
Browse files

Issue #3484065 by grimreaper, pdureau: Carousel item: only add active on the first item.

parent 5389500a
No related branches found
No related tags found
1 merge request!230Issue #3484746 by grimreaper, pdureau: Use "is sequence" Twig test to prevent...
((Drupal, once) => {
Drupal.ui_suite_bootstrap_carousel =
Drupal.ui_suite_bootstrap_carousel || {};
Drupal.ui_suite_bootstrap_carousel = Drupal.ui_suite_bootstrap_carousel || {};
/**
* Set active class.
* Set active class on the first item.
*
* @type {Drupal~behavior}
*
......@@ -12,31 +11,14 @@
*/
Drupal.behaviors.ui_suite_bootstrap_carousel = {
attach(context) {
once(
'carousel-active',
".carousel",
context,
).forEach((carousel) => {
const items = carousel.querySelectorAll('.carousel-inner .carousel-item');
once('carousel-active', '.carousel', context).forEach((carousel) => {
const items = carousel.querySelectorAll(
'.carousel-inner .carousel-item',
);
if (items.length === 0) {
return;
}
// Check if there is an item with the active class.
let activeFound = false;
items.forEach(function(item) {
if (activeFound) {
return;
}
activeFound = item.classList.contains('active');
});
if (activeFound) {
return;
}
// If the carousel have no active items, put the active class on the
// first one.
items.item(0).classList.add('active');
});
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment