Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Allow mulitple modal dialogs to work together by maintaing a stack of…
Browse files Browse the repository at this point in the history
… keydownHandlers, only the top-most of which are enabled.
  • Loading branch information
Ian Wehrman committed May 3, 2013
1 parent 3ec230c commit b79284a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/widgets/Dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ define(function (require, exports, module) {
DIALOG_ID_EXT_CHANGED = "ext-changed-dialog",
DIALOG_ID_EXT_DELETED = "ext-deleted-dialog",
DIALOG_ID_LIVE_DEVELOPMENT = "live-development-error-dialog";

var keydownListeners = [];

function _dismissDialog(dlg, buttonId) {
dlg.data("buttonId", buttonId);
Expand Down Expand Up @@ -177,6 +179,11 @@ define(function (require, exports, module) {

// Remove keydown event handler
window.document.body.removeEventListener("keydown", handleKeyDown, true);
keydownListeners.pop();
if (keydownListeners.length > 0) {
var previousListener = keydownListeners[keydownListeners.length - 1];
window.document.body.addEventListener("keydown", previousListener, true);
}
KeyBindingManager.setEnabled(true);
}).one("shown", function () {
// Set focus to the default button
Expand All @@ -187,6 +194,12 @@ define(function (require, exports, module) {
}

// Listen for dialog keyboard shortcuts
// if there is already a listener, remove it before adding the current listener
if (keydownListeners.length > 0) {
var previousListener = keydownListeners[keydownListeners.length - 1];
window.document.body.removeEventListener("keydown", previousListener, true);
}
keydownListeners.push(handleKeyDown);
window.document.body.addEventListener("keydown", handleKeyDown, true);
KeyBindingManager.setEnabled(false);
});
Expand Down

0 comments on commit b79284a

Please sign in to comment.