Skip to content

Commit

Permalink
Merge pull request #13173 from twbs/fat-9461
Browse files Browse the repository at this point in the history
fixes #9461 - Make carousel ignore non-items in carousel-inner
  • Loading branch information
fat committed Mar 25, 2014
2 parents 6f6bce5 + ce01344 commit 30b14cd
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re

Carousel.prototype.getActiveIndex = function () {
this.$active = this.$element.find('.item.active')
this.$items = this.$active.parent().children()
this.$items = this.$active.parent().children('.item')

return this.$items.index(this.$active)
}
Expand Down
2 changes: 1 addition & 1 deletion dist/js/bootstrap.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/assets/js/raw-files.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/dist/js/bootstrap.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

Carousel.prototype.getActiveIndex = function () {
this.$active = this.$element.find('.item.active')
this.$items = this.$active.parent().children()
this.$items = this.$active.parent().children('.item')

return this.$items.index(this.$active)
}
Expand Down
28 changes: 28 additions & 0 deletions js/tests/unit/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,32 @@ $(function () {
ok($('#myCarousel').data('bs.carousel').options.interval === false, 'data attribute has higher priority than default options')
$('#myCarousel').remove()
})

test('should skip over non-items', function () {
$.support.transition = false

var $template = $(
'<div id="myCarousel" class="carousel" data-interval="1814">'
+ '<div class="carousel-inner">'
+ '<div class="item active">'
+ '<img alt="">'
+ '</div>'
+ '<script type="text/x-metamorph" id="thingy"></script>'
+ '<div class="item">'
+ '<img alt="">'
+ '</div>'
+ '<div class="item">'
+ '</div>'
+ '</div>'
+ '</div>'
)

$template.carousel()

equal($template.find('.item')[0], $template.find('.active')[0], 'the first carousel item should be active')

$template.carousel(1)

equal($template.find('.item')[1], $template.find('.active')[0], 'the second carousel item should be active')
})
})

0 comments on commit 30b14cd

Please sign in to comment.