advagg_js_cdn.module

  1. nittany7 modules/contrib/advagg/advagg_js_cdn/advagg_js_cdn.module
  2. cis7 modules/contrib/advagg/advagg_js_cdn/advagg_js_cdn.module
  3. mooc7 modules/contrib/advagg/advagg_js_cdn/advagg_js_cdn.module

Advanced aggregation js cdn module.

Functions

Namesort descending Description
advagg_js_cdn_get_ui_mapping Return an array of jquery ui files.
advagg_js_cdn_js_alter Implement hook_js_alter.

Constants

Namesort descending Description
ADVAGG_JS_CDN_COMPRESSION Default minification.
ADVAGG_JS_CDN_JQUERY Default value to see if jquery should be grabbed from the Google CDN.
ADVAGG_JS_CDN_JQUERY_UI Default value to see if jquery-ui should be grabbed from the Google CDN.
ADVAGG_JS_CDN_JQUERY_UI_VERSION Default jquery ui version.
ADVAGG_JS_CDN_JQUERY_VERSION Default jquery version.

File

modules/contrib/advagg/advagg_js_cdn/advagg_js_cdn.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Advanced aggregation js cdn module.
  5. */
  6. /**
  7. * Default value to see if jquery should be grabbed from the Google CDN.
  8. */
  9. define('ADVAGG_JS_CDN_JQUERY', TRUE);
  10. /**
  11. * Default value to see if jquery-ui should be grabbed from the Google CDN.
  12. */
  13. define('ADVAGG_JS_CDN_JQUERY_UI', TRUE);
  14. /**
  15. * Default jquery version.
  16. */
  17. define('ADVAGG_JS_CDN_JQUERY_VERSION', '1.4.4');
  18. /**
  19. * Default jquery ui version.
  20. */
  21. define('ADVAGG_JS_CDN_JQUERY_UI_VERSION', '1.8.7');
  22. /**
  23. * Default minification.
  24. */
  25. define('ADVAGG_JS_CDN_COMPRESSION', TRUE);
  26. /**
  27. * Implement hook_js_alter.
  28. */
  29. function advagg_js_cdn_js_alter(&$javascript) {
  30. // Only modify if jquery_update is not enabled,
  31. if (module_exists('jquery_update')) {
  32. return;
  33. }
  34. // Setup variables.
  35. // jquery.
  36. $jquery_version = variable_get('advagg_js_cdn_jquery_version', ADVAGG_JS_CDN_JQUERY_VERSION);
  37. $min = variable_get('advagg_js_cdn_compression', ADVAGG_JS_CDN_COMPRESSION) ? '.min' : '';
  38. // jquery ui.
  39. $jquery_ui_version = variable_get('advagg_js_cdn_jquery_ui_version', ADVAGG_JS_CDN_JQUERY_UI_VERSION);
  40. $ui_mapping = advagg_js_cdn_get_ui_mapping();
  41. $add_in_ui = FALSE;
  42. foreach ($javascript as $name => $values) {
  43. // Only modify if
  44. // advagg_js_cdn_jquery is enabled,
  45. // name is misc/jquery.js,
  46. // and type is file.
  47. if ( variable_get('advagg_js_cdn_jquery', ADVAGG_JS_CDN_JQUERY)
  48. && $name == 'misc/jquery.js'
  49. && $javascript[$name]['type'] == 'file'
  50. ) {
  51. $javascript[$name]['data'] = '//ajax.googleapis.com/ajax/libs/jquery/'. $jquery_version . '/jquery' . $min . '.js';
  52. $javascript[$name]['type'] = 'external';
  53. }
  54. // Only modify if
  55. // advagg_js_cdn_jquery_ui is enabled,
  56. // name is in the $ui_mapping array.
  57. // and type is file.
  58. if ( variable_get('advagg_js_cdn_jquery_ui', ADVAGG_JS_CDN_JQUERY_UI)
  59. && array_key_exists($name, $ui_mapping)
  60. && $javascript[$name]['type'] == 'file'
  61. ) {
  62. // We only need one file
  63. if (!$add_in_ui) {
  64. $add_in_ui = TRUE;
  65. $javascript[$name]['data'] = '//ajax.googleapis.com/ajax/libs/jqueryui/'. $jquery_ui_version . '/jquery-ui' . $min . '.js';
  66. $javascript[$name]['type'] = 'external';
  67. }
  68. else {
  69. unset($javascript[$name]);
  70. }
  71. }
  72. }
  73. }
  74. /**
  75. * Return an array of jquery ui files.
  76. */
  77. function advagg_js_cdn_get_ui_mapping() {
  78. // Replace jQuery UI's JavaScript, beginning by defining the mapping.
  79. $ui_mapping = array(
  80. 'misc/ui/jquery.effects.blind.min.js' => 'effects.blind',
  81. 'misc/ui/jquery.effects.bounce.min.js' => 'effects.bounce',
  82. 'misc/ui/jquery.effects.clip.min.js' => 'effects.clip',
  83. 'misc/ui/jquery.effects.core.min.js' => 'effects.core',
  84. 'misc/ui/jquery.effects.drop.min.js' => 'effects.drop',
  85. 'misc/ui/jquery.effects.explode.min.js' => 'effects.explode',
  86. 'misc/ui/jquery.effects.fade.min.js' => 'effects.fade',
  87. 'misc/ui/jquery.effects.fold.min.js' => 'effects.fold',
  88. 'misc/ui/jquery.effects.highlight.min.js' => 'effects.highlight',
  89. 'misc/ui/jquery.effects.pulsate.min.js' => 'effects.pulsate',
  90. 'misc/ui/jquery.effects.scale.min.js' => 'effects.scale',
  91. 'misc/ui/jquery.effects.shake.min.js' => 'effects.shake',
  92. 'misc/ui/jquery.effects.slide.min.js' => 'effects.slide',
  93. 'misc/ui/jquery.effects.transfer.min.js' => 'effects.transfer',
  94. 'misc/ui/jquery.ui.accordion.min.js' => 'ui.accordion',
  95. 'misc/ui/jquery.ui.autocomplete.min.js' => 'ui.autocomplete',
  96. 'misc/ui/jquery.ui.button.min.js' => 'ui.button',
  97. 'misc/ui/jquery.ui.core.min.js' => 'ui.core',
  98. 'misc/ui/jquery.ui.datepicker.min.js' => 'ui.datepicker',
  99. 'misc/ui/jquery.ui.dialog.min.js' => 'ui.dialog',
  100. 'misc/ui/jquery.ui.draggable.min.js' => 'ui.draggable',
  101. 'misc/ui/jquery.ui.droppable.min.js' => 'ui.droppable',
  102. 'misc/ui/jquery.ui.mouse.min.js' => 'ui.mouse',
  103. 'misc/ui/jquery.ui.position.min.js' => 'ui.position',
  104. 'misc/ui/jquery.ui.progressbar.min.js' => 'ui.progressbar',
  105. 'misc/ui/jquery.ui.resizable.min.js' => 'ui.resizable',
  106. 'misc/ui/jquery.ui.selectable.min.js' => 'ui.selectable',
  107. 'misc/ui/jquery.ui.slider.min.js' => 'ui.slider',
  108. 'misc/ui/jquery.ui.sortable.min.js' => 'ui.sortable',
  109. 'misc/ui/jquery.ui.tabs.min.js' => 'ui.tabs',
  110. 'misc/ui/jquery.ui.widget.min.js' => 'ui.widget',
  111. );
  112. return $ui_mapping;
  113. }