Skip to content

Commit 80b1237

Browse files
committed
Core: Swiper - update to latest
1 parent 2e171fe commit 80b1237

File tree

6 files changed

+105
-15
lines changed

6 files changed

+105
-15
lines changed

src/core/components/swiper/swiper-src/components/a11y/a11y.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const a11y = {
6161
updateNavigation() {
6262
const swiper = this;
6363

64-
if (swiper.params.loop) return;
64+
if (swiper.params.loop || !swiper.navigation) return;
6565
const { $nextEl, $prevEl } = swiper.navigation;
6666

6767
if ($prevEl && $prevEl.length > 0) {

src/core/components/swiper/swiper-src/components/core/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default {
55
initialSlide: 0,
66
speed: 300,
77
cssMode: false,
8+
updateOnWindowResize: true,
89
//
910
preventInteractionOnTransition: false,
1011

src/core/components/swiper/swiper-src/components/core/events/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ function attachEvents() {
6363
}
6464

6565
// Resize handler
66-
swiper.on((Device.ios || Device.android ? 'resize orientationchange observerUpdate' : 'resize observerUpdate'), onResize, true);
66+
if (params.updateOnWindowResize) {
67+
swiper.on((Device.ios || Device.android ? 'resize orientationchange observerUpdate' : 'resize observerUpdate'), onResize, true);
68+
} else {
69+
swiper.on('observerUpdate', onResize, true);
70+
}
6771
}
6872

6973
function detachEvents() {

src/core/components/swiper/swiper-src/components/core/loop/loopFix.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
export default function () {
22
const swiper = this;
3+
4+
swiper.emit('beforeLoopFix');
5+
36
const {
47
activeIndex, slides, loopedSlides, allowSlidePrev, allowSlideNext, snapGrid, rtlTranslate: rtl,
58
} = swiper;
@@ -10,7 +13,6 @@ export default function () {
1013
const snapTranslate = -snapGrid[activeIndex];
1114
const diff = snapTranslate - swiper.getTranslate();
1215

13-
1416
// Fix For Negative Oversliding
1517
if (activeIndex < loopedSlides) {
1618
newIndex = (slides.length - (loopedSlides * 3)) + activeIndex;
@@ -30,4 +32,6 @@ export default function () {
3032
}
3133
swiper.allowSlidePrev = allowSlidePrev;
3234
swiper.allowSlideNext = allowSlideNext;
35+
36+
swiper.emit('loopFix');
3337
}

src/core/components/swiper/swiper-src/components/mousewheel/mousewheel.js

Lines changed: 86 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,46 @@ const Mousewheel = {
144144
if (params.invert) delta = -delta;
145145

146146
if (!swiper.params.freeMode) {
147-
if (Utils.now() - swiper.mousewheel.lastScrollTime > 60) {
148-
if (delta < 0) {
149-
if ((!swiper.isEnd || swiper.params.loop) && !swiper.animating) {
150-
swiper.slideNext();
151-
swiper.emit('scroll', e);
152-
} else if (params.releaseOnEdges) return true;
153-
} else if ((!swiper.isBeginning || swiper.params.loop) && !swiper.animating) {
154-
swiper.slidePrev();
155-
swiper.emit('scroll', e);
156-
} else if (params.releaseOnEdges) return true;
147+
// Register the new event in a variable which stores the relevant data
148+
const newEvent = {
149+
time: Utils.now(),
150+
delta: Math.abs(delta),
151+
direction: Math.sign(delta),
152+
raw: event,
153+
};
154+
155+
// Keep the most recent events
156+
const recentWheelEvents = swiper.mousewheel.recentWheelEvents;
157+
if (recentWheelEvents.length >= 2) {
158+
recentWheelEvents.shift(); // only store the last N events
159+
}
160+
const prevEvent = recentWheelEvents.length ? recentWheelEvents[recentWheelEvents.length - 1] : undefined;
161+
recentWheelEvents.push(newEvent);
162+
163+
// If there is at least one previous recorded event:
164+
// If direction has changed or
165+
// if the scroll is quicker than the previous one:
166+
// Animate the slider.
167+
// Else (this is the first time the wheel is moved):
168+
// Animate the slider.
169+
if (prevEvent) {
170+
if (newEvent.direction !== prevEvent.direction || newEvent.delta > prevEvent.delta) {
171+
swiper.mousewheel.animateSlider(newEvent);
172+
}
173+
} else {
174+
swiper.mousewheel.animateSlider(newEvent);
175+
}
176+
177+
// If it's time to release the scroll:
178+
// Return now so you don't hit the preventDefault.
179+
if (swiper.mousewheel.releaseScroll(newEvent)) {
180+
return true;
157181
}
158-
swiper.mousewheel.lastScrollTime = (new window.Date()).getTime();
159182
} else {
160183
// Freemode or scrollContainer:
161184

162185
// If we recently snapped after a momentum scroll, then ignore wheel events
163-
// to give time for the declereration to finish. Stop ignoring after 500 msecs
186+
// to give time for the deceleration to finish. Stop ignoring after 500 msecs
164187
// or if it's a new scroll (larger delta or inverse sign as last event before
165188
// an end-of-momentum snap).
166189
const newEvent = { time: Utils.now(), delta: Math.abs(delta), direction: Math.sign(delta) };
@@ -261,6 +284,55 @@ const Mousewheel = {
261284
else e.returnValue = false;
262285
return false;
263286
},
287+
animateSlider(newEvent) {
288+
const swiper = this;
289+
// If the movement is NOT big enough and
290+
// if the last time the user scrolled was too close to the current one (avoid continuously triggering the slider):
291+
// Don't go any further (avoid insignificant scroll movement).
292+
if (newEvent.delta >= 6 && Utils.now() - swiper.mousewheel.lastScrollTime < 60) {
293+
// Return false as a default
294+
return true;
295+
}
296+
// If user is scrolling towards the end:
297+
// If the slider hasn't hit the latest slide or
298+
// if the slider is a loop and
299+
// if the slider isn't moving right now:
300+
// Go to next slide and
301+
// emit a scroll event.
302+
// Else (the user is scrolling towards the beginning) and
303+
// if the slider hasn't hit the first slide or
304+
// if the slider is a loop and
305+
// if the slider isn't moving right now:
306+
// Go to prev slide and
307+
// emit a scroll event.
308+
if (newEvent.direction < 0) {
309+
if ((!swiper.isEnd || swiper.params.loop) && !swiper.animating) {
310+
swiper.slideNext();
311+
swiper.emit('scroll', newEvent.raw);
312+
}
313+
} else if ((!swiper.isBeginning || swiper.params.loop) && !swiper.animating) {
314+
swiper.slidePrev();
315+
swiper.emit('scroll', newEvent.raw);
316+
}
317+
// If you got here is because an animation has been triggered so store the current time
318+
swiper.mousewheel.lastScrollTime = (new window.Date()).getTime();
319+
// Return false as a default
320+
return false;
321+
},
322+
releaseScroll(newEvent) {
323+
const swiper = this;
324+
const params = swiper.params.mousewheel;
325+
if (newEvent.direction < 0) {
326+
if (swiper.isEnd && !swiper.params.loop && params.releaseOnEdges) {
327+
// Return true to animate scroll on edges
328+
return true;
329+
}
330+
} else if (swiper.isBeginning && !swiper.params.loop && params.releaseOnEdges) {
331+
// Return true to animate scroll on edges
332+
return true;
333+
}
334+
return false;
335+
},
264336
enable() {
265337
const swiper = this;
266338
const event = Mousewheel.event();
@@ -321,6 +393,8 @@ export default {
321393
handle: Mousewheel.handle.bind(swiper),
322394
handleMouseEnter: Mousewheel.handleMouseEnter.bind(swiper),
323395
handleMouseLeave: Mousewheel.handleMouseLeave.bind(swiper),
396+
animateSlider: Mousewheel.animateSlider.bind(swiper),
397+
releaseScroll: Mousewheel.releaseScroll.bind(swiper),
324398
lastScrollTime: Utils.now(),
325399
lastEventBeforeSnap: undefined,
326400
recentWheelEvents: [],

src/core/components/swiper/swiper-src/components/thumbs/thumbs.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ const Thumbs = {
110110
thumbsToActivate = swiper.params.slidesPerView;
111111
}
112112

113+
if (!swiper.params.thumbs.multipleActiveThumbs) {
114+
thumbsToActivate = 1;
115+
}
116+
117+
thumbsToActivate = Math.floor(thumbsToActivate);
118+
113119
thumbsSwiper.slides.removeClass(thumbActiveClass);
114120
if (thumbsSwiper.params.loop || (thumbsSwiper.params.virtual && thumbsSwiper.params.virtual.enabled)) {
115121
for (let i = 0; i < thumbsToActivate; i += 1) {
@@ -126,6 +132,7 @@ export default {
126132
name: 'thumbs',
127133
params: {
128134
thumbs: {
135+
multipleActiveThumbs: true,
129136
swiper: null,
130137
slideThumbActiveClass: 'swiper-slide-thumb-active',
131138
thumbsContainerClass: 'swiper-container-thumbs',

0 commit comments

Comments
 (0)