- Issue created by @mrupsidown
- πΊπΈUnited States shelane
This module only provides the style processing for view data. All of the JavaScript for Bootstrap carousel behavior should be provided by the theme.
- π¨πSwitzerland mrupsidown
Which is exactly what I am trying to do. Listen to the "slide.bs.carousel" event in my theme JS and which doesn't work. How would you do that?
- πΊπΈUnited States shelane
Can you try:
Drupal.behaviors.bsCarousel = { attach: function (context, settings) { $(once('bs-carousel', '#views-bootstrap-home-slider-block-1', context)).each(function () { // Ensure the carousel element exists $(this).on('slid.bs.carousel', function () { console.log('CAROUSEL HAS SLID'); // This should now work }); }); } };
- π¨πSwitzerland mrupsidown
Thanks for the follow up, unfortunately this doesn't work either.
I tried logging `$(this)` and it seems the element is fine but still nothing from the slid event.
- πΊπΈUnited States shelane
I just saw that there is some javascript in the module related to the carousels. I'm going to update it to remove its dependence on jQuery and see what else it may be doing to interfere.
- πΊπΈUnited States shelane
In light of the other script and changes I made to it to remove jQuery, try this using the dev branch:
(function () { 'use strict'; /** * Attaches the behavior to the user's custom carousel functionality. */ Drupal.behaviors.bsCarousel = { attach: function (context, settings) { // Select the specific carousel element const carousel = document.querySelector('#views-bootstrap-home-slider-block-1'); if (carousel) { // Ensure the carousel has more than one slide const slides = carousel.querySelectorAll('.carousel-inner > div'); if (slides.length > 1) { // Attach the event listener for the 'slid.bs.carousel' event carousel.addEventListener('slid.bs.carousel', function () { console.log('CAROUSEL HAS SLID'); }); } else { console.log('Carousel has only one slide, event listener not attached.'); } } } }; }());