Index: misc/ajax.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/ajax.js,v
retrieving revision 1.28
diff -u -p -r1.28 ajax.js
--- misc/ajax.js	12 Nov 2010 03:02:43 -0000	1.28
+++ misc/ajax.js	17 Nov 2010 18:23:57 -0000
@@ -112,6 +112,7 @@ Drupal.ajax = function (base, element, e
   $.extend(this, defaults, element_settings);
 
   this.element = element;
+  this.element_settings = element_settings;
 
   // Replacing 'nojs' with 'ajax' in the URL allows for an easy method to let
   // the server detect when it needs to degrade gracefully.
@@ -165,35 +166,8 @@ Drupal.ajax = function (base, element, e
   };
 
   // Bind the ajaxSubmit function to the element event.
-  $(this.element).bind(element_settings.event, function () {
-    if (ajax.ajaxing) {
-      return false;
-    }
-
-    try {
-      if (ajax.form) {
-        // If setClick is set, we must set this to ensure that the button's
-        // value is passed.
-        if (ajax.setClick) {
-          // Mark the clicked button. 'form.clk' is a special variable for
-          // ajaxSubmit that tells the system which element got clicked to
-          // trigger the submit. Without it there would be no 'op' or
-          // equivalent.
-          this.form.clk = this;
-        }
-
-        ajax.form.ajaxSubmit(ajax.options);
-      }
-      else {
-        ajax.beforeSerialize(ajax.element, ajax.options);
-        $.ajax(ajax.options);
-      }
-    }
-    catch (e) {
-      alert("An error occurred while attempting to process " + ajax.options.url + ": " + e.message);
-    }
-
-    return false;
+  $(ajax.element).bind(element_settings.event, function () {
+     return ajax.eventResponse(ajax);
   });
 
   // If necessary, enable keyboard submission so that AJAX behaviors
@@ -201,15 +175,71 @@ Drupal.ajax = function (base, element, e
   // action.
   if (element_settings.keypress) {
     $(element_settings.element).keypress(function (event) {
-      // Detect enter key and space bar.
-      if (event.which == 13 || event.which == 32) {
-        $(element_settings.element).trigger(element_settings.event);
-        return false;
-      }
+       return ajax.keypressResponse(ajax, event);
     });
   }
 };
 
+/*
+ * Handle a key press.
+ *
+ * The AJAX object will, if instructed, bind to a key press response. This
+ * will test to see if the key press is valid to trigger this event and
+ * if it is, trigger it for us and prevent other keypresses from triggering.
+ */
+Drupal.ajax.prototype.keypressResponse = function (trigger, event) {
+  // Create a synonym for this to reduce code confusion.
+  var ajax = this;
+
+  // Detect enter key and space bar.
+  if (event.which == 13 || event.which == 32) {
+    $(ajax.element_settings.element).trigger(ajax.element_settings.event);
+    return false;
+  }
+};
+
+/**
+ * Handle an event that triggers an AJAX response.
+ *
+ * When an event that triggers an AJAX response happens, this method will
+ * perform the actual AJAX call. It is bound to the event using
+ * bind() in the constructor, and it uses the options specified on the
+ * ajax object.
+ */
+Drupal.ajax.prototype.eventResponse = function (trigger) {
+  // Create a synonym for this to reduce code confusion.
+  var ajax = this;
+
+  if (ajax.ajaxing) {
+    return false;
+  }
+
+  try {
+    if (ajax.form) {
+      // If setClick is set, we must set this to ensure that the button's
+      // value is passed.
+      if (ajax.setClick) {
+        // Mark the clicked button. 'form.clk' is a special variable for
+        // ajaxSubmit that tells the system which element got clicked to
+        // trigger the submit. Without it there would be no 'op' or
+        // equivalent.
+        trigger.form.clk = trigger;
+      }
+
+      ajax.form.ajaxSubmit(ajax.options);
+    }
+    else {
+      ajax.beforeSerialize(ajax.element, ajax.options);
+      $.ajax(ajax.options);
+    }
+  }
+  catch (e) {
+    alert("An error occurred while attempting to process " + ajax.options.url + ": " + e.message);
+  }
+
+  return false;
+};
+
 /**
  * Handler for the form serialization.
  *
