Tuesday, March 27, 2012

Drupal 6 jquery_update and jQuery 1.7.1

In experimenting jQuery 1.7.1 with Drupal 6, I found my portman application which uses jQuery UI is broken. Searching on Drupal's website, it seems that the discussion has been going on for a while, dating back to jQuery 1.5. There may be other issues with newer jQuery versions as many Drupal modules are not updated to work with new jQuery.

So, this article is written to record my experiment only. Use the information here with caution if you do.

The jquery_update module would not load the minified jQuery 1.7.1 because the version id in the minified file changes for some reason. I choose to patch the jquery_update module -- hopefully jQuery people don't change the version id too often. Below is the patch.

--- jquery_update.module~       2010-04-23 12:34:39.000000000 -0400
+++ jquery_update.module        2012-03-27 10:54:30.170830649 -0400
@@ -96,7 +96,8 @@
  */
 function jquery_update_get_version($jquery_path = NULL) {
   $version = 0;
-  $pattern = '# * jQuery JavaScript Library v([0-9\.a-z]+)#';
+  $pattern1 = '# * jQuery JavaScript Library v([0-9\.a-z]+)#';
+  $pattern2 = '#/*! jQuery v([0-9\.a-z]+) jquery.com | jquery.org/license */#';

   // No file is passed in so default to the file included with this module.
   if (is_null($jquery_path)) {
@@ -105,7 +106,8 @@

   // Return the version provided by jQuery Update.
   $jquery = file_get_contents($jquery_path);
-  if (preg_match($pattern, $jquery, $matches)) {
+  if (preg_match($pattern1, $jquery, $matches)
+      || preg_match($pattern2, $jquery, $matches)) {
     $version = $matches[1];
   }