Skip to content

Commit

Permalink
Fix #13818 by using more robust "find next carousel item" logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cvrebert committed Jul 18, 2014
1 parent f5e2831 commit f53a2b1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion js/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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[itemIndex])
}

Carousel.prototype.to = function (pos) {
var that = this
var activeIndex = this.getItemIndex(this.$active = this.$element.find('.item.active'))
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit f53a2b1

Please sign in to comment.