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