? jqu.patch
Index: jquery_update.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/jquery_update/jquery_update.module,v
retrieving revision 1.5.2.2.2.7
diff -u -r1.5.2.2.2.7 jquery_update.module
--- jquery_update.module	18 Mar 2010 20:04:39 -0000	1.5.2.2.2.7
+++ jquery_update.module	19 Apr 2010 22:28:26 -0000
@@ -11,20 +11,29 @@
  */
 define('JQUERY_UPDATE_REPLACE_PATH', drupal_get_path('module', 'jquery_update') .'/replace');
 
+
 /**
- * Array of jQuery files to replace if jQuery is loaded.
+ * Implementation of hook_js_replacements().
+ * This hook is not a standard Drupal hook, but it is one we hope contrib
+ * modules will adopt when they replace javascript files in the theme layer.
+ * When hook_js_replacements() exists, modules have visibility into which
+ * javascript replacements modules are making before the replacements are
+ * actually made in the theme layer.
+ * 
+ * The return format is $scripts[$type][$old_path] = $new_path.
  */
-function jquery_update_get_replacements() {
+function jquery_update_js_replacements() {
   return array(
     'module' => array(
-      'misc/farbtastic/farbtastic.js' => 'farbtastic.js',
-      'misc/teaser.js' => 'teaser.js',
-      'misc/jquery.form.js' => 'jquery.form.js',
-      'misc/ahah.js' => 'ahah.js',
-      'misc/tabledrag.js' => 'tabledrag.js',
+      'misc/farbtastic/farbtastic.js' => JQUERY_UPDATE_REPLACE_PATH . '/farbtastic.js',
+      'misc/teaser.js' => JQUERY_UPDATE_REPLACE_PATH . '/teaser.js',
+      'misc/jquery.form.js' => JQUERY_UPDATE_REPLACE_PATH . '/jquery.form.js',
+      'misc/ahah.js' => JQUERY_UPDATE_REPLACE_PATH . '/ahah.js',
+      'misc/tabledrag.js' => JQUERY_UPDATE_REPLACE_PATH . '/tabledrag.js',
     ),
     'core' => array(
-      'misc/tabledrag.js' => 'tabledrag.js',
+      'misc/tabledrag.js' => JQUERY_UPDATE_REPLACE_PATH . '/tabledrag.js',
+      'misc/jquery.js' => jquery_update_jquery_path(),
     ),
   );
 }
@@ -62,18 +71,24 @@
       // Get an array of all the JavaScript files loaded by Drupal on this page.
       $scripts = drupal_add_js();
 
-      // Replace jquery.js first.
+      $replacements = jquery_update_js_replacements();
+
+      // Replace jquery.js first to avoid weight problems causing jQuery to
+      // not load first.
       $new_jquery = array(jquery_update_jquery_path() => $scripts['core']['misc/jquery.js']);
       $scripts['core'] = array_merge($new_jquery, $scripts['core']);
+      // Remove original jquery.js from Drupal scripts array because
+      // we replaced it.
       unset($scripts['core']['misc/jquery.js']);
+      // Remove original jquery.js from replacements array because
+      // we replaced it first and don't need it to be replaced again.
+      unset($replacements['core']['misc/jquery.js']);
 
       // Loop through each of the required replacements.
-      foreach (jquery_update_get_replacements() as $type => $replacements) {
-        foreach ($replacements as $find => $replace) {
+      foreach ($replacements as $type => $type_replacements) {
+        foreach ($type_replacements as $find => $replace) {
           // If the file to replace is loaded on this page...
           if (isset($scripts[$type][$find])) {
-            // Create a new entry for the replacement file, and unset the original one.
-            $replace = JQUERY_UPDATE_REPLACE_PATH .'/'. $replace;
             $scripts[$type][$replace] = $scripts[$type][$find];
             unset($scripts[$type][$find]);
           }
