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