|
289 | 289 |
|
290 | 290 | var Carousel = function (element, options) { |
291 | 291 | this.$element = $(element) |
| 292 | + this.$indicators = this.$element.find('.carousel-indicators') |
292 | 293 | this.options = options |
293 | 294 | this.options.pause == 'hover' && this.$element |
294 | 295 | .on('mouseenter', $.proxy(this.pause, this)) |
|
305 | 306 | return this |
306 | 307 | } |
307 | 308 |
|
| 309 | + , getActiveIndex: function () { |
| 310 | + this.$active = this.$element.find('.item.active') |
| 311 | + this.$items = this.$active.parent().children() |
| 312 | + return this.$items.index(this.$active) |
| 313 | + } |
| 314 | + |
308 | 315 | , to: function (pos) { |
309 | | - var $active = this.$element.find('.item.active') |
310 | | - , children = $active.parent().children() |
311 | | - , activePos = children.index($active) |
| 316 | + var activeIndex = this.getActiveIndex() |
312 | 317 | , that = this |
313 | 318 |
|
314 | | - if (pos > (children.length - 1) || pos < 0) return |
| 319 | + if (pos > (this.$items.length - 1) || pos < 0) return |
315 | 320 |
|
316 | 321 | if (this.sliding) { |
317 | 322 | return this.$element.one('slid', function () { |
318 | 323 | that.to(pos) |
319 | 324 | }) |
320 | 325 | } |
321 | 326 |
|
322 | | - if (activePos == pos) { |
| 327 | + if (activeIndex == pos) { |
323 | 328 | return this.pause().cycle() |
324 | 329 | } |
325 | 330 |
|
326 | | - return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos])) |
| 331 | + return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos])) |
327 | 332 | } |
328 | 333 |
|
329 | 334 | , pause: function (e) { |
|
353 | 358 | , isCycling = this.interval |
354 | 359 | , direction = type == 'next' ? 'left' : 'right' |
355 | 360 | , fallback = type == 'next' ? 'first' : 'last' |
| 361 | + , $nextIndicator |
356 | 362 | , that = this |
357 | 363 | , e |
358 | 364 |
|
|
368 | 374 |
|
369 | 375 | if ($next.hasClass('active')) return |
370 | 376 |
|
| 377 | + if (this.$indicators.length) { |
| 378 | + this.$indicators.find('.active').removeClass('active') |
| 379 | + this.$element.one('slid', function () { |
| 380 | + $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()]) |
| 381 | + $nextIndicator && $nextIndicator.addClass('active') |
| 382 | + }) |
| 383 | + } |
| 384 | + |
371 | 385 | if ($.support.transition && this.$element.hasClass('slide')) { |
372 | 386 | this.$element.trigger(e) |
373 | 387 | if (e.isDefaultPrevented()) return |
|
832 | 846 | that.$element.appendTo(document.body) //don't move modals dom position |
833 | 847 | } |
834 | 848 |
|
835 | | - that.$element |
836 | | - .show() |
| 849 | + that.$element.show() |
837 | 850 |
|
838 | 851 | if (transition) { |
839 | 852 | that.$element[0].offsetWidth // force reflow |
|
0 commit comments