X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fviews_responsive_grid%2Fviews_responsive_grid.theme.inc;fp=web%2Fmodules%2Fcontrib%2Fviews_responsive_grid%2Fviews_responsive_grid.theme.inc;h=bf8cfe93d880b88368287bf3aced87c2c383100e;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/views_responsive_grid/views_responsive_grid.theme.inc b/web/modules/contrib/views_responsive_grid/views_responsive_grid.theme.inc new file mode 100644 index 000000000..bf8cfe93d --- /dev/null +++ b/web/modules/contrib/views_responsive_grid/views_responsive_grid.theme.inc @@ -0,0 +1,158 @@ +style_plugin->options; + $horizontal = ($options['alignment'] === 'horizontal'); + + // View classes. + $vars['attributes'] = new Attribute(array( + 'class' => array( + 'views-responsive-grid', + $options['alignment'], + 'cols-' . $options['columns'], + 'clearfix', + ), + )); + + // Setup integers. + $col = 0; + $row = 0; + $row_count = count($vars['rows']); + $remainders = $row_count % $options['columns']; + $num_rows = floor($row_count / $options['columns']); + // Iterate over the view rows array. + foreach ($vars['rows'] as $row_index => $item) { + // Add the current views data row to the rows array. + if ($horizontal) { + $items[$row][$col] = $item; + } + else { + $items[$col][$row] = $item; + } + + // Create attributes for row. + $row_attributes = array('class' => array()); + // Add default views row classes. + if ($options['default_row_class']) { + $row_attributes['class'][] = 'views-row'; + $row_attributes['class'][] = 'row-' . ($row + 1); + } + // Add special views row classes. + if ($options['row_class_special']) { + // First row. + if ($row == 0) { + $row_attributes['class'][] = 'first'; + } + // Last row. + if (($horizontal && $row == (!$remainders ? $num_rows - 1 : $num_rows)) || (!$horizontal && ((!$remainders && $row == $num_rows - 1) || ($remainders && $row == $num_rows)))) { + $row_attributes['class'][] = 'last'; + } + // Zebra striping. + $row_attributes['class'][] = (($row + 1) % 2) ? 'odd' : 'even'; + // Clearfix + if ($horizontal) { + $row_attributes['class'][] = 'clearfix'; + } + } + // Add custom row class. + $row_class = array_filter(explode(' ', $options['row_class'])); + if (!empty($row_class)) { + $row_attributes['class'] = array_merge($row_attributes['class'], $row_class); + } + // Add row attributes to variables array. + if ($horizontal) { + $vars['row_attributes'][$row] = new Attribute($row_attributes); + } + else { + $vars['row_attributes'][$col][$row] = new Attribute($row_attributes); + } + + // Create attributes for columns. + $col_attributes = array('class' => array()); + // Add default views column classes. + if ($options['default_col_class']) { + $col_attributes['class'][] = 'views-col'; + $col_attributes['class'][] = 'col-' . ($col + 1); + } + // Add special views row classes. + if ($options['col_class_special']) { + if ($col == 0) { + $col_attributes['class'][] = 'first'; + } + if ($col == $options['columns'] - 1 || ($row_count <= $num_rows && $col == $row_count)) { + $col_attributes['class'][] = 'last'; + } + // Zebra striping. + $col_attributes['class'][] = (($col + 1) % 2) ? 'odd' : 'even'; + // Clearfix + if (!$horizontal) { + $col_attributes['class'][] = 'clearfix'; + } + } + // Add custom column class. + $col_class = array_filter(explode(' ', $options['col_class'])); + if (!empty($col_class)) { + $col_attributes['class'] = array_merge($col_attributes['class'], $col_class); + } + // Add width to columns. + if ($options['columns'] > 1 && $options['automatic_width']) { + $col_attributes['style'] = 'width: ' . (100 / $options['columns']) . '%;'; + } + // Add column attributes to variables array. + if ($horizontal) { + $vars['col_attributes'][$row][$col] = new Attribute($col_attributes); + } + else { + $vars['col_attributes'][$col] = new Attribute($col_attributes); + } + + // Increase, decrease or reset the appropriate integers. + if ($horizontal) { + if ($col == 0) { + $col++; + } + elseif ($col >= ($options['columns'] - 1)) { + $col = 0; + $row++; + } + else { + $col++; + } + } + else { + $row++; + if (!$remainders && $row == $num_rows) { + $row = 0; + $col++; + } + elseif ($remainders && $row == $num_rows + 1) { + $row = 0; + $col++; + $remainders--; + } + } + $row_count--; + } + // Save the grid items to the variables array. + $vars['items'] = $items; +}