Commit ef5ac02b authored by Jacob Thornton's avatar Jacob Thornton
Browse files

allow prevent default for show and hide event in modal

parent f9f03d89
2 merge requests!2929Responsive video - from zurp's foundation,!28752.0.3 wip
Showing with 53 additions and 14 deletions
+53 -14
No preview for this file type
......@@ -41,13 +41,15 @@
, show: function () {
var that = this
, e = $.Event('show')
if (this.isShown) return
this.$element.trigger(e)
if (this.isShown || e.isDefaultPrevented()) return
$('body').addClass('modal-open')
this.isShown = true
this.$element.trigger('show')
escape.call(this)
backdrop.call(this, function () {
......@@ -74,18 +76,21 @@
, hide: function ( e ) {
e && e.preventDefault()
if (!this.isShown) return
var that = this
e = $.Event('hide')
this.$element.trigger(e)
if (!this.isShown || e.isDefaultPrevented()) return
this.isShown = false
$('body').removeClass('modal-open')
escape.call(this)
this.$element
.trigger('hide')
.removeClass('in')
this.$element.removeClass('in')
$.support.transition && this.$element.hasClass('fade') ?
hideWithTransition.call(this) :
......
......@@ -41,13 +41,15 @@
, show: function () {
var that = this
, e = $.Event('show')
if (this.isShown) return
this.$element.trigger(e)
if (this.isShown || e.isDefaultPrevented()) return
$('body').addClass('modal-open')
this.isShown = true
this.$element.trigger('show')
escape.call(this)
backdrop.call(this, function () {
......@@ -74,18 +76,21 @@
, hide: function ( e ) {
e && e.preventDefault()
if (!this.isShown) return
var that = this
e = $.Event('hide')
this.$element.trigger(e)
if (!this.isShown || e.isDefaultPrevented()) return
this.isShown = false
$('body').removeClass('modal-open')
escape.call(this)
this.$element
.trigger('hide')
.removeClass('in')
this.$element.removeClass('in')
$.support.transition && this.$element.hasClass('fade') ?
hideWithTransition.call(this) :
......
......@@ -29,6 +29,35 @@ $(function () {
.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 () {
stop()
$.support.transition = false
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment