aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Rebert <[email protected]>2014-11-15 22:43:20 -0800
committerChris Rebert <[email protected]>2014-11-15 22:43:20 -0800
commitb7398bc9c40f5f0e3404896adba10915b2a8304e (patch)
tree9032326a827b13b3b63f5d1ac1a7a31d5f6def99
parent8008fe707ec1259afcee1084bf4e79d29ed46ef4 (diff)
downloadbootstrap-b7398bc9c40f5f0e3404896adba10915b2a8304e.tar.xz
bootstrap-b7398bc9c40f5f0e3404896adba10915b2a8304e.zip
honor wrap option in Carousel.getItemForDirection; fixes #15144
-rw-r--r--js/carousel.js11
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]