Drupal 6.x + jQuery 1.4.2 = New Possibilities

Déja Augustine's picture

Software Architect

Blog

Drupal 6.x + jQuery 1.4.2 = New Possibilities

Aug 26, 2010

Déja Augustine

share

jQuery is the bread and butter of rapidly developing a highly-interactive websites, and Drupal has long made use of it, and indeed includes it as part of its core install.

There's only one catch... Drupal 6.x (the current stable version of Drupal) is still living in 2008, shipping with the antiquated jQuery 1.2.6. Over the intervening two years since the release of 1.2.6, there have been substantial additions and upgrades to the jQuery library, as well as several tools (such as the jQTouch library) that rely on those changes. As of the writing of this post, the current jQuery version is 1.4.2.

The jquery_update module has done a fantastic job of letting users upgrade the version of jQuery used by Drupal, but unfortunately the jquery_update module got stuck at 1.3.2.

The culprit: a bug in Drupal's core function drupal_to_js(). This function exports a PHP variable into the JS space. The issue is that it preforms some text modification to convert characters such as ampersands, angle-brackets, and line endings into their escaped unicode equivalents. Unfortunately, it does not do a very complete job and as a result, many issues arise when jQuery is upgraded to 1.4.2.

As is often the case, the Drupal community stepped up and created a patch that fixes the issue (for your convenience, I've attached this patch below). Unfortunately, after more than six weeks, there has been little-to-no movement to include the patch in future releases of Drupal 6.x. This leaves us with the distasteful, but worthwhile, task of repatching the core whenever a new core update is released.

Warning: if you are not comfortable working with PHP, I'd advise against patching as it can occasionally call for hand-editing. As always BACKUP DRUPAL before you upgrade or patch anything.

There is excellent documentation on applying patches over at drupal.org (and a really good babysteps patching guide as well), so I won't go through it all again here. One very handy technique I will share, though, is to create a folder in your sites folder (call it patches, or hacks, or something along those lines) to store your .patch files in so that the .patch files aren't lost when you upgrade your core, so you can easily re-apply them.

Once the bugfix has been applied to the Drupal 6 core, make sure that your jquery_update module is up-to-date and apply this patch to coax jquery_update to use jQuery 1.4.2. This patch is also included in the package attached to this post.

With both patches applied, enable jquery_update and bask in the glory that is jQuery 1.4.2, and welcome Drupal 6.x to 2010!

Patch: drupal_to_js() bug fix - http://drupal.org/node/479368#comment-3198886
Patch: jquery_update to 1.4 - http://drupal.org/node/775924#comment-3274706