aboutsummaryrefslogtreecommitdiff
path: root/js/bootstrap-carousel.js
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2012-12-19 23:39:40 -0800
committerMark Otto <[email protected]>2012-12-19 23:39:40 -0800
commit5d776bcfd2e7da0bcce37252dc983149d8b2d377 (patch)
tree0b46eb3b33008f4d4b4ea3bd73ce82ed77218d7d /js/bootstrap-carousel.js
parentdc6142751feced6761f67503323c0c6e62844d4e (diff)
parentbbe4625672c5122bb2b06c495f9ea41752c10467 (diff)
downloadbootstrap-5d776bcfd2e7da0bcce37252dc983149d8b2d377.tar.xz
bootstrap-5d776bcfd2e7da0bcce37252dc983149d8b2d377.zip
Merge branch '2.2.3' of github.com:twitter/bootstrap into 2.2.3
Diffstat (limited to 'js/bootstrap-carousel.js')
-rw-r--r--js/bootstrap-carousel.js25
1 files changed, 19 insertions, 6 deletions
diff --git a/js/bootstrap-carousel.js b/js/bootstrap-carousel.js
index 71d71bde4..6a1b21f37 100644
--- a/js/bootstrap-carousel.js
+++ b/js/bootstrap-carousel.js
@@ -28,6 +28,7 @@
var Carousel = function (element, options) {
this.$element = $(element)
+ this.$indicators = this.$element.find('.carousel-indicators')
this.options = options
this.options.pause == 'hover' && this.$element
.on('mouseenter', $.proxy(this.pause, this))
@@ -44,13 +45,17 @@
return this
}
+ , getActiveIndex: function () {
+ this.$active = this.$element.find('.item.active')
+ this.$items = this.$active.parent().children()
+ return this.$items.index(this.$active)
+ }
+
, to: function (pos) {
- var $active = this.$element.find('.item.active')
- , children = $active.parent().children()
- , activePos = children.index($active)
+ var activeIndex = this.getActiveIndex()
, that = this
- if (pos > (children.length - 1) || pos < 0) return
+ if (pos > (this.$items.length - 1) || pos < 0) return
if (this.sliding) {
return this.$element.one('slid', function () {
@@ -58,11 +63,11 @@
})
}
- if (activePos == pos) {
+ if (activeIndex == pos) {
return this.pause().cycle()
}
- return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos]))
+ return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos]))
}
, pause: function (e) {
@@ -107,6 +112,14 @@
if ($next.hasClass('active')) return
+ if (this.$indicators.length) {
+ this.$indicators.find('.active').removeClass('active')
+ this.$element.one('slid', function () {
+ var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()])
+ $nextIndicator && $nextIndicator.addClass('active')
+ })
+ }
+
if ($.support.transition && this.$element.hasClass('slide')) {
this.$element.trigger(e)
if (e.isDefaultPrevented()) return