Skip to content

Instantly share code, notes, and snippets.

@willmcneilly
Created October 13, 2011 16:25
Show Gist options
  • Save willmcneilly/1284697 to your computer and use it in GitHub Desktop.
Save willmcneilly/1284697 to your computer and use it in GitHub Desktop.
Hackety hack
/**
* Implementation of moduleName_preprocess_hook().
*
* Replace Drupal core's jquery.js with the new one from jQuery Update module.
*/
function jquery_update_preprocess_page(&$variables) {
// Only do this for pages that have JavaScript on them.
if (!empty($variables['scripts'])) {
// Perform the logic if either jQuery Update's jquery.js is newer than
// core's, or if we're using a different compression type.
if (variable_get('jquery_update_replace', TRUE) ||
variable_get('jquery_update_compression_type', 'pack') != 'pack') {
// Get an array of all the JavaScript files loaded by Drupal on this page.
$scripts = drupal_add_js();
// Replace jquery.js first.
$new_jquery = array(jquery_update_jquery_path() => $scripts['core']['misc/jquery.js']);
$scripts['core'] = array_merge($new_jquery, $scripts['core']);
unset($scripts['core']['misc/jquery.js']);
// Loop through each of the required replacements.
foreach (jquery_update_get_replacements() as $type => $replacements) {
foreach ($replacements as $find => $replace) {
// If the file to replace is loaded on this page...
if (isset($scripts[$type][$find])) {
// Create a new entry for the replacement file, and unset the original one.
$replace = JQUERY_UPDATE_REPLACE_PATH . '/' . $replace;
$scripts[$type][$replace] = $scripts[$type][$find];
unset($scripts[$type][$find]);
}
}
}
unset($scripts['module']['sites/all/modules/jquery_update/replace/jquery.js']); <------------------------
$variables['scripts'] = drupal_get_js('header', $scripts);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment