Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.795
diff -u -r1.795 system.module
--- modules/system/system.module	22 Sep 2009 15:26:46 -0000	1.795
+++ modules/system/system.module	25 Sep 2009 05:37:44 -0000
@@ -201,9 +201,6 @@
       'arguments' => array('version' => NULL),
     ),
     'system_compact_link' => array(),
-    'system_run_cron_image' => array(
-      'arguments' => array('image_path' => NULL),
-    ),
   ));
 }
 
@@ -496,10 +493,10 @@
     'type' => MENU_CALLBACK,
     'file' => 'system.admin.inc',
   );
-  $items['system/run-cron-image'] = array(
+  $items['system/run-cron-check'] = array(
     'title' => 'Execute cron',
-    'page callback' => 'system_run_cron_image',
-    'access callback' => 'system_run_cron_image_access',
+    'page callback' => 'system_run_cron_check',
+    'access callback' => 'system_run_cron_check_access',
     'type' => MENU_CALLBACK,
     'file' => 'system.admin.inc',
   );
@@ -2788,23 +2785,27 @@
  */
 function system_page_build(&$page) {
   // Automatic cron runs.
-  // @see system_run_cron_image()
-  if (system_run_cron_image_access()) {
+  if (system_run_cron_check_access()) {
     $page['page_bottom']['run_cron'] = array(
       // Trigger cron run via AJAX.
       '#attached' => array(
         'js' => array(
-          '(function($){ $.get(' . drupal_json_encode(url('system/run-cron-image')) . '); })(jQuery);' => array('type' => 'inline', 'scope' => 'header'),
+          drupal_get_path('module', 'system') .'/system.js' => array('weight' => JS_DEFAULT - 5),
+          array(
+            'data' => array(
+              // Set the cron check to run only after this UNIX timestamp.
+              'cronCheck' => REQUEST_TIME + variable_get('cron_safe_threshold', DRUPAL_CRON_DEFAULT_THRESHOLD),
+            ),
+            'type' => 'setting',
+          ),
         ),
       ),
-      // Trigger cron run for clients not supporting JavaScript (fall-back).
-      '#markup' => theme('system_run_cron_image', 'system/run-cron-image'),
     );
   }
 }
 
 /**
- * Menu callback; executes cron via an image callback.
+ * Menu callback; executes cron via an AJAX callback.
  *
  * This callback runs cron in a separate HTTP request to prevent "mysterious"
  * slow-downs of regular HTTP requests. It is either invoked via an AJAX request
@@ -2815,16 +2816,12 @@
  * does not process the returned output.
  *
  * @see system_page_alter()
- * @see theme_system_run_cron_image()
- * @see system_run_cron_image_access()
+ * @see theme_system_run_cron_check()
+ * @see system_run_cron_check_access()
  */
-function system_run_cron_image() {
+function system_run_cron_check() {
   drupal_page_is_cacheable(FALSE);
-
-  // Output a transparent 1x1 image to the browser; required for clients not
-  // supporting JavaScript.
-  drupal_set_header('Content-Type', 'image/gif');
-  echo "\x47\x49\x46\x38\x39\x61\x1\x0\x1\x0\x80\xff\x0\xc0\xc0\xc0\x0\x0\x0\x21\xf9\x4\x1\x0\x0\x0\x0\x2c\x0\x0\x0\x0\x1\x0\x1\x0\x0\x2\x2\x44\x1\x0\x3b";
+  $cron_run = FALSE;
 
   // Cron threshold semaphore is used to avoid errors every time the image
   // callback is displayed when a previous cron is still running.
@@ -2846,12 +2843,13 @@
     if (!isset($cron_last) || (REQUEST_TIME - $cron_last > $cron_threshold)) {
       // Lock cron threshold semaphore.
       variable_set('cron_threshold_semaphore', REQUEST_TIME);
-      drupal_cron_run();
+      $cron_run = drupal_cron_run();
       // Release the cron threshold semaphore.
       variable_del('cron_threshold_semaphore');
     }
   }
 
+  drupal_json_output(array('cron_run' => $cron_run));
   exit;
 }
 
@@ -2863,25 +2861,9 @@
  * @return
  *   TRUE if cron threshold is enabled, FALSE otherwise.
  *
- * @see system_run_cron_image()
+ * @see system_run_cron_check()
  * @see system_page_alter()
  */
-function system_run_cron_image_access() {
+function system_run_cron_check_access() {
   return variable_get('cron_safe_threshold', DRUPAL_CRON_DEFAULT_THRESHOLD) > 0;
 }
-
-/**
- * Display image used to run cron automatically.
- *
- * Renders an image pointing to the automatic cron run menu callback for
- * graceful degradation when Javascript is not available. The wrapping NOSCRIPT
- * tag ensures that only browsers not supporting JavaScript render the image.
- *
- * @see system_page_alter()
- * @see system_run_cron_image()
- * @ingroup themeable
- */
-function theme_system_run_cron_image($image_path) {
-  return '<noscript><div id="system-cron-image">' . theme('image', $image_path, '', '', array(), FALSE) . '</div></noscript>';
-}
-
Index: modules/system/system.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.js,v
retrieving revision 1.35
diff -u -r1.35 system.js
--- modules/system/system.js	9 Sep 2009 21:53:15 -0000	1.35
+++ modules/system/system.js	25 Sep 2009 05:37:44 -0000
@@ -164,6 +164,22 @@
 };
 
 /**
+ * Checks to see if the cron should be automatically run.
+ */
+Drupal.behaviors.cronCheck = {
+  attach: function(context, settings) {
+    if (settings.cronCheck || false) {
+      $('body').once('cron-check', function() {
+        // Only execute the cron check if its the right time.
+        if (Math.round(new Date().getTime()/1000.0) > settings.cronCheck) {
+          $.get(settings.basePath + 'system/run-cron-check');
+        }
+      });
+    }
+  }
+};
+
+/**
  * Attach the auto machine readable name behavior.
  *
  * Settings are expected to be an object of elements to process, where the key
