You are here

function jquery_update_jquery_replace in jQuery Update 7.2

Same name and namespace in other branches
  1. 7.3 jquery_update.module \jquery_update_jquery_replace()

Update jQuery to the CDN or local path.

Parameters

array $javascript: The library definition array as seen in hook_library_alter().

string $cdn: The name of the CDN option to use. Possible options are:

  • none
  • google
  • microsoft

string $path: The path to the module where replacements can be found.

string $min: The '.min' to include in the file name if we are requesting a minified version.

string $version: The version of jQuery to use.

1 call to jquery_update_jquery_replace()
jquery_update_library_alter in ./jquery_update.module
Implements hook_library_alter().

File

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

Code

function jquery_update_jquery_replace(&$javascript, $cdn, $path, $min, $version) {

  // Make sure to use the latest version in given branch.
  $trueversion = NULL;
  switch ($version) {
    case '1.5':
      $trueversion = '1.5.2';
      break;
    case '1.7':
      $trueversion = '1.7.2';
      break;
    case '1.8':
      $trueversion = '1.8.3';
      break;
    case '1.9':
      $trueversion = '1.9.1';
      break;
    case '1.10':
      $trueversion = '1.10.2';
      break;
  }
  $javascript['jquery']['version'] = $trueversion;

  // Check for CDN support.
  switch ($cdn) {
    case 'google':
      $javascript['jquery']['js']['misc/jquery.js']['data'] = '//ajax.googleapis.com/ajax/libs/jquery/' . $trueversion . '/jquery' . $min . '.js';
      $javascript['jquery']['js']['misc/jquery.js']['type'] = 'external';
      jquery_update_jquery_backup($javascript, $path, $min, $version);
      break;
    case 'microsoft':
      $javascript['jquery']['js']['misc/jquery.js']['data'] = '//ajax.aspnetcdn.com/ajax/jQuery/jquery-' . $trueversion . $min . '.js';
      $javascript['jquery']['js']['misc/jquery.js']['type'] = 'external';
      jquery_update_jquery_backup($javascript, $path, $min, $version);
      break;
    case 'jquery':
      $javascript['jquery']['js']['misc/jquery.js']['data'] = '//code.jquery.com/jquery-' . $trueversion . $min . '.js';
      $javascript['jquery']['js']['misc/jquery.js']['type'] = 'external';
      jquery_update_jquery_backup($javascript, $path, $min, $version);
      break;
    case 'none':
    default:
      $javascript['jquery']['js']['misc/jquery.js']['data'] = $path . '/replace/jquery/' . $version . '/jquery' . $min . '.js';
      break;
  }
}