? .DS_Store
? js/jquery.md5.js
Index: ctools.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ctools/ctools.module,v
retrieving revision 1.27.2.13
diff -u -p -r1.27.2.13 ctools.module
--- ctools.module	23 Feb 2010 23:14:53 -0000	1.27.2.13
+++ ctools.module	24 Mar 2010 23:08:57 -0000
@@ -163,6 +163,18 @@ function ctools_add_js($file, $module = 
 }
 
 /**
+ * Simple function to add a page id to Drupal.settings.CTools.
+ */
+function ctools_add_page_id() {
+  static $page_id = NULL;
+  if (!isset($page_id)) {
+    $page_id = 'page-' . md5(mt_rand());
+    drupal_add_js(array('CTools' => array('pageId' => $page_id)), 'setting');
+  }
+  return $page_id;
+}
+
+/**
  * Implement hook_init to keep our global CSS at the ready.
  */
 function ctools_init() {
@@ -172,6 +184,10 @@ function ctools_init() {
     ini_set('display_errors', 0);
     register_shutdown_function('ctools_shutdown_handler');
   }
+  else {
+    // Add a setting into the JS that identifies this page.
+    ctools_add_page_id();
+  }
 }
 
 /**
@@ -526,6 +542,57 @@ function ctools_preprocess_page(&$variab
     }
     $variables['content'] = strtr($variables['content'], $tokens);
   }
+
+  // Go through all the JS files being added to the page and catalog them.
+  $js_files = array();
+  foreach (drupal_add_js() as $type => $data) {
+    if ($type != 'inline' && $type != 'setting') {
+      foreach ($data as $path => $info) {
+        $js_files[$path] = TRUE;
+      }
+    }
+  }
+
+  // Go through all CSS files that are being added to the page and catalog them.
+  $css_files = array();
+  $css = drupal_add_css();
+  foreach ($css as $media => $types) {
+    // If CSS preprocessing is off, we still need to output the styles.
+    // Additionally, go through any remaining styles if CSS preprocessing is on and output the non-cached ones.
+    foreach ($types as $type => $files) {
+      if ($type == 'module') {
+        // Setup theme overrides for module styles.
+        $theme_styles = array();
+        foreach (array_keys($css[$media]['theme']) as $theme_style) {
+          $theme_styles[] = basename($theme_style);
+        }
+      }
+      foreach ($types[$type] as $file => $preprocess) {
+        // If the theme supplies its own style using the name of the module style, skip its inclusion.
+        // This includes any RTL styles associated with its main LTR counterpart.
+        if ($type == 'module' && in_array(str_replace('-rtl.css', '.css', basename($file)), $theme_styles)) {
+          // Unset the file to prevent its inclusion when CSS aggregation is enabled.
+          unset($types[$type][$file]);
+          continue;
+        }
+        // Only include the stylesheet if it exists.
+        if (file_exists($file)) {
+          $css_files[$file] = TRUE;
+        }
+      }
+    }
+  }
+
+  // Cache the cataloged JS and CSS so they can be found by an ajax request.
+  $page_id = ctools_add_page_id();
+  $expire = CACHE_TEMPORARY;
+
+  // If the page cache is enabled, respect its cache lifetime.
+  // @TODO: do this for only user_is_anonymous()?
+  if (variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED) {
+    $expire = variable_get('cache_lifetime', 0);
+  }
+  cache_set($page_id, array('js' => $js_files, 'css' => $css_files), 'cache', $expire);
 }
 
 /**
Index: includes/ajax.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ctools/includes/ajax.inc,v
retrieving revision 1.14.2.3
diff -u -p -r1.14.2.3 ajax.inc
--- includes/ajax.inc	17 Feb 2010 01:04:50 -0000	1.14.2.3
+++ includes/ajax.inc	24 Mar 2010 23:08:57 -0000
@@ -449,30 +449,34 @@ function ctools_ajax_command_submit($sel
 function ctools_ajax_render($commands = array()) {
   // Automatically extract any 'settings' added via drupal_add_js() and make
   // them the first command.
-
   $query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1);
 
   $scripts = drupal_add_js(NULL, NULL);
+  $cached_scripts = cache_get($_POST['page_id'], 'cache')->data;
+
   foreach ($scripts as $type => $data) {
     switch ($type) {
       case 'setting':
         $settings = $data;
         break;
       case 'inline':
-        // presently we ignore inline javascript.
+      case 'theme':
+        // Presently we ignore inline javascript.
+        // Theme JS is already added and because of admin themes, this could add
+        // improper JS to the page.
         break;
       default:
         // If JS preprocessing is off, we still need to output the scripts.
         // Additionally, go through any remaining scripts if JS preprocessing is on and output the non-cached ones.
         foreach ($data as $path => $info) {
-          $js_files[] = base_path() . $path . ($info['cache'] ? $query_string : '?' . time());
+          if (!isset($cached_scripts['js'][$path])) {
+            $js_files[] = base_path() . $path . ($info['cache'] ? $query_string : '?' . time());
+          }
         }
     }
   }
 
-
   $css = drupal_add_css();
-
   foreach ($css as $media => $types) {
     // If CSS preprocessing is off, we still need to output the styles.
     // Additionally, go through any remaining styles if CSS preprocessing is on and output the non-cached ones.
@@ -484,20 +488,24 @@ function ctools_ajax_render($commands = 
           $theme_styles[] = basename($theme_style);
         }
       }
-      foreach ($types[$type] as $file => $preprocess) {
-        // If the theme supplies its own style using the name of the module style, skip its inclusion.
-        // This includes any RTL styles associated with its main LTR counterpart.
-        if ($type == 'module' && in_array(str_replace('-rtl.css', '.css', basename($file)), $theme_styles)) {
-          // Unset the file to prevent its inclusion when CSS aggregation is enabled.
-          unset($types[$type][$file]);
-          continue;
-        }
-        // Only include the stylesheet if it exists.
-        if (file_exists($file)) {
-          $css_files[] = array(
-            'file' => base_path() . $file . $query_string,
-            'media' => $media,
-          );
+      // The theme stuff should already be added and because of admin themes,
+      // this could cause different CSS to be added.
+      if ($type != 'theme') {
+        foreach ($types[$type] as $file => $preprocess) {
+          // If the theme supplies its own style using the name of the module style, skip its inclusion.
+          // This includes any RTL styles associated with its main LTR counterpart.
+          if ($type == 'module' && in_array(str_replace('-rtl.css', '.css', basename($file)), $theme_styles)) {
+            // Unset the file to prevent its inclusion when CSS aggregation is enabled.
+            unset($types[$type][$file]);
+            continue;
+          }
+          // Only include the stylesheet if it exists.
+          if (file_exists($file) && !isset($cached_scripts['css'][$file])) {
+            $css_files[] = array(
+              'file' => base_path() . $file . $query_string,
+              'media' => $media,
+            );
+          }
         }
       }
     }
Index: js/ajax-responder.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ctools/js/ajax-responder.js,v
retrieving revision 1.18.2.8
diff -u -p -r1.18.2.8 ajax-responder.js
--- js/ajax-responder.js	22 Feb 2010 19:50:39 -0000	1.18.2.8
+++ js/ajax-responder.js	24 Mar 2010 23:08:57 -0000
@@ -53,7 +53,7 @@
       $.ajax({
         type: "POST",
         url: url,
-        data: { 'js': 1, 'ctools_ajax': 1 },
+        data: { 'js': 1, 'ctools_ajax': 1, 'page_id': Drupal.settings.CTools.pageId },
         global: true,
         success: function (data) {
           Drupal.CTools.AJAX.commandCache[old_url] = data;
@@ -112,7 +112,7 @@
       $.ajax({
         type: "POST",
         url: url,
-        data: { 'js': 1, 'ctools_ajax': 1 },
+        data: { 'js': 1, 'ctools_ajax': 1, 'page_id': Drupal.settings.CTools.pageId },
         global: true,
         success: Drupal.CTools.AJAX.respond,
         error: function(xhr) {
@@ -154,7 +154,7 @@
         $.ajax({
           type: "POST",
           url: url,
-          data: { 'js': 1, 'ctools_ajax': 1 },
+          data: { 'js': 1, 'ctools_ajax': 1, 'page_id': Drupal.settings.CTools.pageId },
           global: true,
           success: Drupal.CTools.AJAX.respond,
           error: function(xhr) {
@@ -173,7 +173,7 @@
         $(form).ajaxSubmit({
           type: "POST",
           url: url,
-          data: { 'js': 1, 'ctools_ajax': 1 },
+          data: { 'js': 1, 'ctools_ajax': 1, 'page_id': Drupal.settings.CTools.pageId },
           global: true,
           success: Drupal.CTools.AJAX.respond,
           error: function(xhr) {
