Mercurial > wikked
comparison static/bootstrap/js/bootstrap-carousel.js @ 88:a5a3d454eac9
Updated Bootstrap.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 05 Apr 2013 08:08:12 -0700 |
parents | 130eccd396d8 |
children |
comparison
equal
deleted
inserted
replaced
87:c0cf67362fb1 | 88:a5a3d454eac9 |
---|---|
1 /* ========================================================== | 1 /* ========================================================== |
2 * bootstrap-carousel.js v2.2.2 | 2 * bootstrap-carousel.js v2.3.1 |
3 * http://twitter.github.com/bootstrap/javascript.html#carousel | 3 * http://twitter.github.com/bootstrap/javascript.html#carousel |
4 * ========================================================== | 4 * ========================================================== |
5 * Copyright 2012 Twitter, Inc. | 5 * Copyright 2012 Twitter, Inc. |
6 * | 6 * |
7 * Licensed under the Apache License, Version 2.0 (the "License"); | 7 * Licensed under the Apache License, Version 2.0 (the "License"); |
26 /* CAROUSEL CLASS DEFINITION | 26 /* CAROUSEL CLASS DEFINITION |
27 * ========================= */ | 27 * ========================= */ |
28 | 28 |
29 var Carousel = function (element, options) { | 29 var Carousel = function (element, options) { |
30 this.$element = $(element) | 30 this.$element = $(element) |
31 this.$indicators = this.$element.find('.carousel-indicators') | |
31 this.options = options | 32 this.options = options |
32 this.options.pause == 'hover' && this.$element | 33 this.options.pause == 'hover' && this.$element |
33 .on('mouseenter', $.proxy(this.pause, this)) | 34 .on('mouseenter', $.proxy(this.pause, this)) |
34 .on('mouseleave', $.proxy(this.cycle, this)) | 35 .on('mouseleave', $.proxy(this.cycle, this)) |
35 } | 36 } |
36 | 37 |
37 Carousel.prototype = { | 38 Carousel.prototype = { |
38 | 39 |
39 cycle: function (e) { | 40 cycle: function (e) { |
40 if (!e) this.paused = false | 41 if (!e) this.paused = false |
42 if (this.interval) clearInterval(this.interval); | |
41 this.options.interval | 43 this.options.interval |
42 && !this.paused | 44 && !this.paused |
43 && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) | 45 && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) |
44 return this | 46 return this |
45 } | 47 } |
46 | 48 |
49 , getActiveIndex: function () { | |
50 this.$active = this.$element.find('.item.active') | |
51 this.$items = this.$active.parent().children() | |
52 return this.$items.index(this.$active) | |
53 } | |
54 | |
47 , to: function (pos) { | 55 , to: function (pos) { |
48 var $active = this.$element.find('.item.active') | 56 var activeIndex = this.getActiveIndex() |
49 , children = $active.parent().children() | |
50 , activePos = children.index($active) | |
51 , that = this | 57 , that = this |
52 | 58 |
53 if (pos > (children.length - 1) || pos < 0) return | 59 if (pos > (this.$items.length - 1) || pos < 0) return |
54 | 60 |
55 if (this.sliding) { | 61 if (this.sliding) { |
56 return this.$element.one('slid', function () { | 62 return this.$element.one('slid', function () { |
57 that.to(pos) | 63 that.to(pos) |
58 }) | 64 }) |
59 } | 65 } |
60 | 66 |
61 if (activePos == pos) { | 67 if (activeIndex == pos) { |
62 return this.pause().cycle() | 68 return this.pause().cycle() |
63 } | 69 } |
64 | 70 |
65 return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos])) | 71 return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos])) |
66 } | 72 } |
67 | 73 |
68 , pause: function (e) { | 74 , pause: function (e) { |
69 if (!e) this.paused = true | 75 if (!e) this.paused = true |
70 if (this.$element.find('.next, .prev').length && $.support.transition.end) { | 76 if (this.$element.find('.next, .prev').length && $.support.transition.end) { |
71 this.$element.trigger($.support.transition.end) | 77 this.$element.trigger($.support.transition.end) |
72 this.cycle() | 78 this.cycle(true) |
73 } | 79 } |
74 clearInterval(this.interval) | 80 clearInterval(this.interval) |
75 this.interval = null | 81 this.interval = null |
76 return this | 82 return this |
77 } | 83 } |
101 | 107 |
102 $next = $next.length ? $next : this.$element.find('.item')[fallback]() | 108 $next = $next.length ? $next : this.$element.find('.item')[fallback]() |
103 | 109 |
104 e = $.Event('slide', { | 110 e = $.Event('slide', { |
105 relatedTarget: $next[0] | 111 relatedTarget: $next[0] |
112 , direction: direction | |
106 }) | 113 }) |
107 | 114 |
108 if ($next.hasClass('active')) return | 115 if ($next.hasClass('active')) return |
116 | |
117 if (this.$indicators.length) { | |
118 this.$indicators.find('.active').removeClass('active') | |
119 this.$element.one('slid', function () { | |
120 var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()]) | |
121 $nextIndicator && $nextIndicator.addClass('active') | |
122 }) | |
123 } | |
109 | 124 |
110 if ($.support.transition && this.$element.hasClass('slide')) { | 125 if ($.support.transition && this.$element.hasClass('slide')) { |
111 this.$element.trigger(e) | 126 this.$element.trigger(e) |
112 if (e.isDefaultPrevented()) return | 127 if (e.isDefaultPrevented()) return |
113 $next.addClass(type) | 128 $next.addClass(type) |
149 , options = $.extend({}, $.fn.carousel.defaults, typeof option == 'object' && option) | 164 , options = $.extend({}, $.fn.carousel.defaults, typeof option == 'object' && option) |
150 , action = typeof option == 'string' ? option : options.slide | 165 , action = typeof option == 'string' ? option : options.slide |
151 if (!data) $this.data('carousel', (data = new Carousel(this, options))) | 166 if (!data) $this.data('carousel', (data = new Carousel(this, options))) |
152 if (typeof option == 'number') data.to(option) | 167 if (typeof option == 'number') data.to(option) |
153 else if (action) data[action]() | 168 else if (action) data[action]() |
154 else if (options.interval) data.cycle() | 169 else if (options.interval) data.pause().cycle() |
155 }) | 170 }) |
156 } | 171 } |
157 | 172 |
158 $.fn.carousel.defaults = { | 173 $.fn.carousel.defaults = { |
159 interval: 5000 | 174 interval: 5000 |
172 } | 187 } |
173 | 188 |
174 /* CAROUSEL DATA-API | 189 /* CAROUSEL DATA-API |
175 * ================= */ | 190 * ================= */ |
176 | 191 |
177 $(document).on('click.carousel.data-api', '[data-slide]', function (e) { | 192 $(document).on('click.carousel.data-api', '[data-slide], [data-slide-to]', function (e) { |
178 var $this = $(this), href | 193 var $this = $(this), href |
179 , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 | 194 , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 |
180 , options = $.extend({}, $target.data(), $this.data()) | 195 , options = $.extend({}, $target.data(), $this.data()) |
196 , slideIndex | |
197 | |
181 $target.carousel(options) | 198 $target.carousel(options) |
199 | |
200 if (slideIndex = $this.attr('data-slide-to')) { | |
201 $target.data('carousel').pause().to(slideIndex).cycle() | |
202 } | |
203 | |
182 e.preventDefault() | 204 e.preventDefault() |
183 }) | 205 }) |
184 | 206 |
185 }(window.jQuery); | 207 }(window.jQuery); |