diff options
| author | Jacob Thornton <[email protected]> | 2012-01-02 22:55:51 -0800 |
|---|---|---|
| committer | Jacob Thornton <[email protected]> | 2012-01-02 22:55:51 -0800 |
| commit | e89618a47f768eddf47164f89176e172b5c2972d (patch) | |
| tree | 946049634400545f27efc16b70626686f05ba96c /js/bootstrap-carousel.js | |
| parent | f5bcfaec2c13eb3102ffc2890a69a7c2b725ff36 (diff) | |
| download | bootstrap-e89618a47f768eddf47164f89176e172b5c2972d.tar.xz bootstrap-e89618a47f768eddf47164f89176e172b5c2972d.zip | |
clean up options implementation for carousel
Diffstat (limited to 'js/bootstrap-carousel.js')
| -rw-r--r-- | js/bootstrap-carousel.js | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/js/bootstrap-carousel.js b/js/bootstrap-carousel.js index 2099b372c..5e37b0f60 100644 --- a/js/bootstrap-carousel.js +++ b/js/bootstrap-carousel.js @@ -25,35 +25,42 @@ /* CAROUSEL CLASS DEFINITION * ========================= */ - var Carousel = function (element) { + var Carousel = function (element, options) { this.$element = $(element) + this.options = $.extend({}, $.fn.carousel.defaults, options) + this.options.slide && this.slide(this.options.slide) } Carousel.prototype = { cycle: function () { this.interval = setInterval($.proxy(this.next, this), 5000) + return this } , pause: function () { clearInterval(this.interval) + return this } , next: function () { - this.slide('next') + return this.slide('next') } , prev: function () { - this.slide('prev') + return this.slide('prev') } , slide: function (type) { var $active = this.$element.find('.active') , $next = $active[type]() + , isCycling = this.interval , direction = type == 'next' ? 'left' : 'right' , fallback = type == 'next' ? 'first' : 'last' , that = this + isCycling && this.pause() + $next = $next.length ? $next : this.$element.find('.item')[fallback]() if (!$.support.transition && this.$element.hasClass('slide')) { @@ -69,6 +76,10 @@ $active.removeClass(['active', direction].join(' ')) }) } + + isCycling && this.cycle() + + return this } } @@ -81,11 +92,17 @@ return this.each(function () { var $this = $(this) , data = $this.data('carousel') - if (!data) $this.data('carousel', (data = new Carousel(this))) - if (typeof option == 'string') data[option]() + , options = typeof option == 'object' && option + if (!data) $this.data('carousel', (data = new Carousel(this, options))) + if (typeof option == 'string' || (option = options.slide)) data[option]() + else data.cycle() }) } + $.fn.carousel.defaults = { + interval: 5000 + } + $.fn.carousel.Constructor = Carousel @@ -96,8 +113,8 @@ $('body').on('click.carousel.data-api', '[data-slide]', function ( e ) { var $this = $(this) , $target = $($this.attr('data-target') || $this.attr('href')) - - $target.carousel($this.attr('data-slide')) + , options = !$target.data('modal') && $.extend({}, $target.data(), $this.data()) + $target.carousel(options) }) }) |
