From ea0faadde5c222cdd8127332b62a6d565a055d80 Mon Sep 17 00:00:00 2001 From: Christopher Morrissey Date: Tue, 18 Sep 2018 08:55:48 -0400 Subject: [PATCH] feature(carousel): carousel-item interval (#26667) adds the ability to assign data-interval to an individual carousel-item --- js/src/carousel.js | 8 +++++ js/tests/unit/carousel.js | 48 ++++++++++++++++++++++++++++ site/docs/4.1/components/carousel.md | 29 +++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/js/src/carousel.js b/js/src/carousel.js index 2d7ab0d672..610319a6e0 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -385,6 +385,14 @@ const Carousel = (($) => { $(activeElement).addClass(directionalClassName) $(nextElement).addClass(directionalClassName) + const nextElementInterval = parseInt(nextElement.getAttribute('data-interval'), 10) + if (nextElementInterval) { + this._config.defaultInterval = this._config.defaultInterval || this._config.interval + this._config.interval = nextElementInterval + } else { + this._config.interval = this._config.defaultInterval || this._config.interval + } + const transitionDuration = Util.getTransitionDurationFromElement(activeElement) $(activeElement) diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index baabcf426f..20b12f4b06 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -445,6 +445,54 @@ $(function () { $carousel.remove() }) + QUnit.test('should set interval from data attribute on individual carousel-item', function (assert) { + assert.expect(2) + var templateHTML = '' + var $carousel = $(templateHTML) + + $carousel.appendTo('body') + $carousel.bootstrapCarousel(1) + assert.strictEqual($carousel.data('bs.carousel')._config.interval, 3814) + $carousel.remove() + + $carousel.appendTo('body') + $carousel.bootstrapCarousel(2) + assert.strictEqual($carousel.data('bs.carousel')._config.interval, 1814, 'reverts to default interval if no data-interval is set') + $carousel.remove() + }) + QUnit.test('should skip over non-items when using item indices', function (assert) { assert.expect(2) var templateHTML = '