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 /js | |
| parent | e9eff0cbffdd4381ee990e6fc78bee6caec92a00 (diff) | |
| download | bootstrap-7f9ff0ba5b679914defd8bdd45bcf930ee201286.tar.xz bootstrap-7f9ff0ba5b679914defd8bdd45bcf930ee201286.zip | |
add js support for carousel indicators
Diffstat (limited to 'js')
| -rw-r--r-- | js/bootstrap-carousel.js | 25 | ||||
| -rw-r--r-- | js/bootstrap-modal.js | 3 |
2 files changed, 20 insertions, 8 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 diff --git a/js/bootstrap-modal.js b/js/bootstrap-modal.js index ed5648025..93c262223 100644 --- a/js/bootstrap-modal.js +++ b/js/bootstrap-modal.js @@ -60,8 +60,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 |
