Category: Development

Drupal – Use a different jQuery version for the frontend and backend

Author(s)

Simon
Simon
On Drupal frontend I want the latest jQuery especially because bootstrap require at least jQuery 1.7. Drupal 7 come with jQuery 1.4 and it’s not going to be updated.
The module jQuery Update take care of updating jQuery to a newer version. I even use the dev version so I can have jQuery 1.8. Sadly this creates some bugs in the admin. To avoid conflict I decided to load a different jQuery version for the backend and the frontend.
To do that you have to create a very small module with this code:
/** * Implements hook_module_implements_alter(). */ function mymodule_module_implements_alter(&$implementations, $hook) { if ($hook == 'library_alter') { if(isset($implementations['jquery_update'])) { // Move jquery update to the end. This will make sure our hook_library_alter // is always called before the jquery_update. $jquery_update = $implementations['jquery_update']; unset($implementations['jquery_update']); $implementations['jquery_update'] = $jquery_update; } } }
/** * Implements hook_library_alter(). */ function mymodule_library_alter(&$libraries, $module) { // If it is the admin theme all we want to do is change the global $conf // variable so when jquery_update runs right after us it will use 1.5. // We are not using path_is_admin(current_path()) because some admin path can use // the frontend theme like node edit page global $theme_key; if (variable_get('admin_theme') == $theme_key) { // Modifying global $conf variable, can be dangerous. Be carefull. global $conf; $conf['jquery_update_jquery_version'] = '1.5'; } }
I also write some patches to try to solve the compatibility problem in jQuery and in core but I prefer to stay safe for now until it’s fixed. If you want to know more about the issue check out http://drupal.org/node/1498858.
On Drupal frontend I want the latest jQuery especially because bootstrap require at least jQuery 1.7. Drupal 7 come with jQuery 1.4 and it’s not going to be updated.
The module jQuery Update take care of updating jQuery to a newer version. I even use the dev version so I can have jQuery 1.8. Sadly this creates some bugs in the admin. To avoid conflict I decided to load a different jQuery version for the backend and the frontend.
To do that you have to create a very small module with this code:
/** * Implements hook_module_implements_alter(). */ function mymodule_module_implements_alter(&$implementations, $hook) { if ($hook == 'library_alter') { if(isset($implementations['jquery_update'])) { // Move jquery update to the end. This will make sure our hook_library_alter // is always called before the jquery_update. $jquery_update = $implementations['jquery_update']; unset($implementations['jquery_update']); $implementations['jquery_update'] = $jquery_update; } } }
/** * Implements hook_library_alter(). */ function mymodule_library_alter(&$libraries, $module) { // If it is the admin theme all we want to do is change the global $conf // variable so when jquery_update runs right after us it will use 1.5. // We are not using path_is_admin(current_path()) because some admin path can use // the frontend theme like node edit page global $theme_key; if (variable_get('admin_theme') == $theme_key) { // Modifying global $conf variable, can be dangerous. Be carefull. global $conf; $conf['jquery_update_jquery_version'] = '1.5'; } }
I also write some patches to try to solve the compatibility problem in jQuery and in core but I prefer to stay safe for now until it’s fixed. If you want to know more about the issue check out http://drupal.org/node/1498858.

More articles

Author(s)

Akira
Akira

Making of : “La nuit des Losers”

lanuitdeslosers.ch, built fast: paper wireframes, a bold hand-drawn identity, then Claude Code to prototype and ship. A mouse-tracking hero animation, a bowling game made of sponsor logos, and a few bugs we’re keeping.
lanuitdeslosers.ch, built fast: paper wireframes, a bold hand-drawn identity, then Claude Code to prototype and ship. A mouse-tracking hero animation, a bowling game made of sponsor logos, and a few bugs we’re keeping.
Making of : “La nuit des Losers”

Author(s)

Pierre
Pierre

Dark mode: necessity or trend

Nous faisons le tri entre idées reçues, réalités techniques et bonnes pratiques de design.
Nous faisons le tri entre idées reçues, réalités techniques et bonnes pratiques de design.
Dark mode: necessity or trend

Author(s)

Yann
Pierre
Yann and Pierre

Experiment #2 – Surway, a social experiments game

Pour notre deuxième expérimentation, nous avons relevé le défi de sortir de notre zone de confort en développant Surway, un jeu vidéo jouable directement dans le navigateur, où les actions de chaque joueur restent inscrites pour tous ceux qui suivront.
Pour notre deuxième expérimentation, nous avons relevé le défi de sortir de notre zone de confort en développant Surway, un jeu vidéo jouable directement dans le navigateur, où les actions de chaque joueur restent inscrites pour tous ceux qui suivront.
Experiment #2 – Surway, a social experiments game