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,212 +0,0 @@
1
-"use strict";
2
-
3
-exports.__esModule = true;
4
-exports.default = void 0;
5
-
6
-var _utils = require("../../utils/utils");
7
-
8
-var _dom = _interopRequireDefault(require("../../utils/dom"));
9
-
10
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
-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); }
13
-
14
-var Thumbs = {
15
-  init: function init() {
16
-    var swiper = this;
17
-    var thumbsParams = swiper.params.thumbs;
18
-    if (swiper.thumbs.initialized) return false;
19
-    swiper.thumbs.initialized = true;
20
-    var SwiperClass = swiper.constructor;
21
-
22
-    if (thumbsParams.swiper instanceof SwiperClass) {
23
-      swiper.thumbs.swiper = thumbsParams.swiper;
24
-      (0, _utils.extend)(swiper.thumbs.swiper.originalParams, {
25
-        watchSlidesProgress: true,
26
-        slideToClickedSlide: false
27
-      });
28
-      (0, _utils.extend)(swiper.thumbs.swiper.params, {
29
-        watchSlidesProgress: true,
30
-        slideToClickedSlide: false
31
-      });
32
-    } else if ((0, _utils.isObject)(thumbsParams.swiper)) {
33
-      swiper.thumbs.swiper = new SwiperClass((0, _utils.extend)({}, thumbsParams.swiper, {
34
-        watchSlidesVisibility: true,
35
-        watchSlidesProgress: true,
36
-        slideToClickedSlide: false
37
-      }));
38
-      swiper.thumbs.swiperCreated = true;
39
-    }
40
-
41
-    swiper.thumbs.swiper.$el.addClass(swiper.params.thumbs.thumbsContainerClass);
42
-    swiper.thumbs.swiper.on('tap', swiper.thumbs.onThumbClick);
43
-    return true;
44
-  },
45
-  onThumbClick: function onThumbClick() {
46
-    var swiper = this;
47
-    var thumbsSwiper = swiper.thumbs.swiper;
48
-    if (!thumbsSwiper) return;
49
-    var clickedIndex = thumbsSwiper.clickedIndex;
50
-    var clickedSlide = thumbsSwiper.clickedSlide;
51
-    if (clickedSlide && (0, _dom.default)(clickedSlide).hasClass(swiper.params.thumbs.slideThumbActiveClass)) return;
52
-    if (typeof clickedIndex === 'undefined' || clickedIndex === null) return;
53
-    var slideToIndex;
54
-
55
-    if (thumbsSwiper.params.loop) {
56
-      slideToIndex = parseInt((0, _dom.default)(thumbsSwiper.clickedSlide).attr('data-swiper-slide-index'), 10);
57
-    } else {
58
-      slideToIndex = clickedIndex;
59
-    }
60
-
61
-    if (swiper.params.loop) {
62
-      var currentIndex = swiper.activeIndex;
63
-
64
-      if (swiper.slides.eq(currentIndex).hasClass(swiper.params.slideDuplicateClass)) {
65
-        swiper.loopFix(); // eslint-disable-next-line
66
-
67
-        swiper._clientLeft = swiper.$wrapperEl[0].clientLeft;
68
-        currentIndex = swiper.activeIndex;
69
-      }
70
-
71
-      var prevIndex = swiper.slides.eq(currentIndex).prevAll("[data-swiper-slide-index=\"" + slideToIndex + "\"]").eq(0).index();
72
-      var nextIndex = swiper.slides.eq(currentIndex).nextAll("[data-swiper-slide-index=\"" + slideToIndex + "\"]").eq(0).index();
73
-      if (typeof prevIndex === 'undefined') slideToIndex = nextIndex;else if (typeof nextIndex === 'undefined') slideToIndex = prevIndex;else if (nextIndex - currentIndex < currentIndex - prevIndex) slideToIndex = nextIndex;else slideToIndex = prevIndex;
74
-    }
75
-
76
-    swiper.slideTo(slideToIndex);
77
-  },
78
-  update: function update(initial) {
79
-    var swiper = this;
80
-    var thumbsSwiper = swiper.thumbs.swiper;
81
-    if (!thumbsSwiper) return;
82
-    var slidesPerView = thumbsSwiper.params.slidesPerView === 'auto' ? thumbsSwiper.slidesPerViewDynamic() : thumbsSwiper.params.slidesPerView;
83
-    var autoScrollOffset = swiper.params.thumbs.autoScrollOffset;
84
-    var useOffset = autoScrollOffset && !thumbsSwiper.params.loop;
85
-
86
-    if (swiper.realIndex !== thumbsSwiper.realIndex || useOffset) {
87
-      var currentThumbsIndex = thumbsSwiper.activeIndex;
88
-      var newThumbsIndex;
89
-      var direction;
90
-
91
-      if (thumbsSwiper.params.loop) {
92
-        if (thumbsSwiper.slides.eq(currentThumbsIndex).hasClass(thumbsSwiper.params.slideDuplicateClass)) {
93
-          thumbsSwiper.loopFix(); // eslint-disable-next-line
94
-
95
-          thumbsSwiper._clientLeft = thumbsSwiper.$wrapperEl[0].clientLeft;
96
-          currentThumbsIndex = thumbsSwiper.activeIndex;
97
-        } // Find actual thumbs index to slide to
98
-
99
-
100
-        var prevThumbsIndex = thumbsSwiper.slides.eq(currentThumbsIndex).prevAll("[data-swiper-slide-index=\"" + swiper.realIndex + "\"]").eq(0).index();
101
-        var nextThumbsIndex = thumbsSwiper.slides.eq(currentThumbsIndex).nextAll("[data-swiper-slide-index=\"" + swiper.realIndex + "\"]").eq(0).index();
102
-        if (typeof prevThumbsIndex === 'undefined') newThumbsIndex = nextThumbsIndex;else if (typeof nextThumbsIndex === 'undefined') newThumbsIndex = prevThumbsIndex;else if (nextThumbsIndex - currentThumbsIndex === currentThumbsIndex - prevThumbsIndex) newThumbsIndex = currentThumbsIndex;else if (nextThumbsIndex - currentThumbsIndex < currentThumbsIndex - prevThumbsIndex) newThumbsIndex = nextThumbsIndex;else newThumbsIndex = prevThumbsIndex;
103
-        direction = swiper.activeIndex > swiper.previousIndex ? 'next' : 'prev';
104
-      } else {
105
-        newThumbsIndex = swiper.realIndex;
106
-        direction = newThumbsIndex > swiper.previousIndex ? 'next' : 'prev';
107
-      }
108
-
109
-      if (useOffset) {
110
-        newThumbsIndex += direction === 'next' ? autoScrollOffset : -1 * autoScrollOffset;
111
-      }
112
-
113
-      if (thumbsSwiper.visibleSlidesIndexes && thumbsSwiper.visibleSlidesIndexes.indexOf(newThumbsIndex) < 0) {
114
-        if (thumbsSwiper.params.centeredSlides) {
115
-          if (newThumbsIndex > currentThumbsIndex) {
116
-            newThumbsIndex = newThumbsIndex - Math.floor(slidesPerView / 2) + 1;
117
-          } else {
118
-            newThumbsIndex = newThumbsIndex + Math.floor(slidesPerView / 2) - 1;
119
-          }
120
-        } else if (newThumbsIndex > currentThumbsIndex) {
121
-          newThumbsIndex = newThumbsIndex - slidesPerView + 1;
122
-        }
123
-
124
-        thumbsSwiper.slideTo(newThumbsIndex, initial ? 0 : undefined);
125
-      }
126
-    } // Activate thumbs
127
-
128
-
129
-    var thumbsToActivate = 1;
130
-    var thumbActiveClass = swiper.params.thumbs.slideThumbActiveClass;
131
-
132
-    if (swiper.params.slidesPerView > 1 && !swiper.params.centeredSlides) {
133
-      thumbsToActivate = swiper.params.slidesPerView;
134
-    }
135
-
136
-    if (!swiper.params.thumbs.multipleActiveThumbs) {
137
-      thumbsToActivate = 1;
138
-    }
139
-
140
-    thumbsToActivate = Math.floor(thumbsToActivate);
141
-    thumbsSwiper.slides.removeClass(thumbActiveClass);
142
-
143
-    if (thumbsSwiper.params.loop || thumbsSwiper.params.virtual && thumbsSwiper.params.virtual.enabled) {
144
-      for (var i = 0; i < thumbsToActivate; i += 1) {
145
-        thumbsSwiper.$wrapperEl.children("[data-swiper-slide-index=\"" + (swiper.realIndex + i) + "\"]").addClass(thumbActiveClass);
146
-      }
147
-    } else {
148
-      for (var _i = 0; _i < thumbsToActivate; _i += 1) {
149
-        thumbsSwiper.slides.eq(swiper.realIndex + _i).addClass(thumbActiveClass);
150
-      }
151
-    }
152
-  }
153
-};
154
-var _default = {
155
-  name: 'thumbs',
156
-  params: {
157
-    thumbs: {
158
-      swiper: null,
159
-      multipleActiveThumbs: true,
160
-      autoScrollOffset: 0,
161
-      slideThumbActiveClass: 'swiper-slide-thumb-active',
162
-      thumbsContainerClass: 'swiper-container-thumbs'
163
-    }
164
-  },
165
-  create: function create() {
166
-    var swiper = this;
167
-    (0, _utils.bindModuleMethods)(swiper, {
168
-      thumbs: _extends({
169
-        swiper: null,
170
-        initialized: false
171
-      }, Thumbs)
172
-    });
173
-  },
174
-  on: {
175
-    beforeInit: function beforeInit(swiper) {
176
-      var thumbs = swiper.params.thumbs;
177
-      if (!thumbs || !thumbs.swiper) return;
178
-      swiper.thumbs.init();
179
-      swiper.thumbs.update(true);
180
-    },
181
-    slideChange: function slideChange(swiper) {
182
-      if (!swiper.thumbs.swiper) return;
183
-      swiper.thumbs.update();
184
-    },
185
-    update: function update(swiper) {
186
-      if (!swiper.thumbs.swiper) return;
187
-      swiper.thumbs.update();
188
-    },
189
-    resize: function resize(swiper) {
190
-      if (!swiper.thumbs.swiper) return;
191
-      swiper.thumbs.update();
192
-    },
193
-    observerUpdate: function observerUpdate(swiper) {
194
-      if (!swiper.thumbs.swiper) return;
195
-      swiper.thumbs.update();
196
-    },
197
-    setTransition: function setTransition(swiper, duration) {
198
-      var thumbsSwiper = swiper.thumbs.swiper;
199
-      if (!thumbsSwiper) return;
200
-      thumbsSwiper.setTransition(duration);
201
-    },
202
-    beforeDestroy: function beforeDestroy(swiper) {
203
-      var thumbsSwiper = swiper.thumbs.swiper;
204
-      if (!thumbsSwiper) return;
205
-
206
-      if (swiper.thumbs.swiperCreated && thumbsSwiper) {
207
-        thumbsSwiper.destroy();
208
-      }
209
-    }
210
-  }
211
-};
212
-exports.default = _default;
213 0
\ No newline at end of file
Browse code

swiper.js version 6.5.0

Benjamin Roth authored on14/03/2021 15:29:46
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,212 @@
1
+"use strict";
2
+
3
+exports.__esModule = true;
4
+exports.default = void 0;
5
+
6
+var _utils = require("../../utils/utils");
7
+
8
+var _dom = _interopRequireDefault(require("../../utils/dom"));
9
+
10
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+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); }
13
+
14
+var Thumbs = {
15
+  init: function init() {
16
+    var swiper = this;
17
+    var thumbsParams = swiper.params.thumbs;
18
+    if (swiper.thumbs.initialized) return false;
19
+    swiper.thumbs.initialized = true;
20
+    var SwiperClass = swiper.constructor;
21
+
22
+    if (thumbsParams.swiper instanceof SwiperClass) {
23
+      swiper.thumbs.swiper = thumbsParams.swiper;
24
+      (0, _utils.extend)(swiper.thumbs.swiper.originalParams, {
25
+        watchSlidesProgress: true,
26
+        slideToClickedSlide: false
27
+      });
28
+      (0, _utils.extend)(swiper.thumbs.swiper.params, {
29
+        watchSlidesProgress: true,
30
+        slideToClickedSlide: false
31
+      });
32
+    } else if ((0, _utils.isObject)(thumbsParams.swiper)) {
33
+      swiper.thumbs.swiper = new SwiperClass((0, _utils.extend)({}, thumbsParams.swiper, {
34
+        watchSlidesVisibility: true,
35
+        watchSlidesProgress: true,
36
+        slideToClickedSlide: false
37
+      }));
38
+      swiper.thumbs.swiperCreated = true;
39
+    }
40
+
41
+    swiper.thumbs.swiper.$el.addClass(swiper.params.thumbs.thumbsContainerClass);
42
+    swiper.thumbs.swiper.on('tap', swiper.thumbs.onThumbClick);
43
+    return true;
44
+  },
45
+  onThumbClick: function onThumbClick() {
46
+    var swiper = this;
47
+    var thumbsSwiper = swiper.thumbs.swiper;
48
+    if (!thumbsSwiper) return;
49
+    var clickedIndex = thumbsSwiper.clickedIndex;
50
+    var clickedSlide = thumbsSwiper.clickedSlide;
51
+    if (clickedSlide && (0, _dom.default)(clickedSlide).hasClass(swiper.params.thumbs.slideThumbActiveClass)) return;
52
+    if (typeof clickedIndex === 'undefined' || clickedIndex === null) return;
53
+    var slideToIndex;
54
+
55
+    if (thumbsSwiper.params.loop) {
56
+      slideToIndex = parseInt((0, _dom.default)(thumbsSwiper.clickedSlide).attr('data-swiper-slide-index'), 10);
57
+    } else {
58
+      slideToIndex = clickedIndex;
59
+    }
60
+
61
+    if (swiper.params.loop) {
62
+      var currentIndex = swiper.activeIndex;
63
+
64
+      if (swiper.slides.eq(currentIndex).hasClass(swiper.params.slideDuplicateClass)) {
65
+        swiper.loopFix(); // eslint-disable-next-line
66
+
67
+        swiper._clientLeft = swiper.$wrapperEl[0].clientLeft;
68
+        currentIndex = swiper.activeIndex;
69
+      }
70
+
71
+      var prevIndex = swiper.slides.eq(currentIndex).prevAll("[data-swiper-slide-index=\"" + slideToIndex + "\"]").eq(0).index();
72
+      var nextIndex = swiper.slides.eq(currentIndex).nextAll("[data-swiper-slide-index=\"" + slideToIndex + "\"]").eq(0).index();
73
+      if (typeof prevIndex === 'undefined') slideToIndex = nextIndex;else if (typeof nextIndex === 'undefined') slideToIndex = prevIndex;else if (nextIndex - currentIndex < currentIndex - prevIndex) slideToIndex = nextIndex;else slideToIndex = prevIndex;
74
+    }
75
+
76
+    swiper.slideTo(slideToIndex);
77
+  },
78
+  update: function update(initial) {
79
+    var swiper = this;
80
+    var thumbsSwiper = swiper.thumbs.swiper;
81
+    if (!thumbsSwiper) return;
82
+    var slidesPerView = thumbsSwiper.params.slidesPerView === 'auto' ? thumbsSwiper.slidesPerViewDynamic() : thumbsSwiper.params.slidesPerView;
83
+    var autoScrollOffset = swiper.params.thumbs.autoScrollOffset;
84
+    var useOffset = autoScrollOffset && !thumbsSwiper.params.loop;
85
+
86
+    if (swiper.realIndex !== thumbsSwiper.realIndex || useOffset) {
87
+      var currentThumbsIndex = thumbsSwiper.activeIndex;
88
+      var newThumbsIndex;
89
+      var direction;
90
+
91
+      if (thumbsSwiper.params.loop) {
92
+        if (thumbsSwiper.slides.eq(currentThumbsIndex).hasClass(thumbsSwiper.params.slideDuplicateClass)) {
93
+          thumbsSwiper.loopFix(); // eslint-disable-next-line
94
+
95
+          thumbsSwiper._clientLeft = thumbsSwiper.$wrapperEl[0].clientLeft;
96
+          currentThumbsIndex = thumbsSwiper.activeIndex;
97
+        } // Find actual thumbs index to slide to
98
+
99
+
100
+        var prevThumbsIndex = thumbsSwiper.slides.eq(currentThumbsIndex).prevAll("[data-swiper-slide-index=\"" + swiper.realIndex + "\"]").eq(0).index();
101
+        var nextThumbsIndex = thumbsSwiper.slides.eq(currentThumbsIndex).nextAll("[data-swiper-slide-index=\"" + swiper.realIndex + "\"]").eq(0).index();
102
+        if (typeof prevThumbsIndex === 'undefined') newThumbsIndex = nextThumbsIndex;else if (typeof nextThumbsIndex === 'undefined') newThumbsIndex = prevThumbsIndex;else if (nextThumbsIndex - currentThumbsIndex === currentThumbsIndex - prevThumbsIndex) newThumbsIndex = currentThumbsIndex;else if (nextThumbsIndex - currentThumbsIndex < currentThumbsIndex - prevThumbsIndex) newThumbsIndex = nextThumbsIndex;else newThumbsIndex = prevThumbsIndex;
103
+        direction = swiper.activeIndex > swiper.previousIndex ? 'next' : 'prev';
104
+      } else {
105
+        newThumbsIndex = swiper.realIndex;
106
+        direction = newThumbsIndex > swiper.previousIndex ? 'next' : 'prev';
107
+      }
108
+
109
+      if (useOffset) {
110
+        newThumbsIndex += direction === 'next' ? autoScrollOffset : -1 * autoScrollOffset;
111
+      }
112
+
113
+      if (thumbsSwiper.visibleSlidesIndexes && thumbsSwiper.visibleSlidesIndexes.indexOf(newThumbsIndex) < 0) {
114
+        if (thumbsSwiper.params.centeredSlides) {
115
+          if (newThumbsIndex > currentThumbsIndex) {
116
+            newThumbsIndex = newThumbsIndex - Math.floor(slidesPerView / 2) + 1;
117
+          } else {
118
+            newThumbsIndex = newThumbsIndex + Math.floor(slidesPerView / 2) - 1;
119
+          }
120
+        } else if (newThumbsIndex > currentThumbsIndex) {
121
+          newThumbsIndex = newThumbsIndex - slidesPerView + 1;
122
+        }
123
+
124
+        thumbsSwiper.slideTo(newThumbsIndex, initial ? 0 : undefined);
125
+      }
126
+    } // Activate thumbs
127
+
128
+
129
+    var thumbsToActivate = 1;
130
+    var thumbActiveClass = swiper.params.thumbs.slideThumbActiveClass;
131
+
132
+    if (swiper.params.slidesPerView > 1 && !swiper.params.centeredSlides) {
133
+      thumbsToActivate = swiper.params.slidesPerView;
134
+    }
135
+
136
+    if (!swiper.params.thumbs.multipleActiveThumbs) {
137
+      thumbsToActivate = 1;
138
+    }
139
+
140
+    thumbsToActivate = Math.floor(thumbsToActivate);
141
+    thumbsSwiper.slides.removeClass(thumbActiveClass);
142
+
143
+    if (thumbsSwiper.params.loop || thumbsSwiper.params.virtual && thumbsSwiper.params.virtual.enabled) {
144
+      for (var i = 0; i < thumbsToActivate; i += 1) {
145
+        thumbsSwiper.$wrapperEl.children("[data-swiper-slide-index=\"" + (swiper.realIndex + i) + "\"]").addClass(thumbActiveClass);
146
+      }
147
+    } else {
148
+      for (var _i = 0; _i < thumbsToActivate; _i += 1) {
149
+        thumbsSwiper.slides.eq(swiper.realIndex + _i).addClass(thumbActiveClass);
150
+      }
151
+    }
152
+  }
153
+};
154
+var _default = {
155
+  name: 'thumbs',
156
+  params: {
157
+    thumbs: {
158
+      swiper: null,
159
+      multipleActiveThumbs: true,
160
+      autoScrollOffset: 0,
161
+      slideThumbActiveClass: 'swiper-slide-thumb-active',
162
+      thumbsContainerClass: 'swiper-container-thumbs'
163
+    }
164
+  },
165
+  create: function create() {
166
+    var swiper = this;
167
+    (0, _utils.bindModuleMethods)(swiper, {
168
+      thumbs: _extends({
169
+        swiper: null,
170
+        initialized: false
171
+      }, Thumbs)
172
+    });
173
+  },
174
+  on: {
175
+    beforeInit: function beforeInit(swiper) {
176
+      var thumbs = swiper.params.thumbs;
177
+      if (!thumbs || !thumbs.swiper) return;
178
+      swiper.thumbs.init();
179
+      swiper.thumbs.update(true);
180
+    },
181
+    slideChange: function slideChange(swiper) {
182
+      if (!swiper.thumbs.swiper) return;
183
+      swiper.thumbs.update();
184
+    },
185
+    update: function update(swiper) {
186
+      if (!swiper.thumbs.swiper) return;
187
+      swiper.thumbs.update();
188
+    },
189
+    resize: function resize(swiper) {
190
+      if (!swiper.thumbs.swiper) return;
191
+      swiper.thumbs.update();
192
+    },
193
+    observerUpdate: function observerUpdate(swiper) {
194
+      if (!swiper.thumbs.swiper) return;
195
+      swiper.thumbs.update();
196
+    },
197
+    setTransition: function setTransition(swiper, duration) {
198
+      var thumbsSwiper = swiper.thumbs.swiper;
199
+      if (!thumbsSwiper) return;
200
+      thumbsSwiper.setTransition(duration);
201
+    },
202
+    beforeDestroy: function beforeDestroy(swiper) {
203
+      var thumbsSwiper = swiper.thumbs.swiper;
204
+      if (!thumbsSwiper) return;
205
+
206
+      if (swiper.thumbs.swiperCreated && thumbsSwiper) {
207
+        thumbsSwiper.destroy();
208
+      }
209
+    }
210
+  }
211
+};
212
+exports.default = _default;
0 213
\ No newline at end of file