Browse code

Refactor and rewrite as contao bundle

Benjamin Roth authored on04/11/2022 22:32:32
Showing1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,87 +0,0 @@
1
-<?php
2
-
3
-$GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/lib/swiper/' . $GLOBALS['TL_ASSETS']['SWIPERJS'] . '/swiper-bundle.min.css';
4
-$GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/css/swiper-custom.css';
5
-
6
-?>
7
-
8
-<script src="/system/modules/eSM_swiper/assets/lib/swiper/<?= $GLOBALS['TL_ASSETS']['SWIPERJS'] ?>/swiper-bundle.min.js"></script>
9
-
10
-<script>
11
-  (function () {
12
-    var cte = document.querySelectorAll(".ce_swiperSliderStart,.swiper-holder");
13
-
14
-    for (var i=0; i<cte.length; i++)
15
-    {
16
-      var e = cte[i].querySelectorAll('.swiper-container')[0];
17
-      var w = e.querySelectorAll('.swiper-wrapper')[0];
18
-      var c = {
19
-        initialSlide: 0,
20
-        speed: 300,
21
-        autoHeight: false,
22
-        effect: 'slide',
23
-        slidesPerView: 1,
24
-        slidesPerGroup: 1,
25
-        preloadImages: true,
26
-        loop: false,
27
-        autoplay: false
28
-      };
29
-
30
-      if (w.hasAttribute('data-config'))
31
-      {
32
-        var s = w.getAttribute('data-config').split(',');
33
-
34
-        c.speed = parseInt(s[1]);
35
-        c.initialSlide = parseInt(s[2]);
36
-
37
-        if (parseInt(s[0]) > 0)
38
-          c.autoplay = {delay: parseInt(s[0]), disableOnInteraction: (parseInt(s[7]) == 1 ? true : false)}
39
-
40
-        if (parseInt(s[3]) != 1)
41
-          c.preloadImages = false;
42
-
43
-        if (parseInt(s[4]) == 1)
44
-          c.loop = true;
45
-
46
-        if (parseInt(s[5]) != '')
47
-          c.navigation = {
48
-            nextEl: cte[i].querySelectorAll('.swiper-button-next')[0],
49
-            prevEl: cte[i].querySelectorAll('.swiper-button-prev')[0],
50
-          };
51
-
52
-        if (parseInt(s[6]) == 1)
53
-          c.pagination = {
54
-            el: '.swiper-pagination',
55
-            clickable: true
56
-          };
57
-
58
-        if (parseInt(s[8]) == 1)
59
-          c.effect = 'fade';
60
-
61
-        if (parseInt(s[9]) > 1)
62
-          c.slidesPerView = parseInt(s[9]);
63
-
64
-        if (parseInt(s[10]) > 1)
65
-          c.slidesPerGroup = parseInt(s[10]);
66
-
67
-        if (parseInt(s[11]) == 1)
68
-          c.autoHeight = true;
69
-
70
-        if (s[12] !== undefined && s[12] !== '')
71
-          c.slideClass = s[12];
72
-
73
-      }
74
-      if (w.hasAttribute('data-breakpoints'))
75
-      {
76
-        try {
77
-          var breakpoints = JSON.parse(w.getAttribute('data-breakpoints'));
78
-          c.breakpoints = breakpoints;
79
-        } catch (e)
80
-        {
81
-          console.log('Swiper.js: breakpoint data attribute is not valid JSON');
82
-        }
83
-      }
84
-      new Swiper(e,c);
85
-    }
86
-  })();
87
-</script>
88 0
\ No newline at end of file
Browse code

Allow navigation arrows to be placed outside by setting

Benjamin Roth authored on17/01/2021 16:23:06
Showing1 changed files
... ...
@@ -9,7 +9,7 @@ $GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/css/swiper-custom.css'
9 9
 
10 10
 <script>
11 11
   (function () {
12
-    var cte = document.querySelectorAll(".ce_swiperSliderStart");
12
+    var cte = document.querySelectorAll(".ce_swiperSliderStart,.swiper-holder");
13 13
 
14 14
     for (var i=0; i<cte.length; i++)
15 15
     {
... ...
@@ -43,10 +43,10 @@ $GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/css/swiper-custom.css'
43 43
         if (parseInt(s[4]) == 1)
44 44
           c.loop = true;
45 45
 
46
-        if (parseInt(s[5]) == 1)
46
+        if (parseInt(s[5]) != '')
47 47
           c.navigation = {
48
-            nextEl: '.swiper-button-next',
49
-            prevEl: '.swiper-button-prev',
48
+            nextEl: cte[i].querySelectorAll('.swiper-button-next')[0],
49
+            prevEl: cte[i].querySelectorAll('.swiper-button-prev')[0],
50 50
           };
51 51
 
52 52
         if (parseInt(s[6]) == 1)
... ...
@@ -82,7 +82,6 @@ $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);
86 85
     }
87 86
   })();
88 87
 </script>
89 88
\ No newline at end of file
Browse code

swiper.js version 6.3.3

Benjamin Roth authored on13/10/2020 19:31:56
Showing1 changed files
... ...
@@ -1,11 +1,11 @@
1 1
 <?php
2 2
 
3
-$GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/lib/swiper/' . $GLOBALS['TL_ASSETS']['SWIPERJS'] . '/css/swiper.min.css';
3
+$GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/lib/swiper/' . $GLOBALS['TL_ASSETS']['SWIPERJS'] . '/swiper-bundle.min.css';
4 4
 $GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/css/swiper-custom.css';
5 5
 
6 6
 ?>
7 7
 
8
-<script src="/system/modules/eSM_swiper/assets/lib/swiper/<?= $GLOBALS['TL_ASSETS']['SWIPERJS'] ?>/js/swiper.min.js"></script>
8
+<script src="/system/modules/eSM_swiper/assets/lib/swiper/<?= $GLOBALS['TL_ASSETS']['SWIPERJS'] ?>/swiper-bundle.min.js"></script>
9 9
 
10 10
 <script>
11 11
   (function () {
Browse code

Add responsive breakpoints options

Benjamin Roth authored on13/10/2020 19:05:02
Showing1 changed files
... ...
@@ -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
Browse code

Fix initialization problem if there are more than one slider on the same page

Benjamin Roth authored on20/08/2020 10:03:46
Showing1 changed files
... ...
@@ -9,8 +9,13 @@ $GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/css/swiper-custom.css'
9 9
 
10 10
 <script>
11 11
   (function () {
12
-    var cte = document.querySelectorAll(".ce_swiperSliderStart"), e, w, s, i, c,
13
-      defaults = {
12
+    var cte = document.querySelectorAll(".ce_swiperSliderStart");
13
+
14
+    for (var i=0; i<cte.length; i++)
15
+    {
16
+      var e = cte[i].querySelectorAll('.swiper-container')[0];
17
+      var w = e.querySelectorAll('.swiper-wrapper')[0];
18
+      var c = {
14 19
         initialSlide: 0,
15 20
         speed: 300,
16 21
         autoHeight: false,
... ...
@@ -22,15 +27,9 @@ $GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/css/swiper-custom.css'
22 27
         autoplay: false
23 28
       };
24 29
 
25
-    for (i=0; i<cte.length; i+=2)
26
-    {
27
-      e = cte[i].querySelectorAll('.swiper-container')[0];
28
-      w = e.querySelectorAll('.swiper-wrapper')[0];
29
-      c = defaults;
30
-
31 30
       if (w.hasAttribute('data-config'))
32 31
       {
33
-        s = w.getAttribute('data-config').split(',');
32
+        var s = w.getAttribute('data-config').split(',');
34 33
 
35 34
         c.speed = parseInt(s[1]);
36 35
         c.initialSlide = parseInt(s[2]);
... ...
@@ -68,8 +67,20 @@ $GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/css/swiper-custom.css'
68 67
         if (parseInt(s[11]) == 1)
69 68
           c.autoHeight = true;
70 69
 
70
+        if (s[12] !== '')
71
+          c.slideClass = s[12];
72
+
73
+      }
74
+      if (w.hasAttribute('data-breakpoints'))
75
+      {
76
+        try {
77
+          var breakpoints = JSON.parse(w.getAttribute('data-breakpoints'));
78
+          c.breakpoints = breakpoints;
79
+        } catch (e)
80
+        {
81
+          console.log('Swiper.js: breakpoint data attribute is not valid JSON');
82
+        }
71 83
       }
72
-console.log(c);
73 84
       new Swiper(e,c);
74 85
     }
75 86
   })();
Browse code

Initial commit

Benjamin Roth authored on19/05/2020 21:59:44
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,76 @@
1
+<?php
2
+
3
+$GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/lib/swiper/' . $GLOBALS['TL_ASSETS']['SWIPERJS'] . '/css/swiper.min.css';
4
+$GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/css/swiper-custom.css';
5
+
6
+?>
7
+
8
+<script src="/system/modules/eSM_swiper/assets/lib/swiper/<?= $GLOBALS['TL_ASSETS']['SWIPERJS'] ?>/js/swiper.min.js"></script>
9
+
10
+<script>
11
+  (function () {
12
+    var cte = document.querySelectorAll(".ce_swiperSliderStart"), e, w, s, i, c,
13
+      defaults = {
14
+        initialSlide: 0,
15
+        speed: 300,
16
+        autoHeight: false,
17
+        effect: 'slide',
18
+        slidesPerView: 1,
19
+        slidesPerGroup: 1,
20
+        preloadImages: true,
21
+        loop: false,
22
+        autoplay: false
23
+      };
24
+
25
+    for (i=0; i<cte.length; i+=2)
26
+    {
27
+      e = cte[i].querySelectorAll('.swiper-container')[0];
28
+      w = e.querySelectorAll('.swiper-wrapper')[0];
29
+      c = defaults;
30
+
31
+      if (w.hasAttribute('data-config'))
32
+      {
33
+        s = w.getAttribute('data-config').split(',');
34
+
35
+        c.speed = parseInt(s[1]);
36
+        c.initialSlide = parseInt(s[2]);
37
+
38
+        if (parseInt(s[0]) > 0)
39
+          c.autoplay = {delay: parseInt(s[0]), disableOnInteraction: (parseInt(s[7]) == 1 ? true : false)}
40
+
41
+        if (parseInt(s[3]) != 1)
42
+          c.preloadImages = false;
43
+
44
+        if (parseInt(s[4]) == 1)
45
+          c.loop = true;
46
+
47
+        if (parseInt(s[5]) == 1)
48
+          c.navigation = {
49
+            nextEl: '.swiper-button-next',
50
+            prevEl: '.swiper-button-prev',
51
+          };
52
+
53
+        if (parseInt(s[6]) == 1)
54
+          c.pagination = {
55
+            el: '.swiper-pagination',
56
+            clickable: true
57
+          };
58
+
59
+        if (parseInt(s[8]) == 1)
60
+          c.effect = 'fade';
61
+
62
+        if (parseInt(s[9]) > 1)
63
+          c.slidesPerView = parseInt(s[9]);
64
+
65
+        if (parseInt(s[10]) > 1)
66
+          c.slidesPerGroup = parseInt(s[10]);
67
+
68
+        if (parseInt(s[11]) == 1)
69
+          c.autoHeight = true;
70
+
71
+      }
72
+console.log(c);
73
+      new Swiper(e,c);
74
+    }
75
+  })();
76
+</script>
0 77
\ No newline at end of file