You are here

function theme_panels_flexible in Panels 5.2

Same name and namespace in other branches
  1. 6.3 plugins/layouts/flexible/flexible.inc \theme_panels_flexible()
  2. 6.2 layouts/flexible/flexible.inc \theme_panels_flexible()
  3. 7.3 plugins/layouts/flexible/flexible.inc \theme_panels_flexible()

File

layouts/flexible.inc, line 277

Code

function theme_panels_flexible($id, $content, $settings) {
  if (empty($settings)) {
    $settings = panels_flexible_default_panels();
  }

  // Special check for updating.
  if (empty($settings['width_type'])) {
    $settings['width_type'] = '%';
    $settings['percent_width'] = 100;
  }
  if ($id) {
    $idstr = " id='{$id}'";
    $idcss = "#{$id}";
  }
  else {
    $idcss = "div.panel-flexible";
  }
  $css = '';
  $output = '';
  for ($row = 1; $row <= intval($settings['rows']); $row++) {
    $output .= "<div class=\"panel-row panel-row-{$row} clear-block\">\n";
    for ($col = 1; $col <= intval($settings["row_{$row}"]["columns"]); $col++) {

      // We do a width reduction formula to help IE out a little bit. If width is 100%, we take 1%
      // off the total; by dividing by the # of columns, that gets us the reduction overall.
      $reduce = 0;
      if ($settings['width_type'] == '%' && $settings['percent_width'] == 100) {
        $reduce = 1 / $settings["row_{$row}"]["columns"];
      }
      if ($col == 1) {
        if (intval($settings["row_{$row}"]["columns"]) == 1) {
          $class = 'panel-col-only';
        }
        else {
          $class = 'panel-col-first';
        }
      }
      elseif ($col == intval($settings["row_{$row}"]["columns"])) {
        $class = 'panel-col-last';
      }
      else {
        $class = 'panel-col-inside';
      }
      $output .= "<div class=\"panel-col panel-col-{$col} {$class}\">\n";
      $output .= "<div class=\"inside\">" . $content["row_{$row}_{$col}"] . "</div>\n";
      $output .= "</div>\n";

      // panel-col-$col
      $css .= "{$idcss} div.panel-row-{$row} div.panel-col-{$col} { width: " . (intval($settings["row_{$row}"]["width_{$col}"]) - $reduce) . $settings["width_type"] . "; }\n";
    }
    $output .= "</div>\n";

    // panel-row-$row
  }

  // Add our potential sidebars
  if (!empty($settings['sidebars']['left']) || !empty($settings['sidebars']['right'])) {

    // provide a wrapper if we have a sidebar
    $output = "<div class=\"panel-sidebar-middle panel-sidebar\">\n{$output}</div>\n";
    if ($settings['sidebars']['width_type'] == '%') {
      $css .= "{$idcss} div.panel-flexible-sidebars div.panel-sidebar-middle { width: " . (intval($settings['percent_width']) - intval($settings['sidebars']['left_width']) - intval($settings['sidebars']['right_width'])) . "; }\n";
    }
  }
  if (!empty($settings['sidebars']['left'])) {
    $size = intval($settings['sidebars']['left_width']) . $settings['sidebars']['width_type'];
    $output = "<div class=\"panel-sidebar panel-sidebar-left panel-col panel-col-first\"><div class=\"inside\">\n" . $content["sidebar_left"] . "</div>\n</div>\n" . $output;
    $css .= "{$idcss} div.panel-flexible-sidebars div.panel-sidebar-left { width: {$size}; margin-left: -{$size}; }\n";
    $css .= "{$idcss} div.panel-flexible-sidebars { padding-left: {$size}; }\n";

    // IE hack
    $css .= "* html {$idcss} div.panel-flexible-sidebars div.panel-sidebar-left { left: {$size}; }\n";
  }
  if (!empty($settings['sidebars']['right'])) {
    $size = intval($settings['sidebars']['right_width']) . $settings['sidebars']['width_type'];
    $output .= "<div class=\"panel-sidebar panel-sidebar-right panel-col panel-col-last\"><div class=\"inside\">\n" . $content["sidebar_right"] . "</div>\n</div>\n";
    $css .= "{$idcss} div.panel-flexible-sidebars div.panel-sidebar-right { width: {$size}; margin-right: -{$size}; }\n";
    $css .= "{$idcss} div.panel-flexible-sidebars { padding-right: {$size}; }\n";
  }

  // Wrap the whole thing up nice and snug
  $sidebar_class = !empty($settings['sidebars']['left']) || !empty($settings['sidebars']['right']) ? ' class="panel-flexible-sidebars"' : '';
  $output = "<div class=\"panel-flexible clear-block\" {$idstr}>\n<div" . $sidebar_class . ">\n" . $output . "</div>\n</div>\n";
  drupal_set_html_head("<style type=\"text/css\" media=\"all\">\n{$css}</style>\n");
  return $output;
}