Mercurial > wikked
comparison static/bootstrap/js/bootstrap-carousel.js @ 61:130eccd396d8
Now using Boostrap with LESS.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 06 Feb 2013 08:22:31 -0800 |
parents | |
children | a5a3d454eac9 |
comparison
equal
deleted
inserted
replaced
60:8250c977bc50 | 61:130eccd396d8 |
---|---|
1 /* ========================================================== | |
2 * bootstrap-carousel.js v2.2.2 | |
3 * http://twitter.github.com/bootstrap/javascript.html#carousel | |
4 * ========================================================== | |
5 * Copyright 2012 Twitter, Inc. | |
6 * | |
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 | |
10 * | |
11 * http://www.apache.org/licenses/LICENSE-2.0 | |
12 * | |
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 * ========================================================== */ | |
19 | |
20 | |
21 !function ($) { | |
22 | |
23 "use strict"; // jshint ;_; | |
24 | |
25 | |
26 /* CAROUSEL CLASS DEFINITION | |
27 * ========================= */ | |
28 | |
29 var Carousel = function (element, options) { | |
30 this.$element = $(element) | |
31 this.options = options | |
32 this.options.pause == 'hover' && this.$element | |
33 .on('mouseenter', $.proxy(this.pause, this)) | |
34 .on('mouseleave', $.proxy(this.cycle, this)) | |
35 } | |
36 | |
37 Carousel.prototype = { | |
38 | |
39 cycle: function (e) { | |
40 if (!e) this.paused = false | |
41 this.options.interval | |
42 && !this.paused | |
43 && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) | |
44 return this | |
45 } | |
46 | |
47 , to: function (pos) { | |
48 var $active = this.$element.find('.item.active') | |
49 , children = $active.parent().children() | |
50 , activePos = children.index($active) | |
51 , that = this | |
52 | |
53 if (pos > (children.length - 1) || pos < 0) return | |
54 | |
55 if (this.sliding) { | |
56 return this.$element.one('slid', function () { | |
57 that.to(pos) | |
58 }) | |
59 } | |
60 | |
61 if (activePos == pos) { | |
62 return this.pause().cycle() | |
63 } | |
64 | |
65 return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos])) | |
66 } | |
67 | |
68 , pause: function (e) { | |
69 if (!e) this.paused = true | |
70 if (this.$element.find('.next, .prev').length && $.support.transition.end) { | |
71 this.$element.trigger($.support.transition.end) | |
72 this.cycle() | |
73 } | |
74 clearInterval(this.interval) | |
75 this.interval = null | |
76 return this | |
77 } | |
78 | |
79 , next: function () { | |
80 if (this.sliding) return | |
81 return this.slide('next') | |
82 } | |
83 | |
84 , prev: function () { | |
85 if (this.sliding) return | |
86 return this.slide('prev') | |
87 } | |
88 | |
89 , slide: function (type, next) { | |
90 var $active = this.$element.find('.item.active') | |
91 , $next = next || $active[type]() | |
92 , isCycling = this.interval | |
93 , direction = type == 'next' ? 'left' : 'right' | |
94 , fallback = type == 'next' ? 'first' : 'last' | |
95 , that = this | |
96 , e | |
97 | |
98 this.sliding = true | |
99 | |
100 isCycling && this.pause() | |
101 | |
102 $next = $next.length ? $next : this.$element.find('.item')[fallback]() | |
103 | |
104 e = $.Event('slide', { | |
105 relatedTarget: $next[0] | |
106 }) | |
107 | |
108 if ($next.hasClass('active')) return | |
109 | |
110 if ($.support.transition && this.$element.hasClass('slide')) { | |
111 this.$element.trigger(e) | |
112 if (e.isDefaultPrevented()) return | |
113 $next.addClass(type) | |
114 $next[0].offsetWidth // force reflow | |
115 $active.addClass(direction) | |
116 $next.addClass(direction) | |
117 this.$element.one($.support.transition.end, function () { | |
118 $next.removeClass([type, direction].join(' ')).addClass('active') | |
119 $active.removeClass(['active', direction].join(' ')) | |
120 that.sliding = false | |
121 setTimeout(function () { that.$element.trigger('slid') }, 0) | |
122 }) | |
123 } else { | |
124 this.$element.trigger(e) | |
125 if (e.isDefaultPrevented()) return | |
126 $active.removeClass('active') | |
127 $next.addClass('active') | |
128 this.sliding = false | |
129 this.$element.trigger('slid') | |
130 } | |
131 | |
132 isCycling && this.cycle() | |
133 | |
134 return this | |
135 } | |
136 | |
137 } | |
138 | |
139 | |
140 /* CAROUSEL PLUGIN DEFINITION | |
141 * ========================== */ | |
142 | |
143 var old = $.fn.carousel | |
144 | |
145 $.fn.carousel = function (option) { | |
146 return this.each(function () { | |
147 var $this = $(this) | |
148 , data = $this.data('carousel') | |
149 , options = $.extend({}, $.fn.carousel.defaults, typeof option == 'object' && option) | |
150 , action = typeof option == 'string' ? option : options.slide | |
151 if (!data) $this.data('carousel', (data = new Carousel(this, options))) | |
152 if (typeof option == 'number') data.to(option) | |
153 else if (action) data[action]() | |
154 else if (options.interval) data.cycle() | |
155 }) | |
156 } | |
157 | |
158 $.fn.carousel.defaults = { | |
159 interval: 5000 | |
160 , pause: 'hover' | |
161 } | |
162 | |
163 $.fn.carousel.Constructor = Carousel | |
164 | |
165 | |
166 /* CAROUSEL NO CONFLICT | |
167 * ==================== */ | |
168 | |
169 $.fn.carousel.noConflict = function () { | |
170 $.fn.carousel = old | |
171 return this | |
172 } | |
173 | |
174 /* CAROUSEL DATA-API | |
175 * ================= */ | |
176 | |
177 $(document).on('click.carousel.data-api', '[data-slide]', function (e) { | |
178 var $this = $(this), href | |
179 , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 | |
180 , options = $.extend({}, $target.data(), $this.data()) | |
181 $target.carousel(options) | |
182 e.preventDefault() | |
183 }) | |
184 | |
185 }(window.jQuery); |