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 /docs/assets/js/bootstrap.js
parente9eff0cbffdd4381ee990e6fc78bee6caec92a00 (diff)
add js support for carousel indicators
Diffstat (limited to 'docs/assets/js/bootstrap.js')
-rw-r--r--docs/assets/js/bootstrap.js29
1 files changed, 21 insertions, 8 deletions
diff --git a/docs/assets/js/bootstrap.js b/docs/assets/js/bootstrap.js
index 612664dd92..f9f8487c32 100644
--- a/docs/assets/js/bootstrap.js
+++ b/docs/assets/js/bootstrap.js
@@ -289,6 +289,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))
@@ -305,13 +306,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 () {
@@ -319,11 +324,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) {
@@ -353,6 +358,7 @@
, isCycling = this.interval
, direction = type == 'next' ? 'left' : 'right'
, fallback = type == 'next' ? 'first' : 'last'
+ , $nextIndicator
, that = this
, e
@@ -368,6 +374,14 @@
if ($next.hasClass('active')) return
+ if (this.$indicators.length) {
+ this.$indicators.find('.active').removeClass('active')
+ this.$element.one('slid', function () {
+ $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
@@ -832,8 +846,7 @@
that.$element.appendTo(document.body) //don't move modals dom position
}
- that.$element
- .show()
+ that.$element.show()
if (transition) {
that.$element[0].offsetWidth // force reflow