Same name in other branches
- 5.0.x advagg_cdn/advagg_cdn.module \advagg_cdn_js_alter()
- 8.x-2.x advagg_cdn/advagg_cdn.module \advagg_cdn_js_alter()
- 8.x-4.x advagg_cdn/advagg_cdn.module \advagg_cdn_js_alter()
Implements hook_js_alter().
File
-
advagg_cdn/
advagg_cdn.module, line 11
Code
function advagg_cdn_js_alter(&$javascript) {
// Setup variables.
$cdn_settings = \Drupal::config('advagg_cdn.settings');
$cdn = $cdn_settings->get('cdn');
$min = $cdn_settings->get('minified') ? '.min' : '';
// If AdvAgg in development mode don't serve minified JS.
if (\Drupal::config('advagg.settings')->get('cache_level') < 0) {
$min = '';
}
$targets = [];
if ($cdn_settings->get('jquery')) {
$path = 'jquery/' . $cdn_settings->get('jquery_version') . '/jquery' . $min . '.js';
$targets['core/assets/vendor/jquery/jquery.min.js'] = [
'google' => 'https://ajax.googleapis.com/ajax/libs/' . $path,
'microsoft' => 'http://ajax.aspnetcdn.com/ajax/jQuery/jquery-' . $cdn_settings->get('jquery_version') . $min . '.js',
'type' => 'external',
'require' => 'window.jQuery',
];
}
if ($cdn_settings->get('jquery_ui_js')) {
$path = $cdn_settings->get('jquery_ui_version') . '/jquery-ui' . $min . '.js';
$targets += [
'core/assets/vendor/jquery.ui/ui/core-min.js' => [
'require' => 'window.jQuery.ui',
'type' => 'external',
'google' => 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . $path,
'microsoft' => 'https://ajax.aspnetcdn.com/ajax/jquery.ui/' . $path,
],
'core/assets/vendor/jquery.ui/ui/effect-blind-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-bounce-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-clip-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-drop-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-explode-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-fade-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-fold-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-highlight-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-puff-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-pulsate-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-scale-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-shake-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-size-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-slide-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/effect-transfer-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/accordion-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/autocomplete-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/button-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/datepicker-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/dialog-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/draggable-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/droppable-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/menu-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/mouse-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/position-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/progressbar-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/resizable-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/selectable-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/selectmenu-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/slider-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/sortable-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/spinner-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/tabs-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/tooltip-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
'core/assets/vendor/jquery.ui/ui/widget-min.js' => [
'unset' => TRUE,
'require' => 'window.jQuery.ui',
],
];
}
foreach ($targets as $name => $values) {
if (isset($javascript[$name])) {
if (isset($values['unset'])) {
unset($javascript[$name]);
}
elseif (isset($values[$cdn])) {
$javascript[$name]['data'] = $values[$cdn];
$javascript[$name]['type'] = $values['type'];
}
// Ensure full jQuery.ui is loaded if required since it is merged on CDN.
if ($values['require'] == 'window.jQuery.ui' && !isset($javascript['core/assets/vendor/jquery.ui/ui/core-min.js'])) {
$javascript['core/assets/vendor/jquery.ui/ui/core-min.js'] = [
'minified' => TRUE,
'weight' => -19.5,
'group' => -100,
'type' => 'external',
'scope' => 'footer',
'browsers' => [],
'data' => $targets['core/assets/vendor/jquery.ui/ui/core-min.js'][$cdn],
];
}
}
}
}