Projet

Général

Profil

Paste
Télécharger (4,99 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panels / plugins / styles / corners / rounded_corners.inc @ 64156087

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of the 'rounded_corners' panel style.
6
 */
7

    
8
// Plugin definition.
9
$plugin = array(
10
  'title' => t('Rounded corners'),
11
  'description' => t('Presents the panes or panels with a rounded corner box around them'),
12
  'render region' => 'panels_rounded_corners_style_render_region',
13
  'render pane' => 'panels_rounded_corners_style_render_pane',
14
  'settings form' => 'panels_rounded_corners_style_settings_form',
15
  'hook theme' => array(
16
    'panels_rounded_corners_box' => array(
17
      'variables' => array('content' => NULL),
18
      'path' => panels_get_path('plugins/styles/corners'),
19
      'template' => 'panels-rounded-corners-box',
20
    ),
21
  ),
22
);
23

    
24
/**
25
 * Render callback.
26
 *
27
 * @ingroup themeable
28
 */
29
function theme_panels_rounded_corners_style_render_region($vars) {
30
  $display = $vars['display'];
31
  $region_id = $vars['region_id'];
32
  $panes = $vars['panes'];
33
  $settings = $vars['settings'];
34

    
35
  $output = '';
36

    
37
  // Determine where to put the box. If empty or 'pane' around each pane. If
38
  // 'panel' then just around the whole panel.
39
  $where = empty($settings['corner_location']) ? 'pane' : $settings['corner_location'];
40

    
41
  $print_separator = FALSE;
42
  foreach ($panes as $pane_id => $pane) {
43
    // Add the separator if we've already displayed a pane.
44
    if ($print_separator) {
45
      $output .= '<div class="panel-separator">&nbsp;</div>';
46
    }
47

    
48
    if ($where == 'pane') {
49
      $output .= theme('panels_rounded_corners_box', array('content' => $pane));
50
    }
51
    else {
52
      $output .= $pane;
53
      $print_separator = TRUE;
54
    }
55
  }
56

    
57
  if ($where == 'panel') {
58
    $output = theme('panels_rounded_corners_box', array('content' => $output));
59
  }
60

    
61
  panels_add_rounded_corners_css($display, $where);
62

    
63
  return $output;
64
}
65

    
66
function panels_add_rounded_corners_css($display, $where) {
67
  static $displays_used = array();
68
  if (empty($displays_used[$display->css_id])) {
69
    panels_rounded_corners_css($display, $where);
70
    $displays_used[$display->css_id] = TRUE;
71
  }
72
}
73

    
74
/**
75
 * Render callback for a single pane.
76
 */
77
function theme_panels_rounded_corners_style_render_pane($vars) {
78
  $content = $vars['content'];
79
  $pane = $vars['pane'];
80
  $display = $vars['display'];
81

    
82
  if (empty($content->content)) {
83
    return;
84
  }
85

    
86
  $output = theme('panels_pane', array('content' => $content, 'pane' => $pane, 'display' => $display));
87

    
88
  // Just stick a box around the standard theme_panels_pane.
89
  $output = theme('panels_rounded_corners_box', array('content' => $output));
90
  panels_add_rounded_corners_css($display, 'pane');
91
  return $output;
92
}
93

    
94
/**
95
 * Settings form callback.
96
 */
97
function panels_rounded_corners_style_settings_form($style_settings) {
98
  $form['corner_location'] = array(
99
    '#type' => 'select',
100
    '#title' => t('Box around'),
101
    '#options' => array(
102
      'pane' => t('Each pane'),
103
      'panel' => t('Each region'),
104
    ),
105
    '#default_value' => (isset($style_settings['corner_location'])) ? $style_settings['corner_location'] : 'ul',
106
    '#description' => t('Choose whether to include the box around each pane (piece of content) or region (each column or region)'),
107
  );
108

    
109
  return $form;
110
}
111

    
112
/**
113
 * Generates the dynamic CSS.
114
 *
115
 * @param $display
116
 *   A Panels display object.
117
 */
118
function panels_rounded_corners_css($display) {
119
  $idstr = empty($display->css_id) ? '.rounded-corner' : "#$display->css_id";
120
  $css_id = 'rounded-corner:' . $idstr;
121

    
122
  ctools_include('css');
123
  $filename = ctools_css_retrieve($css_id);
124
  if (!$filename) {
125
    $filename = ctools_css_store($css_id, _panels_rounded_corners_css($idstr), FALSE);
126
  }
127

    
128
  drupal_add_css($filename, array('preprocess' => TRUE));
129
}
130

    
131
/**
132
 * Generates the dynamic CSS.
133
 */
134
function _panels_rounded_corners_css($idstr) {
135
  $url = panels_get_path('plugins/styles/corners', TRUE);
136

    
137
  $css = <<<EOF
138

    
139
.t-edge, .b-edge, .l-edge, .r-edge, .wrap-corner {
140
  position: relative;
141
  /* hasLayout -1 ? For IE only */
142
  zoom: 1;
143
}
144
$idstr .t-edge {
145
  background: url($url/shadow-t.png) repeat-x 0 top;
146
  font-size: 1px;
147
}
148
$idstr .b-edge {
149
  background: url($url/shadow-b.png) repeat-x 0 bottom;
150
  font-size: 1px;
151
}
152
$idstr .l-edge {
153
  background: url($url/shadow-l.png) repeat-y 0 0;
154
}
155
$idstr .r-edge {
156
  background: url($url/shadow-r.png) repeat-y right 0;
157
}
158
$idstr .wrap-corner {
159
  background: #fff !important;
160
}
161
$idstr .wrap-corner .t-edge, $idstr .wrap-corner .b-edge {
162
  height: 11px;
163
}
164
$idstr .wrap-corner .l, $idstr .wrap-corner .r {
165
  position: absolute;
166
  top: 0;
167
  height: 11px;
168
  width: 11px;
169
  background-image: url($url/corner-bits.png);
170
}
171
$idstr .wrap-corner .l {
172
  left: 0;
173
}
174
$idstr .wrap-corner .r {
175
  right: 0;
176
  background-position: -11px 0;
177
}
178
$idstr .wrap-corner .b-edge .l {
179
  background-position: 0 -11px;
180
}
181
$idstr .wrap-corner .b-edge .r {
182
  background-position: -11px -11px;
183
}
184
$idstr .wrap-corner .r-edge {
185
  padding: 5px 24px;
186
}
187
$idstr div.admin-links {
188
  margin-top: -14px;
189
  margin-left: -12px;
190
}
191

    
192
$idstr .panel-separator {
193
  background: url($url/shadow-b.png) repeat-x 0 center;
194
  font-size: 1px;
195
  height: 30px;
196
}
197

    
198
$idstr .rounded-corner {
199
  margin-bottom: 1em;
200
}
201

    
202
EOF;
203

    
204
  return $css;
205
}