1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-09-27 22:09:04 +02:00

Fix #13818 by using more robust "find next carousel item" logic

Also adds another test for #9461: carousel next/prev should ignore non-items
This commit is contained in:
Chris Rebert
2014-07-07 19:05:48 -07:00
parent fc1db2e74b
commit cbba8e53df
2 changed files with 35 additions and 3 deletions

View File

@@ -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'