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,180 +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
-/* eslint no-underscore-dangle: "off" */
4
-import { getDocument } from 'ssr-window';
5
-import { nextTick, bindModuleMethods } from '../../utils/utils';
6
-var Autoplay = {
7
-  run: function run() {
8
-    var swiper = this;
9
-    var $activeSlideEl = swiper.slides.eq(swiper.activeIndex);
10
-    var delay = swiper.params.autoplay.delay;
11
-
12
-    if ($activeSlideEl.attr('data-swiper-autoplay')) {
13
-      delay = $activeSlideEl.attr('data-swiper-autoplay') || swiper.params.autoplay.delay;
14
-    }
15
-
16
-    clearTimeout(swiper.autoplay.timeout);
17
-    swiper.autoplay.timeout = nextTick(function () {
18
-      var autoplayResult;
19
-
20
-      if (swiper.params.autoplay.reverseDirection) {
21
-        if (swiper.params.loop) {
22
-          swiper.loopFix();
23
-          autoplayResult = swiper.slidePrev(swiper.params.speed, true, true);
24
-          swiper.emit('autoplay');
25
-        } else if (!swiper.isBeginning) {
26
-          autoplayResult = swiper.slidePrev(swiper.params.speed, true, true);
27
-          swiper.emit('autoplay');
28
-        } else if (!swiper.params.autoplay.stopOnLastSlide) {
29
-          autoplayResult = swiper.slideTo(swiper.slides.length - 1, swiper.params.speed, true, true);
30
-          swiper.emit('autoplay');
31
-        } else {
32
-          swiper.autoplay.stop();
33
-        }
34
-      } else if (swiper.params.loop) {
35
-        swiper.loopFix();
36
-        autoplayResult = swiper.slideNext(swiper.params.speed, true, true);
37
-        swiper.emit('autoplay');
38
-      } else if (!swiper.isEnd) {
39
-        autoplayResult = swiper.slideNext(swiper.params.speed, true, true);
40
-        swiper.emit('autoplay');
41
-      } else if (!swiper.params.autoplay.stopOnLastSlide) {
42
-        autoplayResult = swiper.slideTo(0, swiper.params.speed, true, true);
43
-        swiper.emit('autoplay');
44
-      } else {
45
-        swiper.autoplay.stop();
46
-      }
47
-
48
-      if (swiper.params.cssMode && swiper.autoplay.running) swiper.autoplay.run();else if (autoplayResult === false) {
49
-        swiper.autoplay.run();
50
-      }
51
-    }, delay);
52
-  },
53
-  start: function start() {
54
-    var swiper = this;
55
-    if (typeof swiper.autoplay.timeout !== 'undefined') return false;
56
-    if (swiper.autoplay.running) return false;
57
-    swiper.autoplay.running = true;
58
-    swiper.emit('autoplayStart');
59
-    swiper.autoplay.run();
60
-    return true;
61
-  },
62
-  stop: function stop() {
63
-    var swiper = this;
64
-    if (!swiper.autoplay.running) return false;
65
-    if (typeof swiper.autoplay.timeout === 'undefined') return false;
66
-
67
-    if (swiper.autoplay.timeout) {
68
-      clearTimeout(swiper.autoplay.timeout);
69
-      swiper.autoplay.timeout = undefined;
70
-    }
71
-
72
-    swiper.autoplay.running = false;
73
-    swiper.emit('autoplayStop');
74
-    return true;
75
-  },
76
-  pause: function pause(speed) {
77
-    var swiper = this;
78
-    if (!swiper.autoplay.running) return;
79
-    if (swiper.autoplay.paused) return;
80
-    if (swiper.autoplay.timeout) clearTimeout(swiper.autoplay.timeout);
81
-    swiper.autoplay.paused = true;
82
-
83
-    if (speed === 0 || !swiper.params.autoplay.waitForTransition) {
84
-      swiper.autoplay.paused = false;
85
-      swiper.autoplay.run();
86
-    } else {
87
-      swiper.$wrapperEl[0].addEventListener('transitionend', swiper.autoplay.onTransitionEnd);
88
-      swiper.$wrapperEl[0].addEventListener('webkitTransitionEnd', swiper.autoplay.onTransitionEnd);
89
-    }
90
-  },
91
-  onVisibilityChange: function onVisibilityChange() {
92
-    var swiper = this;
93
-    var document = getDocument();
94
-
95
-    if (document.visibilityState === 'hidden' && swiper.autoplay.running) {
96
-      swiper.autoplay.pause();
97
-    }
98
-
99
-    if (document.visibilityState === 'visible' && swiper.autoplay.paused) {
100
-      swiper.autoplay.run();
101
-      swiper.autoplay.paused = false;
102
-    }
103
-  },
104
-  onTransitionEnd: function onTransitionEnd(e) {
105
-    var swiper = this;
106
-    if (!swiper || swiper.destroyed || !swiper.$wrapperEl) return;
107
-    if (e.target !== swiper.$wrapperEl[0]) return;
108
-    swiper.$wrapperEl[0].removeEventListener('transitionend', swiper.autoplay.onTransitionEnd);
109
-    swiper.$wrapperEl[0].removeEventListener('webkitTransitionEnd', swiper.autoplay.onTransitionEnd);
110
-    swiper.autoplay.paused = false;
111
-
112
-    if (!swiper.autoplay.running) {
113
-      swiper.autoplay.stop();
114
-    } else {
115
-      swiper.autoplay.run();
116
-    }
117
-  }
118
-};
119
-export default {
120
-  name: 'autoplay',
121
-  params: {
122
-    autoplay: {
123
-      enabled: false,
124
-      delay: 3000,
125
-      waitForTransition: true,
126
-      disableOnInteraction: true,
127
-      stopOnLastSlide: false,
128
-      reverseDirection: false
129
-    }
130
-  },
131
-  create: function create() {
132
-    var swiper = this;
133
-    bindModuleMethods(swiper, {
134
-      autoplay: _extends({}, Autoplay, {
135
-        running: false,
136
-        paused: false
137
-      })
138
-    });
139
-  },
140
-  on: {
141
-    init: function init(swiper) {
142
-      if (swiper.params.autoplay.enabled) {
143
-        swiper.autoplay.start();
144
-        var document = getDocument();
145
-        document.addEventListener('visibilitychange', swiper.autoplay.onVisibilityChange);
146
-      }
147
-    },
148
-    beforeTransitionStart: function beforeTransitionStart(swiper, speed, internal) {
149
-      if (swiper.autoplay.running) {
150
-        if (internal || !swiper.params.autoplay.disableOnInteraction) {
151
-          swiper.autoplay.pause(speed);
152
-        } else {
153
-          swiper.autoplay.stop();
154
-        }
155
-      }
156
-    },
157
-    sliderFirstMove: function sliderFirstMove(swiper) {
158
-      if (swiper.autoplay.running) {
159
-        if (swiper.params.autoplay.disableOnInteraction) {
160
-          swiper.autoplay.stop();
161
-        } else {
162
-          swiper.autoplay.pause();
163
-        }
164
-      }
165
-    },
166
-    touchEnd: function touchEnd(swiper) {
167
-      if (swiper.params.cssMode && swiper.autoplay.paused && !swiper.params.autoplay.disableOnInteraction) {
168
-        swiper.autoplay.run();
169
-      }
170
-    },
171
-    destroy: function destroy(swiper) {
172
-      if (swiper.autoplay.running) {
173
-        swiper.autoplay.stop();
174
-      }
175
-
176
-      var document = getDocument();
177
-      document.removeEventListener('visibilitychange', swiper.autoplay.onVisibilityChange);
178
-    }
179
-  }
180
-};
181 0
\ No newline at end of file
Browse code

swiper.js version 6.4.5

Benjamin Roth authored on17/01/2021 16:24:34
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,180 @@
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
+/* eslint no-underscore-dangle: "off" */
4
+import { getDocument } from 'ssr-window';
5
+import { nextTick, bindModuleMethods } from '../../utils/utils';
6
+var Autoplay = {
7
+  run: function run() {
8
+    var swiper = this;
9
+    var $activeSlideEl = swiper.slides.eq(swiper.activeIndex);
10
+    var delay = swiper.params.autoplay.delay;
11
+
12
+    if ($activeSlideEl.attr('data-swiper-autoplay')) {
13
+      delay = $activeSlideEl.attr('data-swiper-autoplay') || swiper.params.autoplay.delay;
14
+    }
15
+
16
+    clearTimeout(swiper.autoplay.timeout);
17
+    swiper.autoplay.timeout = nextTick(function () {
18
+      var autoplayResult;
19
+
20
+      if (swiper.params.autoplay.reverseDirection) {
21
+        if (swiper.params.loop) {
22
+          swiper.loopFix();
23
+          autoplayResult = swiper.slidePrev(swiper.params.speed, true, true);
24
+          swiper.emit('autoplay');
25
+        } else if (!swiper.isBeginning) {
26
+          autoplayResult = swiper.slidePrev(swiper.params.speed, true, true);
27
+          swiper.emit('autoplay');
28
+        } else if (!swiper.params.autoplay.stopOnLastSlide) {
29
+          autoplayResult = swiper.slideTo(swiper.slides.length - 1, swiper.params.speed, true, true);
30
+          swiper.emit('autoplay');
31
+        } else {
32
+          swiper.autoplay.stop();
33
+        }
34
+      } else if (swiper.params.loop) {
35
+        swiper.loopFix();
36
+        autoplayResult = swiper.slideNext(swiper.params.speed, true, true);
37
+        swiper.emit('autoplay');
38
+      } else if (!swiper.isEnd) {
39
+        autoplayResult = swiper.slideNext(swiper.params.speed, true, true);
40
+        swiper.emit('autoplay');
41
+      } else if (!swiper.params.autoplay.stopOnLastSlide) {
42
+        autoplayResult = swiper.slideTo(0, swiper.params.speed, true, true);
43
+        swiper.emit('autoplay');
44
+      } else {
45
+        swiper.autoplay.stop();
46
+      }
47
+
48
+      if (swiper.params.cssMode && swiper.autoplay.running) swiper.autoplay.run();else if (autoplayResult === false) {
49
+        swiper.autoplay.run();
50
+      }
51
+    }, delay);
52
+  },
53
+  start: function start() {
54
+    var swiper = this;
55
+    if (typeof swiper.autoplay.timeout !== 'undefined') return false;
56
+    if (swiper.autoplay.running) return false;
57
+    swiper.autoplay.running = true;
58
+    swiper.emit('autoplayStart');
59
+    swiper.autoplay.run();
60
+    return true;
61
+  },
62
+  stop: function stop() {
63
+    var swiper = this;
64
+    if (!swiper.autoplay.running) return false;
65
+    if (typeof swiper.autoplay.timeout === 'undefined') return false;
66
+
67
+    if (swiper.autoplay.timeout) {
68
+      clearTimeout(swiper.autoplay.timeout);
69
+      swiper.autoplay.timeout = undefined;
70
+    }
71
+
72
+    swiper.autoplay.running = false;
73
+    swiper.emit('autoplayStop');
74
+    return true;
75
+  },
76
+  pause: function pause(speed) {
77
+    var swiper = this;
78
+    if (!swiper.autoplay.running) return;
79
+    if (swiper.autoplay.paused) return;
80
+    if (swiper.autoplay.timeout) clearTimeout(swiper.autoplay.timeout);
81
+    swiper.autoplay.paused = true;
82
+
83
+    if (speed === 0 || !swiper.params.autoplay.waitForTransition) {
84
+      swiper.autoplay.paused = false;
85
+      swiper.autoplay.run();
86
+    } else {
87
+      swiper.$wrapperEl[0].addEventListener('transitionend', swiper.autoplay.onTransitionEnd);
88
+      swiper.$wrapperEl[0].addEventListener('webkitTransitionEnd', swiper.autoplay.onTransitionEnd);
89
+    }
90
+  },
91
+  onVisibilityChange: function onVisibilityChange() {
92
+    var swiper = this;
93
+    var document = getDocument();
94
+
95
+    if (document.visibilityState === 'hidden' && swiper.autoplay.running) {
96
+      swiper.autoplay.pause();
97
+    }
98
+
99
+    if (document.visibilityState === 'visible' && swiper.autoplay.paused) {
100
+      swiper.autoplay.run();
101
+      swiper.autoplay.paused = false;
102
+    }
103
+  },
104
+  onTransitionEnd: function onTransitionEnd(e) {
105
+    var swiper = this;
106
+    if (!swiper || swiper.destroyed || !swiper.$wrapperEl) return;
107
+    if (e.target !== swiper.$wrapperEl[0]) return;
108
+    swiper.$wrapperEl[0].removeEventListener('transitionend', swiper.autoplay.onTransitionEnd);
109
+    swiper.$wrapperEl[0].removeEventListener('webkitTransitionEnd', swiper.autoplay.onTransitionEnd);
110
+    swiper.autoplay.paused = false;
111
+
112
+    if (!swiper.autoplay.running) {
113
+      swiper.autoplay.stop();
114
+    } else {
115
+      swiper.autoplay.run();
116
+    }
117
+  }
118
+};
119
+export default {
120
+  name: 'autoplay',
121
+  params: {
122
+    autoplay: {
123
+      enabled: false,
124
+      delay: 3000,
125
+      waitForTransition: true,
126
+      disableOnInteraction: true,
127
+      stopOnLastSlide: false,
128
+      reverseDirection: false
129
+    }
130
+  },
131
+  create: function create() {
132
+    var swiper = this;
133
+    bindModuleMethods(swiper, {
134
+      autoplay: _extends({}, Autoplay, {
135
+        running: false,
136
+        paused: false
137
+      })
138
+    });
139
+  },
140
+  on: {
141
+    init: function init(swiper) {
142
+      if (swiper.params.autoplay.enabled) {
143
+        swiper.autoplay.start();
144
+        var document = getDocument();
145
+        document.addEventListener('visibilitychange', swiper.autoplay.onVisibilityChange);
146
+      }
147
+    },
148
+    beforeTransitionStart: function beforeTransitionStart(swiper, speed, internal) {
149
+      if (swiper.autoplay.running) {
150
+        if (internal || !swiper.params.autoplay.disableOnInteraction) {
151
+          swiper.autoplay.pause(speed);
152
+        } else {
153
+          swiper.autoplay.stop();
154
+        }
155
+      }
156
+    },
157
+    sliderFirstMove: function sliderFirstMove(swiper) {
158
+      if (swiper.autoplay.running) {
159
+        if (swiper.params.autoplay.disableOnInteraction) {
160
+          swiper.autoplay.stop();
161
+        } else {
162
+          swiper.autoplay.pause();
163
+        }
164
+      }
165
+    },
166
+    touchEnd: function touchEnd(swiper) {
167
+      if (swiper.params.cssMode && swiper.autoplay.paused && !swiper.params.autoplay.disableOnInteraction) {
168
+        swiper.autoplay.run();
169
+      }
170
+    },
171
+    destroy: function destroy(swiper) {
172
+      if (swiper.autoplay.running) {
173
+        swiper.autoplay.stop();
174
+      }
175
+
176
+      var document = getDocument();
177
+      document.removeEventListener('visibilitychange', swiper.autoplay.onVisibilityChange);
178
+    }
179
+  }
180
+};
0 181
\ No newline at end of file