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,194 +0,0 @@
1
-function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
-import $ from '../../utils/dom';
4
-import { extend, bindModuleMethods } from '../../utils/utils';
5
-var Cube = {
6
-  setTranslate: function setTranslate() {
7
-    var swiper = this;
8
-    var $el = swiper.$el,
9
-        $wrapperEl = swiper.$wrapperEl,
10
-        slides = swiper.slides,
11
-        swiperWidth = swiper.width,
12
-        swiperHeight = swiper.height,
13
-        rtl = swiper.rtlTranslate,
14
-        swiperSize = swiper.size,
15
-        browser = swiper.browser;
16
-    var params = swiper.params.cubeEffect;
17
-    var isHorizontal = swiper.isHorizontal();
18
-    var isVirtual = swiper.virtual && swiper.params.virtual.enabled;
19
-    var wrapperRotate = 0;
20
-    var $cubeShadowEl;
21
-
22
-    if (params.shadow) {
23
-      if (isHorizontal) {
24
-        $cubeShadowEl = $wrapperEl.find('.swiper-cube-shadow');
25
-
26
-        if ($cubeShadowEl.length === 0) {
27
-          $cubeShadowEl = $('<div class="swiper-cube-shadow"></div>');
28
-          $wrapperEl.append($cubeShadowEl);
29
-        }
30
-
31
-        $cubeShadowEl.css({
32
-          height: swiperWidth + "px"
33
-        });
34
-      } else {
35
-        $cubeShadowEl = $el.find('.swiper-cube-shadow');
36
-
37
-        if ($cubeShadowEl.length === 0) {
38
-          $cubeShadowEl = $('<div class="swiper-cube-shadow"></div>');
39
-          $el.append($cubeShadowEl);
40
-        }
41
-      }
42
-    }
43
-
44
-    for (var i = 0; i < slides.length; i += 1) {
45
-      var $slideEl = slides.eq(i);
46
-      var slideIndex = i;
47
-
48
-      if (isVirtual) {
49
-        slideIndex = parseInt($slideEl.attr('data-swiper-slide-index'), 10);
50
-      }
51
-
52
-      var slideAngle = slideIndex * 90;
53
-      var round = Math.floor(slideAngle / 360);
54
-
55
-      if (rtl) {
56
-        slideAngle = -slideAngle;
57
-        round = Math.floor(-slideAngle / 360);
58
-      }
59
-
60
-      var progress = Math.max(Math.min($slideEl[0].progress, 1), -1);
61
-      var tx = 0;
62
-      var ty = 0;
63
-      var tz = 0;
64
-
65
-      if (slideIndex % 4 === 0) {
66
-        tx = -round * 4 * swiperSize;
67
-        tz = 0;
68
-      } else if ((slideIndex - 1) % 4 === 0) {
69
-        tx = 0;
70
-        tz = -round * 4 * swiperSize;
71
-      } else if ((slideIndex - 2) % 4 === 0) {
72
-        tx = swiperSize + round * 4 * swiperSize;
73
-        tz = swiperSize;
74
-      } else if ((slideIndex - 3) % 4 === 0) {
75
-        tx = -swiperSize;
76
-        tz = 3 * swiperSize + swiperSize * 4 * round;
77
-      }
78
-
79
-      if (rtl) {
80
-        tx = -tx;
81
-      }
82
-
83
-      if (!isHorizontal) {
84
-        ty = tx;
85
-        tx = 0;
86
-      }
87
-
88
-      var transform = "rotateX(" + (isHorizontal ? 0 : -slideAngle) + "deg) rotateY(" + (isHorizontal ? slideAngle : 0) + "deg) translate3d(" + tx + "px, " + ty + "px, " + tz + "px)";
89
-
90
-      if (progress <= 1 && progress > -1) {
91
-        wrapperRotate = slideIndex * 90 + progress * 90;
92
-        if (rtl) wrapperRotate = -slideIndex * 90 - progress * 90;
93
-      }
94
-
95
-      $slideEl.transform(transform);
96
-
97
-      if (params.slideShadows) {
98
-        // Set shadows
99
-        var shadowBefore = isHorizontal ? $slideEl.find('.swiper-slide-shadow-left') : $slideEl.find('.swiper-slide-shadow-top');
100
-        var shadowAfter = isHorizontal ? $slideEl.find('.swiper-slide-shadow-right') : $slideEl.find('.swiper-slide-shadow-bottom');
101
-
102
-        if (shadowBefore.length === 0) {
103
-          shadowBefore = $("<div class=\"swiper-slide-shadow-" + (isHorizontal ? 'left' : 'top') + "\"></div>");
104
-          $slideEl.append(shadowBefore);
105
-        }
106
-
107
-        if (shadowAfter.length === 0) {
108
-          shadowAfter = $("<div class=\"swiper-slide-shadow-" + (isHorizontal ? 'right' : 'bottom') + "\"></div>");
109
-          $slideEl.append(shadowAfter);
110
-        }
111
-
112
-        if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0);
113
-        if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0);
114
-      }
115
-    }
116
-
117
-    $wrapperEl.css({
118
-      '-webkit-transform-origin': "50% 50% -" + swiperSize / 2 + "px",
119
-      '-moz-transform-origin': "50% 50% -" + swiperSize / 2 + "px",
120
-      '-ms-transform-origin': "50% 50% -" + swiperSize / 2 + "px",
121
-      'transform-origin': "50% 50% -" + swiperSize / 2 + "px"
122
-    });
123
-
124
-    if (params.shadow) {
125
-      if (isHorizontal) {
126
-        $cubeShadowEl.transform("translate3d(0px, " + (swiperWidth / 2 + params.shadowOffset) + "px, " + -swiperWidth / 2 + "px) rotateX(90deg) rotateZ(0deg) scale(" + params.shadowScale + ")");
127
-      } else {
128
-        var shadowAngle = Math.abs(wrapperRotate) - Math.floor(Math.abs(wrapperRotate) / 90) * 90;
129
-        var multiplier = 1.5 - (Math.sin(shadowAngle * 2 * Math.PI / 360) / 2 + Math.cos(shadowAngle * 2 * Math.PI / 360) / 2);
130
-        var scale1 = params.shadowScale;
131
-        var scale2 = params.shadowScale / multiplier;
132
-        var offset = params.shadowOffset;
133
-        $cubeShadowEl.transform("scale3d(" + scale1 + ", 1, " + scale2 + ") translate3d(0px, " + (swiperHeight / 2 + offset) + "px, " + -swiperHeight / 2 / scale2 + "px) rotateX(-90deg)");
134
-      }
135
-    }
136
-
137
-    var zFactor = browser.isSafari || browser.isWebView ? -swiperSize / 2 : 0;
138
-    $wrapperEl.transform("translate3d(0px,0," + zFactor + "px) rotateX(" + (swiper.isHorizontal() ? 0 : wrapperRotate) + "deg) rotateY(" + (swiper.isHorizontal() ? -wrapperRotate : 0) + "deg)");
139
-  },
140
-  setTransition: function setTransition(duration) {
141
-    var swiper = this;
142
-    var $el = swiper.$el,
143
-        slides = swiper.slides;
144
-    slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
145
-
146
-    if (swiper.params.cubeEffect.shadow && !swiper.isHorizontal()) {
147
-      $el.find('.swiper-cube-shadow').transition(duration);
148
-    }
149
-  }
150
-};
151
-export default {
152
-  name: 'effect-cube',
153
-  params: {
154
-    cubeEffect: {
155
-      slideShadows: true,
156
-      shadow: true,
157
-      shadowOffset: 20,
158
-      shadowScale: 0.94
159
-    }
160
-  },
161
-  create: function create() {
162
-    var swiper = this;
163
-    bindModuleMethods(swiper, {
164
-      cubeEffect: _extends({}, Cube)
165
-    });
166
-  },
167
-  on: {
168
-    beforeInit: function beforeInit(swiper) {
169
-      if (swiper.params.effect !== 'cube') return;
170
-      swiper.classNames.push(swiper.params.containerModifierClass + "cube");
171
-      swiper.classNames.push(swiper.params.containerModifierClass + "3d");
172
-      var overwriteParams = {
173
-        slidesPerView: 1,
174
-        slidesPerColumn: 1,
175
-        slidesPerGroup: 1,
176
-        watchSlidesProgress: true,
177
-        resistanceRatio: 0,
178
-        spaceBetween: 0,
179
-        centeredSlides: false,
180
-        virtualTranslate: true
181
-      };
182
-      extend(swiper.params, overwriteParams);
183
-      extend(swiper.originalParams, overwriteParams);
184
-    },
185
-    setTranslate: function setTranslate(swiper) {
186
-      if (swiper.params.effect !== 'cube') return;
187
-      swiper.cubeEffect.setTranslate();
188
-    },
189
-    setTransition: function setTransition(swiper, duration) {
190
-      if (swiper.params.effect !== 'cube') return;
191
-      swiper.cubeEffect.setTransition(duration);
192
-    }
193
-  }
194
-};
195 0
\ 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 1
new file mode 100644
... ...
@@ -0,0 +1,194 @@
1
+function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+import $ from '../../utils/dom';
4
+import { extend, bindModuleMethods } from '../../utils/utils';
5
+var Cube = {
6
+  setTranslate: function setTranslate() {
7
+    var swiper = this;
8
+    var $el = swiper.$el,
9
+        $wrapperEl = swiper.$wrapperEl,
10
+        slides = swiper.slides,
11
+        swiperWidth = swiper.width,
12
+        swiperHeight = swiper.height,
13
+        rtl = swiper.rtlTranslate,
14
+        swiperSize = swiper.size,
15
+        browser = swiper.browser;
16
+    var params = swiper.params.cubeEffect;
17
+    var isHorizontal = swiper.isHorizontal();
18
+    var isVirtual = swiper.virtual && swiper.params.virtual.enabled;
19
+    var wrapperRotate = 0;
20
+    var $cubeShadowEl;
21
+
22
+    if (params.shadow) {
23
+      if (isHorizontal) {
24
+        $cubeShadowEl = $wrapperEl.find('.swiper-cube-shadow');
25
+
26
+        if ($cubeShadowEl.length === 0) {
27
+          $cubeShadowEl = $('<div class="swiper-cube-shadow"></div>');
28
+          $wrapperEl.append($cubeShadowEl);
29
+        }
30
+
31
+        $cubeShadowEl.css({
32
+          height: swiperWidth + "px"
33
+        });
34
+      } else {
35
+        $cubeShadowEl = $el.find('.swiper-cube-shadow');
36
+
37
+        if ($cubeShadowEl.length === 0) {
38
+          $cubeShadowEl = $('<div class="swiper-cube-shadow"></div>');
39
+          $el.append($cubeShadowEl);
40
+        }
41
+      }
42
+    }
43
+
44
+    for (var i = 0; i < slides.length; i += 1) {
45
+      var $slideEl = slides.eq(i);
46
+      var slideIndex = i;
47
+
48
+      if (isVirtual) {
49
+        slideIndex = parseInt($slideEl.attr('data-swiper-slide-index'), 10);
50
+      }
51
+
52
+      var slideAngle = slideIndex * 90;
53
+      var round = Math.floor(slideAngle / 360);
54
+
55
+      if (rtl) {
56
+        slideAngle = -slideAngle;
57
+        round = Math.floor(-slideAngle / 360);
58
+      }
59
+
60
+      var progress = Math.max(Math.min($slideEl[0].progress, 1), -1);
61
+      var tx = 0;
62
+      var ty = 0;
63
+      var tz = 0;
64
+
65
+      if (slideIndex % 4 === 0) {
66
+        tx = -round * 4 * swiperSize;
67
+        tz = 0;
68
+      } else if ((slideIndex - 1) % 4 === 0) {
69
+        tx = 0;
70
+        tz = -round * 4 * swiperSize;
71
+      } else if ((slideIndex - 2) % 4 === 0) {
72
+        tx = swiperSize + round * 4 * swiperSize;
73
+        tz = swiperSize;
74
+      } else if ((slideIndex - 3) % 4 === 0) {
75
+        tx = -swiperSize;
76
+        tz = 3 * swiperSize + swiperSize * 4 * round;
77
+      }
78
+
79
+      if (rtl) {
80
+        tx = -tx;
81
+      }
82
+
83
+      if (!isHorizontal) {
84
+        ty = tx;
85
+        tx = 0;
86
+      }
87
+
88
+      var transform = "rotateX(" + (isHorizontal ? 0 : -slideAngle) + "deg) rotateY(" + (isHorizontal ? slideAngle : 0) + "deg) translate3d(" + tx + "px, " + ty + "px, " + tz + "px)";
89
+
90
+      if (progress <= 1 && progress > -1) {
91
+        wrapperRotate = slideIndex * 90 + progress * 90;
92
+        if (rtl) wrapperRotate = -slideIndex * 90 - progress * 90;
93
+      }
94
+
95
+      $slideEl.transform(transform);
96
+
97
+      if (params.slideShadows) {
98
+        // Set shadows
99
+        var shadowBefore = isHorizontal ? $slideEl.find('.swiper-slide-shadow-left') : $slideEl.find('.swiper-slide-shadow-top');
100
+        var shadowAfter = isHorizontal ? $slideEl.find('.swiper-slide-shadow-right') : $slideEl.find('.swiper-slide-shadow-bottom');
101
+
102
+        if (shadowBefore.length === 0) {
103
+          shadowBefore = $("<div class=\"swiper-slide-shadow-" + (isHorizontal ? 'left' : 'top') + "\"></div>");
104
+          $slideEl.append(shadowBefore);
105
+        }
106
+
107
+        if (shadowAfter.length === 0) {
108
+          shadowAfter = $("<div class=\"swiper-slide-shadow-" + (isHorizontal ? 'right' : 'bottom') + "\"></div>");
109
+          $slideEl.append(shadowAfter);
110
+        }
111
+
112
+        if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0);
113
+        if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0);
114
+      }
115
+    }
116
+
117
+    $wrapperEl.css({
118
+      '-webkit-transform-origin': "50% 50% -" + swiperSize / 2 + "px",
119
+      '-moz-transform-origin': "50% 50% -" + swiperSize / 2 + "px",
120
+      '-ms-transform-origin': "50% 50% -" + swiperSize / 2 + "px",
121
+      'transform-origin': "50% 50% -" + swiperSize / 2 + "px"
122
+    });
123
+
124
+    if (params.shadow) {
125
+      if (isHorizontal) {
126
+        $cubeShadowEl.transform("translate3d(0px, " + (swiperWidth / 2 + params.shadowOffset) + "px, " + -swiperWidth / 2 + "px) rotateX(90deg) rotateZ(0deg) scale(" + params.shadowScale + ")");
127
+      } else {
128
+        var shadowAngle = Math.abs(wrapperRotate) - Math.floor(Math.abs(wrapperRotate) / 90) * 90;
129
+        var multiplier = 1.5 - (Math.sin(shadowAngle * 2 * Math.PI / 360) / 2 + Math.cos(shadowAngle * 2 * Math.PI / 360) / 2);
130
+        var scale1 = params.shadowScale;
131
+        var scale2 = params.shadowScale / multiplier;
132
+        var offset = params.shadowOffset;
133
+        $cubeShadowEl.transform("scale3d(" + scale1 + ", 1, " + scale2 + ") translate3d(0px, " + (swiperHeight / 2 + offset) + "px, " + -swiperHeight / 2 / scale2 + "px) rotateX(-90deg)");
134
+      }
135
+    }
136
+
137
+    var zFactor = browser.isSafari || browser.isWebView ? -swiperSize / 2 : 0;
138
+    $wrapperEl.transform("translate3d(0px,0," + zFactor + "px) rotateX(" + (swiper.isHorizontal() ? 0 : wrapperRotate) + "deg) rotateY(" + (swiper.isHorizontal() ? -wrapperRotate : 0) + "deg)");
139
+  },
140
+  setTransition: function setTransition(duration) {
141
+    var swiper = this;
142
+    var $el = swiper.$el,
143
+        slides = swiper.slides;
144
+    slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
145
+
146
+    if (swiper.params.cubeEffect.shadow && !swiper.isHorizontal()) {
147
+      $el.find('.swiper-cube-shadow').transition(duration);
148
+    }
149
+  }
150
+};
151
+export default {
152
+  name: 'effect-cube',
153
+  params: {
154
+    cubeEffect: {
155
+      slideShadows: true,
156
+      shadow: true,
157
+      shadowOffset: 20,
158
+      shadowScale: 0.94
159
+    }
160
+  },
161
+  create: function create() {
162
+    var swiper = this;
163
+    bindModuleMethods(swiper, {
164
+      cubeEffect: _extends({}, Cube)
165
+    });
166
+  },
167
+  on: {
168
+    beforeInit: function beforeInit(swiper) {
169
+      if (swiper.params.effect !== 'cube') return;
170
+      swiper.classNames.push(swiper.params.containerModifierClass + "cube");
171
+      swiper.classNames.push(swiper.params.containerModifierClass + "3d");
172
+      var overwriteParams = {
173
+        slidesPerView: 1,
174
+        slidesPerColumn: 1,
175
+        slidesPerGroup: 1,
176
+        watchSlidesProgress: true,
177
+        resistanceRatio: 0,
178
+        spaceBetween: 0,
179
+        centeredSlides: false,
180
+        virtualTranslate: true
181
+      };
182
+      extend(swiper.params, overwriteParams);
183
+      extend(swiper.originalParams, overwriteParams);
184
+    },
185
+    setTranslate: function setTranslate(swiper) {
186
+      if (swiper.params.effect !== 'cube') return;
187
+      swiper.cubeEffect.setTranslate();
188
+    },
189
+    setTransition: function setTransition(swiper, duration) {
190
+      if (swiper.params.effect !== 'cube') return;
191
+      swiper.cubeEffect.setTransition(duration);
192
+    }
193
+  }
194
+};
0 195
\ No newline at end of file