Index: includes/ajax.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/ajax.inc,v
retrieving revision 1.35
diff -u -p -r1.35 ajax.inc
--- includes/ajax.inc	5 Oct 2010 19:59:10 -0000	1.35
+++ includes/ajax.inc	5 Oct 2010 22:49:44 -0000
@@ -505,7 +505,25 @@ function ajax_footer() {
 }
 
 /**
- * Add AJAX information about a form element to the page to communicate with JavaScript.
+ * Form element process callback to handle #ajax.
+ *
+ * @param $element
+ *   An associative array containing the properties of the element. See
+ *   ajax_process_element().
+ *
+ * @return
+ *   The processed element.
+ */
+function ajax_process_form($element, &$form_state) {
+  $element = ajax_pre_render_element($element);
+  if (isset($element['#ajax_processed'])) {
+    $form_state['cache'] = TRUE;
+  }
+  return $element;
+}
+
+/**
+ * Add AJAX information about an element to the page to communicate with JavaScript.
  *
  * If #ajax['path'] is set on an element, this additional JavaScript is added
  * to the page header to attach the AJAX behaviors. See ajax.js for more
@@ -521,12 +539,16 @@ function ajax_footer() {
  *   - #ajax['effect']
  *
  * @return
- *   None. Additional code is added to the header of the page using
- *   drupal_add_js().
+ *   The processed element with the necessary JavaScript attached to it.
  */
-function ajax_process_form($element, &$form_state) {
-  // Nothing to do if there is neither a callback nor a path.
-  if (!(isset($element['#ajax']['callback']) || isset($element['#ajax']['path']))) {
+function ajax_pre_render_element($element) {
+  // Skip elements already processed by Form API via ajax_process_form().
+  if (isset($element['#processed']) && $element['#processed']) {
+    return $element;
+  }
+
+  // Nothing to do if the element defines no AJAX callback/path, or link href.
+  if (!(isset($element['#ajax']['callback']) || isset($element['#ajax']['path']) || isset($element['#href']))) {
     return $element;
   }
 
@@ -557,6 +579,10 @@ function ajax_process_form($element, &$f
         $element['#ajax']['event'] = 'change';
         break;
 
+      case 'link':
+        $element['#ajax']['event'] = 'click';
+        break;
+
       default:
         return $element;
     }
@@ -569,6 +595,30 @@ function ajax_process_form($element, &$f
 
     $settings = $element['#ajax'];
 
+    // When being invoked outside of Form API context, elements of #type 'link'
+    // do not have a HTML ID, unless manually set in #options['attributes'],
+    // #attributes, or #id. Either take over one of those or generate a new one.
+    // @see drupal_pre_render_link()
+    if (isset($element['#type']) && $element['#type'] == 'link') {
+      if (isset($element['#options']['attributes']['id'])) {
+        $element['#id'] = $element['#options']['attributes']['id'];
+        $element['#attributes']['id'] = $element['#options']['attributes']['id'];
+      }
+      elseif (isset($element['#attributes']['id'])) {
+        $element['#id'] = $element['#attributes']['id'];
+        $element['#options']['attributes']['id'] = $element['#attributes']['id'];
+      }
+      elseif (isset($element['#id'])) {
+        $element['#options']['attributes']['id'] = $element['#id'];
+        $element['#attributes']['id'] = $element['#id'];
+      }
+      else {
+        $element['#id'] = drupal_html_id('ajax-link');
+        $element['#options']['attributes']['id'] = $element['#id'];
+        $element['#attributes']['id'] = $element['#id'];
+      }
+    }
+
     // Assign default settings.
     $settings += array(
       'selector' => '#' . $element['#id'],
@@ -583,37 +633,52 @@ function ajax_process_form($element, &$f
       $settings['method'] = 'replaceWith';
     }
 
-    // Change path to url.
-    $settings['url'] = isset($settings['path']) ? url($settings['path']) : url('system/ajax');
-    unset($settings['path']);
-
-    // Add special data to $settings['submit'] so that when this element
-    // triggers an AJAX submission, Drupal's form processing can determine which
-    // element triggered it.
-    // @see _form_element_triggered_scripted_submission()
-    if (isset($settings['trigger_as'])) {
-      // An element can add a 'trigger_as' key within #ajax to make the element
-      // submit as though another one (for example, a non-button can use this
-      // to submit the form as though a button were clicked). When using this,
-      // the 'name' key is always required to identify the element to trigger
-      // as. The 'value' key is optional, and only needed when multiple elements
-      // share the same name, which is commonly the case for buttons.
-      $settings['submit']['_triggering_element_name'] = $settings['trigger_as']['name'];
-      if (isset($settings['trigger_as']['value'])) {
-        $settings['submit']['_triggering_element_value'] = $settings['trigger_as']['value'];
-      }
-      unset($settings['trigger_as']);
-    }
-    else {
-      // Most of the time, elements can submit as themselves, in which case the
-      // 'trigger_as' key isn't needed, and the element's name is used.
-      $settings['submit']['_triggering_element_name'] = $element['#name'];
-      // If the element is a (non-image) button, its name may not identify it
-      // uniquely, in which case a match on value is also needed.
-      // @see _form_button_was_clicked()
-      if (isset($element['#button_type']) && empty($element['#has_garbage_value'])) {
-        $settings['submit']['_triggering_element_value'] = $element['#value'];
-      }
+    switch ($element['#type']) {
+      case 'link':
+        // If #ajax['path] was not specified, use the href as AJAX request URL.
+        if (isset($settings['path'])) {
+          $settings['url'] = url($settings['path']);
+          unset($settings['path']);
+        }
+        else {
+          $settings['url'] = url($element['#href'], isset($element['#options']) ? $element['#options'] : array());
+        }
+        break;
+
+      default:
+        // Change path to url.
+        $settings['url'] = isset($settings['path']) ? url($settings['path']) : url('system/ajax');
+        unset($settings['path']);
+
+        // Add special data to $settings['submit'] so that when this element
+        // triggers an AJAX submission, Drupal's form processing can determine which
+        // element triggered it.
+        // @see _form_element_triggered_scripted_submission()
+        if (isset($settings['trigger_as'])) {
+          // An element can add a 'trigger_as' key within #ajax to make the element
+          // submit as though another one (for example, a non-button can use this
+          // to submit the form as though a button were clicked). When using this,
+          // the 'name' key is always required to identify the element to trigger
+          // as. The 'value' key is optional, and only needed when multiple elements
+          // share the same name, which is commonly the case for buttons.
+          $settings['submit']['_triggering_element_name'] = $settings['trigger_as']['name'];
+          if (isset($settings['trigger_as']['value'])) {
+            $settings['submit']['_triggering_element_value'] = $settings['trigger_as']['value'];
+          }
+          unset($settings['trigger_as']);
+        }
+        else {
+          // Most of the time, elements can submit as themselves, in which case the
+          // 'trigger_as' key isn't needed, and the element's name is used.
+          $settings['submit']['_triggering_element_name'] = $element['#name'];
+          // If the element is a (non-image) button, its name may not identify it
+          // uniquely, in which case a match on value is also needed.
+          // @see _form_button_was_clicked()
+          if (isset($element['#button_type']) && empty($element['#has_garbage_value'])) {
+            $settings['submit']['_triggering_element_value'] = $element['#value'];
+          }
+        }
+        break;
     }
 
     // Convert a simple #ajax['progress'] string into an array.
@@ -634,8 +699,8 @@ function ajax_process_form($element, &$f
       'type' => 'setting',
       'data' => array('ajax' => array($element['#id'] => $settings)),
     );
-
-    $form_state['cache'] = TRUE;
+    // Allow others to identify whether something was successfully processed.
+    $element['#ajax_processed'] = TRUE;
   }
   return $element;
 }
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1233
diff -u -p -r1.1233 common.inc
--- includes/common.inc	5 Oct 2010 19:59:10 -0000	1.1233
+++ includes/common.inc	5 Oct 2010 23:18:25 -0000
@@ -4008,9 +4008,11 @@ function drupal_get_js($scope = 'header'
 
   // Provide the page with information about the individual JavaScript files
   // used, information not otherwise available when aggregation is enabled.
-  $setting['ajaxPageState']['js'] = array_fill_keys(array_keys($items), 1);
-  unset($setting['ajaxPageState']['js']['settings']);
-  drupal_add_js($setting, 'setting');
+  if (!$skip_alter) {
+    $setting['ajaxPageState']['js'] = array_fill_keys(array_keys($items), 1);
+    unset($setting['ajaxPageState']['js']['settings']);
+    drupal_add_js($setting, 'setting');
+  }
 
   // If we're outputting the header scope, then this might be the final time
   // that drupal_get_js() is running, so add the setting to this output as well
@@ -5143,8 +5145,18 @@ function drupal_pre_render_conditional_c
  *   The passed in elements containing a rendered link in '#markup'.
  */
 function drupal_pre_render_link($elements) {
-  $options = isset($elements['#options']) ? $elements['#options'] : array();
-  $elements['#markup'] = l($elements['#title'], $elements['#href'], $options);
+  // By default, link options to pass to l() are normally set in #options.
+  if (!isset($elements['#options'])) {
+    $elements['#options'] = array();
+  }
+  // However, within the scope of renderable elements, #attributes is a valid
+  // way to specify attributes, too. Take them into account, but do not override
+  // attributes from #options.
+  if (isset($elements['#attributes'])) {
+    $elements['#options'] += array('attributes' => array());
+    $elements['#options']['attributes'] += $elements['#attributes'];
+  }
+  $elements['#markup'] = l($elements['#title'], $elements['#href'], $elements['#options']);
   return $elements;
 }
 
Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.618
diff -u -p -r1.618 theme.inc
--- includes/theme.inc	5 Oct 2010 19:59:10 -0000	1.618
+++ includes/theme.inc	5 Oct 2010 22:49:44 -0000
@@ -108,7 +108,7 @@ function drupal_theme_initialize() {
   // @see ajax_base_page_theme()
   $setting['ajaxPageState'] = array(
     'theme' => $theme_key,
-    'themeToken' => drupal_get_token($theme_key),
+    'theme_token' => drupal_get_token($theme_key),
   );
   drupal_add_js($setting, 'setting');
 }
Index: misc/ajax.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/ajax.js,v
retrieving revision 1.20
diff -u -p -r1.20 ajax.js
--- misc/ajax.js	4 Oct 2010 17:46:01 -0000	1.20
+++ misc/ajax.js	5 Oct 2010 23:19:20 -0000
@@ -176,6 +176,7 @@ Drupal.ajax = function (base, element, e
         ajax.form.ajaxSubmit(options);     
       }
       else {
+        ajax.beforeSerialize(this.element, options);
         $.ajax(options);
       }
     }
@@ -216,31 +217,35 @@ Drupal.ajax.prototype.beforeSerialize = 
     var settings = this.settings || Drupal.settings;
     Drupal.detachBehaviors(this.form, settings, 'serialize');
   }
-};
-
-/**
- * Handler for the form redirection submission.
- */
-Drupal.ajax.prototype.beforeSubmit = function (form_values, element, options) {
-  // Disable the element that received the change.
-  $(this.element).addClass('progress-disabled').attr('disabled', true);
 
   // Prevent duplicate HTML ids in the returned markup.
   // @see drupal_html_id()
+  options.data['ajax_html_ids[]'] = [];
   $('[id]').each(function () {
-    form_values.push({ name: 'ajax_html_ids[]', value: this.id });
+    options.data['ajax_html_ids[]'].push(this.id);
   });
 
   // Allow Drupal to return new JavaScript and CSS files to load without
   // returning the ones already loaded.
-  form_values.push({ name: 'ajax_page_state[theme]', value: Drupal.settings.ajaxPageState.theme });
-  form_values.push({ name: 'ajax_page_state[theme_token]', value: Drupal.settings.ajaxPageState.themeToken });
+  // @see ajax_base_page_theme()
+  // @see drupal_get_css()
+  // @see drupal_get_js()
+  options.data['ajax_page_state[theme]'] = Drupal.settings.ajaxPageState.theme;
+  options.data['ajax_page_state[theme_token]'] = Drupal.settings.ajaxPageState.theme_token;
   for (var key in Drupal.settings.ajaxPageState.css) {
-    form_values.push({ name: 'ajax_page_state[css][' + key + ']', value: 1 });
+    options.data['ajax_page_state[css][' + key + ']'] = 1;
   }
   for (var key in Drupal.settings.ajaxPageState.js) {
-    form_values.push({ name: 'ajax_page_state[js][' + key + ']', value: 1 });
+    options.data['ajax_page_state[js][' + key + ']'] = 1;
   }
+};
+
+/**
+ * Handler for the form redirection submission.
+ */
+Drupal.ajax.prototype.beforeSubmit = function (form_values, element, options) {
+  // Disable the element that received the change.
+  $(this.element).addClass('progress-disabled').attr('disabled', true);
 
   // Insert progressbar or throbber.
   if (this.progress.type == 'bar') {
@@ -279,7 +284,7 @@ Drupal.ajax.prototype.success = function
 
   Drupal.freezeHeight();
 
-  for (i in response) {
+  for (var i in response) {
     if (response[i]['command'] && this.commands[response[i]['command']]) {
       this.commands[response[i]['command']](this, response[i], status);
     }
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.976
diff -u -p -r1.976 system.module
--- modules/system/system.module	5 Oct 2010 19:59:10 -0000	1.976
+++ modules/system/system.module	5 Oct 2010 22:49:44 -0000
@@ -452,7 +452,7 @@ function system_element_info() {
     '#pre_render' => array('drupal_pre_render_markup'),
   );
   $types['link'] = array(
-    '#pre_render' => array('drupal_pre_render_link', 'drupal_pre_render_markup'),
+    '#pre_render' => array('ajax_pre_render_element', 'drupal_pre_render_link', 'drupal_pre_render_markup'),
   );
   $types['fieldset'] = array(
     '#collapsible' => FALSE,
