advagg_js_cdn.module

  1. cis7 sites/all/modules/ulmus/advagg/advagg_js_cdn/advagg_js_cdn.module
  2. cle7 sites/all/modules/ulmus/advagg/advagg_js_cdn/advagg_js_cdn.module
  3. ecd7 sites/all/modules/ulmus/advagg/advagg_js_cdn/advagg_js_cdn.module
  4. elmsmedia7 sites/all/modules/ulmus/advagg/advagg_js_cdn/advagg_js_cdn.module
  5. harmony7 sites/all/modules/ulmus/advagg/advagg_js_cdn/advagg_js_cdn.module
  6. icor7 sites/all/modules/ulmus/advagg/advagg_js_cdn/advagg_js_cdn.module
  7. meedjum_blog7 sites/all/modules/ulmus/advagg/advagg_js_cdn/advagg_js_cdn.module
  8. mooc7 sites/all/modules/ulmus/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 Implements 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

sites/all/modules/ulmus/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. * Implements 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. // @ignore sniffer_commenting_inlinecomment_spacingbefore:4
  44. // @ignore sniffer_whitespace_openbracketspacing_openingwhitespace:8
  45. // Only modify if
  46. // advagg_js_cdn_jquery is enabled,
  47. // name is misc/jquery.js,
  48. // and type is file.
  49. if ( variable_get('advagg_js_cdn_jquery', ADVAGG_JS_CDN_JQUERY)
  50. && $name == 'misc/jquery.js'
  51. && $javascript[$name]['type'] == 'file'
  52. ) {
  53. // Add in backup.
  54. $values['weight'] += 0.00001;
  55. $values['data'] = 'window.jQuery || document.write("<script src=\'' . base_path() . $values['data'] . '\'>\x3C/script>")';
  56. $values['type'] = 'inline';
  57. $javascript[$name . 'backup.js'] = $values;
  58. // Change core to external.
  59. $javascript[$name]['data'] = '//ajax.googleapis.com/ajax/libs/jquery/' . $jquery_version . '/jquery' . $min . '.js';
  60. $javascript[$name]['type'] = 'external';
  61. }
  62. // @ignore sniffer_commenting_inlinecomment_spacingbefore:4
  63. // @ignore sniffer_whitespace_openbracketspacing_openingwhitespace:8
  64. // Only modify if
  65. // advagg_js_cdn_jquery_ui is enabled,
  66. // name is in the $ui_mapping array.
  67. // and type is file.
  68. if ( variable_get('advagg_js_cdn_jquery_ui', ADVAGG_JS_CDN_JQUERY_UI)
  69. && array_key_exists($name, $ui_mapping)
  70. && $javascript[$name]['type'] == 'file'
  71. ) {
  72. // We only need one file.
  73. if (!$add_in_ui) {
  74. // Add in backup.
  75. $values['weight'] += 0.00001;
  76. $values['data'] = 'window.jQuery.ui || document.write("<script src=\'' . base_path() . drupal_get_path('module', 'advagg_js_cdn') . '/js/jquery-ui.js' . '\'>\x3C/script>")';
  77. $values['type'] = 'inline';
  78. $javascript[$name . 'backup.js'] = $values;
  79. // Change core to external.
  80. $add_in_ui = TRUE;
  81. $javascript[$name]['data'] = '//ajax.googleapis.com/ajax/libs/jqueryui/' . $jquery_ui_version . '/jquery-ui' . $min . '.js';
  82. $javascript[$name]['type'] = 'external';
  83. }
  84. else {
  85. unset($javascript[$name]);
  86. }
  87. }
  88. }
  89. }
  90. /**
  91. * Return an array of jquery ui files.
  92. *
  93. * @return array
  94. * array of jQuery UI file locations.
  95. */
  96. function advagg_js_cdn_get_ui_mapping() {
  97. // Replace jQuery UI's JavaScript, beginning by defining the mapping.
  98. $ui_mapping = array(
  99. 'misc/ui/jquery.effects.blind.min.js' => 'effects.blind',
  100. 'misc/ui/jquery.effects.bounce.min.js' => 'effects.bounce',
  101. 'misc/ui/jquery.effects.clip.min.js' => 'effects.clip',
  102. 'misc/ui/jquery.effects.core.min.js' => 'effects.core',
  103. 'misc/ui/jquery.effects.drop.min.js' => 'effects.drop',
  104. 'misc/ui/jquery.effects.explode.min.js' => 'effects.explode',
  105. 'misc/ui/jquery.effects.fade.min.js' => 'effects.fade',
  106. 'misc/ui/jquery.effects.fold.min.js' => 'effects.fold',
  107. 'misc/ui/jquery.effects.highlight.min.js' => 'effects.highlight',
  108. 'misc/ui/jquery.effects.pulsate.min.js' => 'effects.pulsate',
  109. 'misc/ui/jquery.effects.scale.min.js' => 'effects.scale',
  110. 'misc/ui/jquery.effects.shake.min.js' => 'effects.shake',
  111. 'misc/ui/jquery.effects.slide.min.js' => 'effects.slide',
  112. 'misc/ui/jquery.effects.transfer.min.js' => 'effects.transfer',
  113. 'misc/ui/jquery.ui.accordion.min.js' => 'ui.accordion',
  114. 'misc/ui/jquery.ui.autocomplete.min.js' => 'ui.autocomplete',
  115. 'misc/ui/jquery.ui.button.min.js' => 'ui.button',
  116. 'misc/ui/jquery.ui.core.min.js' => 'ui.core',
  117. 'misc/ui/jquery.ui.datepicker.min.js' => 'ui.datepicker',
  118. 'misc/ui/jquery.ui.dialog.min.js' => 'ui.dialog',
  119. 'misc/ui/jquery.ui.draggable.min.js' => 'ui.draggable',
  120. 'misc/ui/jquery.ui.droppable.min.js' => 'ui.droppable',
  121. 'misc/ui/jquery.ui.mouse.min.js' => 'ui.mouse',
  122. 'misc/ui/jquery.ui.position.min.js' => 'ui.position',
  123. 'misc/ui/jquery.ui.progressbar.min.js' => 'ui.progressbar',
  124. 'misc/ui/jquery.ui.resizable.min.js' => 'ui.resizable',
  125. 'misc/ui/jquery.ui.selectable.min.js' => 'ui.selectable',
  126. 'misc/ui/jquery.ui.slider.min.js' => 'ui.slider',
  127. 'misc/ui/jquery.ui.sortable.min.js' => 'ui.sortable',
  128. 'misc/ui/jquery.ui.tabs.min.js' => 'ui.tabs',
  129. 'misc/ui/jquery.ui.widget.min.js' => 'ui.widget',
  130. );
  131. return $ui_mapping;
  132. }