Index: autosave.css
===================================================================
RCS file: autosave.css
diff -N autosave.css
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ autosave.css	28 Dec 2007 15:42:55 -0000
@@ -0,0 +1,34 @@
+#autosave-status {
+  display: none;
+  text-align:left;
+  z-index:99;
+  color:#FFF; 
+  background:#37a;
+  position:fixed;
+  width:100%; 
+  height: 2em;
+  bottom:0px; right:0px;
+  overflow:hidden;
+}
+
+#autosave-status #status {
+  margin-left: 5px;
+}
+
+#autosave-status #view a {
+  margin-left: 40px;
+  color: #FFF;
+  text-decoration: underline;
+}
+
+#autosave-status #delete a {
+  margin-left: 20px;
+  color: #FFF;
+  text-decoration: underline;
+}
+
+#autosave-status #ignore a {
+  margin-left: 20px;
+  color: #FFF;
+  text-decoration: underline;
+}
\ No newline at end of file
Index: autosave.install
===================================================================
RCS file: autosave.install
diff -N autosave.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ autosave.install	28 Dec 2007 15:42:56 -0000
@@ -0,0 +1,32 @@
+<?php
+
+/**
+ * Implementation of hook_install().
+ */
+function autosave_install() {
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      db_query("CREATE TABLE {autosaved_forms} (
+        form_id varchar(255) NOT NULL default '',
+        path varchar(255) NOT NULL default '',
+        uid int(10) NOT NULL default '0',
+        timestamp int(11) NOT NULL default '0',
+        serialized text NOT NULL,
+        PRIMARY KEY (path, uid)
+      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+      break;
+    case 'pgsql':
+      db_query("CREATE TABLE {autosaved_forms} (
+        form_id varchar(255) NOT NULL default '',
+        path varchar(255) NOT NULL default '',
+        uid int(10) NOT NULL default '0',
+        timestamp int(11) NOT NULL default '0',
+        serialized text NOT NULL default '',
+        PRIMARY KEY (path, uid),
+      )");
+      break;
+  }
+
+  drupal_set_message(t('All tables and entries required by the Autosave module have been created.'));
+}
Index: autosave.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/autosave/autosave.js,v
retrieving revision 1.1.2.8
diff -u -F^f -r1.1.2.8 autosave.js
--- autosave.js	17 Apr 2007 17:22:44 -0000	1.1.2.8
+++ autosave.js	28 Dec 2007 15:42:56 -0000
@@ -1,62 +1,58 @@
-// $Id: autosave.js,v 1.1.2.8 2007/04/17 17:22:44 edkwh Exp $
+var form_id;
 
-var changed = false;
+Drupal.attachAutosave = function() {
+  setTimeout('Drupal.saveForm()', Drupal.settings['period'] * 1000);
+}
 
-Drupal.autosaveAttach = function () {
-  url = Drupal.settings.autosave['url'];
-  period = Drupal.settings.autosave['period'];
-  
-  node_form = $('form#node-form');
-  
-  $(node_form).before('<div id="autosave_status">status</div>');
-  $('#autosave_status').css('visibility', 'hidden');
-    
-  $('input[@type=text]', node_form).keyup(Drupal.autosaveKeyUpHandler);
-  $('textarea', node_form).keyup(Drupal.autosaveKeyUpHandler);
-  $('input[@type=radio]', node_form).change(function() {
-    changed = true;
-  });
-  $('input[@type=checkbox]', node_form).click(function() {
-    changed = true;
-  });
-  $('select', node_form).change(function() {
-    changed = true;
+Drupal.saveForm = function() {
+  serialized = $('#' + form_id).formHash();
+  serialized['q'] = Drupal.settings['q'];
+  $.ajax({
+    url: Drupal.settings['autosave_url'],
+    type: "POST",
+    dataType: "xml/html/script/json",
+    data: serialized,
+    complete: function() {
+      $('#autosave-status #status').html('Form autosaved.');
+      $('#autosave-status').slideDown();
+      setTimeout("$('#autosave-status').fadeOut('slow')", 3000);
+    }
   });
   
-  setTimeout('Drupal.autosave("' + url + '", ' + period + ')', period);
-}
-
-Drupal.autosaveKeyUpHandler = function(e) {
-  var key = window.event ? e.keyCode : e.which;
-  var keychar = String.fromCharCode(key);
-  reg = /[\w]/;
-  if (reg.test(keychar)) {
-    changed = true;
-  }
-}
-
-Drupal.autosave = function(url, period) {
-  if (changed == true) {
-    var options = {
-      target: '#autosave_status',
-      url: url,
-      success: function() {
-        $('#autosave_status').css('visibility', 'visible');
-        changed = false;
-      }
-    };
-    $('form#node-form').ajaxSubmit(options);
-  }
-  setTimeout('Drupal.autosave("' + url + '", ' + period + ')', period);
+  setTimeout('Drupal.saveForm()', Drupal.settings['period'] * 1000);
 }
 
-function FCKeditor_OnComplete(editorInstance) {
-  editorInstance.Events.AttachEvent('OnSelectionChange', function() { 
-    changed = true; 
+if (Drupal.jsEnabled) {
+  $(document).ready(function() {
+    form_id = Drupal.settings['form_id'].replace(/_/g, '-');
+    $('body').append('<div id="autosave-status"><span id="status"></span><span id="operations"><span id="view"><a href="#">View</a></span><span id="ignore"><a href="#">Ignore</a></span></span></div>');
+    saved_serialized = Drupal.settings['serialized'];
+    if (saved_serialized) {
+      $('#autosave-status #view a').click(function() {
+        if ($(this).html() == 'View') {
+          $('#' + form_id).formHash(saved_serialized);
+          $(this).html('Reset');
+        }
+        else if ($(this).html() == 'Reset') {
+          form = document.getElementById(form_id);
+          form.reset();
+          $(this).html('View');
+        }
+        return false;
+      });
+      $('#autosave-status #ignore a').click(function() {
+        $('#autosave-status').fadeOut('slow');
+        form = document.getElementById(form_id);
+        form.reset();
+        $('#autosave-status #operations').css('display', 'none');
+        Drupal.attachAutosave();
+        return false;
+      });
+      $('#autosave-status #status').html('This form was autosaved on ' + Drupal.settings['saved_date']);
+      $('#autosave-status').slideDown();
+    }
+    else {
+      Drupal.attachAutosave();
+    }
   });
 }
-
-// Global Killswitch
-if (Drupal.jsEnabled) {
-  $(document).ready(Drupal.autosaveAttach);
-}
\ No newline at end of file
Index: autosave.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/autosave/autosave.module,v
retrieving revision 1.1.2.15
diff -u -F^f -r1.1.2.15 autosave.module
--- autosave.module	19 Apr 2007 13:05:10 -0000	1.1.2.15
+++ autosave.module	28 Dec 2007 15:42:56 -0000
@@ -34,12 +34,12 @@ function autosave_menu($may_cache) {
     );
     
     $items[] = array(
-      'path' => 'admin/content/types/autosave',
+      'path' => 'admin/settings/autosave',
       'title' => t('Autosave'),
+      'description' => t('Configure autosave settings.'),
       'callback' => 'drupal_get_form',
       'callback arguments' => array('autosave_admin_settings'),
       'access' => user_access('administer nodes'),
-      'type' => MENU_LOCAL_TASK,
     );
   }
 
@@ -50,60 +50,23 @@ function autosave_menu($may_cache) {
  * Implementation of hook_form_alter().
  */
 function autosave_form_alter($form_id, &$form) {
-  $content_types = array_filter(variable_get('autosave_content_types', array()));
-  if (isset($form['type']) && in_array($form['type']['#value'], $content_types) && $form['type']['#value'] .'_node_form' == $form_id) {
-    drupal_add_js(drupal_get_path('module', 'autosave') . '/autosave.js');
-    drupal_add_js(drupal_get_path('module', 'autosave') . '/jquery.form.js');
-    
-    $url = url('admin/autosave');
-    $period = variable_get('autosave_period', 10000);
-    
+  global $user;
+  $path = $_GET['q'];
+  drupal_add_js(drupal_get_path('module', 'autosave') .'/autosave.js');
+  drupal_add_js(drupal_get_path('module', 'autosave') .'/jquery.field.js');
+  drupal_add_css(drupal_get_path('module', 'autosave') .'/autosave.css');
+  
+  $settings['period'] = variable_get('autosave_period', 10);
+  $settings['form_id'] = $form_id;
+  $settings['autosave_url'] = url('admin/autosave');
+  $settings['q'] = $path;
+  drupal_add_js($settings, 'setting');
+  
+  if ($autosaved_form = autosave_get_autosaved_form($form_id, $path, $user->uid)) {
     $settings = array();
-    $settings['autosave']['url'] = $url;
-    $settings['autosave']['period'] = $period;
-    
+    $settings['serialized'] = unserialize($autosaved_form['serialized']);
+    $settings['saved_date'] = format_date($autosaved_form['timestamp'], 'medium');
     drupal_add_js($settings, 'setting');
-    
-    // Unset autosave session variables each time a add/edit node form is accessed without any post data. This is to ensure that the previous node 
-    // information is not used when saving the current node should the user leave the add/edit node form without submitting it (autosave session 
-    // variables are cleared each time a node is submitted).    
-    if ((arg(1) == 'add' || arg(2) == 'edit') && !$form['#post']) {
-      unset($_SESSION['nid'], $_SESSION['vid'], $_SESSION['current_revision']);
-    }
-    
-    $form['nid'] = array(
-      '#type' => 'hidden',
-      '#value' => $form['#node']->nid,
-    );
-    $form['vid'] = array(
-      '#type' => 'hidden',
-      '#value' => $form['#node']->vid,
-    );
-    $form['type'] = array(
-      '#type' => 'hidden',
-      '#value' => $form['#node']->type,
-    );
-  }
-}
-
-/**
- * Implementation of hook_nodeapi().
- */
-function autosave_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
-  switch ($op) {
-    case 'submit':
-      if ($node->op == t('Submit') && $_SESSION['nid']) {
-        // Sets the node information based on the autosaved node. This is important when submitting a new node as a node was created previously by autosave.
-        // If the nid is not set to the autosaved nid, a new node will be created instead.
-        $node->nid = $_SESSION['nid'];
-        $node->vid = $_SESSION['vid'];
-        $node->revision = 1;        
-        $node->log = '';
-        
-        // Clears autosave session variables.
-        unset($_SESSION['nid'], $_SESSION['vid'], $_SESSION['current_revision']);
-      }
-     break;
   }
 }
 
@@ -115,25 +78,14 @@ function autosave_admin_settings() {
   
   $path = drupal_get_path('module', 'autosave');
   
-  if (!file_exists($path .'/jquery.form.js')) {
-    drupal_set_message(t('Unable to find the jQuery Form Plugin in !path. Please <a href="http://dev.jquery.com/browser/trunk/plugins/form/jquery.form.js?format=txt">download jquery.form.js</a> and place it into !path.', array('!path' => $path)), 'error');
-  }
-  
-  foreach ($types as $type) {
-    $options[$type->type] = $type->name;
+  if (!file_exists($path .'/jquery.field.js')) {
+    drupal_set_message(t('Unable to find the jQuery Field Plugin in !path. Please <a href="http://plugins.jquery.com/files/jquery.field.js_4.txt">download jquery.field.js</a> and place it into !path.', array('!path' => $path)), 'error');
   }
   
-  $form['autosave_content_types'] = array(
-    '#type' => 'checkboxes',
-    '#title' => t('Enable autosave for the following content types'),
-    '#options' => $options,
-    '#default_value' => variable_get('autosave_content_types', 0),
-  );
-  
   $form['autosave_period'] = array(
     '#type' => 'textfield',
-    '#title' => t('Autosave after this amount milliseconds has passed'),
-    '#default_value' => variable_get('autosave_period', 10000),
+    '#title' => t('Autosave after this amount of seconds have passed'),
+    '#default_value' => variable_get('autosave_period', 10),
   );
   
   return system_settings_form($form);
@@ -144,74 +96,25 @@ function autosave_admin_settings() {
  */
 function autosave_save($unset = NULL) {
   global $user;
+  $path = $_POST['q'];
+  $form_id = $_POST['form_id'];
+  unset($_POST['form_id'], $_POST['form_token'], $_POST['q'], $_POST['op']);
+  $serialized = serialize($_POST);
+  
+  db_query("DELETE FROM {autosaved_forms} WHERE form_id = '%s' AND path = '%s' AND uid = %d", $form_id, $path, $user->uid);
+  db_query("INSERT INTO {autosaved_forms} (form_id, path, uid, timestamp, serialized) VALUES ('%s', '%s', %d, %d, '%s')",
+    $form_id, $path, $user->uid, time(), $serialized);
   
-  $nid = $_POST['nid'];
-  $type = $_POST['type'];
-  
-  $node = new stdClass();
-  if ($nid) {
-    // Node exists.
-    if (!$_SESSION['vid']) {
-      // Get the current revision of the node prior to autosaving.
-      $node = node_load($nid);
-      $_SESSION['current_revision'] = $node->vid;
-      $_POST['revision'] = 1;
-    }
-    else {
-      // Load the previous autosaved revision.
-      $node = node_load($nid, $_SESSION['vid']);
-    }
-  }
-  else {
-    // Node doens't exist.
-    if ($nid = $_SESSION['nid']) {
-      // Node was saved previously by autosave.
-      $node->nid = $nid;
-      $node->vid = $_SESSION['vid'];
-      // Check if node is a new node to determine if status should be left unchanged or unpublished.
-      if (!$_SESSION['current_revision']) {
-        // Not a new node, change the autosaved node status to unpublished. 
-        $_POST['status'] = 0;
-      }
-    }
-    else {
-      // First time node is autosaved. Set status to unpublished.
-      $_POST['status'] = 0;
-      $_POST['revision'] = 1;
-    }
-    // Set other node fields that are required to create a new node.
-    $node->uid = $user->uid;
-    $node->name = $user->name;
-    $node->type = $type;
-    $_POST['changed'] = time();
-  }
-  
-  $log = 'Autosaved at ' . date('g:i:s a');
-  $_POST['log'] = $log;
-  $node->log = $log;
-  
-  // Submit the node form.
-  $result = drupal_execute($type .'_node_form', $_POST, $node);
-  // Get all messages from the autosaved operation.
-  $messages = drupal_get_messages(NULL, FALSE);
-  
-  // Check if errors are found; if no errors, continue with the autosave process.
-  if (!array_key_exists('error', $messages)) {
-    // Obtain the nid from the return url of drupal_execute; 'node/nid'
-    $nid = substr($result, strrpos($result, '/') + 1);
-    $node = node_load($nid, NULL, TRUE);
-
-    $_SESSION['nid'] = $node->nid;
-    $_SESSION['vid'] = $node->vid;
+  exit();
+}
 
-    if ($_SESSION['current_revision']) {
-      // Reverts an existing node to it's original revision instead of the autosaved revision.
-      db_query("UPDATE {node} SET vid = %d, changed = %d WHERE nid = %d", $_SESSION['current_revision'], $_POST['changed'], $node->nid);
-      // Update the autosaved node revision log to reflect the time it was autosaved.
-      db_query("UPDATE {node_revisions} SET log = '%s' WHERE vid = %d", $log, $_SESSION['vid']);
-    }
-  }
+function autosave_get_autosaved_form($form_id, $path, $uid) {
+  $result = db_query("SELECT form_id, serialized, timestamp FROM {autosaved_forms} WHERE form_id = '%s' AND path = '%s' AND uid = %d", $form_id, $path, $uid);
   
-  print "<em>$log</em>:". theme('status_messages');
-  exit();
+  while ($data = db_fetch_object($result)) {
+    $form['form_id'] = $data->form_id;
+    $form['serialized'] = $data->serialized;
+    $form['timestamp'] = $data->timestamp;
+  }
+  return $form;
 }
