[Dialogs] Close dialogs by pressing the ESC key

Issue #1197
This commit is contained in:
Colm Seale
2016-12-29 00:06:47 +00:00
parent 94319df69b
commit bee22311a7
3 changed files with 62 additions and 3 deletions

View File

@ -35,11 +35,15 @@ define(
* @memberof platform/commonUI/dialog
* @constructor
*/
function DialogService(overlayService, $q, $log) {
function DialogService(overlayService, $q, $log, $document) {
this.overlayService = overlayService;
this.$q = $q;
this.$log = $log;
this.activeOverlay = undefined;
this.findBody = function () {
return $document.find('body');
};
}
/**
@ -76,13 +80,22 @@ define(
// Cancel or X button click
function cancel() {
deferred.reject();
self.findBody().off('keydown', handleEscKeydown);
self.dismissOverlay(overlay);
}
function handleEscKeydown(event){
if (event.keyCode === 27) {
cancel();
}
}
// Add confirm/cancel callbacks
model.confirm = confirm;
model.cancel = cancel;
this.findBody().on('keydown', handleEscKeydown);
if (this.canShowDialog(model)) {
// Add the overlay using the OverlayService, which
// will handle actual insertion into the DOM