Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfat <jacobthornton@gmail.com>2012-12-20 11:25:25 +0400
committerfat <jacobthornton@gmail.com>2012-12-20 11:25:25 +0400
commit7f9ff0ba5b679914defd8bdd45bcf930ee201286 (patch)
treec82e4853b9607f6d94d323ba202a574cc8a3f168 /js/bootstrap-carousel.js
parente9eff0cbffdd4381ee990e6fc78bee6caec92a00 (diff)
add js support for carousel indicators
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 71d71bde47..6a1b21f370 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