mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-27 07:14:36 +02:00
ensure hidePrevented.bs.modal
can be prevented (#31696)
This commit is contained in:
@@ -234,7 +234,7 @@ class Modal {
|
|||||||
const hideEventPrevented = $.Event(EVENT_HIDE_PREVENTED)
|
const hideEventPrevented = $.Event(EVENT_HIDE_PREVENTED)
|
||||||
|
|
||||||
$(this._element).trigger(hideEventPrevented)
|
$(this._element).trigger(hideEventPrevented)
|
||||||
if (hideEventPrevented.defaultPrevented) {
|
if (hideEventPrevented.isDefaultPrevented()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -976,4 +976,43 @@ $(function () {
|
|||||||
backdrop: 'static'
|
backdrop: 'static'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
QUnit.test('should get modal-static class when clicking outside of modal-content if backdrop = static', function (assert) {
|
||||||
|
assert.expect(1)
|
||||||
|
var done = assert.async()
|
||||||
|
var $modal = $('<div class="modal" data-backdrop="static"><div class="modal-dialog" style="transition-duration: 20ms;"/></div>').appendTo('#qunit-fixture')
|
||||||
|
|
||||||
|
$modal.on('shown.bs.modal', function () {
|
||||||
|
$modal.trigger('click')
|
||||||
|
setTimeout(function () {
|
||||||
|
assert.ok($modal.hasClass('modal-static'), 'has modal-static class')
|
||||||
|
done()
|
||||||
|
}, 0)
|
||||||
|
})
|
||||||
|
.bootstrapModal({
|
||||||
|
backdrop: 'static'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
QUnit.test('should not get modal-static class when clicking outside of modal-content if backdrop = static and event is prevented', function (assert) {
|
||||||
|
assert.expect(2)
|
||||||
|
var done = assert.async()
|
||||||
|
var $modal = $('<div class="modal" data-backdrop="static"><div class="modal-dialog" style="transition-duration: 20ms;"/></div>').appendTo('#qunit-fixture')
|
||||||
|
|
||||||
|
$modal.on('hidePrevented.bs.modal', function (e) {
|
||||||
|
assert.ok(true, 'should trigger hidePrevented event')
|
||||||
|
e.preventDefault()
|
||||||
|
})
|
||||||
|
|
||||||
|
$modal.on('shown.bs.modal', function () {
|
||||||
|
$modal.trigger('click')
|
||||||
|
setTimeout(function () {
|
||||||
|
assert.notOk($modal.hasClass('modal-static'), 'should not have modal-static class')
|
||||||
|
done()
|
||||||
|
}, 0)
|
||||||
|
})
|
||||||
|
.bootstrapModal({
|
||||||
|
backdrop: 'static'
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user