function panels_flexible_get_css_group in Panels 7.3
Same name and namespace in other branches
- 6.3 plugins/layouts/flexible/flexible.inc \panels_flexible_get_css_group()
Construct an array with all of the CSS properties for a group.
This will parse down into children and produce all of the CSS needed if you start from the top.
3 calls to panels_flexible_get_css_group()
- panels_ajax_flexible_edit_add in plugins/
layouts/ flexible/ flexible.inc - AJAX responder to add a new row, column or region to a flexible layout.
- panels_ajax_flexible_edit_remove in plugins/
layouts/ flexible/ flexible.inc - Panels remove AJAX responder.
- panels_flexible_render_css_group in plugins/
layouts/ flexible/ flexible.inc - Render the CSS for a group of items to be displayed together.
File
- plugins/
layouts/ flexible/ flexible.inc, line 829 - Flexible layout plugin.
Code
function panels_flexible_get_css_group(&$css, $renderer, $list, $owner_id, $type, $item_id) {
if ($type != 'row') {
// Go through our items and break up into right/center/right groups so we
// can figure out our offsets.
// right == any items on the right that are 'fixed'.
// middle == all fluid items.
// right == any items on the right that are 'fixed'.
$left = $middle = $right = array();
$left_total = $right_total = $middle_total = 0;
$current = 'left';
foreach ($list as $id) {
if ($renderer->settings['items'][$id]['width_type'] == 'px') {
// Fixed:
if ($current == 'left') {
$left[] = $id;
$renderer->positions[$id] = 'left';
$left_total += $renderer->settings['items'][$id]['width'];
}
else {
$current = 'right';
$right[] = $id;
$renderer->positions[$id] = 'right';
$right_total += $renderer->settings['items'][$id]['width'];
}
}
else {
// Fluid:
if ($current != 'right') {
$current = 'middle';
$middle[] = $id;
$renderer->positions[$id] = 'middle';
$middle_total += $renderer->settings['items'][$id]['width'];
}
// Fall through: if current is 'right' and we ran into a 'fluid' then
// it gets *dropped* because that is invalid.
}
}
// Go through our right sides and create CSS.
foreach ($left as $id) {
$class = "." . $renderer->base[$type] . "-{$id}";
$css[$class] = array(
'position' => 'relative',
'float' => 'left',
'background-color' => 'transparent',
'width' => $renderer->settings['items'][$id]['width'] . "px",
);
}
// Do the same for right.
$right_pixels = 0;
foreach ($right as $id) {
$class = "." . $renderer->base[$type] . "-{$id}";
$css[$class] = array(
'float' => 'left',
'width' => $renderer->settings['items'][$id]['width'] . "px",
);
}
$max = count($middle) - 1;
if ($middle_total) {
// Because we love IE so much, auto scale everything to 99%. This
// means adding up the actual widths and then providing a multiplier
// to each so that the total is 99%.
$scale = $renderer->scale_base / $middle_total;
foreach ($middle as $position => $id) {
$class = "." . $renderer->base[$type] . "-{$id}";
$css[$class] = array(
'float' => 'left',
'width' => number_format($renderer->settings['items'][$id]['width'] * $scale, 4, '.', '') . "%",
);
// Store this so we can use it later.
// @todo: Store the scale, not the new width, so .js can adjust
// bi-directionally.
$renderer->scale[$id] = $scale;
}
}
// If there is any total remaining, we need to offset the splitter
// by this much too.
if ($left_total) {
// Add this even if it's 0 so we can handle removals.
$css["{$owner_id}-inside"]['padding-left'] = '0px';
if ($renderer->admin || count($middle)) {
$css["{$owner_id}-middle"]['margin-left'] = $left_total . 'px';
// IE hack!
$css["* html {$owner_id}-left"]['left'] = $left_total . "px";
// Make this one very specific to the admin CSS so that preview
// does not stomp it.
$css[".panel-flexible-admin {$owner_id}-inside"]['padding-left'] = '0px';
}
else {
$css["{$owner_id}-inside"]['margin-left'] = '-' . $left_total . 'px';
$css["{$owner_id}-inside"]['padding-left'] = $left_total . 'px';
// IE hack!
$css["* html {$owner_id}-inside"]['left'] = $left_total . "px";
}
}
if ($right_total) {
$css["{$owner_id}-middle"]['margin-right'] = $right_total . 'px';
}
$css["{$owner_id}-inside"]['padding-right'] = '0px';
}
// If the canvas has a fixed width set, and this is the canvas, fix the
// width.
if ($item_id == 'canvas') {
$item = $renderer->settings['items'][$item_id];
if (!empty($item['fixed_width']) && intval($item['fixed_width'])) {
$css['.' . $renderer->base['canvas']]['width'] = intval($item['fixed_width']) . 'px';
}
else {
$css['.' . $renderer->base['canvas']]['width'] = 'auto';
}
}
// Go through each item and process children.
foreach ($list as $id) {
$item = $renderer->settings['items'][$id];
if (empty($item['children'])) {
continue;
}
if ($type == 'column') {
// Columns can only contain rows.
$child_type = 'row';
}
else {
$child_type = isset($item['contains']) ? $item['contains'] : 'region';
}
$class = "." . $renderer->base[$type] . "-{$id}";
panels_flexible_get_css_group($css, $renderer, $item['children'], $class, $child_type, $id);
}
}