From: Christopher Morrissey Date: Tue, 18 Sep 2018 12:55:48 +0000 (-0400) Subject: feature(carousel): carousel-item interval (#26667) X-Git-Tag: v4.2.0~304 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ea0faadde5c222cdd8127332b62a6d565a055d80;p=thirdparty%2Fbootstrap.git feature(carousel): carousel-item interval (#26667) adds the ability to assign data-interval to an individual carousel-item --- 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 = '