From 712b89ed4ebe71e44f2a7081be7ba372d8ca3f42 Mon Sep 17 00:00:00 2001
From: fat <jacobthornton@gmail.com>
Date: Sat, 17 Aug 2013 14:24:38 -0700
Subject: [PATCH] fixes #9362

---
 js/modal.js            |  4 +++-
 js/tests/unit/modal.js | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/js/modal.js b/js/modal.js
index 1a692e6af1..0b392d1615 100644
--- a/js/modal.js
+++ b/js/modal.js
@@ -25,7 +25,7 @@
 
   var Modal = function (element, options) {
     this.options   = options
-    this.$element  = $(element).on('click.dismiss.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this))
+    this.$element  = $(element)
     this.$backdrop =
     this.isShown   = null
 
@@ -54,6 +54,8 @@
 
     this.escape()
 
+    this.$element.on('click.dismiss.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this))
+
     this.backdrop(function () {
       var transition = $.support.transition && that.$element.hasClass('fade')
 
diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js
index 2c610d83d9..5755d27511 100644
--- a/js/tests/unit/modal.js
+++ b/js/tests/unit/modal.js
@@ -174,4 +174,23 @@ $(function () {
         })
         .modal("show")
     })
+
+    test("should close reopened modal with [data-dismiss=modal] click", function () {
+      stop()
+      $.support.transition = false
+      var div = $("<div id='modal-test'><div class='contents'><div id='close' data-dismiss='modal'></div></div></div>")
+      div
+        .bind("shown.bs.modal", function () {
+          $('#close').click()
+          ok(!$('#modal-test').is(":visible"), 'modal hidden')
+        })
+        .one("hidden.bs.modal", function() {
+          div.one('hidden.bs.modal', function () {
+            start()
+          }).modal("show")
+        })
+        .modal("show")
+
+      div.remove()
+    })
 })
-- 
GitLab