advagg_css_cdn.module

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

Advanced aggregation js cdn module.

Functions

Namesort descending Description
advagg_css_cdn_advagg_css_groups_alter Implement hook_advagg_css_groups_alter.
advagg_css_cdn_css_alter Implement hook_css_alter.
advagg_css_cdn_get_ui_mapping Return an array of jquery ui files.

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

modules/contrib/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. * Implement 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. // Only modify if
  29. // advagg_css_cdn_jquery_ui is enabled,
  30. // name is in the $ui_mapping array.
  31. // and type is file.
  32. if ( variable_get('advagg_css_cdn_jquery_ui', ADVAGG_CSS_CDN_JQUERY_UI)
  33. && array_key_exists($name, $ui_mapping)
  34. && $css[$name]['type'] == 'file'
  35. ) {
  36. $css[$name]['data'] = '//ajax.googleapis.com/ajax/libs/jqueryui/'. $jquery_ui_version . '/themes/base/jquery.' . $ui_mapping[$name] . '.css';
  37. $css[$name]['type'] = 'external';
  38. }
  39. }
  40. }
  41. /**
  42. * Return an array of jquery ui files.
  43. */
  44. function advagg_css_cdn_get_ui_mapping() {
  45. // Replace jQuery UI's CSS, beginning by defining the mapping.
  46. $ui_mapping = array(
  47. 'misc/ui/jquery.ui.accordion.css' => 'ui.accordion',
  48. 'misc/ui/jquery.ui.autocomplete.css' => 'ui.autocomplete',
  49. 'misc/ui/jquery.ui.button.css' => 'ui.button',
  50. 'misc/ui/jquery.ui.core.css' => 'ui.core',
  51. 'misc/ui/jquery.ui.datepicker.css' => 'ui.datepicker',
  52. 'misc/ui/jquery.ui.dialog.css' => 'ui.dialog',
  53. 'misc/ui/jquery.ui.progressbar.css' => 'ui.progressbar',
  54. 'misc/ui/jquery.ui.resizable.css' => 'ui.resizable',
  55. 'misc/ui/jquery.ui.selectable.css' => 'ui.selectable',
  56. 'misc/ui/jquery.ui.slider.css' => 'ui.slider',
  57. 'misc/ui/jquery.ui.tabs.css' => 'ui.tabs',
  58. 'misc/ui/jquery.ui.theme.css' => 'ui.theme',
  59. );
  60. return $ui_mapping;
  61. }
  62. /**
  63. * Implement hook_advagg_css_groups_alter.
  64. */
  65. function advagg_css_cdn_advagg_css_groups_alter(&$css_groups, $preprocess_css) {
  66. // Work around a bug with seven_css_alter.
  67. // http://drupal.org/node/1937860
  68. $theme_keys[] = $GLOBALS['theme'];
  69. if (!empty($GLOBALS['base_theme_info'])) {
  70. foreach ($GLOBALS['base_theme_info'] as $base) {
  71. $theme_keys[] = $base->name;
  72. }
  73. }
  74. $match = FALSE;
  75. foreach ($theme_keys as $name) {
  76. if ($name == 'seven') {
  77. $match = TRUE;
  78. }
  79. }
  80. if (empty($match)) {
  81. return;
  82. }
  83. $target = FALSE;
  84. $last_group = FALSE;
  85. $last_key = FALSE;
  86. $kill_key = FALSE;
  87. $replaced = FALSE;
  88. foreach ($css_groups as $key => $group) {
  89. if (empty($target)) {
  90. if ($group['type'] == 'external' && $group['preprocess'] && $preprocess_css) {
  91. foreach ($group['items'] as $k => $value) {
  92. if ($value['data'] == 'themes/seven/jquery.ui.theme.css') {
  93. // Type should be file and not external (core bug).
  94. $value['type'] = 'file';
  95. $target = $value;
  96. unset($css_groups[$key]['items'][$k]);
  97. if (empty($css_groups[$key]['items'])) {
  98. unset($css_groups[$key]);
  99. $kill_key = $key;
  100. }
  101. }
  102. }
  103. }
  104. }
  105. else {
  106. $diff = array_merge(array_diff($group['browsers'], $target['browsers']), array_diff($target['browsers'], $group['browsers']));
  107. if ( $group['type'] != $target['type']
  108. || $group['group'] != $target['group']
  109. || $group['every_page'] != $target['every_page']
  110. || $group['media'] != $target['media']
  111. || $group['media'] != $target['media']
  112. || $group['preprocess'] != $target['preprocess']
  113. || !empty($diff)
  114. ) {
  115. if (!empty($last_group)) {
  116. $diff = array_merge(array_diff($last_group['browsers'], $target['browsers']), array_diff($target['browsers'], $last_group['browsers']));
  117. if ( $last_group['type'] != $target['type']
  118. || $last_group['group'] != $target['group']
  119. || $last_group['every_page'] != $target['every_page']
  120. || $last_group['media'] != $target['media']
  121. || $last_group['media'] != $target['media']
  122. || $last_group['preprocess'] != $target['preprocess']
  123. || !empty($diff)
  124. ) {
  125. // Insert New
  126. $css_groups[$kill_key] = array(
  127. 'group' => $target['group'],
  128. 'type' => $target['type'],
  129. 'every_page' => $target['every_page'],
  130. 'media' => $target['media'],
  131. 'preprocess' => $target['preprocess'],
  132. 'browsers' => $target['browsers'],
  133. 'items' => array($target),
  134. );
  135. $replaced = TRUE;
  136. }
  137. else {
  138. // Insert above.
  139. $css_groups[$last_key]['items'][] = $target;
  140. $replaced = TRUE;
  141. }
  142. }
  143. }
  144. else {
  145. // Insert below.
  146. array_unshift($css_groups[$key]['items'], $target);
  147. $replaced = TRUE;
  148. }
  149. }
  150. $last_group = $group;
  151. $last_key = $key;
  152. if ($replaced) {
  153. break;
  154. }
  155. }
  156. ksort($css_groups);
  157. }