-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not call next when the carousel or the parent isn't visible #23524
Changes from all commits
768c17a
3f78769
fb2cfd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -842,4 +842,80 @@ $(function () { | |
}) | ||
$textArea.trigger(eventKeyDown) | ||
}) | ||
|
||
QUnit.test('Should not go to the next item when the carousel is not visible', function (assert) { | ||
assert.expect(2) | ||
var done = assert.async() | ||
var html = '<div id="myCarousel" class="carousel slide" data-interval="50" style="display: none;">' | ||
+ ' <div class="carousel-inner">' | ||
+ ' <div id="firstItem" class="carousel-item active">' | ||
+ ' <img alt="">' | ||
+ ' </div>' | ||
+ ' <div class="carousel-item">' | ||
+ ' <img alt="">' | ||
+ ' </div>' | ||
+ ' <div class="carousel-item">' | ||
+ ' <img alt="">' | ||
+ ' </div>' | ||
+ ' <a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>' | ||
+ ' <a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' | ||
+ '</div>' | ||
var $html = $(html) | ||
$html | ||
.appendTo('#qunit-fixture') | ||
.bootstrapCarousel() | ||
|
||
var $firstItem = $('#firstItem') | ||
setTimeout(function () { | ||
assert.ok($firstItem.hasClass('active')) | ||
$html | ||
.bootstrapCarousel('dispose') | ||
.attr('style', 'visibility: hidden;') | ||
.bootstrapCarousel() | ||
|
||
setTimeout(function () { | ||
assert.ok($firstItem.hasClass('active')) | ||
done() | ||
}, 80) | ||
}, 80) | ||
}) | ||
|
||
QUnit.test('Should not go to the next item when the parent of the carousel is not visible', function (assert) { | ||
assert.expect(2) | ||
var done = assert.async() | ||
var html = '<div id="parent" style="display: none;">' | ||
+ ' <div id="myCarousel" class="carousel slide" data-interval="50" style="display: none;">' | ||
+ ' <div class="carousel-inner">' | ||
+ ' <div id="firstItem" class="carousel-item active">' | ||
+ ' <img alt="">' | ||
+ ' </div>' | ||
+ ' <div class="carousel-item">' | ||
+ ' <img alt="">' | ||
+ ' </div>' | ||
+ ' <div class="carousel-item">' | ||
+ ' <img alt="">' | ||
+ ' </div>' | ||
+ ' <a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>' | ||
+ ' <a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' | ||
+ ' </div>' | ||
+ '</div>' | ||
var $html = $(html) | ||
$html.appendTo('#qunit-fixture') | ||
var $parent = $html.find('#parent') | ||
var $carousel = $html.find('#myCarousel') | ||
$carousel.bootstrapCarousel() | ||
var $firstItem = $('#firstItem') | ||
|
||
setTimeout(function () { | ||
assert.ok($firstItem.hasClass('active')) | ||
$carousel.bootstrapCarousel('dispose') | ||
$parent.attr('style', 'visibility: hidden;') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sets There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, looks good to me then. If you can't think of anything else, please merge :) |
||
$carousel.bootstrapCarousel() | ||
|
||
setTimeout(function () { | ||
assert.ok($firstItem.hasClass('active')) | ||
done() | ||
}, 80) | ||
}, 80) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure those 2 checks aren't identical?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the first one just check if the parent or the carousel don't have
display: none;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For more informations and precise explanations (with a better English 😆) : https://api.jquery.com/hidden-selector/