rounded_corners.inc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. /**
  3. * @file
  4. * Definition of the 'rounded_corners' panel style.
  5. */
  6. // Plugin definition.
  7. $plugin = array(
  8. 'title' => t('Rounded corners'),
  9. 'description' => t('Presents the panes or panels with a rounded corner box around them'),
  10. 'render region' => 'panels_rounded_corners_style_render_region',
  11. 'render pane' => 'panels_rounded_corners_style_render_pane',
  12. 'settings form' => 'panels_rounded_corners_style_settings_form',
  13. 'hook theme' => array(
  14. 'panels_rounded_corners_box' => array(
  15. 'variables' => array('content' => NULL),
  16. 'path' => panels_get_path('plugins/styles/corners'),
  17. 'template' => 'panels-rounded-corners-box',
  18. ),
  19. ),
  20. );
  21. /**
  22. * Render callback.
  23. *
  24. * @ingroup themeable
  25. */
  26. function theme_panels_rounded_corners_style_render_region($vars) {
  27. $display = $vars['display'];
  28. $region_id = $vars['region_id'];
  29. $panes = $vars['panes'];
  30. $settings = $vars['settings'];
  31. $output = '';
  32. // Determine where to put the box. If empty or 'pane' around each pane. If
  33. // 'panel' then just around the whole panel.
  34. $where = empty($settings['corner_location']) ? 'pane' : $settings['corner_location'];
  35. $print_separator = FALSE;
  36. foreach ($panes as $pane_id => $pane) {
  37. // Add the separator if we've already displayed a pane.
  38. if ($print_separator) {
  39. $output .= '<div class="panel-separator">&nbsp;</div>';
  40. }
  41. if ($where == 'pane') {
  42. $output .= theme('panels_rounded_corners_box', array('content' => $pane));
  43. }
  44. else {
  45. $output .= $pane;
  46. $print_separator = TRUE;
  47. }
  48. }
  49. if ($where == 'panel') {
  50. $output = theme('panels_rounded_corners_box', array('content' => $output));
  51. }
  52. panels_add_rounded_corners_css($display, $where);
  53. return $output;
  54. }
  55. function panels_add_rounded_corners_css($display, $where) {
  56. static $displays_used = array();
  57. if (empty($displays_used[$display->css_id])) {
  58. panels_rounded_corners_css($display, $where);
  59. $displays_used[$display->css_id] = TRUE;
  60. }
  61. }
  62. /**
  63. * Render callback for a single pane.
  64. */
  65. function theme_panels_rounded_corners_style_render_pane($vars) {
  66. $content = $vars['content'];
  67. $pane = $vars['pane'];
  68. $display = $vars['display'];
  69. if (empty($content->content)) {
  70. return;
  71. }
  72. $output = theme('panels_pane', array('content' => $content, 'pane' => $pane, 'display' => $display));
  73. // Just stick a box around the standard theme_panels_pane.
  74. $output = theme('panels_rounded_corners_box', array('content' => $output));
  75. panels_add_rounded_corners_css($display, 'pane');
  76. return $output;
  77. }
  78. /**
  79. * Settings form callback.
  80. */
  81. function panels_rounded_corners_style_settings_form($style_settings) {
  82. $form['corner_location'] = array(
  83. '#type' => 'select',
  84. '#title' => t('Box around'),
  85. '#options' => array(
  86. 'pane' => t('Each pane'),
  87. 'panel' => t('Each region'),
  88. ),
  89. '#default_value' => (isset($style_settings['corner_location'])) ? $style_settings['corner_location'] : 'ul',
  90. '#description' => t('Choose whether to include the box around each pane (piece of content) or region (each column or region)'),
  91. );
  92. return $form;
  93. }
  94. /**
  95. * Generates the dynamic CSS.
  96. *
  97. * @param $display
  98. * A Panels display object.
  99. */
  100. function panels_rounded_corners_css($display) {
  101. $idstr = empty($display->css_id) ? '.rounded-corner' : "#$display->css_id";
  102. $css_id = 'rounded-corner:' . $idstr;
  103. ctools_include('css');
  104. $filename = ctools_css_retrieve($css_id);
  105. if (!$filename) {
  106. $filename = ctools_css_store($css_id, _panels_rounded_corners_css($idstr), FALSE);
  107. }
  108. drupal_add_css($filename, array('preprocess' => TRUE));
  109. }
  110. /**
  111. * Generates the dynamic CSS.
  112. */
  113. function _panels_rounded_corners_css($idstr) {
  114. $url = panels_get_path('plugins/styles/corners', TRUE);
  115. $css = <<<EOF
  116. .t-edge, .b-edge, .l-edge, .r-edge, .wrap-corner {
  117. position: relative;
  118. /* hasLayout -1 ? For IE only */
  119. zoom: 1;
  120. }
  121. $idstr .t-edge {
  122. background: url($url/shadow-t.png) repeat-x 0 top;
  123. font-size: 1px;
  124. }
  125. $idstr .b-edge {
  126. background: url($url/shadow-b.png) repeat-x 0 bottom;
  127. font-size: 1px;
  128. }
  129. $idstr .l-edge {
  130. background: url($url/shadow-l.png) repeat-y 0 0;
  131. }
  132. $idstr .r-edge {
  133. background: url($url/shadow-r.png) repeat-y right 0;
  134. }
  135. $idstr .wrap-corner {
  136. background: #fff !important;
  137. }
  138. $idstr .wrap-corner .t-edge, $idstr .wrap-corner .b-edge {
  139. height: 11px;
  140. }
  141. $idstr .wrap-corner .l, $idstr .wrap-corner .r {
  142. position: absolute;
  143. top: 0;
  144. height: 11px;
  145. width: 11px;
  146. background-image: url($url/corner-bits.png);
  147. }
  148. $idstr .wrap-corner .l {
  149. left: 0;
  150. }
  151. $idstr .wrap-corner .r {
  152. right: 0;
  153. background-position: -11px 0;
  154. }
  155. $idstr .wrap-corner .b-edge .l {
  156. background-position: 0 -11px;
  157. }
  158. $idstr .wrap-corner .b-edge .r {
  159. background-position: -11px -11px;
  160. }
  161. $idstr .wrap-corner .r-edge {
  162. padding: 5px 24px;
  163. }
  164. $idstr div.admin-links {
  165. margin-top: -14px;
  166. margin-left: -12px;
  167. }
  168. $idstr .panel-separator {
  169. background: url($url/shadow-b.png) repeat-x 0 center;
  170. font-size: 1px;
  171. height: 30px;
  172. }
  173. $idstr .rounded-corner {
  174. margin-bottom: 1em;
  175. }
  176. EOF;
  177. return $css;
  178. }