at_core.submit.builders.inc

  1. cis7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/forms/at_core.submit.builders.inc
  2. cle7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/forms/at_core.submit.builders.inc
  3. ecd7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/forms/at_core.submit.builders.inc
  4. elmsmedia7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/forms/at_core.submit.builders.inc
  5. harmony7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/forms/at_core.submit.builders.inc
  6. icor7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/forms/at_core.submit.builders.inc
  7. meedjum_blog7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/forms/at_core.submit.builders.inc
  8. mooc7 sites/all/themes/ulmus/adaptivetheme/at_core/inc/forms/at_core.submit.builders.inc

Page Layout CSS Builder.

Functions

Namesort descending Description
at_build_font_families Build font family CSS.
at_build_page_layout Build Page Layouts
at_build_panels_layout_css Panels CSS Builder, programatically builds and optimizes CSS.

Globals

Namesort descending Description
$theme_key

File

sites/all/themes/ulmus/adaptivetheme/at_core/inc/forms/at_core.submit.builders.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Page Layout CSS Builder.
  5. */
  6. global $theme_key, $theme_name;
  7. $theme_name = $theme_key;
  8. $path_to_at_core = drupal_get_path('theme', 'adaptivetheme');
  9. require_once($path_to_at_core . '/inc/plugins.inc');
  10. /**
  11. * Build Page Layouts
  12. *
  13. * Unlike the Panels layouts which hold CSS in their data array the Page layout
  14. * plugins each include a unique CSS builder function. This is required because
  15. * page layouts are all bespoke and can accept arbitrary user input for the
  16. * sidebar widths and must support three value units - pixles, em's and
  17. * percentages. In other words building a one-size-fits-all builder function
  18. * would be overly complex and its far more flexible for themers to be able to
  19. * define thier own.
  20. *
  21. * As values come in from the submit function they are dispatched to the right
  22. * builder function.
  23. *
  24. * @param $method, tells the function which layout builder function to call.
  25. * @param $sidebar_first, an arbitrary numeric value.
  26. * @param $sidebar_second, an arbitrary numeric value.
  27. * @param $sidebar_unit, one of px, em or %.
  28. * @param $theme_name, the active theme.
  29. *
  30. * @see three_col_grail_layout() for an example of a builder function with docs.
  31. */
  32. function at_build_page_layout($method, $sidebar_first, $sidebar_second, $sidebar_unit, $theme_name = NULL) {
  33. // Use the passed in theme_name, else grab it from global $theme_key
  34. if ($theme_name == NULL) {
  35. global $theme_key;
  36. $theme_name = $theme_key;
  37. }
  38. $output = '';
  39. // We need to invoke at_load_plugins() to get the function names, this is
  40. // rather expensive but we're in a submit function so IMO this is OK.
  41. at_load_plugins($theme_name, $plugin_type = 'page_layout');
  42. $builder_functions = responsive_page_layouts_data_structure($theme_name);
  43. foreach ($builder_functions as $function_prefix => $redundant_values) {
  44. if ($method === $function_prefix) {
  45. $function = $function_prefix . '_layout';
  46. $output = $function($sidebar_first, $sidebar_second, $sidebar_unit);
  47. }
  48. }
  49. return $output;
  50. }
  51. /**
  52. * Panels CSS Builder, programatically builds and optimizes CSS.
  53. *
  54. * Adaptivetheme panels layout plugins do not have CSS files, instead the CSS is
  55. * held in the data structure inside the actual plugin inc file. This data is
  56. * extracted, compared and output for all panel layouts per device type. The CSS
  57. * is highly optimized with no repetition of style declarations. The output is
  58. * embedded within media queries (or not, depending on theme settings) and
  59. * printed to file.
  60. *
  61. * @param $panel_styles
  62. * @param $device_panels_data
  63. *
  64. * @see adaptivetheme_five_5x20_panels_layouts() for an example of the CSS in
  65. * the data array with good docs and guidelines.
  66. */
  67. function at_build_panels_layout_css($panel_styles, $device_panels_data) {
  68. $output = '';
  69. $declarations = $these_groups = $these_selectors_styles = array();
  70. foreach ($panel_styles as $panel_subtypes_data) {
  71. foreach ($panel_subtypes_data as $panel_subtype => $panel_subtype_styles_data) {
  72. if (in_array($panel_subtype, $device_panels_data)) {
  73. foreach ($panel_subtype_styles_data as $data_type_array) {
  74. foreach ($data_type_array as $declaration_type => $declaration_block) {
  75. foreach ($declaration_block as $selector => $declaration) {
  76. $selectors[$declaration_type][] = $selector;
  77. $declarations[$declaration_type] = array($declaration_type => $declaration);
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }
  84. foreach ($declarations as $type => $groups) {
  85. foreach ($groups as $group) {
  86. $these_groups[$group] = $selectors[$type];
  87. }
  88. }
  89. foreach ($these_groups as $css_styles => $selector_array) {
  90. $merged_css = $css_styles;
  91. $these_selectors_styles[] = implode(',', $selector_array) . ' {' . $merged_css . '}';
  92. }
  93. $output = implode('', $these_selectors_styles);
  94. return $output;
  95. }
  96. /**
  97. * Build font family CSS.
  98. *
  99. * @param $element
  100. * @param $selector
  101. * @param $font_values
  102. */
  103. function at_build_font_families($element, $selector, $font_values) {
  104. $output = '';
  105. // Format values as valid CSS
  106. $font_styles = array();
  107. if (!empty($font_values)) {
  108. if (isset($font_values['font_size']) && $font_values['font_size'] === '<none>') {
  109. $font_values['font_size'] = '';
  110. }
  111. $font_styles[] = $font_values['font_style'] ? 'font-style:' . $font_values['font_style'] . ';' : '';
  112. $font_styles[] = $font_values['font_weight'] ? 'font-weight:' . $font_values['font_weight'] . ';' : '';
  113. $font_styles[] = $font_values['font_size'] ? 'font-size:' . $font_values['font_size'] . ';' : '';
  114. $font_styles[] = $font_values['font_family'] ? 'font-family:' . $font_values['font_family'] : '';
  115. }
  116. $font_styles = implode('', $font_styles);
  117. $css = array();
  118. switch ($element) {
  119. case $element:
  120. if ($font_styles) {
  121. $css[] = $selector . '{' . $font_styles . '}';
  122. }
  123. break;
  124. }
  125. $output = implode("\n", $css);
  126. return $output;
  127. }