Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.773 diff -u -p -r1.773 common.inc --- includes/common.inc 24 Jun 2008 22:09:52 -0000 1.773 +++ includes/common.inc 27 Jun 2008 12:48:08 -0000 @@ -2212,6 +2212,7 @@ function drupal_add_tabledrag($table_id, static $js_added = FALSE; if (!$js_added) { drupal_add_js('misc/tabledrag.js', 'core'); + drupal_add_js('misc/unsaved.js', 'core'); $js_added = TRUE; } Index: misc/tabledrag.js =================================================================== RCS file: /cvs/drupal/drupal/misc/tabledrag.js,v retrieving revision 1.18 diff -u -p -r1.18 tabledrag.js --- misc/tabledrag.js 24 Jun 2008 16:52:18 -0000 1.18 +++ misc/tabledrag.js 27 Jun 2008 12:48:08 -0000 @@ -447,6 +447,7 @@ Drupal.tableDrag.prototype.dropRow = fun self.rowObject.markChanged(); if (self.changed == false) { $(Drupal.theme('tableDragChangedWarning')).insertBefore(self.table).hide().fadeIn('slow'); + Drupal.markPageUnsaved(); // add warning popup self.changed = true; } } Index: misc/unsaved.js =================================================================== RCS file: misc/unsaved.js diff -N misc/unsaved.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ misc/unsaved.js 27 Jun 2008 12:48:09 -0000 @@ -0,0 +1,41 @@ +// $Id:$ + +/* + * Called when there is unsaved data on the page to warn users leaving + * (or reloading) page that they would lose their changes. The + * onbeforeunload event works in FF, IE and Safari, but not in Opera + * (yet). The form of the dialog is unmodifiable: + * + * Are you sure you want to navigate away from this page? + * Your message here + * Press OK to continue, or Cancel to stay on the current page. + */ +Drupal.markPageUnsaved = function(msg) { + if (!$('body').is('.has-unsaved-changes')) { // Only do it once. + $('body').addClass('has-unsaved-changes'); + if (!msg) { // default message + msg = Drupal.t("If you continue your unsaved changes will be lost."); + } + window.onbeforeunload = function(event) {return msg;}; + // Allow submit buttons to not get warning message. + Drupal.behaviors.unsaved($('body')); + } +}; + +/* + * All submit buttons and image buttons need to remove the + * onBeforeUnload event so the warning message does not come up on + * form submission. Needs to be a behavior so forms that get added by + * AJAX/AHAH can still submit without warning. + */ +Drupal.behaviors.unsaved = function(context) { + if ($('body').is('.has-unsaved-changes')) { + $(':submit,input:image', context).not('.unsaved-processed').each(function() { + $(this).addClass('unsaved-processed'); + $(this).click(function() { + // Turn off the warning before submit triggers it. + window.onbeforeunload = null; + }); + }); + } +};