views:

88

answers:

4

hi,

I need to use the latest version of jQuery in my Drupal.

jQuery update module is not enough because it doesn't update jquery to its latest version.

Is there anyway to use the latest version of jquery in the front-end, and the drupal included version for the back-end ?

Should I work on the theme templates files ? Is this going to cause issues ?

thanks

A: 

Are you using separate themes for front-end and back-end? You can probably add some code to the themename_preprocess_page() function in the front-end's template.php to replace the jquery files in that theme only.

marcvangend
yes I'm using different themes. Exactly.. but I was wondering if this is safe. For example.. let's say I'm using lightbox module which requires jQuery: it is developed with the old jquery.. could it cause conflicts ?
Patrick
The problem is that jQuery is not used from a theme, but also from Drupal core codes.
kiamlaluno
Of course, kiamlaluno is right. However Drupal core and modules like CCK and Views mainly use jQuery on admin pages and much less on front-end pages. So, if you can make sure that your admin theme uses 1.2.6 while your front end theme uses 1.4.2, you have a lot less problems to solve.
marcvangend
There are modules that use jQuery for pages that are not administrative ones.
kiamlaluno
Conclusion: I'm going to have issues even if I only upgrade the front-end theme jquery.
Patrick
+1  A: 

Drupal includes the jQuery library in each page that uses JavaScript. The only way to use a more recent version of jQuery than the one Drupal comes with is to install jQuery Update, which provides also a script for compatibility with scripts using an older version of the library.

If you are going to simply replace the jQuery library contained in /misc, then Drupal scripts will stop to work (I tried doing that, and that was the result). Loading a more recent version after Drupal loaded the library in /misc will also cause problems.

To complete the information, there was a module that came with its own version of the jQuery library that was then binded to $ui; in that way, other code would still use the default jQuery library, while your module / theme would use the more recent library. The module simply loaded its own version of jQuery, and then executed the following JavaScript line:

window.$ui = jQuery.noConflict(true);

Using the same approach you would be able to load the latest version of jQuery without creating any conflict with existing modules. This system doesn't work if you are using a module developed from somebody else, and that uses Javascript code that uses $; it works for your custom module / theme you run on your site, though.

kiamlaluno
jQuery Update is usually what I recommend too, but unfortunately, the latest stable release ships with version 1.2.6 and the latest alpha release comes with 1.3.2. For people who really need jQuery 1.4.x, there is no perfect solution yet.
marcvangend
@marcvangend: that's the point. I totally agree, thanks.
Patrick
A: 

1) Download jquery-1.4.2.js and jquery-1.4.2.min.js. 2) Copy them to jquery_update/replace folder. 3) Edit jquery_update.module: replace function jquery_update_jquery_path(){} with

function jquery_update_jquery_path() { 
    $jquery_file = preg_match('/(admin|edit|add)/', request_uri()) ?
        array('none' => 'jquery.js',       'min' => 'jquery.min.js') :
        array('none' => 'jquery-1.4.2.js', 'min' => 'jquery-1.4.2.min.js');
    return JQUERY_UPDATE_REPLACE_PATH . '/' . $jquery_file[variable_get('jquery_update_compression_type', 'min')];
} 
k0teg
This is going to create me problems with some modules using jquery for front-end. See other answers/comments.
Patrick
A: 

What about using jQuery.noConflict()? I don't know of any concrete examples of Drupal modules that work in jQuery 1.2/1.3 but break in 1.4 to test this, but ostensibly loading jQuery 1.4 after Drupal loads jQuery 1.2/1.3 (so, add it to your theme) and using var jNew = jQuery.noConflict() would pass $() back to the jQuery most of Drupal expects, and allow you to use jNew() to do the jQuery 1.4 stuff you need to do.

Mark Trapp
I will try this solution. So, just to see if I understood well: when I select my items using jNew() I'm using the new jquery instead of the old one !?
Patrick
That's correct. Drupal and its modules will still select things with `$()` or `jQuery()` and never suspect that there's another version of jQuery also loaded.
Mark Trapp