hates the internet

Post thumbnail is Sun Server Rack by david

jQuery.noConflict in Drupal 6.15.

The problem stems from the fact that, by default, Drupal 6.15 doesn't use jQuery in noConflict mode so jQuery and MooTools wind up fighting each other over the coveted $ variable.  A few carefully crafted Google queries later I learned that this will most likely be fixed in version 7, but that didn't help me now.  There were quite a few forum posts that seemed as though they might, but I couldn't get any of the patches they contained to apply any semblance of quietly, which is understandable as most were pushing 2 years old.  Naturally, I didn't feel like creating a jQuery-based equivalent because JonDesign's gallery really truly is pretty damned slick (kudos, should you ever read this), so I thought I'd fix the problem myself.

One of the main reasons I like jQuery so much is it's extremely trivial to make it play nicely with other JavaScript libraries whether or not they usurp $.  Accomplishing this is well documented all over the internet and is simply wrapping your code in:

;(function($) {
// your jQuery code here, merrily using $
})(jQuery);

So basically, with 2 lines of code we can guarantee that jQuery is always going to be assigned to $, regardless of whether or not somebody further down the line invokes noConflict() or loads another library.  This is essentially what needs to be done to a few of the files in Drupal's misc/ directory.

The end result of all this mucking about is this patch.  This patch carries no warranty or guarantee, but it did work for me and it applied cleanly against a virgin Durpal 6.15.

In the templates that use SmoothGallery, I add a script block containing jQuery.noConflict(); before loading MooTools, but I'm pretty sure it's not needed.

Some plugins will require you to give their JavaScript files the same treatment if they're required to pay nice, but I didn't really have any problems.

Post new comment

The content of this field is kept private and will not be shown publicly.