Commit 55e8cd7d authored by TravisCarden's avatar TravisCarden

Issue #1862084 by TravisCarden: Added Prompt user to save changes before leaving the page.

parent e4f38f8d
......@@ -35,4 +35,25 @@
}
};
/**
* Prompts the user if they try to leave the page with unsaved changes.
*
* Note: Auto-checked items are not considered unsaved changes for the
* purcpose of this feature.
*/
Drupal.behaviors.checklistapiPromptBeforeLeaving = {
getFormState: function () {
return $('#checklistapi-checklist-form :checkbox.checklistapi-item').serializeArray().toString();
},
attach: function () {
var beginningState = this.getFormState();
$(window).bind('beforeunload', function () {
var endingState = Drupal.behaviors.checklistapiPromptBeforeLeaving.getFormState();
if (beginningState !== endingState) {
return Drupal.t('Your changes will be lost if you leave the page without saving.');
}
});
}
};
})(jQuery);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment