Index: jquery_update.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/jquery_update/jquery_update.module,v
retrieving revision 1.2
diff -u -r1.2 jquery_update.module
--- jquery_update.module	21 May 2008 05:04:45 -0000	1.2
+++ jquery_update.module	15 Jun 2008 01:07:49 -0000
@@ -6,6 +6,63 @@
  * Updates Drupal to use the latest version of jQuery.
  */
 
+//defines a constant to be used as the default version to load when using the Google AJAX Libraries API  
+define('GAL_API_VERSION_DEFAULT', '1.2.6'); 
+ 
+/**
+ * Implementation of hook_menu().
+ * 
+ * Creates a menu item for the jQuery Update administrative page.
+ */
+function jquery_update_menu() {
+  $items = array();
+  $items['admin/settings/jquery_update'] = array(
+    //use capitalized Jquery (sic) to avoid menu item showing up at the bottom
+    'title' => t('Jquery Update'),
+    'description' => t('Set whether jQuery Update should use the Google AJAX Libraries API.'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('jquery_update_admin'),
+    'access arguments' => array('administer jQuery update'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+  return $items;
+}
+
+/**
+ * Generates the administration form.
+ */
+function jquery_update_admin() {
+  $form = array();
+  $form['google_api'] = array(
+    '#type' => 'fieldset',
+    '#title' => 'Google AJAX Libraries API',
+    '#description' => t('By default, jQuery Update serves a local copy of the updated jquery.js file; however, it can optionally use the <a href="google_ajax">Google AJAX Libraries API</a> instead.', array('@google_ajax' => 'http://code.google.com/apis/ajaxlibs/')),
+  );
+  $form['google_api']['use_google'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Use the Google AJAX Libraries API to load jQuery.'),
+    '#default_value' => variable_get('use_google', 0),
+  );
+  
+  //field should ideally be disabled by default until $use_google is checked (but that requires issue #227966 to be fixed)
+  $form['google_api']['jquery_version'] = array(
+    '#type' => 'select',
+    '#title' => t('jQuery Version'),
+    '#default_value' => variable_get('jquery_version', GAL_API_VERSION_DEFAULT),
+    '#description' => t('Specify the version of jQuery to load. See the Google AJAX Libraries API Developer\'s Guide for <a href="@supported-versions">supported versions</a>.', array('@supported-versions' => 'http://code.google.com/apis/ajaxlibs/documentation/#jquery')),
+    '#options' => array('1.2.6' => '1.2.6'),
+    '#required' => TRUE,
+  );
+  return system_settings_form($form);
+}
+
+/**
+ * Implementation of hook_perm().
+ */
+function jquery_update_perm() {
+  return array('administer jQuery update');
+}
+
 /**
  * Implementation of hook_theme_registry_alter().
  *
@@ -33,13 +90,19 @@
   if (!empty($variables['scripts'])) {
     // Get an array of all the JavaScript files loaded by Drupal on this page.
     $scripts = drupal_add_js();
-
-    // Create a $scripts record for our new jQuery file.
-    $jquery_path = drupal_get_path('module', 'jquery_update') . '/jquery.js';
-    $new_jquery = array($jquery_path => $scripts['core']['misc/jquery.js']);
-
-    // Replace misc/jquery.js with ours.
-    $scripts['core'] = array_merge($new_jquery, $scripts['core']);
+    
+    if (variable_get('use_google', 0) == 1) {    
+      $head = drupal_get_html_head();
+      $head .= '<script src="http://ajax.googleapis.com/ajax/libs/jquery/'. variable_get('jquery_version', GAL_API_VERSION_DEFAULT) .'/jquery.min.js" type="text/javascript"></script>' . PHP_EOL;
+      $variables['head'] = $head;    
+    } else {    
+      // Create a $scripts record for our new jQuery file.
+      $jquery_path = drupal_get_path('module', 'jquery_update') . '/jquery.js';
+      $new_jquery = array($jquery_path => $scripts['core']['misc/jquery.js']);
+  
+      // Replace misc/jquery.js with ours.
+      $scripts['core'] = array_merge($new_jquery, $scripts['core']);
+    }
     unset($scripts['core']['misc/jquery.js']);
     $variables['scripts'] = drupal_get_js('header', $scripts);
   }
@@ -55,14 +118,17 @@
  */
 function jquery_update_get_version() {
   $version = 0;
-  $pattern = '# * jQuery ([0-9\.a-z]+) - New Wave Javascript#';
-  $jquery_path = drupal_get_path('module', 'jquery_update') . '/jquery.js';
-
-  // Return the version provided by jQuery Update.
-  $jquery = file_get_contents($jquery_path);
-  if (preg_match($pattern, $jquery, $matches)) {
-    $version = $matches[1];
-  }
-
+  if (variable_get('use_google', 0) == 1) {
+    $version = variable_get('jquery_version', GAL_API_VERSION_DEFAULT);
+  } else {
+    $pattern = '# * jQuery ([0-9\.a-z]+) - New Wave Javascript#';
+    $jquery_path = drupal_get_path('module', 'jquery_update') . '/jquery.js';
+  
+    // Return the version provided by jQuery Update.
+    $jquery = file_get_contents($jquery_path);
+    if (preg_match($pattern, $jquery, $matches)) {
+      $version = $matches[1];
+    }  
+  }  
   return $version;
 }

