| 1 |
Drupal.node_edit_protection = {};
|
| 2 |
Drupal.node_edit_protection.confirmNavigate = function() {
|
| 3 |
return confirm(Drupal.t("You are about to leave a form that may contain changes that will not be saved.") + "\n\n" + Drupal.t("Click <OK> to continue anyway."));
|
| 4 |
};
|
| 5 |
|
| 6 |
Drupal.behaviors.nodeEditProtection = function(context) {
|
| 7 |
|
| 8 |
// If they leave an input field, assume they changed it.
|
| 9 |
$(".node-form :input").each(function() {
|
| 10 |
$(this).blur(function() {
|
| 11 |
$(window).attr('node_edit_protection_edited', true);
|
| 12 |
});
|
| 13 |
});
|
| 14 |
|
| 15 |
// Let all form submit buttons through
|
| 16 |
$(".node-form input[@type='submit']").each(function() {
|
| 17 |
$(this).addClass('node-edit-protection-processed');
|
| 18 |
$(this).click(function() {
|
| 19 |
$(window).attr('node_edit_protection_clicked', true);
|
| 20 |
});
|
| 21 |
});
|
| 22 |
|
| 23 |
// Catch all links and buttons
|
| 24 |
$("a, button, input[@type='submit']:not(.node-edit-protection-processed)").each(function() {
|
| 25 |
$(this).click(function() {
|
| 26 |
var edited = $(window).attr('node_edit_protection_edited');
|
| 27 |
if(edited) {
|
| 28 |
$(window).attr('node_edit_protection_clicked', true);
|
| 29 |
return Drupal.node_edit_protection.confirmNavigate();
|
| 30 |
}
|
| 31 |
});
|
| 32 |
});
|
| 33 |
|
| 34 |
$(window).unload(function() {
|
| 35 |
var clicked = $(this).attr('node_edit_protection_clicked');
|
| 36 |
var edited = $(this).attr('node_edit_protection_edited');
|
| 37 |
if(edited && !clicked) {
|
| 38 |
return Drupal.node_edit_protection.confirmNavigate();
|
| 39 |
}
|
| 40 |
});
|
| 41 |
};
|