Merge pull request #2339 from lisa761/modal-dialogs

Closes dialogs when escape key is pressed
This commit is contained in:
Antonin Delpeuch 2020-03-01 11:33:43 +00:00 committed by GitHub
commit 9356b846b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -289,7 +289,6 @@ function SqlExporterDialog(options) {
this._elmts.cancelButton.click(function() { self._dismiss(); }); this._elmts.cancelButton.click(function() { self._dismiss(); });
this._elmts.downloadButton.click(function() { self._download(); }); this._elmts.downloadButton.click(function() { self._download(); });
this._elmts.downloadPreviewButton.click(function(evt) { self._previewDownload(); }); this._elmts.downloadPreviewButton.click(function(evt) { self._previewDownload(); });
this._configureUIFromOptionCode(options); this._configureUIFromOptionCode(options);
this._updateOptionCode(); this._updateOptionCode();
}; };

View File

@ -35,6 +35,13 @@ DialogSystem = {
_layers: [] _layers: []
}; };
var escapeKey = function(event) {
var level = DialogSystem._layers.length;
if (event.keyCode == 27) {
DialogSystem.dismissUntil(level - 1);
}
}
DialogSystem.showDialog = function(elmt, onCancel) { DialogSystem.showDialog = function(elmt, onCancel) {
var overlay = $('<div>&nbsp;</div>') var overlay = $('<div>&nbsp;</div>')
.addClass("dialog-overlay") .addClass("dialog-overlay")
@ -61,6 +68,8 @@ DialogSystem.showDialog = function(elmt, onCancel) {
var level = DialogSystem._layers.length; var level = DialogSystem._layers.length;
$(window).keydown(escapeKey);
return level; return level;
}; };
@ -90,6 +99,7 @@ DialogSystem.dismissUntil = function(level) {
for (var i = DialogSystem._layers.length - 1; i >= level; i--) { for (var i = DialogSystem._layers.length - 1; i >= level; i--) {
DialogSystem.dismissLevel(i); DialogSystem.dismissLevel(i);
} }
$(window).off('keydown', escapeKey);
DialogSystem._layers = DialogSystem._layers.slice(0, level); DialogSystem._layers = DialogSystem._layers.slice(0, level);
}; };