diff --git a/js/modal.js b/js/modal.js index 7433de4c8e..43e961baa9 100644 --- a/js/modal.js +++ b/js/modal.js @@ -160,11 +160,12 @@ this.$backdrop = $('
') .appendTo(document.body) - this.$backdrop.click( - this.options.backdrop == 'static' ? - $.proxy(this.$element[0].focus, this.$element[0]) - : $.proxy(this.hide, this) - ) + this.$element.on('click', $.proxy(function (e) { + if (e.target !== e.currentTarget) return + this.options.backdrop == 'static' + ? this.$element[0].focus.call(this.$element[0]) + : this.hide.call(this) + }, this)) if (doAnimate) this.$backdrop[0].offsetWidth // force reflow diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index 9187b5e23a..90762ea901 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -134,4 +134,23 @@ $(function () { }) .modal("show") }) + + test("should close modal when clicking outside of modal-content", function () { + stop() + $.support.transition = false + var div = $("