--- jquery_update.module.orig 2009-11-26 21:02:40.000000000 -0500 +++ jquery_update.module 2009-11-26 22:05:32.000000000 -0500 @@ -59,11 +59,6 @@ function jquery_update_preprocess_page(& // Get an array of all the JavaScript files loaded by Drupal on this page. $scripts = drupal_add_js(); - // Replace jquery.js first. - $new_jquery = array(jquery_update_jquery_path() => $scripts['core']['misc/jquery.js']); - $scripts['core'] = array_merge($new_jquery, $scripts['core']); - unset($scripts['core']['misc/jquery.js']); - // Loop through each of the required replacements. foreach (jquery_update_get_replacements() as $type => $replacements) { foreach ($replacements as $find => $replace) { @@ -77,7 +72,22 @@ function jquery_update_preprocess_page(& } } - $variables['scripts'] = drupal_get_js('header', $scripts); + // Replace jquery.js + $new_jquery_type = variable_get('jquery_update_compression_type', 'min'); + $new_jquery_path = jquery_update_jquery_path($new_jquery_type); + $new_jquery = array($new_jquery_path => $scripts['core']['misc/jquery.js']); + unset($scripts['core']['misc/jquery.js']); + + // Build output based on type + if ($new_jquery_type == 'google') { + // process separately to ensure jquery.js comes first + $variables['scripts'] = jquery_update_get_external_js($new_jquery_path); + $variables['scripts'] .= drupal_get_js('header', $scripts); + } + else { + $scripts['core'] = array_merge($new_jquery, $scripts['core']); + $variables['scripts'] = drupal_get_js('header', $scripts); + } } } } @@ -147,8 +157,9 @@ function jquery_update_settings() { '#type' => 'radios', '#title' => t('Choose jQuery compression level'), '#options' => array( - 'min' => t('Production (Minified)'), - 'none' => t('Development (Uncompressed Code)'), + 'min' => t('Production (Local, Minified)'), + 'google' => t('Google CDN (External, Minified, Compressed)'), + 'none' => t('Development (Local, Uncompressed Code)'), ), '#default_value' => variable_get('jquery_update_compression_type', 'min'), ); @@ -159,7 +170,25 @@ function jquery_update_settings() { /** * Return the path to the jQuery file. */ -function jquery_update_jquery_path() { - $jquery_file = array('none' => 'jquery.js', 'min' => 'jquery.min.js'); - return JQUERY_UPDATE_REPLACE_PATH .'/'. $jquery_file[variable_get('jquery_update_compression_type', 'min')]; +function jquery_update_jquery_path($jquery_type = NULL) { + if ($jquery_type === NULL) { + $jquery_type = variable_get('jquery_update_compression_type', 'min'); + } + switch ($jquery_type) { + case 'none': + return JQUERY_UPDATE_REPLACE_PATH . '/' . 'jquery.js'; + case 'min': + return JQUERY_UPDATE_REPLACE_PATH . '/' . 'jquery.min.js'; + case 'google': + return 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'; + } + + return JQUERY_UPDATE_REPLACE_PATH . '/' . 'jquery.min.js'; +} + +/** + * Return script tag for an external file + */ +function jquery_update_get_external_js($path) { + return '\n"; }