Skip to content

Instantly share code, notes, and snippets.

@gavinblair
Created April 7, 2011 15:14
Show Gist options
  • Save gavinblair/907973 to your computer and use it in GitHub Desktop.
Save gavinblair/907973 to your computer and use it in GitHub Desktop.
Use the latest jQuery with your Drupal theme
<?php
function {theme_name}_preprocess(&$vars, $hook) {
if (arg(0) != 'admin' && $hook == "page") {
// Get an array of all JavaScripts that have been added
$javascript = drupal_add_js(NULL, NULL, 'header');
// Remove the original jQuery library and Drupal's JS include
unset($javascript['core']['misc/jquery.js']);
unset($javascript['core']['misc/drupal.js']);
// Add in our new jQuery library and Drupal's JS include
// We do it this way to keep the includes in the same order
$core = array(
//Alternative jQuery
drupal_get_path('theme', '{theme_name}').'/js/libs/jquery-1.5.1.min.js' => array(
'cache' => TRUE,
'defer' => FALSE,
),
'misc/drupal.js' => array(
'cache' => TRUE,
'defer' => FALSE,
)
);
// Merge back into the array of core JavaScripts
$javascript['core'] = array_merge($javascript['core'], $core);
// Rerender the block of JavaScripts
$vars['scripts'] = drupal_get_js(NULL, $javascript);
}
}
?>
@gavinblair
Copy link
Author

Adding a second jQuery in another namespace was suggested, but I don't like the thought of loading jQuery twice - it's small but not that small.

I'm not sure, 1.5.1 is what came with the HTML5 Boilerplate.

@gavinblair
Copy link
Author

My goal is to have the frontend completely independent of Drupal styles and scripts.

@SeanJA
Copy link

SeanJA commented Apr 7, 2011

My goal is to have the frontend completely independent of Drupal styles and scripts.

A lofty goal, but there are lots of modules that use javascript on the front end...

@SeanJA
Copy link

SeanJA commented Apr 7, 2011

Which admin menu are you using?

@gavinblair
Copy link
Author

I was using a module called Administration, but now I'm using a module called Toolbars

@gavinblair
Copy link
Author

wow Toolbar is really bad - switching to SimpleMenu. Working fine so far!

@SeanJA
Copy link

SeanJA commented Apr 11, 2011

totally using this on http://i.seanja.com so I can use a lightbox plugin to show the images full size

@SeanJA
Copy link

SeanJA commented Apr 12, 2011

Hmmm... it doesn't really work with compression turned on...

@gavinblair
Copy link
Author

Does it include it? Does it include Drupal's jQuery instead?

@SeanJA
Copy link

SeanJA commented Apr 12, 2011

I think it might be, I am going to try it out again when I get home to see what it is actually doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment