1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Disable keyboard handler when dialogs are open

This commit is contained in:
Nick O'Leary 2020-07-09 20:41:55 +01:00
parent 1df2f5e96a
commit 97b7479081
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
5 changed files with 38 additions and 6 deletions

View File

@ -159,7 +159,11 @@ RED.clipboard = (function() {
} }
} }
], ],
open: function( event, ui ) {
RED.keyboard.disable();
},
close: function(e) { close: function(e) {
RED.keyboard.enable();
if (popover) { if (popover) {
popover.close(true); popover.close(true);
currentPopoverError = null; currentPopoverError = null;

View File

@ -17,6 +17,8 @@ RED.keyboard = (function() {
var isMac = /Mac/i.test(window.navigator.platform); var isMac = /Mac/i.test(window.navigator.platform);
var handlersActive = true;
var handlers = {}; var handlers = {};
var partialState; var partialState;
@ -225,6 +227,9 @@ RED.keyboard = (function() {
} }
} }
d3.select(window).on("keydown",function() { d3.select(window).on("keydown",function() {
if (!handlersActive) {
return;
}
if (metaKeyCodes[d3.event.keyCode]) { if (metaKeyCodes[d3.event.keyCode]) {
return; return;
} }
@ -570,6 +575,13 @@ RED.keyboard = (function() {
return pane; return pane;
} }
function enable() {
handlersActive = true;
}
function disable() {
handlersActive = false;
}
return { return {
init: init, init: init,
add: addHandler, add: addHandler,
@ -579,7 +591,9 @@ RED.keyboard = (function() {
}, },
revertToDefault: revertToDefault, revertToDefault: revertToDefault,
formatKey: formatKey, formatKey: formatKey,
validateKey: validateKey validateKey: validateKey,
disable: disable,
enable: enable
} }
})(); })();

View File

@ -472,6 +472,8 @@ RED.library = (function() {
autoOpen: false, autoOpen: false,
width: 800, width: 800,
resizable: false, resizable: false,
open: function( event, ui ) { RED.keyboard.disable() },
close: function( event, ui ) { RED.keyboard.enable() },
classes: { classes: {
"ui-dialog": "red-ui-editor-dialog", "ui-dialog": "red-ui-editor-dialog",
"ui-dialog-titlebar-close": "hide", "ui-dialog-titlebar-close": "hide",
@ -556,9 +558,11 @@ RED.library = (function() {
} }
], ],
open: function(e) { open: function(e) {
RED.keyboard.disable();
$(this).parent().find(".ui-dialog-titlebar-close").hide(); $(this).parent().find(".ui-dialog-titlebar-close").hide();
}, },
close: function(e) { close: function(e) {
RED.keyboard.enable();
if (libraryEditor) { if (libraryEditor) {
libraryEditor.destroy(); libraryEditor.destroy();
libraryEditor = null; libraryEditor = null;

View File

@ -2263,6 +2263,12 @@ RED.projects = (function() {
autoOpen: false, autoOpen: false,
width: 600, width: 600,
resizable: false, resizable: false,
open: function(e) {
RED.keyboard.disable();
},
close: function(e) {
RED.keyboard.enable();
},
classes: { classes: {
"ui-dialog": "red-ui-editor-dialog", "ui-dialog": "red-ui-editor-dialog",
"ui-dialog-titlebar-close": "hide", "ui-dialog-titlebar-close": "hide",

View File

@ -39,7 +39,11 @@ RED.user = (function() {
closeOnEscape: !!opts.cancelable, closeOnEscape: !!opts.cancelable,
width: 600, width: 600,
resizable: false, resizable: false,
draggable: false draggable: false,
close: function( event, ui ) {
$("#node-dialog-login").dialog('destroy').remove();
RED.keyboard.enable()
}
}); });
$("#node-dialog-login-fields").empty(); $("#node-dialog-login-fields").empty();
@ -98,10 +102,10 @@ RED.user = (function() {
data: body data: body
}).done(function(data,textStatus,xhr) { }).done(function(data,textStatus,xhr) {
RED.settings.set("auth-tokens",data); RED.settings.set("auth-tokens",data);
$("#node-dialog-login").dialog('destroy').remove();
if (opts.updateMenu) { if (opts.updateMenu) {
updateUserMenu(); updateUserMenu();
} }
$("#node-dialog-login").dialog("close");
done(); done();
}).fail(function(jqXHR,textStatus,errorThrown) { }).fail(function(jqXHR,textStatus,errorThrown) {
RED.settings.remove("auth-tokens"); RED.settings.remove("auth-tokens");
@ -143,7 +147,8 @@ RED.user = (function() {
} }
if (opts.cancelable) { if (opts.cancelable) {
$("#node-dialog-login-cancel").button().on("click", function( event ) { $("#node-dialog-login-cancel").button().on("click", function( event ) {
$("#node-dialog-login").dialog('destroy').remove(); $("#node-dialog-login").dialog('close');
}); });
} }
@ -152,8 +157,7 @@ RED.user = (function() {
$("#node-dialog-login-image").load(function() { $("#node-dialog-login-image").load(function() {
dialog.dialog("open"); dialog.dialog("open");
}).attr("src",loginImageSrc); }).attr("src",loginImageSrc);
RED.keyboard.disable();
} }
}); });
} }