Browse code

Remove old version 5

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