Commit b5cecab3 authored by merlinofchaos's avatar merlinofchaos

Spiffy improvements to grid view

parent cb1b8e01
......@@ -2473,6 +2473,7 @@ class views_plugin_style_grid extends views_plugin_style {
function options($display) {
return array(
'columns' => 4,
'alignment' => 'horizontal',
);
}
......@@ -2485,6 +2486,13 @@ class views_plugin_style_grid extends views_plugin_style {
'#title' => t('Number of columns'),
'#default_value' => $this->options['columns'],
);
$form['alignment'] = array(
'#type' => 'radios',
'#title' => t('Alignment'),
'#options' => array('horizontal' => t('Horizontal'), 'vertical' => t('Vertical')),
'#default_value' => $this->options['alignment'],
'#description' => t('Horizontal alignment will place items starting in the upper left and moving right. Vertical alignment will place items starting in the upper left and moving down.'),
);
}
}
......
......@@ -274,12 +274,39 @@ function template_preprocess_views_view_grid(&$vars) {
$columns = $options['columns'];
$rows = array();
$row = array();
foreach($vars['rows'] as $count => $item) {
$row[] = $item;
if (($count + 1) % $columns == 0) {
if ($options['alignment'] == 'horizontal') {
$row = array();
foreach ($vars['rows'] as $count => $item) {
$row[] = $item;
if (($count + 1) % $columns == 0) {
$rows[] = $row;
$row = array();
}
}
if ($row) {
$rows[] = $row;
$row = array();
}
}
else {
$num_rows = floor(count($vars['rows']) / $columns);
// The remainders are the 'odd' columns that are slightly longer.
$remainders = count($vars['rows']) % $columns;
$row = 0;
$col = 0;
foreach ($vars['rows'] as $count => $item) {
$rows[$row][$col] = $item;
$row++;
if (!$remainders && $row == $num_rows) {
$row = 0;
$col++;
}
else if ($remainders && $row == $num_rows + 1) {
$row = 0;
$col++;
$remainders--;
}
}
}
$vars['rows'] = $rows;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment