Add a disableDirtyFormCheck function so we're not relying on sharing variables between scripts

This commit is contained in:
Matt Westcott 2016-04-28 13:08:27 +01:00
parent cc7e6196c5
commit 4c96595d90
2 changed files with 8 additions and 8 deletions

View file

@ -53,7 +53,7 @@ function initTagField(id, autocompleteUrl) {
* prompting the user even when nothing has been changed.
*/
var canDirtyFormCheck = true;
var dirtyFormCheckIsActive = true;
function enableDirtyFormCheck(formSelector, options) {
var $form = $(formSelector);
@ -75,17 +75,17 @@ function enableDirtyFormCheck(formSelector, options) {
}
});
if (!canDirtyFormCheck) {
triggeredByIgnoredButton = true;
}
if (canDirtyFormCheck && !triggeredByIgnoredButton && (alwaysDirty || $form.serialize() != initialData)) {
if (dirtyFormCheckIsActive && !triggeredByIgnoredButton && (alwaysDirty || $form.serialize() != initialData)) {
event.returnValue = confirmationMessage;
return confirmationMessage;
}
});
}
function disableDirtyFormCheck() {
dirtyFormCheckIsActive = false;
}
$(function() {
// Add class to the body from which transitions may be hung so they don't appear to transition as the page loads
$('body').addClass('ready');

View file

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