diff --git a/js/src/carousel.js b/js/src/carousel.js index f2a1ccdfc287..83aa9c008d8d 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -85,7 +85,6 @@ const SELECTOR_ACTIVE = '.active' const SELECTOR_ITEM = '.carousel-item' const SELECTOR_ACTIVE_ITEM = SELECTOR_ACTIVE + SELECTOR_ITEM const SELECTOR_ITEM_IMG = '.carousel-item img' -const SELECTOR_NEXT_PREV = '.carousel-item-next, .carousel-item-prev' const SELECTOR_INDICATORS = '.carousel-indicators' const SELECTOR_DATA_SLIDE = '[data-bs-slide], [data-bs-slide-to]' const SELECTOR_DATA_RIDE = '[data-bs-ride="carousel"]' @@ -100,7 +99,6 @@ class Carousel extends BaseComponent { super(element) this._interval = null - this._isPaused = false this._isSliding = false this.touchTimeout = null this._swipeHelper = null @@ -138,26 +136,15 @@ class Carousel extends BaseComponent { this._slide(ORDER_PREV) } - pause(event) { - if (!event) { - this._isPaused = true - } - - if (SelectorEngine.findOne(SELECTOR_NEXT_PREV, this._element)) { - triggerTransitionEnd(this._element) - this.cycle(true) - } + pause() { + triggerTransitionEnd(this._element) // just to execute remaining queued Callback this._clearInterval() } - cycle(event) { - if (!event) { - this._isPaused = false - } - + cycle() { this._clearInterval() - if (this._config.interval && !this._isPaused) { + if (this._config.interval) { this._updateInterval() this._interval = setInterval((this.nextWhenVisible).bind(this), this._config.interval) @@ -177,8 +164,6 @@ class Carousel extends BaseComponent { } if (activeIndex === index) { - this.pause() - this.cycle() return } @@ -216,8 +201,8 @@ class Carousel extends BaseComponent { } if (this._config.pause === 'hover') { - EventHandler.on(this._element, EVENT_MOUSEENTER, event => this.pause(event)) - EventHandler.on(this._element, EVENT_MOUSELEAVE, event => this.cycle(event)) + EventHandler.on(this._element, EVENT_MOUSEENTER, () => this.pause()) + EventHandler.on(this._element, EVENT_MOUSELEAVE, () => this.cycle()) } if (this._config.touch && Swipe.isSupported()) { @@ -245,7 +230,7 @@ class Carousel extends BaseComponent { clearTimeout(this.touchTimeout) } - this.touchTimeout = setTimeout(event => this.cycle(event), TOUCHEVENT_COMPAT_WAIT + this._config.interval) + this.touchTimeout = setTimeout(() => this.cycle(), TOUCHEVENT_COMPAT_WAIT + this._config.interval) } } @@ -367,13 +352,10 @@ class Carousel extends BaseComponent { this._isSliding = false triggerEvent(EVENT_SLID) + this.cycle() } this._queueCallback(completeCallBack, activeElement, this._isAnimated()) - - if (this._interval) { - this.cycle() - } } _isAnimated() { @@ -448,7 +430,6 @@ class Carousel extends BaseComponent { } if (_config.interval && _config.ride) { - data.pause() data.cycle() } }) diff --git a/js/tests/unit/carousel.spec.js b/js/tests/unit/carousel.spec.js index c55c5071df4e..bd6512df3832 100644 --- a/js/tests/unit/carousel.spec.js +++ b/js/tests/unit/carousel.spec.js @@ -839,32 +839,6 @@ describe('Carousel', () => { }) describe('pause', () => { - it('should call cycle if the carousel have carousel-item-next and carousel-item-prev class', () => { - fixtureEl.innerHTML = [ - '' - ].join('') - - const carouselEl = fixtureEl.querySelector('#myCarousel') - const carousel = new Carousel(carouselEl) - - spyOn(carousel, 'cycle') - spyOn(carousel, '_clearInterval') - - carousel.pause() - - expect(carousel.cycle).toHaveBeenCalledWith(true) - expect(carousel._clearInterval).toHaveBeenCalled() - expect(carousel._isPaused).toEqual(true) - }) - it('should not call cycle if nothing is in transition', () => { fixtureEl.innerHTML = [ '