mirror of
https://github.com/twbs/bootstrap.git
synced 2025-06-06 00:03:01 -04:00
allow prevent default for show and hide event in modal
This commit is contained in:
parent
f9f03d8976
commit
ef5ac02b69
Binary file not shown.
19
docs/assets/js/bootstrap-modal.js
vendored
19
docs/assets/js/bootstrap-modal.js
vendored
@ -41,13 +41,15 @@
|
|||||||
|
|
||||||
, show: function () {
|
, show: function () {
|
||||||
var that = this
|
var that = this
|
||||||
|
, e = $.Event('show')
|
||||||
|
|
||||||
if (this.isShown) return
|
this.$element.trigger(e)
|
||||||
|
|
||||||
|
if (this.isShown || e.isDefaultPrevented()) return
|
||||||
|
|
||||||
$('body').addClass('modal-open')
|
$('body').addClass('modal-open')
|
||||||
|
|
||||||
this.isShown = true
|
this.isShown = true
|
||||||
this.$element.trigger('show')
|
|
||||||
|
|
||||||
escape.call(this)
|
escape.call(this)
|
||||||
backdrop.call(this, function () {
|
backdrop.call(this, function () {
|
||||||
@ -74,18 +76,21 @@
|
|||||||
, hide: function ( e ) {
|
, hide: function ( e ) {
|
||||||
e && e.preventDefault()
|
e && e.preventDefault()
|
||||||
|
|
||||||
if (!this.isShown) return
|
|
||||||
|
|
||||||
var that = this
|
var that = this
|
||||||
|
|
||||||
|
e = $.Event('hide')
|
||||||
|
|
||||||
|
this.$element.trigger(e)
|
||||||
|
|
||||||
|
if (!this.isShown || e.isDefaultPrevented()) return
|
||||||
|
|
||||||
this.isShown = false
|
this.isShown = false
|
||||||
|
|
||||||
$('body').removeClass('modal-open')
|
$('body').removeClass('modal-open')
|
||||||
|
|
||||||
escape.call(this)
|
escape.call(this)
|
||||||
|
|
||||||
this.$element
|
this.$element.removeClass('in')
|
||||||
.trigger('hide')
|
|
||||||
.removeClass('in')
|
|
||||||
|
|
||||||
$.support.transition && this.$element.hasClass('fade') ?
|
$.support.transition && this.$element.hasClass('fade') ?
|
||||||
hideWithTransition.call(this) :
|
hideWithTransition.call(this) :
|
||||||
|
19
js/bootstrap-modal.js
vendored
19
js/bootstrap-modal.js
vendored
@ -41,13 +41,15 @@
|
|||||||
|
|
||||||
, show: function () {
|
, show: function () {
|
||||||
var that = this
|
var that = this
|
||||||
|
, e = $.Event('show')
|
||||||
|
|
||||||
if (this.isShown) return
|
this.$element.trigger(e)
|
||||||
|
|
||||||
|
if (this.isShown || e.isDefaultPrevented()) return
|
||||||
|
|
||||||
$('body').addClass('modal-open')
|
$('body').addClass('modal-open')
|
||||||
|
|
||||||
this.isShown = true
|
this.isShown = true
|
||||||
this.$element.trigger('show')
|
|
||||||
|
|
||||||
escape.call(this)
|
escape.call(this)
|
||||||
backdrop.call(this, function () {
|
backdrop.call(this, function () {
|
||||||
@ -74,18 +76,21 @@
|
|||||||
, hide: function ( e ) {
|
, hide: function ( e ) {
|
||||||
e && e.preventDefault()
|
e && e.preventDefault()
|
||||||
|
|
||||||
if (!this.isShown) return
|
|
||||||
|
|
||||||
var that = this
|
var that = this
|
||||||
|
|
||||||
|
e = $.Event('hide')
|
||||||
|
|
||||||
|
this.$element.trigger(e)
|
||||||
|
|
||||||
|
if (!this.isShown || e.isDefaultPrevented()) return
|
||||||
|
|
||||||
this.isShown = false
|
this.isShown = false
|
||||||
|
|
||||||
$('body').removeClass('modal-open')
|
$('body').removeClass('modal-open')
|
||||||
|
|
||||||
escape.call(this)
|
escape.call(this)
|
||||||
|
|
||||||
this.$element
|
this.$element.removeClass('in')
|
||||||
.trigger('hide')
|
|
||||||
.removeClass('in')
|
|
||||||
|
|
||||||
$.support.transition && this.$element.hasClass('fade') ?
|
$.support.transition && this.$element.hasClass('fade') ?
|
||||||
hideWithTransition.call(this) :
|
hideWithTransition.call(this) :
|
||||||
|
29
js/tests/unit/bootstrap-modal.js
vendored
29
js/tests/unit/bootstrap-modal.js
vendored
@ -29,6 +29,35 @@ $(function () {
|
|||||||
.modal("show")
|
.modal("show")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("should fire show event", function () {
|
||||||
|
stop()
|
||||||
|
$.support.transition = false
|
||||||
|
$("<div id='modal-test'></div>")
|
||||||
|
.bind("show", function () {
|
||||||
|
ok(true, "show was called")
|
||||||
|
})
|
||||||
|
.bind("shown", function () {
|
||||||
|
$(this).remove()
|
||||||
|
start()
|
||||||
|
})
|
||||||
|
.modal("show")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("should not fire shown when default prevented", function () {
|
||||||
|
stop()
|
||||||
|
$.support.transition = false
|
||||||
|
$("<div id='modal-test'></div>")
|
||||||
|
.bind("show", function (e) {
|
||||||
|
e.preventDefault()
|
||||||
|
ok(true, "show was called")
|
||||||
|
start()
|
||||||
|
})
|
||||||
|
.bind("shown", function () {
|
||||||
|
ok(false, "shown was called")
|
||||||
|
})
|
||||||
|
.modal("show")
|
||||||
|
})
|
||||||
|
|
||||||
test("should hide modal when hide is called", function () {
|
test("should hide modal when hide is called", function () {
|
||||||
stop()
|
stop()
|
||||||
$.support.transition = false
|
$.support.transition = false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user