diff options
| author | fat <[email protected]> | 2012-12-19 23:25:25 -0800 |
|---|---|---|
| committer | fat <[email protected]> | 2012-12-19 23:25:25 -0800 |
| commit | 7f9ff0ba5b679914defd8bdd45bcf930ee201286 (patch) | |
| tree | c82e4853b9607f6d94d323ba202a574cc8a3f168 /docs/assets/js/bootstrap.js | |
| parent | e9eff0cbffdd4381ee990e6fc78bee6caec92a00 (diff) | |
| download | bootstrap-7f9ff0ba5b679914defd8bdd45bcf930ee201286.tar.xz bootstrap-7f9ff0ba5b679914defd8bdd45bcf930ee201286.zip | |
add js support for carousel indicators
Diffstat (limited to 'docs/assets/js/bootstrap.js')
| -rw-r--r-- | docs/assets/js/bootstrap.js | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/docs/assets/js/bootstrap.js b/docs/assets/js/bootstrap.js index 612664dd9..f9f8487c3 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 |
