Prevent more accidental shortcut triggers
Do not allow browser keyboard shortcuts to trigger route functions, e.g. pressing Ctrl+P triggers printing in most browsers, but should not at the same time switch BRouter-Web to POI mode. This can be prevented by filtering for modifiers. In the same fashion, when modal dialogs or dropdowns are open it should not be possible to activate map functions in the background now. Finally, inhibit shortcuts in number input fields too, as found in the editable number input fields in the customize profile options. Previously only regular text input fields were protected. To make those checks easier to use, they are deduplicated and moved to Util.js.
This commit is contained in:
parent
fbd3d3d383
commit
08c8cfa8be
4 changed files with 38 additions and 20 deletions
30
js/Util.js
30
js/Util.js
|
|
@ -67,5 +67,35 @@ BR.Util = {
|
|||
}
|
||||
$el.remove();
|
||||
return env;
|
||||
},
|
||||
|
||||
keyboardShortcutsAllowed: function(keyEvent) {
|
||||
// Skip auto-repeating key events
|
||||
if (keyEvent.repeat) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Suppress shortcut handling when a text or number input field is focussed
|
||||
if (
|
||||
document.activeElement.type == 'number' ||
|
||||
document.activeElement.type == 'text' ||
|
||||
document.activeElement.type == 'textarea'
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only allow shortcuts without modifiers for now, to prevent triggering map functions
|
||||
// when browser shortcuts are triggered (e.g. Ctrl+P for print should not add a POI)
|
||||
if (keyEvent.ctrlKey || keyEvent.metaKey || keyEvent.altKey) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Do not allow shortcuts triggering actions behind Bootstrap's
|
||||
// modal dialogs or when dropdown menus are opened
|
||||
if ($('.modal.show').length || $('.dropdown.show').length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue