aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/bootstrap-carousel.js78
1 files changed, 74 insertions, 4 deletions
diff --git a/js/bootstrap-carousel.js b/js/bootstrap-carousel.js
index ed4b8f3fa..fa5247c97 100644
--- a/js/bootstrap-carousel.js
+++ b/js/bootstrap-carousel.js
@@ -25,12 +25,63 @@
/* CAROUSEL CLASS DEFINITION
* ========================= */
- var Carousel = function () {
-
+ 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), this.options.interval)
+ return this
+ }
+
+ , pause: function () {
+ clearInterval(this.interval)
+ return this
+ }
+
+ , next: function () {
+ return this.slide('next')
+ }
+
+ , prev: function () {
+ 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')) {
+ $active.removeClass('active')
+ $next.addClass('active')
+ } else {
+ $next.addClass(type)
+ $next[0].offsetWidth // force reflow
+ $active.addClass(direction)
+ $next.addClass(direction)
+ this.$element.one($.support.transition.end, function () {
+ $next.removeClass([type, direction].join(' ')).addClass('active')
+ $active.removeClass(['active', direction].join(' '))
+ })
+ }
+
+ isCycling && this.cycle()
+
+ return this
+ }
+
}
@@ -41,11 +92,30 @@
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].call($this)
+ , 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
+
+ /* CAROUSEL DATA-API
+ * ================= */
+
+ $(function () {
+ $('body').on('click.carousel.data-api', '[data-slide]', function ( e ) {
+ var $this = $(this)
+ , $target = $($this.attr('data-target') || $this.attr('href'))
+ , options = !$target.data('modal') && $.extend({}, $target.data(), $this.data())
+ $target.carousel(options)
+ })
+ })
+
}( window.jQuery ) \ No newline at end of file