]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Only close modal if escape was hit with keydown; fixes #13929 14000/head
authorHeinrich Fenkart <hnrch02@gmail.com>
Tue, 1 Jul 2014 03:50:31 +0000 (05:50 +0200)
committerHeinrich Fenkart <hnrch02@gmail.com>
Tue, 1 Jul 2014 03:50:31 +0000 (05:50 +0200)
js/modal.js
js/tests/unit/modal.js

index 29eedf117ad2ac1368ebba585e70fc247bf14a2c..92eff470ad1b553ca874ceeb943a39bcd85b0c96 100644 (file)
 
   Modal.prototype.escape = function () {
     if (this.isShown && this.options.keyboard) {
-      this.$element.on('keyup.dismiss.bs.modal', $.proxy(function (e) {
+      this.$element.on('keydown.dismiss.bs.modal', $.proxy(function (e) {
         e.which == 27 && this.hide()
       }, this))
     } else if (!this.isShown) {
-      this.$element.off('keyup.dismiss.bs.modal')
+      this.$element.off('keydown.dismiss.bs.modal')
     }
   }
 
index a415129aaef07cb8f9d2bc12415cc86899f70e43..5ee58616f1f697aa17da9d0c10bf470b882a286d 100644 (file)
@@ -164,6 +164,44 @@ $(function () {
       .bootstrapModal('show')
   })
 
+  test('should close modal when escape key is pressed via keydown', function () {
+    stop()
+
+    var div = $('<div id="modal-test"/>')
+    div
+      .on('shown.bs.modal', function () {
+        ok($('#modal-test').length, 'modal insterted into dom')
+        ok($('#modal-test').is(':visible'), 'modal visible')
+        div.trigger($.Event('keydown', { which: 27 }))
+
+        setTimeout(function () {
+          ok(!$('#modal-test').is(':visible'), 'modal hidden')
+          div.remove()
+          start()
+        }, 0)
+      })
+      .bootstrapModal('show')
+  })
+
+  test('should not close modal when escape key is pressed via keyup', function () {
+    stop()
+
+    var div = $('<div id="modal-test"/>')
+    div
+      .on('shown.bs.modal', function () {
+        ok($('#modal-test').length, 'modal insterted into dom')
+        ok($('#modal-test').is(':visible'), 'modal visible')
+        div.trigger($.Event('keyup', { which: 27 }))
+
+        setTimeout(function () {
+          ok($('#modal-test').is(':visible'), 'modal still visible')
+          div.remove()
+          start()
+        }, 0)
+      })
+      .bootstrapModal('show')
+  })
+
   test('should trigger hide event once when clicking outside of modal-content', function () {
     stop()
     $.support.transition = false