mirror of
https://github.com/twbs/bootstrap.git
synced 2024-11-29 11:24:18 +01:00
Don't fire show event if show is prevented because other element is still transitioning
Fixes #14844. Closes #14845.
This commit is contained in:
parent
a096c3f6f6
commit
e811a24118
@ -38,17 +38,21 @@
|
||||
Collapse.prototype.show = function () {
|
||||
if (this.transitioning || this.$element.hasClass('in')) return
|
||||
|
||||
var activesData
|
||||
var actives = this.$parent && this.$parent.find('> .panel').children('.in, .collapsing')
|
||||
|
||||
if (actives && actives.length) {
|
||||
activesData = actives.data('bs.collapse')
|
||||
if (activesData && activesData.transitioning) return
|
||||
}
|
||||
|
||||
var startEvent = $.Event('show.bs.collapse')
|
||||
this.$element.trigger(startEvent)
|
||||
if (startEvent.isDefaultPrevented()) return
|
||||
|
||||
var actives = this.$parent && this.$parent.find('> .panel').children('.in, .collapsing')
|
||||
|
||||
if (actives && actives.length) {
|
||||
var hasData = actives.data('bs.collapse')
|
||||
if (hasData && hasData.transitioning) return
|
||||
Plugin.call(actives, 'hide')
|
||||
hasData || actives.data('bs.collapse', null)
|
||||
activesData || actives.data('bs.collapse', null)
|
||||
}
|
||||
|
||||
var dimension = this.dimension()
|
||||
|
@ -263,4 +263,39 @@ $(function () {
|
||||
$target3.click()
|
||||
})
|
||||
|
||||
test('should not fire show event if show is prevented because other element is still transitioning', function () {
|
||||
stop()
|
||||
|
||||
var accordionHTML = '<div id="accordion">'
|
||||
+ '<div class="panel"/>'
|
||||
+ '<div class="panel"/>'
|
||||
+ '</div>'
|
||||
var showFired = false
|
||||
var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.panel')
|
||||
|
||||
var $target1 = $('<a data-toggle="collapse" href="#body1" data-parent="#accordion"/>').appendTo($groups.eq(0))
|
||||
|
||||
$('<div id="body1" class="collapse"/>')
|
||||
.appendTo($groups.eq(0))
|
||||
.on('show.bs.collapse', function () {
|
||||
showFired = true
|
||||
})
|
||||
|
||||
var $target2 = $('<a data-toggle="collapse" href="#body2" data-parent="#accordion"/>').appendTo($groups.eq(1))
|
||||
var $body2 = $('<div id="body2" class="collapse"/>').appendTo($groups.eq(1))
|
||||
|
||||
$target2.click()
|
||||
|
||||
$body2
|
||||
.toggleClass('in collapsing')
|
||||
.data('bs.collapse').transitioning = 1
|
||||
|
||||
$target1.click()
|
||||
|
||||
setTimeout(function () {
|
||||
ok(!showFired, 'show event didn\'t fire')
|
||||
start()
|
||||
}, 1)
|
||||
})
|
||||
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user