You are here

function jquery_update_jquery_migrate_replace in jQuery Update 7.3

Enable and configure the jQuery Migrate Plugin

Parameters

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

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 jQuery version to be used.

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

File

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

Code

function jquery_update_jquery_migrate_replace(&$libraries, $path, $min, $version) {

  // Immediately return if jQuery Migrate isn't enabled or jQuery version
  // isn't at least 1.9 or higher.
  if (!variable_get('jquery_update_jquery_migrate_enable', FALSE) || !version_compare($version, '1.9', '>=')) {
    return;
  }
  if (version_compare($version, '3.0', '>=')) {
    $migrate_version = '3';
  }
  else {
    $migrate_version = '1';
  }
  $file = $path . '/replace/jquery-migrate/' . $migrate_version . '/jquery-migrate' . $min . '.js';

  // Note: this adds jQuery Migrate to the "system" module's library definition.
  $libraries['jquery.migrate'] = array(
    'title' => 'jQuery Migrate',
    'website' => 'http://plugins.jquery.com/migrate',
    'version' => $migrate_version,
    'js' => array(
      $file => array(
        'group' => JS_LIBRARY,
        // Ensure weight is higher than jQuery.
        'weight' => -19.8,
      ),
    ),
  );

  // Configure the jQuery Migrate plugin.
  // Note: This must be done after jQuery has loaded, but before the jQuery
  // migrate plugin has loaded.
  $data = 'jQuery.migrateMute=' . (variable_get('jquery_update_jquery_migrate_warnings', FALSE) ? 'false' : 'true') . ';';
  $data .= 'jQuery.migrateTrace=' . (variable_get('jquery_update_jquery_migrate_trace', FALSE) ? 'true' : 'false') . ';';
  $libraries['jquery.migrate']['js'][] = array(
    'data' => $data,
    'type' => 'inline',
    'group' => JS_LIBRARY,
    // Ensure weight is lower than jQuery Migrate.
    'weight' => -19.899999999,
  );

  // Check for CDN support.
  if (variable_get('jquery_update_jquery_migrate_cdn', 'none') === 'jquery') {
    $libraries['jquery.migrate']['js'][$file]['data'] = '//code.jquery.com/jquery-migrate-' . ($migrate_version === '3' ? '3.0.0' : '1.4.1') . $min . '.js';
    $libraries['jquery.migrate']['js'][$file]['type'] = 'external';
    jquery_update_jquery_migrate_backup($libraries, $path, $min, $migrate_version);
  }

  // Add jQuery Migrate as a dependency to jQuery.
  // Note: this is fine as the weight set above ensures it loads after jQuery.
  $libraries['jquery']['dependencies'][] = array(
    'system',
    'jquery.migrate',
  );
}