advagg_css_cdn.module

  1. cis7 sites/all/modules/ulmus/advagg/advagg_css_cdn/advagg_css_cdn.module
  2. cle7 sites/all/modules/ulmus/advagg/advagg_css_cdn/advagg_css_cdn.module
  3. ecd7 sites/all/modules/ulmus/advagg/advagg_css_cdn/advagg_css_cdn.module
  4. elmsmedia7 sites/all/modules/ulmus/advagg/advagg_css_cdn/advagg_css_cdn.module
  5. harmony7 sites/all/modules/ulmus/advagg/advagg_css_cdn/advagg_css_cdn.module
  6. icor7 sites/all/modules/ulmus/advagg/advagg_css_cdn/advagg_css_cdn.module
  7. meedjum_blog7 sites/all/modules/ulmus/advagg/advagg_css_cdn/advagg_css_cdn.module
  8. mooc7 sites/all/modules/ulmus/advagg/advagg_css_cdn/advagg_css_cdn.module

Advanced aggregation js cdn module.

Functions

Constants

Namesort descending Description
ADVAGG_CSS_CDN_JQUERY_UI Default value to see if jquery-ui should be grabbed from the Google CDN.
ADVAGG_CSS_CDN_JQUERY_UI_VERSION Default jquery ui version.

File

sites/all/modules/ulmus/advagg/advagg_css_cdn/advagg_css_cdn.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Advanced aggregation js cdn module.
  5. */
  6. /**
  7. * Default value to see if jquery-ui should be grabbed from the Google CDN.
  8. */
  9. define('ADVAGG_CSS_CDN_JQUERY_UI', TRUE);
  10. /**
  11. * Default jquery ui version.
  12. */
  13. define('ADVAGG_CSS_CDN_JQUERY_UI_VERSION', '1.8.7');
  14. /**
  15. * Implements hook_css_alter().
  16. */
  17. function advagg_css_cdn_css_alter(&$css) {
  18. // Only modify if jquery_update is not enabled,
  19. if (module_exists('jquery_update')) {
  20. return;
  21. }
  22. // Setup variables.
  23. // jquery ui.
  24. $jquery_ui_version = variable_get('advagg_css_cdn_jquery_ui_version', ADVAGG_CSS_CDN_JQUERY_UI_VERSION);
  25. $ui_mapping = advagg_css_cdn_get_ui_mapping();
  26. $add_in_ui = FALSE;
  27. foreach ($css as $name => $values) {
  28. // @ignore sniffer_commenting_inlinecomment_spacingbefore:4
  29. // @ignore sniffer_whitespace_openbracketspacing_openingwhitespace:8
  30. // Only modify if
  31. // advagg_css_cdn_jquery_ui is enabled,
  32. // name is in the $ui_mapping array.
  33. // and type is file.
  34. if ( variable_get('advagg_css_cdn_jquery_ui', ADVAGG_CSS_CDN_JQUERY_UI)
  35. && array_key_exists($name, $ui_mapping)
  36. && $css[$name]['type'] == 'file'
  37. ) {
  38. $css[$name]['data'] = '//ajax.googleapis.com/ajax/libs/jqueryui/' . $jquery_ui_version . '/themes/base/jquery.' . $ui_mapping[$name] . '.css';
  39. $css[$name]['type'] = 'external';
  40. // Fallback can not work do to "SecurityError: The operation is insecure."
  41. }
  42. }
  43. }
  44. /**
  45. * Return an array of jquery ui files.
  46. */
  47. function advagg_css_cdn_get_ui_mapping() {
  48. // Replace jQuery UI's CSS, beginning by defining the mapping.
  49. $ui_mapping = array(
  50. 'misc/ui/jquery.ui.accordion.css' => 'ui.accordion',
  51. 'misc/ui/jquery.ui.autocomplete.css' => 'ui.autocomplete',
  52. 'misc/ui/jquery.ui.button.css' => 'ui.button',
  53. 'misc/ui/jquery.ui.core.css' => 'ui.core',
  54. 'misc/ui/jquery.ui.datepicker.css' => 'ui.datepicker',
  55. 'misc/ui/jquery.ui.dialog.css' => 'ui.dialog',
  56. 'misc/ui/jquery.ui.progressbar.css' => 'ui.progressbar',
  57. 'misc/ui/jquery.ui.resizable.css' => 'ui.resizable',
  58. 'misc/ui/jquery.ui.selectable.css' => 'ui.selectable',
  59. 'misc/ui/jquery.ui.slider.css' => 'ui.slider',
  60. 'misc/ui/jquery.ui.tabs.css' => 'ui.tabs',
  61. 'misc/ui/jquery.ui.theme.css' => 'ui.theme',
  62. );
  63. return $ui_mapping;
  64. }
  65. /**
  66. * Implements hook_advagg_css_groups_alter().
  67. */
  68. function advagg_css_cdn_advagg_css_groups_alter(&$css_groups, $preprocess_css) {
  69. // Work around a bug with seven_css_alter.
  70. // http://drupal.org/node/1937860
  71. $theme_keys[] = $GLOBALS['theme'];
  72. if (!empty($GLOBALS['base_theme_info'])) {
  73. foreach ($GLOBALS['base_theme_info'] as $base) {
  74. $theme_keys[] = $base->name;
  75. }
  76. }
  77. $match = FALSE;
  78. foreach ($theme_keys as $name) {
  79. if ($name == 'seven') {
  80. $match = TRUE;
  81. }
  82. }
  83. if (empty($match)) {
  84. return;
  85. }
  86. $target = FALSE;
  87. $last_group = FALSE;
  88. $last_key = FALSE;
  89. $kill_key = FALSE;
  90. $replaced = FALSE;
  91. foreach ($css_groups as $key => $group) {
  92. if (empty($target)) {
  93. if ($group['type'] == 'external' && $group['preprocess'] && $preprocess_css) {
  94. foreach ($group['items'] as $k => $value) {
  95. if ($value['data'] == 'themes/seven/jquery.ui.theme.css') {
  96. // Type should be file and not external (core bug).
  97. $value['type'] = 'file';
  98. $target = $value;
  99. unset($css_groups[$key]['items'][$k]);
  100. if (empty($css_groups[$key]['items'])) {
  101. unset($css_groups[$key]);
  102. $kill_key = $key;
  103. }
  104. }
  105. }
  106. }
  107. }
  108. else {
  109. $diff = array_merge(array_diff_assoc($group['browsers'], $target['browsers']), array_diff_assoc($target['browsers'], $group['browsers']));
  110. // @ignore sniffer_whitespace_openbracketspacing_openingwhitespace:8
  111. if ( $group['type'] != $target['type']
  112. || $group['group'] != $target['group']
  113. || $group['every_page'] != $target['every_page']
  114. || $group['media'] != $target['media']
  115. || $group['media'] != $target['media']
  116. || $group['preprocess'] != $target['preprocess']
  117. || !empty($diff)
  118. ) {
  119. if (!empty($last_group)) {
  120. $diff = array_merge(array_diff_assoc($last_group['browsers'], $target['browsers']), array_diff_assoc($target['browsers'], $last_group['browsers']));
  121. // @ignore sniffer_whitespace_openbracketspacing_openingwhitespace:8
  122. if ( $last_group['type'] != $target['type']
  123. || $last_group['group'] != $target['group']
  124. || $last_group['every_page'] != $target['every_page']
  125. || $last_group['media'] != $target['media']
  126. || $last_group['media'] != $target['media']
  127. || $last_group['preprocess'] != $target['preprocess']
  128. || !empty($diff)
  129. ) {
  130. // Insert New.
  131. $css_groups[$kill_key] = array(
  132. 'group' => $target['group'],
  133. 'type' => $target['type'],
  134. 'every_page' => $target['every_page'],
  135. 'media' => $target['media'],
  136. 'preprocess' => $target['preprocess'],
  137. 'browsers' => $target['browsers'],
  138. 'items' => array($target),
  139. );
  140. $replaced = TRUE;
  141. }
  142. else {
  143. // Insert above.
  144. $css_groups[$last_key]['items'][] = $target;
  145. $replaced = TRUE;
  146. }
  147. }
  148. }
  149. else {
  150. // Insert below.
  151. array_unshift($css_groups[$key]['items'], $target);
  152. $replaced = TRUE;
  153. }
  154. }
  155. $last_group = $group;
  156. $last_key = $key;
  157. if ($replaced) {
  158. break;
  159. }
  160. }
  161. ksort($css_groups);
  162. }