? 655388_66.patch
? 655388_72.patch
? 839068.patch
? 839068.patch.1
? sites/default/files
? sites/default/settings.php
Index: modules/overlay/overlay-parent.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/overlay/overlay-parent.js,v
retrieving revision 1.48
diff -u -p -r1.48 overlay-parent.js
--- modules/overlay/overlay-parent.js	13 Jun 2010 05:47:47 -0000	1.48
+++ modules/overlay/overlay-parent.js	30 Jun 2010 02:14:12 -0000
@@ -43,6 +43,10 @@ Drupal.behaviors.overlayParent = {
  *   child document is fully loaded.
  * - drupalOverlayLoad: This event is triggered when the overlay is finished
  *   loading.
+ * - drupalOverlaySaveFormData: This event is triggered when the overlay is
+ *   saving form data for possible restoration.
+ * - drupalOverlayLoadFormData: This event is triggered when the overlay is
+ *   restoring form data back into the form.
  * - drupalOverlayResize: This event is triggered when the overlay is being
  *   resized to match the parent window.
  */
@@ -50,7 +54,8 @@ Drupal.overlay = Drupal.overlay || {
   isOpen: false,
   isOpening: false,
   isClosing: false,
-  isLoading: false
+  isLoading: false,
+  formData: {}
 };
 
 Drupal.overlay.prototype = {};
@@ -180,6 +185,9 @@ Drupal.overlay.close = function () {
     return false;
   }
 
+  // Save any form data present.
+  this.saveFormData();
+
   this.isClosing = true;
   this.isOpen = false;
   $(document.documentElement).removeClass('overlay-open');
@@ -232,6 +240,47 @@ Drupal.overlay.redirect = function (url)
 };
 
 /**
+ * Save form data within the overlay to a JavaScript variable so we can restore
+ * the data later if the form was closed accidentally.
+ */
+Drupal.overlay.saveFormData = function() {
+  var iframeDocument = this.activeFrame[0].contentDocument || this.activeFrame[0].contentWindow.document;
+  var overlay = this;
+  $('form', iframeDocument).each(function() {
+    var $form = $(this);
+    var formId = $form.attr('id');
+    // Overwrite any old data, replace it with the newer data. If we eventually
+    // do come back to this form, we'll want to re-populate it with the most up
+    // to date data available to us.
+    overlay.formData[formId] = {};
+    $form.find(':input').each(function() {
+      var name = $(this).attr('name');
+      // Basic validation: make sure the name is a non-empty string, and bypass
+      // input fields that aren't worth saving.
+      if (typeof name == 'string' && name.length && name != 'form_build_id' && name != 'form_token' && name != 'form_id' && name != 'op') {
+        // For checkboxes, store whether or not it's checked instead of storing
+        // an arbitrary value.
+        if ($(this).is(':checkbox')) {
+          overlay.formData[formId][name] = $(this).is(':checked');
+        }
+        // For radio buttons, only save the value if this specific radio button
+        // is currently selected.
+        else if ($(this).is(':radio')) {
+          if ($(this).is(':checked')) {
+            overlay.formData[formId][name] = $(this).val();
+          }
+        }
+        // For everything else, just store the value.
+        else {
+          overlay.formData[formId][name] = $(this).val();
+        }
+      }
+    });
+  });
+  $(document).trigger('drupalOverlaySaveFormData');
+}
+
+/**
  * Bind the child window.
  *
  * Note that this function is fired earlier than Drupal.overlay.loadChild.
@@ -272,6 +321,50 @@ Drupal.overlay.loadChild = function (eve
   if (this.isOpen && !this.isClosing) {
     // And child document is an actual overlayChild.
     if (iframeWindow.Drupal && iframeWindow.Drupal.overlayChild) {
+      // If we have re-opened a form that we closed without submitting earlier,
+      // restore the saved data into the form now.
+      var overlay = this;
+      $('form', iframeDocument).each(function() {
+        var $form = $(this);
+        var formId = $form.attr('id');
+        if (typeof overlay.formData[formId] == 'object') {
+          $form.find(':input').each(function() {
+            var name = $(this).attr('name');
+            // Basic validation: make sure the name is a non-empty string.
+            if (typeof name == 'string' && name.length && typeof overlay.formData[formId][name] != 'undefined') {
+              // With checkboxes, we don't change the value; instead, we change
+              // the "checked" attribute.
+              if ($(this).is(':checkbox')) {
+                if (overlay.formData[formId][name]) {
+                  $(this).attr('checked', 'checked').change();
+                }
+                else {
+                  $(this).removeAttr('checked').change();
+                }
+              }
+              // With radios, we also don't change the value; instead, we alter
+              // the "checked" attribute, checking it only if its value matches
+              // the value stored.
+              else if ($(this).is(':radio')) {
+                if ($(this).val() == overlay.formData[formId][name]) {
+                  $(this).attr('checked', 'checked').change();
+                }
+                else {
+                  $(this).removeAttr('checked').change();
+                }
+              }
+              // For all other elements, just set the value to the stored data.
+              else {
+                $(this).val(overlay.formData[formId][name]);
+              }
+            }
+          });
+          $(document).trigger('drupalOverlayLoadFormData');
+        }
+      });
+
+      this.saveFormData();
+
       this.activeFrame = $(iframe)
         .addClass('overlay-active')
         // Add a title attribute to the iframe for accessibility.
