Skip to content

Instantly share code, notes, and snippets.

@kevinchampion
Created March 6, 2015 01:17
Show Gist options
  • Save kevinchampion/1283f7875658d5678c4c to your computer and use it in GitHub Desktop.
Save kevinchampion/1283f7875658d5678c4c to your computer and use it in GitHub Desktop.
Manual Drupal jQuery version change using hook_js_alter().
/**
* Implements hook_js_alter().
*/
function invideous_ooyala_integration_js_alter(&$javascript) {
$node = menu_get_object();
if (!empty($node) && $node->type == 'event') {
$state = _eversport_videofield_get_state($node);
$video = _eversport_videofield_get_video_by_state($state, $node);
if ($video['invideous_paywall_enable']) {
$new_player_events = variable_get('eversport_new_player_events', array());
if (in_array($node->nid, $new_player_events)) {
// Copy jquery to get all its properties.
$javascript['//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js'] = $javascript['sites/all/modules/contrib/jquery_update/replace/jquery/1.7/jquery.min.js'];
$javascript['//code.jquery.com/jquery-migrate-1.2.1.min.js'] = $javascript['sites/all/modules/contrib/jquery_update/replace/jquery/1.7/jquery.min.js'];
// Remove jquery.
unset($javascript['sites/all/modules/contrib/jquery_update/replace/jquery/1.7/jquery.min.js']);
// Add jquery 2.0.2.
$javascript['//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js']['data'] = '//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js';
$javascript['//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js']['type'] = 'external';
$javascript['//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js']['version'] = '2.0.2';
// Add jquery-migrate to patch functionality deprecated and removed in
// jquery 1.9 since we're using 2.0.2 now.
$javascript['//code.jquery.com/jquery-migrate-1.2.1.min.js']['data'] = '//code.jquery.com/jquery-migrate-1.2.1.min.js';
$javascript['//code.jquery.com/jquery-migrate-1.2.1.min.js']['type'] = 'external';
$javascript['//code.jquery.com/jquery-migrate-1.2.1.min.js']['version'] = '1.2.1';
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment