diff options
| author | Chris Rebert <[email protected]> | 2014-11-17 01:43:22 -0800 |
|---|---|---|
| committer | Chris Rebert <[email protected]> | 2014-11-17 01:43:22 -0800 |
| commit | 8df9298b1e8696dcbf0bae54bff1816bd8df061a (patch) | |
| tree | 344e0449df6195c6b28298f742d8d91ede2d6852 /js/carousel.js | |
| parent | d782eed426728a9a5ebe600a2f264c0f27a22c8f (diff) | |
| parent | b7398bc9c40f5f0e3404896adba10915b2a8304e (diff) | |
| download | bootstrap-8df9298b1e8696dcbf0bae54bff1816bd8df061a.tar.xz bootstrap-8df9298b1e8696dcbf0bae54bff1816bd8df061a.zip | |
Merge pull request #15152 from twbs/fix-15144
honor wrap option in Carousel.getItemForDirection
[skip validator]
Diffstat (limited to 'js/carousel.js')
| -rw-r--r-- | js/carousel.js | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/js/carousel.js b/js/carousel.js index 282d618fe..99a077c10 100644 --- a/js/carousel.js +++ b/js/carousel.js @@ -70,8 +70,11 @@ } Carousel.prototype.getItemForDirection = function (direction, active) { - var delta = direction == 'prev' ? -1 : 1 var activeIndex = this.getItemIndex(active) + var willWrap = (direction == 'prev' && activeIndex === 0) + || (direction == 'next' && activeIndex == (this.$items.length - 1)) + if (willWrap && !this.options.wrap) return active + var delta = direction == 'prev' ? -1 : 1 var itemIndex = (activeIndex + delta) % this.$items.length return this.$items.eq(itemIndex) } @@ -116,14 +119,8 @@ var $next = next || this.getItemForDirection(type, $active) var isCycling = this.interval var direction = type == 'next' ? 'left' : 'right' - var fallback = type == 'next' ? 'first' : 'last' var that = this - if (!$next.length) { - if (!this.options.wrap) return - $next = this.$element.find('.item')[fallback]() - } - if ($next.hasClass('active')) return (this.sliding = false) var relatedTarget = $next[0] |
