Browse code

Add responsive breakpoints options

Benjamin Roth authored on13/10/2020 19:05:02
Showing5 changed files
... ...
@@ -12,7 +12,8 @@
12 12
   ],
13 13
   "require":{
14 14
     "php": "^5.6 || ^7.0",
15
-    "contao/core-bundle": "^4.4"
15
+    "contao/core-bundle": "^4.4",
16
+    "menatwork/contao-multicolumnwizard-bundle": "^3.4"
16 17
   },
17 18
   "conflict": {
18 19
     "contao/core": "*",
... ...
@@ -25,7 +25,7 @@ $GLOBALS['TL_DCA']['tl_content']['config']['onsubmit_callback'][] = array('tl_co
25 25
 $GLOBALS['TL_DCA']['tl_content']['palettes']['__selector__'][] = 'eSM_addImage';
26 26
 $GLOBALS['TL_DCA']['tl_content']['palettes']['__selector__'][] = 'eSM_addText';
27 27
 $GLOBALS['TL_DCA']['tl_content']['palettes']['__selector__'][] = 'eSM_slider_addImageLink';
28
-$GLOBALS['TL_DCA']['tl_content']['palettes']['swiperSliderStart'] = '{type_legend},type;{swiper_legend},eSM_slider_autoPlaySpeed,eSM_slider_speed,eSM_slider_initialSlide,eSM_slider_preload,eSM_slider_slidesToShow,eSM_slider_slidesToScroll,eSM_slider_infinite,eSM_slider_arrows,eSM_slider_pagination,eSM_slider_stopOnInteraction,eSM_slider_fade,eSM_slider_adaptiveHeight;{image_legend},eSM_addImage;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID,space;{invisible_legend:hide},invisible,start,stop';
28
+$GLOBALS['TL_DCA']['tl_content']['palettes']['swiperSliderStart'] = '{type_legend},type;{swiper_legend},eSM_slider_autoPlaySpeed,eSM_slider_speed,eSM_slider_initialSlide,eSM_slider_preload,eSM_slider_slidesToShow,eSM_slider_slidesToScroll,eSM_slider_infinite,eSM_slider_arrows,eSM_slider_pagination,eSM_slider_stopOnInteraction,eSM_slider_fade,eSM_slider_adaptiveHeight;{breakpoint_legend:hide},eSM_slider_breakpoints;{image_legend},eSM_addImage;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID,space;{invisible_legend:hide},invisible,start,stop';
29 29
 $GLOBALS['TL_DCA']['tl_content']['palettes']['swiperSliderStop'] = '{type_legend},type;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests;{invisible_legend:hide},invisible,start,stop';
30 30
 $GLOBALS['TL_DCA']['tl_content']['palettes']['swiperSliderSlideStart'] = '{type_legend},type;{swiper_legend},eSM_addImage;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID,space;{invisible_legend:hide},invisible,start,stop';
31 31
 $GLOBALS['TL_DCA']['tl_content']['palettes']['swiperSliderSlideStop'] = '{type_legend},type;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests;{invisible_legend:hide},invisible,start,stop';
... ...
@@ -149,6 +149,38 @@ $GLOBALS['TL_DCA']['tl_content']['fields']['eSM_slider_adaptiveHeight'] = array
149 149
   'sql'                     => "char(1) NOT NULL default ''"
150 150
 );
151 151
 
152
+$GLOBALS['TL_DCA']['tl_content']['fields']['eSM_slider_breakpoints'] = array
153
+(
154
+  'exclude'   => true,
155
+  'inputType' => 'multiColumnWizard',
156
+  'eval'      => array
157
+  (
158
+    'columnFields' => array
159
+    (
160
+      'breakpoint_width'      => [
161
+        'label'     => &$GLOBALS['TL_LANG']['tl_content']['eSM_slider_breakpoints_width'],
162
+        'exclude'   => true,
163
+        'inputType' => 'text',
164
+        'eval'      => array('rgxp'=>'natural','minval'=>1,'style' => 'width: 95%;'),
165
+      ],
166
+      'breakpoint_slidesToShow'      => [
167
+        'label'     => &$GLOBALS['TL_LANG']['tl_content']['eSM_slider_breakpoints_slidesToShow'],
168
+        'exclude'   => true,
169
+        'inputType' => 'text',
170
+        'eval'      => array('rgxp'=>'natural','minval'=>1,'style' => 'width: 95%;'),
171
+      ],
172
+      'breakpoint_slidesToScroll'      => [
173
+        'label'     => &$GLOBALS['TL_LANG']['tl_content']['eSM_slider_breakpoints_slidesToScroll'],
174
+        'exclude'   => true,
175
+        'inputType' => 'text',
176
+        'eval'      => array('rgxp'=>'natural','minval'=>1,'style' => 'width: 95%;'),
177
+      ],
178
+    ),
179
+  ),
180
+  'sql'       => 'blob NULL',
181
+);
182
+
183
+
152 184
 $GLOBALS['TL_DCA']['tl_content']['fields']['eSM_slider_text'] = array
153 185
 (
154 186
     'label'                   => &$GLOBALS['TL_LANG']['tl_content']['eSM_slider_text'],
... ...
@@ -51,6 +51,26 @@ class ContentSwiperSliderStart extends \ContentElement
51 51
 		// Slider configuration
52 52
 		$this->Template->config = $this->eSM_slider_autoPlaySpeed . ',' . $this->eSM_slider_speed . ',' . $this->eSM_slider_initialSlide . ',' . $this->eSM_slider_preload . ',' . $this->eSM_slider_infinite . ',' . $this->eSM_slider_arrows . ',' . $this->eSM_slider_pagination . ',' . $this->eSM_slider_stopOnInteraction . ',' . $this->eSM_slider_fade . ',' . $this->eSM_slider_slidesToShow . ',' . $this->eSM_slider_slidesToScroll . ',' . $this->eSM_slider_adaptiveHeight;
53 53
 
54
+		// Breakpoint config
55
+    $this->eSM_slider_breakpoints = \StringUtil::deserialize($this->eSM_slider_breakpoints);
56
+    if (is_array($this->eSM_slider_breakpoints))
57
+    {
58
+      $arrBreakpoints = array();
59
+
60
+      foreach ($this->eSM_slider_breakpoints as $breakpoint)
61
+      {
62
+        if (is_numeric($breakpoint['breakpoint_width']) && is_numeric($breakpoint['breakpoint_slidesToShow']) && is_numeric($breakpoint['breakpoint_slidesToScroll']))
63
+        {
64
+          $arrBreakpoints[$breakpoint['breakpoint_width']] = array('slidesPerView'=>$breakpoint['breakpoint_slidesToShow'],'slidesPerGroup'=>$breakpoint['breakpoint_slidesToScroll']);
65
+        }
66
+      }
67
+
68
+      if (count($arrBreakpoints))
69
+      {
70
+        $this->Template->breakpoints = json_encode($arrBreakpoints,JSON_NUMERIC_CHECK );
71
+      }
72
+    }
73
+
54 74
 		// Background image
55 75
     if ($this->eSM_addImage && $this->multiSRC)
56 76
     {
... ...
@@ -31,6 +31,6 @@
31 31
      <div class="swiper-pagination"></div>
32 32
     <?php endif; ?>
33 33
 
34
-    <div class="swiper-wrapper" data-config="<?= $this->config ?>">
34
+    <div class="swiper-wrapper" data-config="<?= $this->config ?>"<?php if ($this->breakpoints): ?> data-breakpoints='<?= $this->breakpoints ?>'<?php endif; ?>>
35 35
 
36 36
 <?php $this->endblock(); ?>
... ...
@@ -67,7 +67,7 @@ $GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/css/swiper-custom.css'
67 67
         if (parseInt(s[11]) == 1)
68 68
           c.autoHeight = true;
69 69
 
70
-        if (s[12] !== '')
70
+        if (s[12] !== undefined && s[12] !== '')
71 71
           c.slideClass = s[12];
72 72
 
73 73
       }
... ...
@@ -82,6 +82,7 @@ $GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/css/swiper-custom.css'
82 82
         }
83 83
       }
84 84
       new Swiper(e,c);
85
+      console.log(c);
85 86
     }
86 87
   })();
87 88
 </script>
88 89
\ No newline at end of file