]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
change how carousel indicators activate #12592 13770/head
authorKatie Zhu <to.kzhu@gmail.com>
Tue, 10 Jun 2014 04:54:31 +0000 (21:54 -0700)
committerKatie Zhu <to.kzhu@gmail.com>
Tue, 10 Jun 2014 04:59:03 +0000 (21:59 -0700)
js/carousel.js

index e2cb67a5ef59aa465a13dd1785ae65981310c73f..f0117980d96037ba533ff250945b39c636804516 100644 (file)
     return this
   }
 
-  Carousel.prototype.getActiveIndex = function () {
-    this.$active = this.$element.find('.item.active')
-    this.$items  = this.$active.parent().children('.item')
-
-    return this.$items.index(this.$active)
+  Carousel.prototype.getItemIndex = function (item) {
+    this.$items = item.parent().children('.item')
+    return this.$items.index(item || this.$active)
   }
 
   Carousel.prototype.to = function (pos) {
     var that        = this
-    var activeIndex = this.getActiveIndex()
+    var activeIndex = this.getItemIndex(this.$active = this.$element.find('.item.active'))
 
     if (pos > (this.$items.length - 1) || pos < 0) return
 
 
     if (this.$indicators.length) {
       this.$indicators.find('.active').removeClass('active')
-      this.$element.one('slid.bs.carousel', function () { // yes, "slid"
-        var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()])
-        $nextIndicator && $nextIndicator.addClass('active')
-      })
+      var $nextIndicator = $(this.$indicators.children()[this.getItemIndex($next)])
+      $nextIndicator && $nextIndicator.addClass('active')
     }
 
     var slidEvent = $.Event('slid.bs.carousel', { relatedTarget: relatedTarget, direction: direction }) // yes, "slid"