1
/* ==========================================================
2
* bootstrap-carousel.js v2.0.2
3
* http://twitter.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
* ========================================================== */
25
/* CAROUSEL CLASS DEFINITION
26
* ========================= */
28
var Carousel = function (element, options) {
29
this.$element = $(element)
30
this.options = $.extend({}, $.fn.carousel.defaults, options)
31
this.options.slide && this.slide(this.options.slide)
32
this.options.pause == 'hover' && this.$element
33
.on('mouseenter', $.proxy(this.pause, this))
34
.on('mouseleave', $.proxy(this.cycle, this))
37
Carousel.prototype = {
40
this.interval = setInterval($.proxy(this.next, this), this.options.interval)
44
, to: function (pos) {
45
var $active = this.$element.find('.active')
46
, children = $active.parent().children()
47
, activePos = children.index($active)
50
if (pos > (children.length - 1) || pos < 0) return
53
return this.$element.one('slid', function () {
58
if (activePos == pos) {
59
return this.pause().cycle()
62
return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos]))
65
, pause: function () {
66
clearInterval(this.interval)
72
if (this.sliding) return
73
return this.slide('next')
77
if (this.sliding) return
78
return this.slide('prev')
81
, slide: function (type, next) {
82
var $active = this.$element.find('.active')
83
, $next = next || $active[type]()
84
, isCycling = this.interval
85
, direction = type == 'next' ? 'left' : 'right'
86
, fallback = type == 'next' ? 'first' : 'last'
91
isCycling && this.pause()
93
$next = $next.length ? $next : this.$element.find('.item')[fallback]()
95
if ($next.hasClass('active')) return
97
if (!$.support.transition && this.$element.hasClass('slide')) {
98
this.$element.trigger('slide')
99
$active.removeClass('active')
100
$next.addClass('active')
102
this.$element.trigger('slid')
105
$next[0].offsetWidth // force reflow
106
$active.addClass(direction)
107
$next.addClass(direction)
108
this.$element.trigger('slide')
109
this.$element.one($.support.transition.end, function () {
110
$next.removeClass([type, direction].join(' ')).addClass('active')
111
$active.removeClass(['active', direction].join(' '))
113
setTimeout(function () { that.$element.trigger('slid') }, 0)
117
isCycling && this.cycle()
125
/* CAROUSEL PLUGIN DEFINITION
126
* ========================== */
128
$.fn.carousel = function ( option ) {
129
return this.each(function () {
131
, data = $this.data('carousel')
132
, options = typeof option == 'object' && option
133
if (!data) $this.data('carousel', (data = new Carousel(this, options)))
134
if (typeof option == 'number') data.to(option)
135
else if (typeof option == 'string' || (option = options.slide)) data[option]()
140
$.fn.carousel.defaults = {
145
$.fn.carousel.Constructor = Carousel
149
* ================= */
152
$('body').on('click.carousel.data-api', '[data-slide]', function ( e ) {
153
var $this = $(this), href
154
, $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
155
, options = !$target.data('modal') && $.extend({}, $target.data(), $this.data())
156
$target.carousel(options)
b'\\ No newline at end of file'