mirror of
https://github.com/twbs/bootstrap.git
synced 2022-11-09 12:25:43 -05:00
fixes #9111
This commit is contained in:
parent
dbed9da774
commit
a4f0e8d37a
4 changed files with 166 additions and 143 deletions
3
dist/js/bootstrap.js
vendored
3
dist/js/bootstrap.js
vendored
|
@ -925,6 +925,7 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") }
|
||||||
this.$element
|
this.$element
|
||||||
.removeClass('in')
|
.removeClass('in')
|
||||||
.attr('aria-hidden', true)
|
.attr('aria-hidden', true)
|
||||||
|
.off('click.dismiss.modal')
|
||||||
|
|
||||||
$.support.transition && this.$element.hasClass('fade') ?
|
$.support.transition && this.$element.hasClass('fade') ?
|
||||||
this.$element
|
this.$element
|
||||||
|
@ -977,7 +978,7 @@ if (!jQuery) { throw new Error("Bootstrap requires jQuery") }
|
||||||
this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
|
this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
|
||||||
.appendTo(document.body)
|
.appendTo(document.body)
|
||||||
|
|
||||||
this.$element.on('click', $.proxy(function (e) {
|
this.$element.on('click.dismiss.modal', $.proxy(function (e) {
|
||||||
if (e.target !== e.currentTarget) return
|
if (e.target !== e.currentTarget) return
|
||||||
this.options.backdrop == 'static'
|
this.options.backdrop == 'static'
|
||||||
? this.$element[0].focus.call(this.$element[0])
|
? this.$element[0].focus.call(this.$element[0])
|
||||||
|
|
2
dist/js/bootstrap.min.js
vendored
2
dist/js/bootstrap.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -103,6 +103,7 @@
|
||||||
this.$element
|
this.$element
|
||||||
.removeClass('in')
|
.removeClass('in')
|
||||||
.attr('aria-hidden', true)
|
.attr('aria-hidden', true)
|
||||||
|
.off('click.dismiss.modal')
|
||||||
|
|
||||||
$.support.transition && this.$element.hasClass('fade') ?
|
$.support.transition && this.$element.hasClass('fade') ?
|
||||||
this.$element
|
this.$element
|
||||||
|
@ -155,7 +156,7 @@
|
||||||
this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
|
this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
|
||||||
.appendTo(document.body)
|
.appendTo(document.body)
|
||||||
|
|
||||||
this.$element.on('click', $.proxy(function (e) {
|
this.$element.on('click.dismiss.modal', $.proxy(function (e) {
|
||||||
if (e.target !== e.currentTarget) return
|
if (e.target !== e.currentTarget) return
|
||||||
this.options.backdrop == 'static'
|
this.options.backdrop == 'static'
|
||||||
? this.$element[0].focus.call(this.$element[0])
|
? this.$element[0].focus.call(this.$element[0])
|
||||||
|
|
|
@ -1,156 +1,177 @@
|
||||||
$(function () {
|
$(function () {
|
||||||
|
|
||||||
module("modal")
|
module("modal")
|
||||||
|
|
||||||
test("should provide no conflict", function () {
|
test("should provide no conflict", function () {
|
||||||
var modal = $.fn.modal.noConflict()
|
var modal = $.fn.modal.noConflict()
|
||||||
ok(!$.fn.modal, 'modal was set back to undefined (org value)')
|
ok(!$.fn.modal, 'modal was set back to undefined (org value)')
|
||||||
$.fn.modal = modal
|
$.fn.modal = modal
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should be defined on jquery object", function () {
|
test("should be defined on jquery object", function () {
|
||||||
var div = $("<div id='modal-test'></div>")
|
var div = $("<div id='modal-test'></div>")
|
||||||
ok(div.modal, 'modal method is defined')
|
ok(div.modal, 'modal method is defined')
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should return element", function () {
|
test("should return element", function () {
|
||||||
var div = $("<div id='modal-test'></div>")
|
var div = $("<div id='modal-test'></div>")
|
||||||
ok(div.modal() == div, 'document.body returned')
|
ok(div.modal() == div, 'document.body returned')
|
||||||
$('#modal-test').remove()
|
$('#modal-test').remove()
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should expose defaults var for settings", function () {
|
test("should expose defaults var for settings", function () {
|
||||||
ok($.fn.modal.Constructor.DEFAULTS, 'default object exposed')
|
ok($.fn.modal.Constructor.DEFAULTS, 'default object exposed')
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should insert into dom when show method is called", function () {
|
test("should insert into dom when show method is called", function () {
|
||||||
stop()
|
stop()
|
||||||
$.support.transition = false
|
$.support.transition = false
|
||||||
$("<div id='modal-test'></div>")
|
$("<div id='modal-test'></div>")
|
||||||
.on("shown.bs.modal", function () {
|
.on("shown.bs.modal", function () {
|
||||||
ok($('#modal-test').length, 'modal inserted into dom')
|
ok($('#modal-test').length, 'modal inserted into dom')
|
||||||
$(this).remove()
|
$(this).remove()
|
||||||
start()
|
start()
|
||||||
})
|
})
|
||||||
.modal("show")
|
.modal("show")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should fire show event", function () {
|
test("should fire show event", function () {
|
||||||
stop()
|
stop()
|
||||||
$.support.transition = false
|
$.support.transition = false
|
||||||
$("<div id='modal-test'></div>")
|
$("<div id='modal-test'></div>")
|
||||||
.on("show.bs.modal", function () {
|
.on("show.bs.modal", function () {
|
||||||
ok(true, "show was called")
|
ok(true, "show was called")
|
||||||
})
|
})
|
||||||
.on("shown.bs.modal", function () {
|
.on("shown.bs.modal", function () {
|
||||||
$(this).remove()
|
$(this).remove()
|
||||||
start()
|
start()
|
||||||
})
|
})
|
||||||
.modal("show")
|
.modal("show")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should not fire shown when default prevented", function () {
|
test("should not fire shown when default prevented", function () {
|
||||||
stop()
|
stop()
|
||||||
$.support.transition = false
|
$.support.transition = false
|
||||||
$("<div id='modal-test'></div>")
|
$("<div id='modal-test'></div>")
|
||||||
.on("show.bs.modal", function (e) {
|
.on("show.bs.modal", function (e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
ok(true, "show was called")
|
ok(true, "show was called")
|
||||||
start()
|
start()
|
||||||
})
|
})
|
||||||
.on("shown.bs.modal", function () {
|
.on("shown.bs.modal", function () {
|
||||||
ok(false, "shown was called")
|
ok(false, "shown was called")
|
||||||
})
|
})
|
||||||
.modal("show")
|
.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
|
||||||
|
|
||||||
$("<div id='modal-test'></div>")
|
$("<div id='modal-test'></div>")
|
||||||
.on("shown.bs.modal", function () {
|
.on("shown.bs.modal", function () {
|
||||||
ok($('#modal-test').is(":visible"), 'modal visible')
|
ok($('#modal-test').is(":visible"), 'modal visible')
|
||||||
ok($('#modal-test').length, 'modal inserted into dom')
|
ok($('#modal-test').length, 'modal inserted into dom')
|
||||||
$(this).modal("hide")
|
$(this).modal("hide")
|
||||||
})
|
})
|
||||||
.on("hidden.bs.modal", function() {
|
.on("hidden.bs.modal", function() {
|
||||||
ok(!$('#modal-test').is(":visible"), 'modal hidden')
|
ok(!$('#modal-test').is(":visible"), 'modal hidden')
|
||||||
$('#modal-test').remove()
|
$('#modal-test').remove()
|
||||||
start()
|
start()
|
||||||
})
|
})
|
||||||
.modal("show")
|
.modal("show")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should toggle when toggle is called", function () {
|
test("should toggle when toggle is called", function () {
|
||||||
stop()
|
stop()
|
||||||
$.support.transition = false
|
$.support.transition = false
|
||||||
var div = $("<div id='modal-test'></div>")
|
var div = $("<div id='modal-test'></div>")
|
||||||
div
|
div
|
||||||
.on("shown.bs.modal", function () {
|
.on("shown.bs.modal", function () {
|
||||||
ok($('#modal-test').is(":visible"), 'modal visible')
|
ok($('#modal-test').is(":visible"), 'modal visible')
|
||||||
ok($('#modal-test').length, 'modal inserted into dom')
|
ok($('#modal-test').length, 'modal inserted into dom')
|
||||||
div.modal("toggle")
|
div.modal("toggle")
|
||||||
})
|
})
|
||||||
.on("hidden.bs.modal", function() {
|
.on("hidden.bs.modal", function() {
|
||||||
ok(!$('#modal-test').is(":visible"), 'modal hidden')
|
ok(!$('#modal-test').is(":visible"), 'modal hidden')
|
||||||
div.remove()
|
div.remove()
|
||||||
start()
|
start()
|
||||||
})
|
})
|
||||||
.modal("toggle")
|
.modal("toggle")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should remove from dom when click [data-dismiss=modal]", function () {
|
test("should remove from dom when click [data-dismiss=modal]", function () {
|
||||||
stop()
|
stop()
|
||||||
$.support.transition = false
|
$.support.transition = false
|
||||||
var div = $("<div id='modal-test'><span class='close' data-dismiss='modal'></span></div>")
|
var div = $("<div id='modal-test'><span class='close' data-dismiss='modal'></span></div>")
|
||||||
div
|
div
|
||||||
.on("shown.bs.modal", function () {
|
.on("shown.bs.modal", function () {
|
||||||
ok($('#modal-test').is(":visible"), 'modal visible')
|
ok($('#modal-test').is(":visible"), 'modal visible')
|
||||||
ok($('#modal-test').length, 'modal inserted into dom')
|
ok($('#modal-test').length, 'modal inserted into dom')
|
||||||
div.find('.close').click()
|
div.find('.close').click()
|
||||||
})
|
})
|
||||||
.on("hidden.bs.modal", function() {
|
.on("hidden.bs.modal", function() {
|
||||||
ok(!$('#modal-test').is(":visible"), 'modal hidden')
|
ok(!$('#modal-test').is(":visible"), 'modal hidden')
|
||||||
div.remove()
|
div.remove()
|
||||||
start()
|
start()
|
||||||
})
|
})
|
||||||
.modal("toggle")
|
.modal("toggle")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should allow modal close with 'backdrop:false'", function () {
|
test("should allow modal close with 'backdrop:false'", function () {
|
||||||
stop()
|
stop()
|
||||||
$.support.transition = false
|
$.support.transition = false
|
||||||
var div = $("<div>", { id: 'modal-test', "data-backdrop": false })
|
var div = $("<div>", { id: 'modal-test', "data-backdrop": false })
|
||||||
div
|
div
|
||||||
.on("shown.bs.modal", function () {
|
.on("shown.bs.modal", function () {
|
||||||
ok($('#modal-test').is(":visible"), 'modal visible')
|
ok($('#modal-test').is(":visible"), 'modal visible')
|
||||||
div.modal("hide")
|
div.modal("hide")
|
||||||
})
|
})
|
||||||
.on("hidden.bs.modal", function() {
|
.on("hidden.bs.modal", function() {
|
||||||
ok(!$('#modal-test').is(":visible"), 'modal hidden')
|
ok(!$('#modal-test').is(":visible"), 'modal hidden')
|
||||||
div.remove()
|
div.remove()
|
||||||
start()
|
start()
|
||||||
})
|
})
|
||||||
.modal("show")
|
.modal("show")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should close modal when clicking outside of modal-content", function () {
|
test("should close modal when clicking outside of modal-content", function () {
|
||||||
stop()
|
stop()
|
||||||
$.support.transition = false
|
$.support.transition = false
|
||||||
var div = $("<div id='modal-test'><div class='contents'></div></div>")
|
var div = $("<div id='modal-test'><div class='contents'></div></div>")
|
||||||
div
|
div
|
||||||
.bind("shown.bs.modal", function () {
|
.bind("shown.bs.modal", function () {
|
||||||
ok($('#modal-test').length, 'modal insterted into dom')
|
ok($('#modal-test').length, 'modal insterted into dom')
|
||||||
$('.contents').click()
|
$('.contents').click()
|
||||||
ok($('#modal-test').is(":visible"), 'modal visible')
|
ok($('#modal-test').is(":visible"), 'modal visible')
|
||||||
$('#modal-test').click()
|
$('#modal-test').click()
|
||||||
})
|
})
|
||||||
.bind("hidden.bs.modal", function() {
|
.bind("hidden.bs.modal", function() {
|
||||||
ok(!$('#modal-test').is(":visible"), 'modal hidden')
|
ok(!$('#modal-test').is(":visible"), 'modal hidden')
|
||||||
div.remove()
|
div.remove()
|
||||||
start()
|
start()
|
||||||
})
|
})
|
||||||
.modal("show")
|
.modal("show")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("should trigger hide event once when clicking outside of modal-content", function () {
|
||||||
|
stop()
|
||||||
|
$.support.transition = false
|
||||||
|
var div = $("<div id='modal-test'><div class='contents'></div></div>")
|
||||||
|
var triggered
|
||||||
|
div
|
||||||
|
.bind("shown.bs.modal", function () {
|
||||||
|
triggered = 0
|
||||||
|
$('#modal-test').click()
|
||||||
|
})
|
||||||
|
.one("hidden.bs.modal", function() {
|
||||||
|
div.modal("show")
|
||||||
|
})
|
||||||
|
.bind("hide.bs.modal", function () {
|
||||||
|
triggered += 1
|
||||||
|
ok(triggered === 1, 'modal hide triggered once')
|
||||||
|
start()
|
||||||
|
})
|
||||||
|
.modal("show")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue