aboutsummaryrefslogtreecommitdiff
path: root/js/carousel.js
diff options
context:
space:
mode:
authorChris Rebert <[email protected]>2014-07-31 11:36:56 -0700
committerChris Rebert <[email protected]>2014-07-31 11:36:56 -0700
commitf026cfb8310f31db94823d031a382de5d5b0520b (patch)
treec34519f8d1ec1d6c43ad12747f0bd2f61b18a6b3 /js/carousel.js
parentd38fd028d620d7861e067b87526a773cd4b7dc1b (diff)
parentcbba8e53df2cfea3273072d94408fd2981dce460 (diff)
downloadbootstrap-f026cfb8310f31db94823d031a382de5d5b0520b.tar.xz
bootstrap-f026cfb8310f31db94823d031a382de5d5b0520b.zip
Merge pull request #14069 from twbs/fix-13818
Use more robust "find next carousel item" logic
Diffstat (limited to 'js/carousel.js')
-rw-r--r--js/carousel.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/js/carousel.js b/js/carousel.js
index b7da1ba53..86383edae 100644
--- a/js/carousel.js
+++ b/js/carousel.js
@@ -63,6 +63,13 @@
return this.$items.index(item || this.$active)
}
+ Carousel.prototype.getItemForDirection = function (direction, active) {
+ var delta = direction == 'prev' ? -1 : 1
+ var activeIndex = this.getItemIndex(active)
+ var itemIndex = (activeIndex + delta) % this.$items.length
+ return this.$items.eq(itemIndex)
+ }
+
Carousel.prototype.to = function (pos) {
var that = this
var activeIndex = this.getItemIndex(this.$active = this.$element.find('.item.active'))
@@ -72,7 +79,7 @@
if (this.sliding) return this.$element.one('slid.bs.carousel', function () { that.to(pos) }) // yes, "slid"
if (activeIndex == pos) return this.pause().cycle()
- return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos]))
+ return this.slide(pos > activeIndex ? 'next' : 'prev', this.$items.eq(pos))
}
Carousel.prototype.pause = function (e) {
@@ -100,7 +107,7 @@
Carousel.prototype.slide = function (type, next) {
var $active = this.$element.find('.item.active')
- var $next = next || $active[type]()
+ var $next = next || this.getItemForDirection(type, $active)
var isCycling = this.interval
var direction = type == 'next' ? 'left' : 'right'
var fallback = type == 'next' ? 'first' : 'last'