1 /* ========================================================================
2 * Bootstrap: carousel.js v3.0.0
3 * http://twbs.github.com/bootstrap/javascript.html#carousel
4 * ========================================================================
5 * Copyright 2012 Twitter, Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ======================================================================== */
21 +function ($) { "use strict";
23 // CAROUSEL CLASS DEFINITION
24 // =========================
26 var Carousel = function (element, options) {
27 this.$element = $(element)
28 this.$indicators = this.$element.find('.carousel-indicators')
29 this.options = options
36 this.options.pause == 'hover' && this.$element
37 .on('mouseenter', $.proxy(this.pause, this))
38 .on('mouseleave', $.proxy(this.cycle, this))
46 Carousel.prototype.cycle = function (e) {
47 e || (this.paused = false)
49 this.interval && clearInterval(this.interval)
53 && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
58 Carousel.prototype.getActiveIndex = function () {
59 this.$active = this.$element.find('.item.active')
60 this.$items = this.$active.parent().children()
62 return this.$items.index(this.$active)
65 Carousel.prototype.to = function (pos) {
67 var activeIndex = this.getActiveIndex()
69 if (pos > (this.$items.length - 1) || pos < 0) return
71 if (this.sliding) return this.$element.one('slid', function () { that.to(pos) })
72 if (activeIndex == pos) return this.pause().cycle()
74 return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos]))
77 Carousel.prototype.pause = function (e) {
78 e || (this.paused = true)
80 if (this.$element.find('.next, .prev').length && $.support.transition.end) {
81 this.$element.trigger($.support.transition.end)
85 this.interval = clearInterval(this.interval)
90 Carousel.prototype.next = function () {
91 if (this.sliding) return
92 return this.slide('next')
95 Carousel.prototype.prev = function () {
96 if (this.sliding) return
97 return this.slide('prev')
100 Carousel.prototype.slide = function (type, next) {
101 var $active = this.$element.find('.item.active')
102 var $next = next || $active[type]()
103 var isCycling = this.interval
104 var direction = type == 'next' ? 'left' : 'right'
105 var fallback = type == 'next' ? 'first' : 'last'
110 isCycling && this.pause()
112 $next = $next.length ? $next : this.$element.find('.item')[fallback]()
114 var e = $.Event('slide.bs.carousel', { relatedTarget: $next[0], direction: direction })
116 if ($next.hasClass('active')) return
118 if (this.$indicators.length) {
119 this.$indicators.find('.active').removeClass('active')
120 this.$element.one('slid', function () {
121 var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()])
122 $nextIndicator && $nextIndicator.addClass('active')
126 if ($.support.transition && this.$element.hasClass('slide')) {
127 this.$element.trigger(e)
128 if (e.isDefaultPrevented()) return
130 $next[0].offsetWidth // force reflow
131 $active.addClass(direction)
132 $next.addClass(direction)
134 .one($.support.transition.end, function () {
135 $next.removeClass([type, direction].join(' ')).addClass('active')
136 $active.removeClass(['active', direction].join(' '))
138 setTimeout(function () { that.$element.trigger('slid') }, 0)
140 .emulateTransitionEnd(600)
142 this.$element.trigger(e)
143 if (e.isDefaultPrevented()) return
144 $active.removeClass('active')
145 $next.addClass('active')
147 this.$element.trigger('slid')
150 isCycling && this.cycle()
156 // CAROUSEL PLUGIN DEFINITION
157 // ==========================
159 var old = $.fn.carousel
161 $.fn.carousel = function (option) {
162 return this.each(function () {
164 var data = $this.data('bs.carousel')
165 var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option)
166 var action = typeof option == 'string' ? option : options.slide
168 if (!data) $this.data('bs.carousel', (data = new Carousel(this, options)))
169 if (typeof option == 'number') data.to(option)
170 else if (action) data[action]()
171 else if (options.interval) data.pause().cycle()
175 $.fn.carousel.Constructor = Carousel
178 // CAROUSEL NO CONFLICT
179 // ====================
181 $.fn.carousel.noConflict = function () {
190 $(document).on('click.bs.carousel.data-api', '[data-slide], [data-slide-to]', function (e) {
191 var $this = $(this), href
192 var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
193 var options = $.extend({}, $target.data(), $this.data())
194 var slideIndex = $this.attr('data-slide-to')
195 if (slideIndex) options.interval = false
197 $target.carousel(options)
199 if (slideIndex = $this.attr('data-slide-to')) {
200 $target.data('bs.carousel').to(slideIndex)
206 $(window).on('load', function () {
207 $('[data-ride="carousel"]').each(function () {
208 var $carousel = $(this)
209 $carousel.carousel($carousel.data())