annotate static/bootstrap/js/carousel.js @ 149:d29e2f337b00

Updated to Bootstrap 3.0.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 12 Dec 2013 21:54:04 -0800
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
149
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 /* ========================================================================
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 * Bootstrap: carousel.js v3.0.3
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 * http://getbootstrap.com/javascript/#carousel
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 * ========================================================================
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 * Copyright 2013 Twitter, Inc.
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 *
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 * Licensed under the Apache License, Version 2.0 (the "License");
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 * you may not use this file except in compliance with the License.
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 * You may obtain a copy of the License at
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 *
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 * http://www.apache.org/licenses/LICENSE-2.0
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 *
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 * Unless required by applicable law or agreed to in writing, software
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 * distributed under the License is distributed on an "AS IS" BASIS,
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 * See the License for the specific language governing permissions and
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 * limitations under the License.
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 * ======================================================================== */
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 +function ($) { "use strict";
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 // CAROUSEL CLASS DEFINITION
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 // =========================
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 var Carousel = function (element, options) {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 this.$element = $(element)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 this.$indicators = this.$element.find('.carousel-indicators')
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 this.options = options
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 this.paused =
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 this.sliding =
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 this.interval =
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 this.$active =
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 this.$items = null
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 this.options.pause == 'hover' && this.$element
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 .on('mouseenter', $.proxy(this.pause, this))
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 .on('mouseleave', $.proxy(this.cycle, this))
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 Carousel.DEFAULTS = {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 interval: 5000
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 , pause: 'hover'
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 , wrap: true
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 Carousel.prototype.cycle = function (e) {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 e || (this.paused = false)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50 this.interval && clearInterval(this.interval)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 this.options.interval
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 && !this.paused
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 return this
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 Carousel.prototype.getActiveIndex = function () {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 this.$active = this.$element.find('.item.active')
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 this.$items = this.$active.parent().children()
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 return this.$items.index(this.$active)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66 Carousel.prototype.to = function (pos) {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67 var that = this
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68 var activeIndex = this.getActiveIndex()
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70 if (pos > (this.$items.length - 1) || pos < 0) return
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 if (this.sliding) return this.$element.one('slid.bs.carousel', function () { that.to(pos) })
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 if (activeIndex == pos) return this.pause().cycle()
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos]))
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 Carousel.prototype.pause = function (e) {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 e || (this.paused = true)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81 if (this.$element.find('.next, .prev').length && $.support.transition.end) {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 this.$element.trigger($.support.transition.end)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83 this.cycle(true)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 this.interval = clearInterval(this.interval)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 return this
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91 Carousel.prototype.next = function () {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
92 if (this.sliding) return
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 return this.slide('next')
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96 Carousel.prototype.prev = function () {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 if (this.sliding) return
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 return this.slide('prev')
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 Carousel.prototype.slide = function (type, next) {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102 var $active = this.$element.find('.item.active')
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103 var $next = next || $active[type]()
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104 var isCycling = this.interval
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 var direction = type == 'next' ? 'left' : 'right'
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106 var fallback = type == 'next' ? 'first' : 'last'
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
107 var that = this
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109 if (!$next.length) {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
110 if (!this.options.wrap) return
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 $next = this.$element.find('.item')[fallback]()
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
112 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114 this.sliding = true
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
116 isCycling && this.pause()
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
117
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
118 var e = $.Event('slide.bs.carousel', { relatedTarget: $next[0], direction: direction })
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120 if ($next.hasClass('active')) return
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
121
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122 if (this.$indicators.length) {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
123 this.$indicators.find('.active').removeClass('active')
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124 this.$element.one('slid.bs.carousel', function () {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
125 var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()])
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 $nextIndicator && $nextIndicator.addClass('active')
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127 })
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
129
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
130 if ($.support.transition && this.$element.hasClass('slide')) {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 this.$element.trigger(e)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132 if (e.isDefaultPrevented()) return
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133 $next.addClass(type)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134 $next[0].offsetWidth // force reflow
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135 $active.addClass(direction)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136 $next.addClass(direction)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137 $active
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
138 .one($.support.transition.end, function () {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
139 $next.removeClass([type, direction].join(' ')).addClass('active')
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
140 $active.removeClass(['active', direction].join(' '))
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
141 that.sliding = false
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
142 setTimeout(function () { that.$element.trigger('slid.bs.carousel') }, 0)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
143 })
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
144 .emulateTransitionEnd(600)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
145 } else {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
146 this.$element.trigger(e)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
147 if (e.isDefaultPrevented()) return
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
148 $active.removeClass('active')
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
149 $next.addClass('active')
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
150 this.sliding = false
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
151 this.$element.trigger('slid.bs.carousel')
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
152 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
153
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
154 isCycling && this.cycle()
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
155
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
156 return this
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
157 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
158
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
159
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
160 // CAROUSEL PLUGIN DEFINITION
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
161 // ==========================
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
162
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
163 var old = $.fn.carousel
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
164
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
165 $.fn.carousel = function (option) {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
166 return this.each(function () {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
167 var $this = $(this)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
168 var data = $this.data('bs.carousel')
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
169 var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
170 var action = typeof option == 'string' ? option : options.slide
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
171
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
172 if (!data) $this.data('bs.carousel', (data = new Carousel(this, options)))
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
173 if (typeof option == 'number') data.to(option)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
174 else if (action) data[action]()
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
175 else if (options.interval) data.pause().cycle()
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
176 })
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
177 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
178
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
179 $.fn.carousel.Constructor = Carousel
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
180
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
181
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
182 // CAROUSEL NO CONFLICT
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
183 // ====================
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
184
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
185 $.fn.carousel.noConflict = function () {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
186 $.fn.carousel = old
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
187 return this
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
188 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
189
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
190
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
191 // CAROUSEL DATA-API
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
192 // =================
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
193
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
194 $(document).on('click.bs.carousel.data-api', '[data-slide], [data-slide-to]', function (e) {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
195 var $this = $(this), href
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
196 var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
197 var options = $.extend({}, $target.data(), $this.data())
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
198 var slideIndex = $this.attr('data-slide-to')
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
199 if (slideIndex) options.interval = false
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
200
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
201 $target.carousel(options)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
202
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
203 if (slideIndex = $this.attr('data-slide-to')) {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
204 $target.data('bs.carousel').to(slideIndex)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
205 }
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
206
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
207 e.preventDefault()
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
208 })
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
209
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
210 $(window).on('load', function () {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
211 $('[data-ride="carousel"]').each(function () {
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
212 var $carousel = $(this)
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
213 $carousel.carousel($carousel.data())
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
214 })
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
215 })
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
216
d29e2f337b00 Updated to Bootstrap 3.0.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
217 }(jQuery);