Fix keyboard shortcuts such as Ctrl+S giving unnecessary warning

This commit is contained in:
kapito 2016-04-27 09:46:12 +01:00 committed by Matt Westcott
parent 15e5225d4b
commit cc7e6196c5
2 changed files with 10 additions and 1 deletions

View file

@ -52,6 +52,9 @@ function initTagField(id, autocompleteUrl) {
* - alwaysDirty - When set to true the form will always be considered dirty,
* prompting the user even when nothing has been changed.
*/
var canDirtyFormCheck = true;
function enableDirtyFormCheck(formSelector, options) {
var $form = $(formSelector);
var $ignoredButtons = $form.find(
@ -72,7 +75,11 @@ function enableDirtyFormCheck(formSelector, options) {
}
});
if (!triggeredByIgnoredButton && (alwaysDirty || $form.serialize() != initialData)) {
if (!canDirtyFormCheck) {
triggeredByIgnoredButton = true;
}
if (canDirtyFormCheck && !triggeredByIgnoredButton && (alwaysDirty || $form.serialize() != initialData)) {
event.returnValue = confirmationMessage;
return confirmationMessage;
}

View file

@ -366,11 +366,13 @@ function initCollapsibleBlocks() {
function initKeyboardShortcuts() {
Mousetrap.bind(['mod+p'], function(e) {
canDirtyFormCheck = false;
$('.action-preview').trigger('click');
return false;
});
Mousetrap.bind(['mod+s'], function(e) {
canDirtyFormCheck = false;
$('.action-save').trigger('click');
return false;
});