You are here

function jquery_update_jquery_update_alter in jQuery Update 6.2

Implements hook_jquery_update_alter().

See also

hook_jquery_update_alter()

File

./jquery_update.module, line 13
Updates Drupal to use the latest version of jQuery.

Code

function jquery_update_jquery_update_alter(&$javascript) {
  $path = drupal_get_path('module', 'jquery_update') . '/replace/';
  $scripts = jquery_update_get_replacements();

  // Replace jquery.js first.
  $jquerypath = jquery_update_jquery_path();
  $new_jquery = array(
    $jquerypath => $javascript['core']['misc/jquery.js'],
  );
  $javascript['core'] = array_merge($new_jquery, $javascript['core']);
  $javascript['core'][$jquerypath]['version'] = variable_get('jquery_update_jquery_version', '1.3');
  unset($javascript['core']['misc/jquery.js']);

  // Loop through each of the required replacements.
  foreach ($scripts as $type => $replacements) {
    foreach ($replacements as $find => $replace) {

      // If the file to replace is loaded on this page...
      if (isset($javascript[$type][$find])) {

        // Create a new entry for the replacement file, and unset the original one.
        $javascript[$type][$path . $replace] = $javascript[$type][$find];
        unset($javascript[$type][$find]);
      }
    }
  }
}