Today for a customer I had to use a special plugin for jQuery that needs a jQuery version equal or major than 1.6.1.
As you know Drupal 7 is shipped with jQuery 1.4.4 and so is not ready for the plugin I need to use, there is a plugin that update jQuery and jQuery UI but where is the fun?
The procedure is pretty quick:
- Download the jQuery version you need from from the official source.
- Place the jQuery version you downloaded in your theme js’s folder (like MYTHEME/js/).
- Create/Modify your theme’s
template.php file as described below.
That is.
Now for the template.php, you need to use the hook_js_alter to replace the native jQuery:
function MYTHEME_js_alter(&$javascript) {
//We define the path of our new jquery core file
//assuming we are using the minified version 1.8.3
$jquery_path = drupal_get_path('theme','MYTHEME') . '/js/jquery-1.8.3.min.js';
//We duplicate the important information from the Drupal one
$javascript[$jquery_path] = $javascript['misc/jquery.js'];
//..and we update the information that we care about
$javascript[$jquery_path]['version'] = '1.8.3';
$javascript[$jquery_path]['data'] = $jquery_path;
//Then we remove the Drupal core version
unset($javascript['misc/jquery.js']);
}
After we clear the cache we will have the new jQuery version.
Keep in mind that changing the jQuery version may create some incompatibility issues with the other Drupal core scripts.
Enjoy!
Like this:
Like Loading...