Browse code

Add flexbox extension to rocksolid columns again

Benjamin Roth authored on10/03/2019 13:23:11
Showing11 changed files
... ...
@@ -11,7 +11,8 @@
11 11
     ],
12 12
     "require": {
13 13
         "php": "^5.6 || ^7.0",
14
-        "contao/core-bundle": "^4.4"
14
+        "contao/core-bundle": "^4.4",
15
+        "madeyourday/contao-rocksolid-columns": "^2.0"
15 16
     },
16 17
     "conflict": {
17 18
         "contao/core": "*",
18 19
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+<?php
2
+
3
+/*
4
+ * This file is part of eSales Media ContentHelperBundle
5
+ *
6
+ * (c) Benjamin Roth
7
+ *
8
+ * @license proprietary
9
+ */
10
+
11
+namespace EsalesMedia\ContentHelperBundle\EventListener;
12
+
13
+use Contao\CoreBundle\Framework\FrameworkAwareInterface;
14
+use Contao\CoreBundle\Framework\FrameworkAwareTrait;
15
+use Contao\LayoutModel;
16
+use Contao\PageModel;
17
+use Contao\PageRegular;
18
+
19
+class PageListener implements FrameworkAwareInterface
20
+{
21
+    use FrameworkAwareTrait;
22
+
23
+    public function onGeneratePage(PageModel $page, LayoutModel $layout, PageRegular $pageRegular)
24
+    {
25
+        if ($layout->rs_columns_load_css_flex) {
26
+            $assetsDir = 'web/bundles/esalesmediacontenthelper';
27
+            $GLOBALS['TL_CSS'][] = $assetsDir . '/css/columns-flex.scss||static';
28
+        }
29
+    }
30
+}
0 31
new file mode 100644
... ...
@@ -0,0 +1,56 @@
1
+<?php
2
+
3
+/*
4
+ * This file is part of eSales Media ContentHelperBundle
5
+ *
6
+ * (c) Benjamin Roth
7
+ *
8
+ * @license proprietary
9
+ */
10
+
11
+namespace EsalesMedia\ContentHelperBundle\FrontendController;
12
+
13
+
14
+/**
15
+ * Extends column start content element
16
+ */
17
+class ColumnStart extends \MadeYourDay\RockSolidColumns\Element\ColumnStart
18
+{
19
+
20
+  /**
21
+   * Add class if needed
22
+   * @param \ContentModel $objElement
23
+   * @param string $strColumn
24
+   */
25
+	public function __construct(\ContentModel $objElement, $strColumn = 'main')
26
+	{
27
+        parent::__construct($objElement, $strColumn);
28
+
29
+        if ($this->es_rs_columns_valign && $this->es_rs_columns_valign == 'top')
30
+        {
31
+          $this->arrData['cssID'][1] = trim($this->cssID[1].' -valign-top');
32
+        } else if ($this->es_rs_columns_valign && $this->es_rs_columns_valign == 'center')
33
+        {
34
+          $this->arrData['cssID'][1] = trim($this->cssID[1].' -valign-center');
35
+        } else if ($this->es_rs_columns_valign && $this->es_rs_columns_valign == 'bottom')
36
+        {
37
+          $this->arrData['cssID'][1] = trim($this->cssID[1].' -valign-bottom');
38
+        } else if ($this->es_rs_columns_valign && $this->es_rs_columns_valign == 'stretch')
39
+        {
40
+            $this->arrData['cssID'][1] = trim($this->cssID[1].' -valign-stretch');
41
+        }
42
+
43
+        if ($this->es_rs_column_sort_large)
44
+        {
45
+            $this->arrData['cssID'][1] = trim($this->cssID[1].' -large-order-'.intval($this->es_rs_column_sort_large));
46
+        }
47
+        if ($this->es_rs_column_sort_medium)
48
+        {
49
+            $this->arrData['cssID'][1] = trim($this->cssID[1].' -medium-order-'.intval($this->es_rs_column_sort_medium));
50
+        }
51
+        if ($this->es_rs_column_sort_small)
52
+        {
53
+            $this->arrData['cssID'][1] = trim($this->cssID[1].' -small-order-'.intval($this->es_rs_column_sort_small));
54
+        }
55
+	}
56
+}
0 57
new file mode 100644
... ...
@@ -0,0 +1,43 @@
1
+<?php
2
+
3
+/*
4
+ * This file is part of eSales Media ContentHelperBundle
5
+ *
6
+ * (c) Benjamin Roth
7
+ *
8
+ * @license proprietary
9
+ */
10
+
11
+namespace EsalesMedia\ContentHelperBundle\FrontendController;
12
+
13
+
14
+/**
15
+ * Extends columns start content element
16
+ */
17
+class ColumnsStart extends \MadeYourDay\RockSolidColumns\Element\ColumnsStart
18
+{
19
+
20
+  /**
21
+   * Add class if needed
22
+   * @param \ContentModel $objElement
23
+   * @param string $strColumn
24
+   */
25
+	public function __construct(\ContentModel $objElement, $strColumn = 'main')
26
+	{
27
+        parent::__construct($objElement, $strColumn);
28
+
29
+        if ($this->es_rs_columns_valign && $this->es_rs_columns_valign == 'top')
30
+        {
31
+          $this->arrData['cssID'][1] = trim($this->cssID[1].' -valign-top');
32
+        } else if ($this->es_rs_columns_valign && $this->es_rs_columns_valign == 'center')
33
+        {
34
+          $this->arrData['cssID'][1] = trim($this->cssID[1].' -valign-center');
35
+        } else if ($this->es_rs_columns_valign && $this->es_rs_columns_valign == 'bottom')
36
+        {
37
+            $this->arrData['cssID'][1] = trim($this->cssID[1].' -valign-bottom');
38
+        } else if ($this->es_rs_columns_valign && $this->es_rs_columns_valign == 'stretch')
39
+        {
40
+            $this->arrData['cssID'][1] = trim($this->cssID[1].' -valign-stretch');
41
+        }
42
+	}
43
+}
... ...
@@ -10,3 +10,7 @@ services:
10 10
     esalesmedia_content_helper.listener.template:
11 11
         class: \EsalesMedia\ContentHelperBundle\EventListener\TemplateListener
12 12
         public: true
13
+
14
+    esalesmedia_content_helper.listener.page:
15
+        class: \EsalesMedia\ContentHelperBundle\EventListener\PageListener
16
+        public: true
... ...
@@ -8,8 +8,15 @@
8 8
  * @license proprietary
9 9
  */
10 10
 
11
+/**
12
+ * Content elements
13
+ */
14
+$GLOBALS['TL_CTE']['rs_columns']['rs_columns_start'] = 'EsalesMedia\\ContentHelperBundle\\FrontendController\\ColumnsStart';
15
+$GLOBALS['TL_CTE']['rs_columns']['rs_column_start'] = 'EsalesMedia\\ContentHelperBundle\\FrontendController\\ColumnStart';
16
+
11 17
 
12 18
 /**
13 19
  * Hooks
14 20
  */
15 21
 $GLOBALS['TL_HOOKS']['parseTemplate'][] = array('esalesmedia_content_helper.listener.template','onParseTemplate');
22
+$GLOBALS['TL_HOOKS']['generatePage'][] = array('esalesmedia_content_helper.listener.page','onGeneratePage');
... ...
@@ -13,8 +13,10 @@
13 13
  */
14 14
 foreach ($GLOBALS['TL_DCA']['tl_content']['palettes'] as $key => $palette)
15 15
 {
16
-  $GLOBALS['TL_DCA']['tl_content']['palettes'][$key] = str_replace(',cssID;', ',cssID,es_spacing;', $palette);
16
+    \Contao\CoreBundle\DataContainer\PaletteManipulator::create()->addField('es_spacing','cssID')->addField('es_padding','es_spacing')->applyToPalette($key,'tl_content');
17 17
 }
18
+\Contao\CoreBundle\DataContainer\PaletteManipulator::create()->addLegend('col_layout_legend','rs_columns_legend')->addField('es_rs_columns_valign','col_layout_legend',\Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_APPEND)->applyToPalette('rs_columns_start','tl_content');
19
+\Contao\CoreBundle\DataContainer\PaletteManipulator::create()->addLegend('col_layout_legend','protected_legend')->addField('es_rs_column_sort_large','col_layout_legend',\Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_APPEND)->addField('es_rs_column_sort_medium','es_rs_column_sort_large')->addField('es_rs_column_sort_small','es_rs_column_sort_medium')->addField('es_rs_columns_valign','es_rs_column_sort_small')->applyToPalette('rs_columns_start','tl_content');
18 20
 
19 21
 /*
20 22
  * Add fields
... ...
@@ -27,6 +29,54 @@ $GLOBALS['TL_DCA']['tl_content']['fields']['es_spacing'] = array
27 29
   'inputType'               => 'select',
28 30
   'options'                 => array('default','paragraph'),
29 31
   'reference'               => &$GLOBALS['TL_LANG']['tl_content']['REF']['es_spacing'],
30
-  'eval'                    => array('tl_class'=>'w50','mandatory'=>false,'includeBlankOption'=>true),
32
+  'eval'                    => array('tl_class'=>'clr w50','mandatory'=>false,'includeBlankOption'=>true),
31 33
   'sql'                     => "varchar(32) NOT NULL default ''"
32 34
 );
35
+
36
+$GLOBALS['TL_DCA']['tl_content']['fields']['es_padding'] = array
37
+(
38
+    'label'                   => &$GLOBALS['TL_LANG']['tl_content']['es_padding'],
39
+    'exclude'                 => true,
40
+    'inputType'               => 'checkbox',
41
+    'reference'               => &$GLOBALS['TL_LANG']['tl_content']['REF']['es_padding'],
42
+    'eval'                    => array('tl_class'=>'w50 m12'),
43
+    'sql'                     => "char(1) NOT NULL default ''"
44
+);
45
+
46
+$GLOBALS['TL_DCA']['tl_content']['fields']['es_rs_columns_valign'] = array
47
+(
48
+    'label'                   => &$GLOBALS['TL_LANG']['tl_content']['es_rs_columns_valign'],
49
+    'exclude'                 => true,
50
+    'inputType'               => 'select',
51
+    'options'                 => array('top','center','bottom','stretch'),
52
+    'reference'               => &$GLOBALS['TL_LANG']['tl_content']['REF']['es_rs_columns_valign'],
53
+    'eval'                    => array('tl_class'=>'w50','mandatory'=>false,'includeBlankOption'=>true),
54
+    'sql'                     => "varchar(16) NOT NULL default ''"
55
+);
56
+
57
+$GLOBALS['TL_DCA']['tl_content']['fields']['es_rs_column_sort_small'] = array
58
+(
59
+    'label'                   => &$GLOBALS['TL_LANG']['tl_content']['es_rs_column_sort_small'],
60
+    'exclude'                 => true,
61
+    'inputType'               => 'text',
62
+    'eval'                    => array('tl_class'=>'rs_columns_w33', 'rgxp'=>'natural','maxval'=>6),
63
+    'sql'                     => "varchar(255) NOT NULL default ''"
64
+);
65
+
66
+$GLOBALS['TL_DCA']['tl_content']['fields']['es_rs_column_sort_medium'] = array
67
+(
68
+    'label'                   => &$GLOBALS['TL_LANG']['tl_content']['es_rs_column_sort_medium'],
69
+    'exclude'                 => true,
70
+    'inputType'               => 'text',
71
+    'eval'                    => array('tl_class'=>'rs_columns_w33', 'rgxp'=>'natural','maxval'=>6),
72
+    'sql'                     => "varchar(255) NOT NULL default ''"
73
+);
74
+
75
+$GLOBALS['TL_DCA']['tl_content']['fields']['es_rs_column_sort_large'] = array
76
+(
77
+    'label'                   => &$GLOBALS['TL_LANG']['tl_content']['es_rs_column_sort_large'],
78
+    'exclude'                 => true,
79
+    'inputType'               => 'text',
80
+    'eval'                    => array('tl_class'=>'rs_columns_w33', 'rgxp'=>'natural','maxval'=>6),
81
+    'sql'                     => "varchar(255) NOT NULL default ''"
82
+);
33 83
new file mode 100644
... ...
@@ -0,0 +1,28 @@
1
+<?php
2
+
3
+/*
4
+ * This file is part of eSales Media ContentHelperBundle
5
+ *
6
+ * (c) Benjamin Roth
7
+ *
8
+ * @license proprietary
9
+ */
10
+
11
+/*
12
+ * Modify palettes
13
+ */
14
+
15
+\Contao\CoreBundle\DataContainer\PaletteManipulator::create()->addField('rs_columns_load_css_flex','rs_columns_load_css')->applyToPalette('default','tl_layout');
16
+
17
+/*
18
+ * Add fields
19
+ */
20
+
21
+$GLOBALS['TL_DCA']['tl_layout']['fields']['rs_columns_load_css_flex'] = array
22
+(
23
+  'label'                   => &$GLOBALS['TL_LANG']['tl_layout']['rs_columns_load_css_flex'],
24
+  'exclude'                 => true,
25
+  'inputType'               => 'checkbox',
26
+  'eval'                    => array('tl_class'=>'w50'),
27
+  'sql'                     => "char(1) NOT NULL default '1'",
28
+);
... ...
@@ -1,13 +1,11 @@
1 1
 <?php
2 2
 
3
-/**
4
- * Tweaks for Contao
3
+/*
4
+ * This file is part of eSales Media ContentHelperBundle
5 5
  *
6
- * Copyright (c) 2014 Benjamin Roth [http://www.esales-media.de]
6
+ * (c) Benjamin Roth
7 7
  *
8
- * @package eSM_tweaks
9
- * @link    http://www.esales-media.de
10
- * @license commercial
8
+ * @license proprietary
11 9
  */
12 10
 
13 11
 /**
... ...
@@ -15,9 +13,28 @@
15 13
  */
16 14
 $GLOBALS['TL_LANG']['tl_content']['es_spacing'][0] = 'Abstand nach dem Element';
17 15
 $GLOBALS['TL_LANG']['tl_content']['es_spacing'][1] = 'Fügt einen Abstand nach dem Element ein.';
16
+$GLOBALS['TL_LANG']['tl_content']['es_padding'][0] = 'Innenabstand';
17
+$GLOBALS['TL_LANG']['tl_content']['es_padding'][1] = 'Es wird Oben und Unten ein Innenabstand angewendet.';
18
+$GLOBALS['TL_LANG']['tl_content']['es_rs_columns_valign'][0] = 'Vertikale Ausrichtung';
19
+$GLOBALS['TL_LANG']['tl_content']['es_rs_columns_valign'][1] = 'Vertikale Ausrichtung des Spalteninhalts.';
20
+$GLOBALS['TL_LANG']['tl_content']['es_rs_column_sort_large'][0] = 'Desktop-Sortierung';
21
+$GLOBALS['TL_LANG']['tl_content']['es_rs_column_sort_large'][1] = 'Anordnung der Spalte am Desktop.';
22
+$GLOBALS['TL_LANG']['tl_content']['es_rs_column_sort_medium'][0] = 'Tablet-Sortierung';
23
+$GLOBALS['TL_LANG']['tl_content']['es_rs_column_sort_medium'][1] = 'Anordnung der Spalte am Tablet.';
24
+$GLOBALS['TL_LANG']['tl_content']['es_rs_column_sort_small'][0] = 'Mobile-Sortierung';
25
+$GLOBALS['TL_LANG']['tl_content']['es_rs_column_sort_small'][1] = 'Anordnung der Spalte am Mobilgerät.';
26
+
27
+/**
28
+ * Legends
29
+ */
30
+$GLOBALS['TL_LANG']['tl_content']['col_layout_legend'] = 'Spaltenlayout';
18 31
 
19 32
 /**
20 33
  * References
21 34
  */
22 35
 $GLOBALS['TL_LANG']['tl_content']['REF']['es_spacing']['default'] = 'Standard';
23 36
 $GLOBALS['TL_LANG']['tl_content']['REF']['es_spacing']['paragraph'] = 'Absatz';
37
+$GLOBALS['TL_LANG']['tl_content']['REF']['es_rs_columns_valign']['top'] = 'Oben';
38
+$GLOBALS['TL_LANG']['tl_content']['REF']['es_rs_columns_valign']['center'] = 'Mitte';
39
+$GLOBALS['TL_LANG']['tl_content']['REF']['es_rs_columns_valign']['bottom'] = 'Unten';
40
+$GLOBALS['TL_LANG']['tl_content']['REF']['es_rs_columns_valign']['stretch'] = 'Gleiche Höhe';
24 41
new file mode 100644
... ...
@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+/*
4
+ * This file is part of eSales Media ContentHelperBundle
5
+ *
6
+ * (c) Benjamin Roth
7
+ *
8
+ * @license proprietary
9
+ */
10
+
11
+/**
12
+ * Fields
13
+ */
14
+$GLOBALS['TL_LANG']['tl_layout']['rs_columns_load_css_flex'][0] = 'Flexbox Spalten-Stylesheet laden';
15
+$GLOBALS['TL_LANG']['tl_layout']['rs_columns_load_css_flex'][1] = 'Ermöglicht die Verwendung der Spaltenumschlagelemente. Alternativ können Sie Ihr eigenes Stylesheet einbinden.';
0 16
new file mode 100644
... ...
@@ -0,0 +1,97 @@
1
+@mixin column-classes($gutter-width, $max-columns, $class-name) {
2
+  @for $cols from 1 through $max-columns {
3
+    @for $span from 1 through $cols {
4
+      &.-#{unquote($class-name)}-col-#{$cols}-#{$span} {
5
+        flex-basis: 100% / $cols * $span - ($gutter-width * 100%);
6
+        order: 6;
7
+      }
8
+    }
9
+  }
10
+
11
+  @for $cols from 1 through $max-columns {
12
+    &.-#{unquote($class-name)}-order-#{$cols} {
13
+      order: $cols;
14
+    }
15
+  }
16
+}
17
+
18
+$gutter-width: floor((1 / 960) * 1000000) / 1000000 * 30;
19
+
20
+.rs-columns {
21
+  display: flex;
22
+  align-items: flex-start;
23
+  flex-wrap: wrap;
24
+  margin-left: -#{$gutter-width * 100%};
25
+  margin-top: -#{$gutter-width * 100%};
26
+
27
+  &.-valign-center {
28
+    align-items: center;
29
+  }
30
+  &.-valign-bottom {
31
+    align-items: flex-end;
32
+  }
33
+  &.-valign-stretch {
34
+    align-items: stretch;
35
+  }
36
+}
37
+
38
+.rs-column {
39
+  flex: 0;
40
+  max-width: 100%;
41
+  min-width: 0;
42
+  margin-top: $gutter-width * 100%;
43
+  margin-left: $gutter-width * 100%;
44
+  order: 6;
45
+
46
+  > * + * {
47
+    margin-top: 30px;
48
+  }
49
+
50
+  @include column-classes($gutter-width, 6, large);
51
+
52
+  &.-valign-center {
53
+    align-self: center;
54
+  }
55
+  &.-valign-bottom {
56
+    align-self: flex-end;
57
+  }
58
+  &.-valign-stretch {
59
+    align-self: stretch;
60
+  }
61
+}
62
+
63
+// Tablet portrait format (viewport width 900px and below)
64
+@media screen and (max-width: 900px) {
65
+  $gutter-width: floor((1 / 900) * 1000000) / 1000000 * 30;
66
+
67
+  .rs-columns {
68
+    margin-left: -#{$gutter-width * 100%};
69
+    margin-top: -#{$gutter-width * 100%};
70
+  }
71
+
72
+  .rs-column {
73
+    margin-top: $gutter-width * 100%;
74
+    margin-left: $gutter-width * 100%;
75
+    order: 6;
76
+
77
+    @include column-classes($gutter-width, 6, medium);
78
+  }
79
+}
80
+
81
+// Mobile (viewport width 599px and below)
82
+@media screen and (max-width: 599px) {
83
+  $gutter-width: floor((1 / 599) * 1000000) / 1000000 * 30;
84
+
85
+  .rs-columns {
86
+    margin-left: -#{$gutter-width * 100%};
87
+    margin-top: -#{$gutter-width * 100%};
88
+  }
89
+
90
+  .rs-column {
91
+    margin-top: $gutter-width * 100%;
92
+    margin-left: $gutter-width * 100%;
93
+    order: 6;
94
+
95
+    @include column-classes($gutter-width, 6, small);
96
+  }
97
+}