foreach ($blocks as $block) {
- $gradient = $this->_gradient($block['background_gradient']);
- $background_colour = empty($block['background_gradient']['color1']) ? '' : 'background-color: '. $block['background_gradient']['color1'] .';';
- $text_colour = $gradient ? 'light' : 'dark';
+ // Generate ID for CSS
+ $id = 'block-' . strtolower(CubeIT_Util_Text::str2URL($block['title']));
+
+ // Text colour is based on whether block has a gradient or not
+ $text_colour = $this->hasGradient($block) ? 'light' : 'dark';
+
+ $res .= '<div class="feature-block text-'. $text_colour .' '. $block['layout'] .'" id="'. $id .'">';
+
+ $res .= $this->_CSS($id, $block);
- $res .= '<div class="feature-block text-'. $text_colour .' '. $block['layout'] .'" style="'. $background_colour . $gradient .'">';
$res .= '<div class="feature-inner">';
if (is_array($block['icon'])) {
return $res;
}
+ protected function hasGradient($block) {
+ $gradient = $block['background_gradient'];
+ return !(empty($gradient['color1']) || empty($gradient['color2']));
+ }
+
+ protected function hasBGImage($block) {
+ return is_array($block['background_image']);
+ }
+
+ protected function _CSS($id, $block) {
+
+ $gradient = $block['background_gradient'];
+ $res = '<style scoped>';
+
+ $res .= "#$id {";
+ $res .= $this->_backgroundColour($block);
+
+ // Main CSS - block can have a bg image, a gradient, both or neither.
+ if ($this->hasBGImage($block)) {
+ $res .= $this->_backgroundImage($block);
+ } elseif ($this->hasGradient($block)) {
+ $res .= $this->_gradient($block);
+ }
+
+ $res .= '}';
+
+ // Mobile version - swap background images for a gradient / solid colour
+ // Todo: consider using breakpoints instead of relying on .m class (to be decided depending on how other breakpoints are handled)
+ $res .= ".m #$id {";
+
+ if ($this->hasGradient($block)) {
+ $res .= $this->_gradient($block);
+ } else {
+ $res .= 'background-image: none;';
+ }
+
+ $res .= '}';
+ $res .= '</style>';
+
+ return $res;
+ }
+
+ protected function _backgroundColour($block) {
+ if (empty($block['background_gradient']['color1'])) {
+ return '';
+ }
+
+ return 'background-color: '. $block['background_gradient']['color1'] .';';
+ }
+
+ protected function _backgroundImage($block) {
+ if (!is_array($block['background_image'])) return '';
+
+ $path = CubeIT_View_Helper_ImageCms::getPath($block['background_image']);
+
+ return "background-image: url('$path');";
+ }
+
+ protected function _gradient($block) {
+
+ $gradient = $block['background_gradient'];
- protected function _gradient($gradient) {
if (empty($gradient['color1']) || empty($gradient['color2'])) {
- return false;
+ return '';
}
$angle = '45deg';
.feature-block {
position: relative;
overflow: hidden;
+ background-repeat: no-repeat;
+ background-size: 100%;
// Block layouts
&.rectangle-right, &.rectangle-bottom {
width: percentage(3/6);
padding-bottom: percentage(2/6); // 3:2 aspect ratio
}
+ &.rectangle-right {
+ background-position: center right;
+ }
+ &.rectangle-bottom, &.square-bottom {
+ background-position: center bottom;
+ }
+
&.square-top, &.square-bottom {
width: percentage(2/6);
padding-bottom: percentage(2/6); // 1:1 aspect ratio
}
+ &.square-top {
+ background-position: center top;
+ }
&.small-rectangle-tall {
width: percentage(1/6);
.square-top & {
margin-top: 50%;
-
+ padding-top: 30px;
}
}