@gem-sdk/swiper 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +11 -0
- package/modules/a11y-element.css +9 -0
- package/modules/a11y-element.min.css +1 -0
- package/modules/a11y.css +9 -0
- package/modules/a11y.less +9 -0
- package/modules/a11y.min.css +1 -0
- package/modules/a11y.min.mjs +2 -0
- package/modules/a11y.min.mjs.map +1 -0
- package/modules/a11y.mjs +377 -0
- package/modules/a11y.scss +9 -0
- package/modules/autoplay-element.css +0 -0
- package/modules/autoplay-element.min.css +0 -0
- package/modules/autoplay.css +0 -0
- package/modules/autoplay.less +0 -0
- package/modules/autoplay.min.css +0 -0
- package/modules/autoplay.min.mjs +2 -0
- package/modules/autoplay.min.mjs.map +1 -0
- package/modules/autoplay.mjs +304 -0
- package/modules/autoplay.scss +0 -0
- package/modules/controller-element.css +0 -0
- package/modules/controller-element.min.css +0 -0
- package/modules/controller.css +0 -0
- package/modules/controller.less +0 -0
- package/modules/controller.min.css +0 -0
- package/modules/controller.min.mjs +2 -0
- package/modules/controller.min.mjs.map +1 -0
- package/modules/controller.mjs +191 -0
- package/modules/controller.scss +0 -0
- package/modules/effect-cards-element.css +9 -0
- package/modules/effect-cards-element.min.css +1 -0
- package/modules/effect-cards.css +9 -0
- package/modules/effect-cards.less +10 -0
- package/modules/effect-cards.min.css +1 -0
- package/modules/effect-cards.min.mjs +2 -0
- package/modules/effect-cards.min.mjs.map +1 -0
- package/modules/effect-cards.mjs +128 -0
- package/modules/effect-cards.scss +10 -0
- package/modules/effect-coverflow-element.css +0 -0
- package/modules/effect-coverflow-element.min.css +0 -0
- package/modules/effect-coverflow.css +0 -0
- package/modules/effect-coverflow.less +2 -0
- package/modules/effect-coverflow.min.css +0 -0
- package/modules/effect-coverflow.min.mjs +2 -0
- package/modules/effect-coverflow.min.mjs.map +1 -0
- package/modules/effect-coverflow.mjs +104 -0
- package/modules/effect-coverflow.scss +2 -0
- package/modules/effect-creative-element.css +6 -0
- package/modules/effect-creative-element.min.css +1 -0
- package/modules/effect-creative.css +6 -0
- package/modules/effect-creative.less +7 -0
- package/modules/effect-creative.min.css +1 -0
- package/modules/effect-creative.min.mjs +2 -0
- package/modules/effect-creative.min.mjs.map +1 -0
- package/modules/effect-creative.mjs +146 -0
- package/modules/effect-creative.scss +7 -0
- package/modules/effect-cube-element.css +53 -0
- package/modules/effect-cube-element.min.css +1 -0
- package/modules/effect-cube.css +62 -0
- package/modules/effect-cube.less +71 -0
- package/modules/effect-cube.min.css +1 -0
- package/modules/effect-cube.min.mjs +2 -0
- package/modules/effect-cube.min.mjs.map +1 -0
- package/modules/effect-cube.mjs +174 -0
- package/modules/effect-cube.scss +71 -0
- package/modules/effect-fade-element.css +16 -0
- package/modules/effect-fade-element.min.css +1 -0
- package/modules/effect-fade.css +16 -0
- package/modules/effect-fade.less +20 -0
- package/modules/effect-fade.min.css +1 -0
- package/modules/effect-fade.min.mjs +2 -0
- package/modules/effect-fade.min.mjs.map +1 -0
- package/modules/effect-fade.mjs +66 -0
- package/modules/effect-fade.scss +20 -0
- package/modules/effect-flip-element.css +17 -0
- package/modules/effect-flip-element.min.css +1 -0
- package/modules/effect-flip.css +26 -0
- package/modules/effect-flip.less +30 -0
- package/modules/effect-flip.min.css +1 -0
- package/modules/effect-flip.min.mjs +2 -0
- package/modules/effect-flip.min.mjs.map +1 -0
- package/modules/effect-flip.mjs +111 -0
- package/modules/effect-flip.scss +30 -0
- package/modules/free-mode-element.css +4 -0
- package/modules/free-mode-element.min.css +1 -0
- package/modules/free-mode.css +4 -0
- package/modules/free-mode.less +4 -0
- package/modules/free-mode.min.css +1 -0
- package/modules/free-mode.min.mjs +2 -0
- package/modules/free-mode.min.mjs.map +1 -0
- package/modules/free-mode.mjs +237 -0
- package/modules/free-mode.scss +4 -0
- package/modules/grid-element.css +7 -0
- package/modules/grid-element.min.css +1 -0
- package/modules/grid.css +7 -0
- package/modules/grid.less +7 -0
- package/modules/grid.min.css +1 -0
- package/modules/grid.min.mjs +2 -0
- package/modules/grid.min.mjs.map +1 -0
- package/modules/grid.mjs +155 -0
- package/modules/grid.scss +7 -0
- package/modules/hash-navigation-element.css +0 -0
- package/modules/hash-navigation-element.min.css +0 -0
- package/modules/hash-navigation.css +0 -0
- package/modules/hash-navigation.less +2 -0
- package/modules/hash-navigation.min.css +0 -0
- package/modules/hash-navigation.min.mjs +2 -0
- package/modules/hash-navigation.min.mjs.map +1 -0
- package/modules/hash-navigation.mjs +93 -0
- package/modules/hash-navigation.scss +0 -0
- package/modules/history-element.css +0 -0
- package/modules/history-element.min.css +0 -0
- package/modules/history.css +0 -0
- package/modules/history.less +0 -0
- package/modules/history.min.css +0 -0
- package/modules/history.min.mjs +2 -0
- package/modules/history.min.mjs.map +1 -0
- package/modules/history.mjs +142 -0
- package/modules/history.scss +0 -0
- package/modules/index.min.mjs +2 -0
- package/modules/index.min.mjs.map +1 -0
- package/modules/index.mjs +23 -0
- package/modules/keyboard-element.css +0 -0
- package/modules/keyboard-element.min.css +0 -0
- package/modules/keyboard.css +0 -0
- package/modules/keyboard.less +0 -0
- package/modules/keyboard.min.css +0 -0
- package/modules/keyboard.min.mjs +2 -0
- package/modules/keyboard.min.mjs.map +1 -0
- package/modules/keyboard.mjs +117 -0
- package/modules/keyboard.scss +0 -0
- package/modules/manipulation-element.css +0 -0
- package/modules/manipulation-element.min.css +0 -0
- package/modules/manipulation.css +0 -0
- package/modules/manipulation.less +0 -0
- package/modules/manipulation.min.css +0 -0
- package/modules/manipulation.min.mjs +2 -0
- package/modules/manipulation.min.mjs.map +1 -0
- package/modules/manipulation.mjs +193 -0
- package/modules/manipulation.scss +0 -0
- package/modules/mousewheel-element.css +0 -0
- package/modules/mousewheel-element.min.css +0 -0
- package/modules/mousewheel.css +0 -0
- package/modules/mousewheel.less +0 -0
- package/modules/mousewheel.min.css +0 -0
- package/modules/mousewheel.min.mjs +2 -0
- package/modules/mousewheel.min.mjs.map +1 -0
- package/modules/mousewheel.mjs +395 -0
- package/modules/mousewheel.scss +0 -0
- package/modules/navigation-element.css +63 -0
- package/modules/navigation-element.min.css +1 -0
- package/modules/navigation.css +86 -0
- package/modules/navigation.less +86 -0
- package/modules/navigation.min.css +1 -0
- package/modules/navigation.min.mjs +2 -0
- package/modules/navigation.min.mjs.map +1 -0
- package/modules/navigation.mjs +200 -0
- package/modules/navigation.scss +87 -0
- package/modules/pagination-element.css +184 -0
- package/modules/pagination-element.min.css +1 -0
- package/modules/pagination.css +184 -0
- package/modules/pagination.less +187 -0
- package/modules/pagination.min.css +1 -0
- package/modules/pagination.min.mjs +2 -0
- package/modules/pagination.min.mjs.map +1 -0
- package/modules/pagination.mjs +467 -0
- package/modules/pagination.scss +188 -0
- package/modules/parallax-element.css +0 -0
- package/modules/parallax-element.min.css +0 -0
- package/modules/parallax.css +0 -0
- package/modules/parallax.less +0 -0
- package/modules/parallax.min.css +0 -0
- package/modules/parallax.min.mjs +2 -0
- package/modules/parallax.min.mjs.map +1 -0
- package/modules/parallax.mjs +124 -0
- package/modules/parallax.scss +0 -0
- package/modules/scrollbar-element.css +58 -0
- package/modules/scrollbar-element.min.css +1 -0
- package/modules/scrollbar.css +58 -0
- package/modules/scrollbar.less +59 -0
- package/modules/scrollbar.min.css +1 -0
- package/modules/scrollbar.min.mjs +2 -0
- package/modules/scrollbar.min.mjs.map +1 -0
- package/modules/scrollbar.mjs +366 -0
- package/modules/scrollbar.scss +61 -0
- package/modules/thumbs-element.css +0 -0
- package/modules/thumbs-element.min.css +0 -0
- package/modules/thumbs.css +0 -0
- package/modules/thumbs.less +5 -0
- package/modules/thumbs.min.css +0 -0
- package/modules/thumbs.min.mjs +2 -0
- package/modules/thumbs.min.mjs.map +1 -0
- package/modules/thumbs.mjs +197 -0
- package/modules/thumbs.scss +5 -0
- package/modules/virtual-element.css +19 -0
- package/modules/virtual-element.min.css +1 -0
- package/modules/virtual.css +19 -0
- package/modules/virtual.less +26 -0
- package/modules/virtual.min.css +1 -0
- package/modules/virtual.min.mjs +2 -0
- package/modules/virtual.min.mjs.map +1 -0
- package/modules/virtual.mjs +349 -0
- package/modules/virtual.scss +26 -0
- package/modules/zoom-element.css +5 -0
- package/modules/zoom-element.min.css +1 -0
- package/modules/zoom.css +21 -0
- package/modules/zoom.less +23 -0
- package/modules/zoom.min.css +1 -0
- package/modules/zoom.min.mjs +2 -0
- package/modules/zoom.min.mjs.map +1 -0
- package/modules/zoom.mjs +701 -0
- package/modules/zoom.scss +21 -0
- package/package.json +213 -0
- package/shared/classes-to-selector.min.mjs +2 -0
- package/shared/classes-to-selector.min.mjs.map +1 -0
- package/shared/classes-to-selector.mjs +9 -0
- package/shared/create-element-if-not-defined.min.mjs +2 -0
- package/shared/create-element-if-not-defined.min.mjs.map +1 -0
- package/shared/create-element-if-not-defined.mjs +21 -0
- package/shared/create-shadow.min.mjs +2 -0
- package/shared/create-shadow.min.mjs.map +1 -0
- package/shared/create-shadow.mjs +14 -0
- package/shared/effect-init.min.mjs +2 -0
- package/shared/effect-init.min.mjs.map +1 -0
- package/shared/effect-init.mjs +58 -0
- package/shared/effect-target.min.mjs +2 -0
- package/shared/effect-target.min.mjs.map +1 -0
- package/shared/effect-target.mjs +12 -0
- package/shared/effect-virtual-transition-end.min.mjs +2 -0
- package/shared/effect-virtual-transition-end.min.mjs.map +1 -0
- package/shared/effect-virtual-transition-end.mjs +48 -0
- package/shared/get-element-params.min.mjs +2 -0
- package/shared/get-element-params.min.mjs.map +1 -0
- package/shared/get-element-params.mjs +113 -0
- package/shared/ssr-window.esm.min.mjs +2 -0
- package/shared/ssr-window.esm.min.mjs.map +1 -0
- package/shared/ssr-window.esm.mjs +146 -0
- package/shared/swiper-core.min.mjs +2 -0
- package/shared/swiper-core.min.mjs.map +1 -0
- package/shared/swiper-core.mjs +3969 -0
- package/shared/update-on-virtual-data.min.mjs +2 -0
- package/shared/update-on-virtual-data.min.mjs.map +1 -0
- package/shared/update-on-virtual-data.mjs +131 -0
- package/shared/update-swiper.min.mjs +2 -0
- package/shared/update-swiper.min.mjs.map +1 -0
- package/shared/update-swiper.mjs +238 -0
- package/shared/utils.min.mjs +2 -0
- package/shared/utils.min.mjs.map +1 -0
- package/shared/utils.mjs +343 -0
- package/swiper-bundle.css +735 -0
- package/swiper-bundle.js +9870 -0
- package/swiper-bundle.min.css +13 -0
- package/swiper-bundle.min.js +14 -0
- package/swiper-bundle.min.js.map +1 -0
- package/swiper-bundle.min.mjs +14 -0
- package/swiper-bundle.min.mjs.map +1 -0
- package/swiper-bundle.mjs +42 -0
- package/swiper-effect-utils.d.ts +28 -0
- package/swiper-effect-utils.min.mjs +14 -0
- package/swiper-effect-utils.min.mjs.map +1 -0
- package/swiper-effect-utils.mjs +17 -0
- package/swiper-element-bundle.js +10477 -0
- package/swiper-element-bundle.min.js +14 -0
- package/swiper-element-bundle.min.js.map +1 -0
- package/swiper-element-bundle.min.mjs +14 -0
- package/swiper-element-bundle.min.mjs.map +1 -0
- package/swiper-element-bundle.mjs +288 -0
- package/swiper-element.d.ts +444 -0
- package/swiper-element.js +5037 -0
- package/swiper-element.min.js +14 -0
- package/swiper-element.min.js.map +1 -0
- package/swiper-element.min.mjs +14 -0
- package/swiper-element.min.mjs.map +1 -0
- package/swiper-element.mjs +287 -0
- package/swiper-react.d.ts +501 -0
- package/swiper-react.mjs +394 -0
- package/swiper-vars.less +1 -0
- package/swiper-vars.scss +1 -0
- package/swiper-vue.d.ts +866 -0
- package/swiper-vue.mjs +838 -0
- package/swiper.css +228 -0
- package/swiper.d.ts +5 -0
- package/swiper.js +4418 -0
- package/swiper.less +251 -0
- package/swiper.min.css +13 -0
- package/swiper.min.js +14 -0
- package/swiper.min.js.map +1 -0
- package/swiper.min.mjs +14 -0
- package/swiper.min.mjs.map +1 -0
- package/swiper.mjs +13 -0
- package/swiper.scss +252 -0
- package/types/index.d.ts +6 -0
- package/types/modules/a11y.d.ts +110 -0
- package/types/modules/autoplay.d.ts +133 -0
- package/types/modules/controller.d.ts +35 -0
- package/types/modules/effect-cards.d.ts +33 -0
- package/types/modules/effect-coverflow.d.ts +45 -0
- package/types/modules/effect-creative.d.ts +86 -0
- package/types/modules/effect-cube.d.ts +30 -0
- package/types/modules/effect-fade.d.ts +12 -0
- package/types/modules/effect-flip.d.ts +18 -0
- package/types/modules/free-mode.d.ts +64 -0
- package/types/modules/grid.d.ts +21 -0
- package/types/modules/hash-navigation.d.ts +38 -0
- package/types/modules/history.d.ts +43 -0
- package/types/modules/index.d.ts +51 -0
- package/types/modules/keyboard.d.ts +46 -0
- package/types/modules/manipulation.d.ts +70 -0
- package/types/modules/mousewheel.d.ts +86 -0
- package/types/modules/navigation.d.ts +105 -0
- package/types/modules/pagination.d.ts +307 -0
- package/types/modules/parallax.d.ts +12 -0
- package/types/modules/public-api.d.ts +23 -0
- package/types/modules/scrollbar.d.ts +140 -0
- package/types/modules/thumbs.d.ts +54 -0
- package/types/modules/virtual.d.ts +135 -0
- package/types/modules/zoom.d.ts +91 -0
- package/types/shared.d.ts +13 -0
- package/types/swiper-class.d.ts +522 -0
- package/types/swiper-events.d.ts +359 -0
- package/types/swiper-options.d.ts +1217 -0
|
@@ -0,0 +1,3969 @@
|
|
|
1
|
+
import { a as getWindow, g as getDocument } from './ssr-window.esm.mjs';
|
|
2
|
+
import { b as elementParents, q as elementStyle, e as elementChildren, a as setCSSProperty, h as elementOuterSize, r as elementNextAll, t as elementPrevAll, k as getTranslate, u as animateCSSModeScroll, n as nextTick, v as showWarning, c as createElement, w as elementIsChildOf, f as now, x as extend, i as elementIndex, y as deleteProps } from './utils.mjs';
|
|
3
|
+
|
|
4
|
+
let support;
|
|
5
|
+
function calcSupport() {
|
|
6
|
+
const window = getWindow();
|
|
7
|
+
const document = getDocument();
|
|
8
|
+
return {
|
|
9
|
+
smoothScroll: document.documentElement && document.documentElement.style && 'scrollBehavior' in document.documentElement.style,
|
|
10
|
+
touch: !!('ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch)
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function getSupport() {
|
|
14
|
+
if (!support) {
|
|
15
|
+
support = calcSupport();
|
|
16
|
+
}
|
|
17
|
+
return support;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let deviceCached;
|
|
21
|
+
function calcDevice(_temp) {
|
|
22
|
+
let {
|
|
23
|
+
userAgent
|
|
24
|
+
} = _temp === void 0 ? {} : _temp;
|
|
25
|
+
const support = getSupport();
|
|
26
|
+
const window = getWindow();
|
|
27
|
+
const platform = window.navigator.platform;
|
|
28
|
+
const ua = userAgent || window.navigator.userAgent;
|
|
29
|
+
const device = {
|
|
30
|
+
ios: false,
|
|
31
|
+
android: false
|
|
32
|
+
};
|
|
33
|
+
const screenWidth = window.screen.width;
|
|
34
|
+
const screenHeight = window.screen.height;
|
|
35
|
+
const android = ua.match(/(Android);?[\s\/]+([\d.]+)?/); // eslint-disable-line
|
|
36
|
+
let ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
|
|
37
|
+
const ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
|
|
38
|
+
const iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/);
|
|
39
|
+
const windows = platform === 'Win32';
|
|
40
|
+
let macos = platform === 'MacIntel';
|
|
41
|
+
|
|
42
|
+
// iPadOs 13 fix
|
|
43
|
+
const iPadScreens = ['1024x1366', '1366x1024', '834x1194', '1194x834', '834x1112', '1112x834', '768x1024', '1024x768', '820x1180', '1180x820', '810x1080', '1080x810'];
|
|
44
|
+
if (!ipad && macos && support.touch && iPadScreens.indexOf(`${screenWidth}x${screenHeight}`) >= 0) {
|
|
45
|
+
ipad = ua.match(/(Version)\/([\d.]+)/);
|
|
46
|
+
if (!ipad) ipad = [0, 1, '13_0_0'];
|
|
47
|
+
macos = false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Android
|
|
51
|
+
if (android && !windows) {
|
|
52
|
+
device.os = 'android';
|
|
53
|
+
device.android = true;
|
|
54
|
+
}
|
|
55
|
+
if (ipad || iphone || ipod) {
|
|
56
|
+
device.os = 'ios';
|
|
57
|
+
device.ios = true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Export object
|
|
61
|
+
return device;
|
|
62
|
+
}
|
|
63
|
+
function getDevice(overrides) {
|
|
64
|
+
if (overrides === void 0) {
|
|
65
|
+
overrides = {};
|
|
66
|
+
}
|
|
67
|
+
if (!deviceCached) {
|
|
68
|
+
deviceCached = calcDevice(overrides);
|
|
69
|
+
}
|
|
70
|
+
return deviceCached;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let browser;
|
|
74
|
+
function calcBrowser() {
|
|
75
|
+
const window = getWindow();
|
|
76
|
+
const device = getDevice();
|
|
77
|
+
let needPerspectiveFix = false;
|
|
78
|
+
function isSafari() {
|
|
79
|
+
const ua = window.navigator.userAgent.toLowerCase();
|
|
80
|
+
return ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0;
|
|
81
|
+
}
|
|
82
|
+
if (isSafari()) {
|
|
83
|
+
const ua = String(window.navigator.userAgent);
|
|
84
|
+
if (ua.includes('Version/')) {
|
|
85
|
+
const [major, minor] = ua.split('Version/')[1].split(' ')[0].split('.').map(num => Number(num));
|
|
86
|
+
needPerspectiveFix = major < 16 || major === 16 && minor < 2;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const isWebView = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(window.navigator.userAgent);
|
|
90
|
+
const isSafariBrowser = isSafari();
|
|
91
|
+
const need3dFix = isSafariBrowser || isWebView && device.ios;
|
|
92
|
+
return {
|
|
93
|
+
isSafari: needPerspectiveFix || isSafariBrowser,
|
|
94
|
+
needPerspectiveFix,
|
|
95
|
+
need3dFix,
|
|
96
|
+
isWebView
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function getBrowser() {
|
|
100
|
+
if (!browser) {
|
|
101
|
+
browser = calcBrowser();
|
|
102
|
+
}
|
|
103
|
+
return browser;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function Resize(_ref) {
|
|
107
|
+
let {
|
|
108
|
+
swiper,
|
|
109
|
+
on,
|
|
110
|
+
emit
|
|
111
|
+
} = _ref;
|
|
112
|
+
const window = getWindow();
|
|
113
|
+
let observer = null;
|
|
114
|
+
let animationFrame = null;
|
|
115
|
+
const resizeHandler = () => {
|
|
116
|
+
if (!swiper || swiper.destroyed || !swiper.initialized) return;
|
|
117
|
+
emit('beforeResize');
|
|
118
|
+
emit('resize');
|
|
119
|
+
};
|
|
120
|
+
const createObserver = () => {
|
|
121
|
+
if (!swiper || swiper.destroyed || !swiper.initialized) return;
|
|
122
|
+
observer = new ResizeObserver(entries => {
|
|
123
|
+
animationFrame = window.requestAnimationFrame(() => {
|
|
124
|
+
const {
|
|
125
|
+
width,
|
|
126
|
+
height
|
|
127
|
+
} = swiper;
|
|
128
|
+
let newWidth = width;
|
|
129
|
+
let newHeight = height;
|
|
130
|
+
entries.forEach(_ref2 => {
|
|
131
|
+
let {
|
|
132
|
+
contentBoxSize,
|
|
133
|
+
contentRect,
|
|
134
|
+
target
|
|
135
|
+
} = _ref2;
|
|
136
|
+
if (target && target !== swiper.el) return;
|
|
137
|
+
newWidth = contentRect ? contentRect.width : (contentBoxSize[0] || contentBoxSize).inlineSize;
|
|
138
|
+
newHeight = contentRect ? contentRect.height : (contentBoxSize[0] || contentBoxSize).blockSize;
|
|
139
|
+
});
|
|
140
|
+
if (newWidth !== width || newHeight !== height) {
|
|
141
|
+
resizeHandler();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
observer.observe(swiper.el);
|
|
146
|
+
};
|
|
147
|
+
const removeObserver = () => {
|
|
148
|
+
if (animationFrame) {
|
|
149
|
+
window.cancelAnimationFrame(animationFrame);
|
|
150
|
+
}
|
|
151
|
+
if (observer && observer.unobserve && swiper.el) {
|
|
152
|
+
observer.unobserve(swiper.el);
|
|
153
|
+
observer = null;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const orientationChangeHandler = () => {
|
|
157
|
+
if (!swiper || swiper.destroyed || !swiper.initialized) return;
|
|
158
|
+
emit('orientationchange');
|
|
159
|
+
};
|
|
160
|
+
on('init', () => {
|
|
161
|
+
if (swiper.params.resizeObserver && typeof window.ResizeObserver !== 'undefined') {
|
|
162
|
+
createObserver();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
window.addEventListener('resize', resizeHandler);
|
|
166
|
+
window.addEventListener('orientationchange', orientationChangeHandler);
|
|
167
|
+
});
|
|
168
|
+
on('destroy', () => {
|
|
169
|
+
removeObserver();
|
|
170
|
+
window.removeEventListener('resize', resizeHandler);
|
|
171
|
+
window.removeEventListener('orientationchange', orientationChangeHandler);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function Observer(_ref) {
|
|
176
|
+
let {
|
|
177
|
+
swiper,
|
|
178
|
+
extendParams,
|
|
179
|
+
on,
|
|
180
|
+
emit
|
|
181
|
+
} = _ref;
|
|
182
|
+
const observers = [];
|
|
183
|
+
const window = getWindow();
|
|
184
|
+
const attach = function (target, options) {
|
|
185
|
+
if (options === void 0) {
|
|
186
|
+
options = {};
|
|
187
|
+
}
|
|
188
|
+
const ObserverFunc = window.MutationObserver || window.WebkitMutationObserver;
|
|
189
|
+
const observer = new ObserverFunc(mutations => {
|
|
190
|
+
// The observerUpdate event should only be triggered
|
|
191
|
+
// once despite the number of mutations. Additional
|
|
192
|
+
// triggers are redundant and are very costly
|
|
193
|
+
if (swiper.__preventObserver__) return;
|
|
194
|
+
if (mutations.length === 1) {
|
|
195
|
+
emit('observerUpdate', mutations[0]);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const observerUpdate = function observerUpdate() {
|
|
199
|
+
emit('observerUpdate', mutations[0]);
|
|
200
|
+
};
|
|
201
|
+
if (window.requestAnimationFrame) {
|
|
202
|
+
window.requestAnimationFrame(observerUpdate);
|
|
203
|
+
} else {
|
|
204
|
+
window.setTimeout(observerUpdate, 0);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
observer.observe(target, {
|
|
208
|
+
attributes: typeof options.attributes === 'undefined' ? true : options.attributes,
|
|
209
|
+
childList: swiper.isElement || (typeof options.childList === 'undefined' ? true : options).childList,
|
|
210
|
+
characterData: typeof options.characterData === 'undefined' ? true : options.characterData
|
|
211
|
+
});
|
|
212
|
+
observers.push(observer);
|
|
213
|
+
};
|
|
214
|
+
const init = () => {
|
|
215
|
+
if (!swiper.params.observer) return;
|
|
216
|
+
if (swiper.params.observeParents) {
|
|
217
|
+
const containerParents = elementParents(swiper.hostEl);
|
|
218
|
+
for (let i = 0; i < containerParents.length; i += 1) {
|
|
219
|
+
attach(containerParents[i]);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// Observe container
|
|
223
|
+
attach(swiper.hostEl, {
|
|
224
|
+
childList: swiper.params.observeSlideChildren
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// Observe wrapper
|
|
228
|
+
attach(swiper.wrapperEl, {
|
|
229
|
+
attributes: false
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
const destroy = () => {
|
|
233
|
+
observers.forEach(observer => {
|
|
234
|
+
observer.disconnect();
|
|
235
|
+
});
|
|
236
|
+
observers.splice(0, observers.length);
|
|
237
|
+
};
|
|
238
|
+
extendParams({
|
|
239
|
+
observer: false,
|
|
240
|
+
observeParents: false,
|
|
241
|
+
observeSlideChildren: false
|
|
242
|
+
});
|
|
243
|
+
on('init', init);
|
|
244
|
+
on('destroy', destroy);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/* eslint-disable no-underscore-dangle */
|
|
248
|
+
|
|
249
|
+
var eventsEmitter = {
|
|
250
|
+
on(events, handler, priority) {
|
|
251
|
+
const self = this;
|
|
252
|
+
if (!self.eventsListeners || self.destroyed) return self;
|
|
253
|
+
if (typeof handler !== 'function') return self;
|
|
254
|
+
const method = priority ? 'unshift' : 'push';
|
|
255
|
+
events.split(' ').forEach(event => {
|
|
256
|
+
if (!self.eventsListeners[event]) self.eventsListeners[event] = [];
|
|
257
|
+
self.eventsListeners[event][method](handler);
|
|
258
|
+
});
|
|
259
|
+
return self;
|
|
260
|
+
},
|
|
261
|
+
once(events, handler, priority) {
|
|
262
|
+
const self = this;
|
|
263
|
+
if (!self.eventsListeners || self.destroyed) return self;
|
|
264
|
+
if (typeof handler !== 'function') return self;
|
|
265
|
+
function onceHandler() {
|
|
266
|
+
self.off(events, onceHandler);
|
|
267
|
+
if (onceHandler.__emitterProxy) {
|
|
268
|
+
delete onceHandler.__emitterProxy;
|
|
269
|
+
}
|
|
270
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
271
|
+
args[_key] = arguments[_key];
|
|
272
|
+
}
|
|
273
|
+
handler.apply(self, args);
|
|
274
|
+
}
|
|
275
|
+
onceHandler.__emitterProxy = handler;
|
|
276
|
+
return self.on(events, onceHandler, priority);
|
|
277
|
+
},
|
|
278
|
+
onAny(handler, priority) {
|
|
279
|
+
const self = this;
|
|
280
|
+
if (!self.eventsListeners || self.destroyed) return self;
|
|
281
|
+
if (typeof handler !== 'function') return self;
|
|
282
|
+
const method = priority ? 'unshift' : 'push';
|
|
283
|
+
if (self.eventsAnyListeners.indexOf(handler) < 0) {
|
|
284
|
+
self.eventsAnyListeners[method](handler);
|
|
285
|
+
}
|
|
286
|
+
return self;
|
|
287
|
+
},
|
|
288
|
+
offAny(handler) {
|
|
289
|
+
const self = this;
|
|
290
|
+
if (!self.eventsListeners || self.destroyed) return self;
|
|
291
|
+
if (!self.eventsAnyListeners) return self;
|
|
292
|
+
const index = self.eventsAnyListeners.indexOf(handler);
|
|
293
|
+
if (index >= 0) {
|
|
294
|
+
self.eventsAnyListeners.splice(index, 1);
|
|
295
|
+
}
|
|
296
|
+
return self;
|
|
297
|
+
},
|
|
298
|
+
off(events, handler) {
|
|
299
|
+
const self = this;
|
|
300
|
+
if (!self.eventsListeners || self.destroyed) return self;
|
|
301
|
+
if (!self.eventsListeners) return self;
|
|
302
|
+
events.split(' ').forEach(event => {
|
|
303
|
+
if (typeof handler === 'undefined') {
|
|
304
|
+
self.eventsListeners[event] = [];
|
|
305
|
+
} else if (self.eventsListeners[event]) {
|
|
306
|
+
self.eventsListeners[event].forEach((eventHandler, index) => {
|
|
307
|
+
if (eventHandler === handler || eventHandler.__emitterProxy && eventHandler.__emitterProxy === handler) {
|
|
308
|
+
self.eventsListeners[event].splice(index, 1);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
return self;
|
|
314
|
+
},
|
|
315
|
+
emit() {
|
|
316
|
+
const self = this;
|
|
317
|
+
if (!self.eventsListeners || self.destroyed) return self;
|
|
318
|
+
if (!self.eventsListeners) return self;
|
|
319
|
+
let events;
|
|
320
|
+
let data;
|
|
321
|
+
let context;
|
|
322
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
323
|
+
args[_key2] = arguments[_key2];
|
|
324
|
+
}
|
|
325
|
+
if (typeof args[0] === 'string' || Array.isArray(args[0])) {
|
|
326
|
+
events = args[0];
|
|
327
|
+
data = args.slice(1, args.length);
|
|
328
|
+
context = self;
|
|
329
|
+
} else {
|
|
330
|
+
events = args[0].events;
|
|
331
|
+
data = args[0].data;
|
|
332
|
+
context = args[0].context || self;
|
|
333
|
+
}
|
|
334
|
+
data.unshift(context);
|
|
335
|
+
const eventsArray = Array.isArray(events) ? events : events.split(' ');
|
|
336
|
+
eventsArray.forEach(event => {
|
|
337
|
+
if (self.eventsAnyListeners && self.eventsAnyListeners.length) {
|
|
338
|
+
self.eventsAnyListeners.forEach(eventHandler => {
|
|
339
|
+
eventHandler.apply(context, [event, ...data]);
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
if (self.eventsListeners && self.eventsListeners[event]) {
|
|
343
|
+
self.eventsListeners[event].forEach(eventHandler => {
|
|
344
|
+
eventHandler.apply(context, data);
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
return self;
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
function updateSize() {
|
|
353
|
+
const swiper = this;
|
|
354
|
+
let width;
|
|
355
|
+
let height;
|
|
356
|
+
const el = swiper.el;
|
|
357
|
+
if (typeof swiper.params.width !== 'undefined' && swiper.params.width !== null) {
|
|
358
|
+
width = swiper.params.width;
|
|
359
|
+
} else {
|
|
360
|
+
width = el.clientWidth;
|
|
361
|
+
}
|
|
362
|
+
if (typeof swiper.params.height !== 'undefined' && swiper.params.height !== null) {
|
|
363
|
+
height = swiper.params.height;
|
|
364
|
+
} else {
|
|
365
|
+
height = el.clientHeight;
|
|
366
|
+
}
|
|
367
|
+
if (width === 0 && swiper.isHorizontal() || height === 0 && swiper.isVertical()) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Subtract paddings
|
|
372
|
+
width = width - parseInt(elementStyle(el, 'padding-left') || 0, 10) - parseInt(elementStyle(el, 'padding-right') || 0, 10);
|
|
373
|
+
height = height - parseInt(elementStyle(el, 'padding-top') || 0, 10) - parseInt(elementStyle(el, 'padding-bottom') || 0, 10);
|
|
374
|
+
if (Number.isNaN(width)) width = 0;
|
|
375
|
+
if (Number.isNaN(height)) height = 0;
|
|
376
|
+
Object.assign(swiper, {
|
|
377
|
+
width,
|
|
378
|
+
height,
|
|
379
|
+
size: swiper.isHorizontal() ? width : height
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function updateSlides() {
|
|
384
|
+
const swiper = this;
|
|
385
|
+
function getDirectionPropertyValue(node, label) {
|
|
386
|
+
return parseFloat(node.getPropertyValue(swiper.getDirectionLabel(label)) || 0);
|
|
387
|
+
}
|
|
388
|
+
const params = swiper.params;
|
|
389
|
+
const {
|
|
390
|
+
wrapperEl,
|
|
391
|
+
slidesEl,
|
|
392
|
+
size: swiperSize,
|
|
393
|
+
rtlTranslate: rtl,
|
|
394
|
+
wrongRTL
|
|
395
|
+
} = swiper;
|
|
396
|
+
const isVirtual = swiper.virtual && params.virtual.enabled;
|
|
397
|
+
const previousSlidesLength = isVirtual ? swiper.virtual.slides.length : swiper.slides.length;
|
|
398
|
+
const slides = elementChildren(slidesEl, `.${swiper.params.slideClass}, swiper-slide`);
|
|
399
|
+
const slidesLength = isVirtual ? swiper.virtual.slides.length : slides.length;
|
|
400
|
+
let snapGrid = [];
|
|
401
|
+
const slidesGrid = [];
|
|
402
|
+
const slidesSizesGrid = [];
|
|
403
|
+
let offsetBefore = params.slidesOffsetBefore;
|
|
404
|
+
if (typeof offsetBefore === 'function') {
|
|
405
|
+
offsetBefore = params.slidesOffsetBefore.call(swiper);
|
|
406
|
+
}
|
|
407
|
+
let offsetAfter = params.slidesOffsetAfter;
|
|
408
|
+
if (typeof offsetAfter === 'function') {
|
|
409
|
+
offsetAfter = params.slidesOffsetAfter.call(swiper);
|
|
410
|
+
}
|
|
411
|
+
const previousSnapGridLength = swiper.snapGrid.length;
|
|
412
|
+
const previousSlidesGridLength = swiper.slidesGrid.length;
|
|
413
|
+
let spaceBetween = params.spaceBetween;
|
|
414
|
+
let slidePosition = -offsetBefore;
|
|
415
|
+
let prevSlideSize = 0;
|
|
416
|
+
let index = 0;
|
|
417
|
+
if (typeof swiperSize === 'undefined') {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
|
|
421
|
+
spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * swiperSize;
|
|
422
|
+
} else if (typeof spaceBetween === 'string') {
|
|
423
|
+
spaceBetween = parseFloat(spaceBetween);
|
|
424
|
+
}
|
|
425
|
+
swiper.virtualSize = -spaceBetween;
|
|
426
|
+
|
|
427
|
+
// reset margins
|
|
428
|
+
slides.forEach(slideEl => {
|
|
429
|
+
if (rtl) {
|
|
430
|
+
slideEl.style.marginLeft = '';
|
|
431
|
+
} else {
|
|
432
|
+
slideEl.style.marginRight = '';
|
|
433
|
+
}
|
|
434
|
+
slideEl.style.marginBottom = '';
|
|
435
|
+
slideEl.style.marginTop = '';
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
// reset cssMode offsets
|
|
439
|
+
if (params.centeredSlides && params.cssMode) {
|
|
440
|
+
setCSSProperty(wrapperEl, '--swiper-centered-offset-before', '');
|
|
441
|
+
setCSSProperty(wrapperEl, '--swiper-centered-offset-after', '');
|
|
442
|
+
}
|
|
443
|
+
const gridEnabled = params.grid && params.grid.rows > 1 && swiper.grid;
|
|
444
|
+
if (gridEnabled) {
|
|
445
|
+
swiper.grid.initSlides(slides);
|
|
446
|
+
} else if (swiper.grid) {
|
|
447
|
+
swiper.grid.unsetSlides();
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// Calc slides
|
|
451
|
+
let slideSize;
|
|
452
|
+
const shouldResetSlideSize = params.slidesPerView === 'auto' && params.breakpoints && Object.keys(params.breakpoints).filter(key => {
|
|
453
|
+
return typeof params.breakpoints[key].slidesPerView !== 'undefined';
|
|
454
|
+
}).length > 0;
|
|
455
|
+
for (let i = 0; i < slidesLength; i += 1) {
|
|
456
|
+
slideSize = 0;
|
|
457
|
+
let slide;
|
|
458
|
+
if (slides[i]) slide = slides[i];
|
|
459
|
+
if (gridEnabled) {
|
|
460
|
+
swiper.grid.updateSlide(i, slide, slides);
|
|
461
|
+
}
|
|
462
|
+
if (slides[i] && elementStyle(slide, 'display') === 'none') continue; // eslint-disable-line
|
|
463
|
+
|
|
464
|
+
if (params.slidesPerView === 'auto') {
|
|
465
|
+
if (shouldResetSlideSize) {
|
|
466
|
+
slides[i].style[swiper.getDirectionLabel('width')] = ``;
|
|
467
|
+
}
|
|
468
|
+
const slideStyles = getComputedStyle(slide);
|
|
469
|
+
const currentTransform = slide.style.transform;
|
|
470
|
+
const currentWebKitTransform = slide.style.webkitTransform;
|
|
471
|
+
if (currentTransform) {
|
|
472
|
+
slide.style.transform = 'none';
|
|
473
|
+
}
|
|
474
|
+
if (currentWebKitTransform) {
|
|
475
|
+
slide.style.webkitTransform = 'none';
|
|
476
|
+
}
|
|
477
|
+
if (params.roundLengths) {
|
|
478
|
+
slideSize = swiper.isHorizontal() ? elementOuterSize(slide, 'width', true) : elementOuterSize(slide, 'height', true);
|
|
479
|
+
} else {
|
|
480
|
+
// eslint-disable-next-line
|
|
481
|
+
const width = getDirectionPropertyValue(slideStyles, 'width');
|
|
482
|
+
const paddingLeft = getDirectionPropertyValue(slideStyles, 'padding-left');
|
|
483
|
+
const paddingRight = getDirectionPropertyValue(slideStyles, 'padding-right');
|
|
484
|
+
const marginLeft = getDirectionPropertyValue(slideStyles, 'margin-left');
|
|
485
|
+
const marginRight = getDirectionPropertyValue(slideStyles, 'margin-right');
|
|
486
|
+
const boxSizing = slideStyles.getPropertyValue('box-sizing');
|
|
487
|
+
if (boxSizing && boxSizing === 'border-box') {
|
|
488
|
+
slideSize = width + marginLeft + marginRight;
|
|
489
|
+
} else {
|
|
490
|
+
const {
|
|
491
|
+
clientWidth,
|
|
492
|
+
offsetWidth
|
|
493
|
+
} = slide;
|
|
494
|
+
slideSize = width + paddingLeft + paddingRight + marginLeft + marginRight + (offsetWidth - clientWidth);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
if (currentTransform) {
|
|
498
|
+
slide.style.transform = currentTransform;
|
|
499
|
+
}
|
|
500
|
+
if (currentWebKitTransform) {
|
|
501
|
+
slide.style.webkitTransform = currentWebKitTransform;
|
|
502
|
+
}
|
|
503
|
+
if (params.roundLengths) slideSize = Math.floor(slideSize);
|
|
504
|
+
} else {
|
|
505
|
+
slideSize = (swiperSize - (params.slidesPerView - 1) * spaceBetween) / params.slidesPerView;
|
|
506
|
+
if (params.roundLengths) slideSize = Math.floor(slideSize);
|
|
507
|
+
if (slides[i]) {
|
|
508
|
+
slides[i].style[swiper.getDirectionLabel('width')] = `${slideSize}px`;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if (slides[i]) {
|
|
512
|
+
slides[i].swiperSlideSize = slideSize;
|
|
513
|
+
}
|
|
514
|
+
slidesSizesGrid.push(slideSize);
|
|
515
|
+
if (params.centeredSlides) {
|
|
516
|
+
slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween;
|
|
517
|
+
if (prevSlideSize === 0 && i !== 0) slidePosition = slidePosition - swiperSize / 2 - spaceBetween;
|
|
518
|
+
if (i === 0) slidePosition = slidePosition - swiperSize / 2 - spaceBetween;
|
|
519
|
+
if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0;
|
|
520
|
+
if (params.roundLengths) slidePosition = Math.floor(slidePosition);
|
|
521
|
+
if (index % params.slidesPerGroup === 0) snapGrid.push(slidePosition);
|
|
522
|
+
slidesGrid.push(slidePosition);
|
|
523
|
+
} else {
|
|
524
|
+
if (params.roundLengths) slidePosition = Math.floor(slidePosition);
|
|
525
|
+
if ((index - Math.min(swiper.params.slidesPerGroupSkip, index)) % swiper.params.slidesPerGroup === 0) snapGrid.push(slidePosition);
|
|
526
|
+
slidesGrid.push(slidePosition);
|
|
527
|
+
slidePosition = slidePosition + slideSize + spaceBetween;
|
|
528
|
+
}
|
|
529
|
+
swiper.virtualSize += slideSize + spaceBetween;
|
|
530
|
+
prevSlideSize = slideSize;
|
|
531
|
+
index += 1;
|
|
532
|
+
}
|
|
533
|
+
swiper.virtualSize = Math.max(swiper.virtualSize, swiperSize) + offsetAfter;
|
|
534
|
+
if (rtl && wrongRTL && (params.effect === 'slide' || params.effect === 'coverflow')) {
|
|
535
|
+
wrapperEl.style.width = `${swiper.virtualSize + spaceBetween}px`;
|
|
536
|
+
}
|
|
537
|
+
if (params.setWrapperSize) {
|
|
538
|
+
wrapperEl.style[swiper.getDirectionLabel('width')] = `${swiper.virtualSize + spaceBetween}px`;
|
|
539
|
+
}
|
|
540
|
+
if (gridEnabled) {
|
|
541
|
+
swiper.grid.updateWrapperSize(slideSize, snapGrid);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// Remove last grid elements depending on width
|
|
545
|
+
if (!params.centeredSlides) {
|
|
546
|
+
const newSlidesGrid = [];
|
|
547
|
+
for (let i = 0; i < snapGrid.length; i += 1) {
|
|
548
|
+
let slidesGridItem = snapGrid[i];
|
|
549
|
+
if (params.roundLengths) slidesGridItem = Math.floor(slidesGridItem);
|
|
550
|
+
if (snapGrid[i] <= swiper.virtualSize - swiperSize) {
|
|
551
|
+
newSlidesGrid.push(slidesGridItem);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
snapGrid = newSlidesGrid;
|
|
555
|
+
if (Math.floor(swiper.virtualSize - swiperSize) - Math.floor(snapGrid[snapGrid.length - 1]) > 1) {
|
|
556
|
+
snapGrid.push(swiper.virtualSize - swiperSize);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
if (isVirtual && params.loop) {
|
|
560
|
+
const size = slidesSizesGrid[0] + spaceBetween;
|
|
561
|
+
if (params.slidesPerGroup > 1) {
|
|
562
|
+
const groups = Math.ceil((swiper.virtual.slidesBefore + swiper.virtual.slidesAfter) / params.slidesPerGroup);
|
|
563
|
+
const groupSize = size * params.slidesPerGroup;
|
|
564
|
+
for (let i = 0; i < groups; i += 1) {
|
|
565
|
+
snapGrid.push(snapGrid[snapGrid.length - 1] + groupSize);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
for (let i = 0; i < swiper.virtual.slidesBefore + swiper.virtual.slidesAfter; i += 1) {
|
|
569
|
+
if (params.slidesPerGroup === 1) {
|
|
570
|
+
snapGrid.push(snapGrid[snapGrid.length - 1] + size);
|
|
571
|
+
}
|
|
572
|
+
slidesGrid.push(slidesGrid[slidesGrid.length - 1] + size);
|
|
573
|
+
swiper.virtualSize += size;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
if (snapGrid.length === 0) snapGrid = [0];
|
|
577
|
+
if (spaceBetween !== 0) {
|
|
578
|
+
const key = swiper.isHorizontal() && rtl ? 'marginLeft' : swiper.getDirectionLabel('marginRight');
|
|
579
|
+
slides.filter((_, slideIndex) => {
|
|
580
|
+
if (!params.cssMode || params.loop) return true;
|
|
581
|
+
if (slideIndex === slides.length - 1) {
|
|
582
|
+
return false;
|
|
583
|
+
}
|
|
584
|
+
return true;
|
|
585
|
+
}).forEach(slideEl => {
|
|
586
|
+
slideEl.style[key] = `${spaceBetween}px`;
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
if (params.centeredSlides && params.centeredSlidesBounds) {
|
|
590
|
+
let allSlidesSize = 0;
|
|
591
|
+
slidesSizesGrid.forEach(slideSizeValue => {
|
|
592
|
+
allSlidesSize += slideSizeValue + (spaceBetween || 0);
|
|
593
|
+
});
|
|
594
|
+
allSlidesSize -= spaceBetween;
|
|
595
|
+
const maxSnap = allSlidesSize > swiperSize ? allSlidesSize - swiperSize : 0;
|
|
596
|
+
snapGrid = snapGrid.map(snap => {
|
|
597
|
+
if (snap <= 0) return -offsetBefore;
|
|
598
|
+
if (snap > maxSnap) return maxSnap + offsetAfter;
|
|
599
|
+
return snap;
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
if (params.centerInsufficientSlides) {
|
|
603
|
+
let allSlidesSize = 0;
|
|
604
|
+
slidesSizesGrid.forEach(slideSizeValue => {
|
|
605
|
+
allSlidesSize += slideSizeValue + (spaceBetween || 0);
|
|
606
|
+
});
|
|
607
|
+
allSlidesSize -= spaceBetween;
|
|
608
|
+
const offsetSize = (params.slidesOffsetBefore || 0) + (params.slidesOffsetAfter || 0);
|
|
609
|
+
if (allSlidesSize + offsetSize < swiperSize) {
|
|
610
|
+
const allSlidesOffset = (swiperSize - allSlidesSize - offsetSize) / 2;
|
|
611
|
+
snapGrid.forEach((snap, snapIndex) => {
|
|
612
|
+
snapGrid[snapIndex] = snap - allSlidesOffset;
|
|
613
|
+
});
|
|
614
|
+
slidesGrid.forEach((snap, snapIndex) => {
|
|
615
|
+
slidesGrid[snapIndex] = snap + allSlidesOffset;
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
Object.assign(swiper, {
|
|
620
|
+
slides,
|
|
621
|
+
snapGrid,
|
|
622
|
+
slidesGrid,
|
|
623
|
+
slidesSizesGrid
|
|
624
|
+
});
|
|
625
|
+
if (params.centeredSlides && params.cssMode && !params.centeredSlidesBounds) {
|
|
626
|
+
setCSSProperty(wrapperEl, '--swiper-centered-offset-before', `${-snapGrid[0]}px`);
|
|
627
|
+
setCSSProperty(wrapperEl, '--swiper-centered-offset-after', `${swiper.size / 2 - slidesSizesGrid[slidesSizesGrid.length - 1] / 2}px`);
|
|
628
|
+
const addToSnapGrid = -swiper.snapGrid[0];
|
|
629
|
+
const addToSlidesGrid = -swiper.slidesGrid[0];
|
|
630
|
+
swiper.snapGrid = swiper.snapGrid.map(v => v + addToSnapGrid);
|
|
631
|
+
swiper.slidesGrid = swiper.slidesGrid.map(v => v + addToSlidesGrid);
|
|
632
|
+
}
|
|
633
|
+
if (slidesLength !== previousSlidesLength) {
|
|
634
|
+
swiper.emit('slidesLengthChange');
|
|
635
|
+
}
|
|
636
|
+
if (snapGrid.length !== previousSnapGridLength) {
|
|
637
|
+
if (swiper.params.watchOverflow) swiper.checkOverflow();
|
|
638
|
+
swiper.emit('snapGridLengthChange');
|
|
639
|
+
}
|
|
640
|
+
if (slidesGrid.length !== previousSlidesGridLength) {
|
|
641
|
+
swiper.emit('slidesGridLengthChange');
|
|
642
|
+
}
|
|
643
|
+
if (params.watchSlidesProgress) {
|
|
644
|
+
swiper.updateSlidesOffset();
|
|
645
|
+
}
|
|
646
|
+
swiper.emit('slidesUpdated');
|
|
647
|
+
if (!isVirtual && !params.cssMode && (params.effect === 'slide' || params.effect === 'fade')) {
|
|
648
|
+
const backFaceHiddenClass = `${params.containerModifierClass}backface-hidden`;
|
|
649
|
+
const hasClassBackfaceClassAdded = swiper.el.classList.contains(backFaceHiddenClass);
|
|
650
|
+
if (slidesLength <= params.maxBackfaceHiddenSlides) {
|
|
651
|
+
if (!hasClassBackfaceClassAdded) swiper.el.classList.add(backFaceHiddenClass);
|
|
652
|
+
} else if (hasClassBackfaceClassAdded) {
|
|
653
|
+
swiper.el.classList.remove(backFaceHiddenClass);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function updateAutoHeight(speed) {
|
|
659
|
+
const swiper = this;
|
|
660
|
+
const activeSlides = [];
|
|
661
|
+
const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
|
|
662
|
+
let newHeight = 0;
|
|
663
|
+
let i;
|
|
664
|
+
if (typeof speed === 'number') {
|
|
665
|
+
swiper.setTransition(speed);
|
|
666
|
+
} else if (speed === true) {
|
|
667
|
+
swiper.setTransition(swiper.params.speed);
|
|
668
|
+
}
|
|
669
|
+
const getSlideByIndex = index => {
|
|
670
|
+
if (isVirtual) {
|
|
671
|
+
return swiper.slides[swiper.getSlideIndexByData(index)];
|
|
672
|
+
}
|
|
673
|
+
return swiper.slides[index];
|
|
674
|
+
};
|
|
675
|
+
// Find slides currently in view
|
|
676
|
+
if (swiper.params.slidesPerView !== 'auto' && swiper.params.slidesPerView > 1) {
|
|
677
|
+
if (swiper.params.centeredSlides) {
|
|
678
|
+
(swiper.visibleSlides || []).forEach(slide => {
|
|
679
|
+
activeSlides.push(slide);
|
|
680
|
+
});
|
|
681
|
+
} else {
|
|
682
|
+
for (i = 0; i < Math.ceil(swiper.params.slidesPerView); i += 1) {
|
|
683
|
+
const index = swiper.activeIndex + i;
|
|
684
|
+
if (index > swiper.slides.length && !isVirtual) break;
|
|
685
|
+
activeSlides.push(getSlideByIndex(index));
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
} else {
|
|
689
|
+
activeSlides.push(getSlideByIndex(swiper.activeIndex));
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// Find new height from highest slide in view
|
|
693
|
+
for (i = 0; i < activeSlides.length; i += 1) {
|
|
694
|
+
if (typeof activeSlides[i] !== 'undefined') {
|
|
695
|
+
const height = activeSlides[i].offsetHeight;
|
|
696
|
+
newHeight = height > newHeight ? height : newHeight;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// Update Height
|
|
701
|
+
if (newHeight || newHeight === 0) swiper.wrapperEl.style.height = `${newHeight}px`;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
function updateSlidesOffset() {
|
|
705
|
+
const swiper = this;
|
|
706
|
+
const slides = swiper.slides;
|
|
707
|
+
// eslint-disable-next-line
|
|
708
|
+
const minusOffset = swiper.isElement ? swiper.isHorizontal() ? swiper.wrapperEl.offsetLeft : swiper.wrapperEl.offsetTop : 0;
|
|
709
|
+
for (let i = 0; i < slides.length; i += 1) {
|
|
710
|
+
slides[i].swiperSlideOffset = (swiper.isHorizontal() ? slides[i].offsetLeft : slides[i].offsetTop) - minusOffset - swiper.cssOverflowAdjustment();
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
const toggleSlideClasses$1 = (slideEl, condition, className) => {
|
|
715
|
+
if (condition && !slideEl.classList.contains(className)) {
|
|
716
|
+
slideEl.classList.add(className);
|
|
717
|
+
} else if (!condition && slideEl.classList.contains(className)) {
|
|
718
|
+
slideEl.classList.remove(className);
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
function updateSlidesProgress(translate) {
|
|
722
|
+
if (translate === void 0) {
|
|
723
|
+
translate = this && this.translate || 0;
|
|
724
|
+
}
|
|
725
|
+
const swiper = this;
|
|
726
|
+
const params = swiper.params;
|
|
727
|
+
const {
|
|
728
|
+
slides,
|
|
729
|
+
rtlTranslate: rtl,
|
|
730
|
+
snapGrid
|
|
731
|
+
} = swiper;
|
|
732
|
+
if (slides.length === 0) return;
|
|
733
|
+
if (typeof slides[0].swiperSlideOffset === 'undefined') swiper.updateSlidesOffset();
|
|
734
|
+
let offsetCenter = -translate;
|
|
735
|
+
if (rtl) offsetCenter = translate;
|
|
736
|
+
swiper.visibleSlidesIndexes = [];
|
|
737
|
+
swiper.visibleSlides = [];
|
|
738
|
+
let spaceBetween = params.spaceBetween;
|
|
739
|
+
if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
|
|
740
|
+
spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * swiper.size;
|
|
741
|
+
} else if (typeof spaceBetween === 'string') {
|
|
742
|
+
spaceBetween = parseFloat(spaceBetween);
|
|
743
|
+
}
|
|
744
|
+
for (let i = 0; i < slides.length; i += 1) {
|
|
745
|
+
const slide = slides[i];
|
|
746
|
+
let slideOffset = slide.swiperSlideOffset;
|
|
747
|
+
if (params.cssMode && params.centeredSlides) {
|
|
748
|
+
slideOffset -= slides[0].swiperSlideOffset;
|
|
749
|
+
}
|
|
750
|
+
const slideProgress = (offsetCenter + (params.centeredSlides ? swiper.minTranslate() : 0) - slideOffset) / (slide.swiperSlideSize + spaceBetween);
|
|
751
|
+
const originalSlideProgress = (offsetCenter - snapGrid[0] + (params.centeredSlides ? swiper.minTranslate() : 0) - slideOffset) / (slide.swiperSlideSize + spaceBetween);
|
|
752
|
+
const slideBefore = -(offsetCenter - slideOffset);
|
|
753
|
+
const slideAfter = slideBefore + swiper.slidesSizesGrid[i];
|
|
754
|
+
const isFullyVisible = slideBefore >= 0 && slideBefore <= swiper.size - swiper.slidesSizesGrid[i];
|
|
755
|
+
const isVisible = slideBefore >= 0 && slideBefore < swiper.size - 1 || slideAfter > 1 && slideAfter <= swiper.size || slideBefore <= 0 && slideAfter >= swiper.size;
|
|
756
|
+
if (isVisible) {
|
|
757
|
+
swiper.visibleSlides.push(slide);
|
|
758
|
+
swiper.visibleSlidesIndexes.push(i);
|
|
759
|
+
}
|
|
760
|
+
toggleSlideClasses$1(slide, isVisible, params.slideVisibleClass);
|
|
761
|
+
toggleSlideClasses$1(slide, isFullyVisible, params.slideFullyVisibleClass);
|
|
762
|
+
slide.progress = rtl ? -slideProgress : slideProgress;
|
|
763
|
+
slide.originalProgress = rtl ? -originalSlideProgress : originalSlideProgress;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
function updateProgress(translate) {
|
|
768
|
+
const swiper = this;
|
|
769
|
+
if (typeof translate === 'undefined') {
|
|
770
|
+
const multiplier = swiper.rtlTranslate ? -1 : 1;
|
|
771
|
+
// eslint-disable-next-line
|
|
772
|
+
translate = swiper && swiper.translate && swiper.translate * multiplier || 0;
|
|
773
|
+
}
|
|
774
|
+
const params = swiper.params;
|
|
775
|
+
const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
|
|
776
|
+
let {
|
|
777
|
+
progress,
|
|
778
|
+
isBeginning,
|
|
779
|
+
isEnd,
|
|
780
|
+
progressLoop
|
|
781
|
+
} = swiper;
|
|
782
|
+
const wasBeginning = isBeginning;
|
|
783
|
+
const wasEnd = isEnd;
|
|
784
|
+
if (translatesDiff === 0) {
|
|
785
|
+
progress = 0;
|
|
786
|
+
isBeginning = true;
|
|
787
|
+
isEnd = true;
|
|
788
|
+
} else {
|
|
789
|
+
progress = (translate - swiper.minTranslate()) / translatesDiff;
|
|
790
|
+
const isBeginningRounded = Math.abs(translate - swiper.minTranslate()) < 1;
|
|
791
|
+
const isEndRounded = Math.abs(translate - swiper.maxTranslate()) < 1;
|
|
792
|
+
isBeginning = isBeginningRounded || progress <= 0;
|
|
793
|
+
isEnd = isEndRounded || progress >= 1;
|
|
794
|
+
if (isBeginningRounded) progress = 0;
|
|
795
|
+
if (isEndRounded) progress = 1;
|
|
796
|
+
}
|
|
797
|
+
if (params.loop) {
|
|
798
|
+
const firstSlideIndex = swiper.getSlideIndexByData(0);
|
|
799
|
+
const lastSlideIndex = swiper.getSlideIndexByData(swiper.slides.length - 1);
|
|
800
|
+
const firstSlideTranslate = swiper.slidesGrid[firstSlideIndex];
|
|
801
|
+
const lastSlideTranslate = swiper.slidesGrid[lastSlideIndex];
|
|
802
|
+
const translateMax = swiper.slidesGrid[swiper.slidesGrid.length - 1];
|
|
803
|
+
const translateAbs = Math.abs(translate);
|
|
804
|
+
if (translateAbs >= firstSlideTranslate) {
|
|
805
|
+
progressLoop = (translateAbs - firstSlideTranslate) / translateMax;
|
|
806
|
+
} else {
|
|
807
|
+
progressLoop = (translateAbs + translateMax - lastSlideTranslate) / translateMax;
|
|
808
|
+
}
|
|
809
|
+
if (progressLoop > 1) progressLoop -= 1;
|
|
810
|
+
}
|
|
811
|
+
Object.assign(swiper, {
|
|
812
|
+
progress,
|
|
813
|
+
progressLoop,
|
|
814
|
+
isBeginning,
|
|
815
|
+
isEnd
|
|
816
|
+
});
|
|
817
|
+
if (params.watchSlidesProgress || params.centeredSlides && params.autoHeight) swiper.updateSlidesProgress(translate);
|
|
818
|
+
if (isBeginning && !wasBeginning) {
|
|
819
|
+
swiper.emit('reachBeginning toEdge');
|
|
820
|
+
}
|
|
821
|
+
if (isEnd && !wasEnd) {
|
|
822
|
+
swiper.emit('reachEnd toEdge');
|
|
823
|
+
}
|
|
824
|
+
if (wasBeginning && !isBeginning || wasEnd && !isEnd) {
|
|
825
|
+
swiper.emit('fromEdge');
|
|
826
|
+
}
|
|
827
|
+
swiper.emit('progress', progress);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
const toggleSlideClasses = (slideEl, condition, className) => {
|
|
831
|
+
if (condition && !slideEl.classList.contains(className)) {
|
|
832
|
+
slideEl.classList.add(className);
|
|
833
|
+
} else if (!condition && slideEl.classList.contains(className)) {
|
|
834
|
+
slideEl.classList.remove(className);
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
function updateSlidesClasses() {
|
|
838
|
+
const swiper = this;
|
|
839
|
+
const {
|
|
840
|
+
slides,
|
|
841
|
+
params,
|
|
842
|
+
slidesEl,
|
|
843
|
+
activeIndex
|
|
844
|
+
} = swiper;
|
|
845
|
+
const isVirtual = swiper.virtual && params.virtual.enabled;
|
|
846
|
+
const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
|
|
847
|
+
const getFilteredSlide = selector => {
|
|
848
|
+
return elementChildren(slidesEl, `.${params.slideClass}${selector}, swiper-slide${selector}`)[0];
|
|
849
|
+
};
|
|
850
|
+
let activeSlide;
|
|
851
|
+
let prevSlide;
|
|
852
|
+
let nextSlide;
|
|
853
|
+
if (isVirtual) {
|
|
854
|
+
if (params.loop) {
|
|
855
|
+
let slideIndex = activeIndex - swiper.virtual.slidesBefore;
|
|
856
|
+
if (slideIndex < 0) slideIndex = swiper.virtual.slides.length + slideIndex;
|
|
857
|
+
if (slideIndex >= swiper.virtual.slides.length) slideIndex -= swiper.virtual.slides.length;
|
|
858
|
+
activeSlide = getFilteredSlide(`[data-swiper-slide-index="${slideIndex}"]`);
|
|
859
|
+
} else {
|
|
860
|
+
activeSlide = getFilteredSlide(`[data-swiper-slide-index="${activeIndex}"]`);
|
|
861
|
+
}
|
|
862
|
+
} else {
|
|
863
|
+
if (gridEnabled) {
|
|
864
|
+
activeSlide = slides.find(slideEl => slideEl.column === activeIndex);
|
|
865
|
+
nextSlide = slides.find(slideEl => slideEl.column === activeIndex + 1);
|
|
866
|
+
prevSlide = slides.find(slideEl => slideEl.column === activeIndex - 1);
|
|
867
|
+
} else {
|
|
868
|
+
activeSlide = slides[activeIndex];
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
if (activeSlide) {
|
|
872
|
+
if (!gridEnabled) {
|
|
873
|
+
// Next Slide
|
|
874
|
+
nextSlide = elementNextAll(activeSlide, `.${params.slideClass}, swiper-slide`)[0];
|
|
875
|
+
if (params.loop && !nextSlide) {
|
|
876
|
+
nextSlide = slides[0];
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
// Prev Slide
|
|
880
|
+
prevSlide = elementPrevAll(activeSlide, `.${params.slideClass}, swiper-slide`)[0];
|
|
881
|
+
if (params.loop && !prevSlide === 0) {
|
|
882
|
+
prevSlide = slides[slides.length - 1];
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
slides.forEach(slideEl => {
|
|
887
|
+
toggleSlideClasses(slideEl, slideEl === activeSlide, params.slideActiveClass);
|
|
888
|
+
toggleSlideClasses(slideEl, slideEl === nextSlide, params.slideNextClass);
|
|
889
|
+
toggleSlideClasses(slideEl, slideEl === prevSlide, params.slidePrevClass);
|
|
890
|
+
});
|
|
891
|
+
swiper.emitSlidesClasses();
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
const processLazyPreloader = (swiper, imageEl) => {
|
|
895
|
+
if (!swiper || swiper.destroyed || !swiper.params) return;
|
|
896
|
+
const slideSelector = () => swiper.isElement ? `swiper-slide` : `.${swiper.params.slideClass}`;
|
|
897
|
+
const slideEl = imageEl.closest(slideSelector());
|
|
898
|
+
if (slideEl) {
|
|
899
|
+
let lazyEl = slideEl.querySelector(`.${swiper.params.lazyPreloaderClass}`);
|
|
900
|
+
if (!lazyEl && swiper.isElement) {
|
|
901
|
+
if (slideEl.shadowRoot) {
|
|
902
|
+
lazyEl = slideEl.shadowRoot.querySelector(`.${swiper.params.lazyPreloaderClass}`);
|
|
903
|
+
} else {
|
|
904
|
+
// init later
|
|
905
|
+
requestAnimationFrame(() => {
|
|
906
|
+
if (slideEl.shadowRoot) {
|
|
907
|
+
lazyEl = slideEl.shadowRoot.querySelector(`.${swiper.params.lazyPreloaderClass}`);
|
|
908
|
+
if (lazyEl) lazyEl.remove();
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
if (lazyEl) lazyEl.remove();
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
const unlazy = (swiper, index) => {
|
|
917
|
+
if (!swiper.slides[index]) return;
|
|
918
|
+
const imageEl = swiper.slides[index].querySelector('[loading="lazy"]');
|
|
919
|
+
if (imageEl) imageEl.removeAttribute('loading');
|
|
920
|
+
};
|
|
921
|
+
const preload = swiper => {
|
|
922
|
+
if (!swiper || swiper.destroyed || !swiper.params) return;
|
|
923
|
+
let amount = swiper.params.lazyPreloadPrevNext;
|
|
924
|
+
const len = swiper.slides.length;
|
|
925
|
+
if (!len || !amount || amount < 0) return;
|
|
926
|
+
amount = Math.min(amount, len);
|
|
927
|
+
const slidesPerView = swiper.params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(swiper.params.slidesPerView);
|
|
928
|
+
const activeIndex = swiper.activeIndex;
|
|
929
|
+
if (swiper.params.grid && swiper.params.grid.rows > 1) {
|
|
930
|
+
const activeColumn = activeIndex;
|
|
931
|
+
const preloadColumns = [activeColumn - amount];
|
|
932
|
+
preloadColumns.push(...Array.from({
|
|
933
|
+
length: amount
|
|
934
|
+
}).map((_, i) => {
|
|
935
|
+
return activeColumn + slidesPerView + i;
|
|
936
|
+
}));
|
|
937
|
+
swiper.slides.forEach((slideEl, i) => {
|
|
938
|
+
if (preloadColumns.includes(slideEl.column)) unlazy(swiper, i);
|
|
939
|
+
});
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
const slideIndexLastInView = activeIndex + slidesPerView - 1;
|
|
943
|
+
if (swiper.params.rewind || swiper.params.loop) {
|
|
944
|
+
for (let i = activeIndex - amount; i <= slideIndexLastInView + amount; i += 1) {
|
|
945
|
+
const realIndex = (i % len + len) % len;
|
|
946
|
+
if (realIndex < activeIndex || realIndex > slideIndexLastInView) unlazy(swiper, realIndex);
|
|
947
|
+
}
|
|
948
|
+
} else {
|
|
949
|
+
for (let i = Math.max(activeIndex - amount, 0); i <= Math.min(slideIndexLastInView + amount, len - 1); i += 1) {
|
|
950
|
+
if (i !== activeIndex && (i > slideIndexLastInView || i < activeIndex)) {
|
|
951
|
+
unlazy(swiper, i);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
};
|
|
956
|
+
|
|
957
|
+
function getActiveIndexByTranslate(swiper) {
|
|
958
|
+
const {
|
|
959
|
+
slidesGrid,
|
|
960
|
+
params
|
|
961
|
+
} = swiper;
|
|
962
|
+
const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
|
|
963
|
+
let activeIndex;
|
|
964
|
+
for (let i = 0; i < slidesGrid.length; i += 1) {
|
|
965
|
+
if (typeof slidesGrid[i + 1] !== 'undefined') {
|
|
966
|
+
if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1] - (slidesGrid[i + 1] - slidesGrid[i]) / 2) {
|
|
967
|
+
activeIndex = i;
|
|
968
|
+
} else if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1]) {
|
|
969
|
+
activeIndex = i + 1;
|
|
970
|
+
}
|
|
971
|
+
} else if (translate >= slidesGrid[i]) {
|
|
972
|
+
activeIndex = i;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
// Normalize slideIndex
|
|
976
|
+
if (params.normalizeSlideIndex) {
|
|
977
|
+
if (activeIndex < 0 || typeof activeIndex === 'undefined') activeIndex = 0;
|
|
978
|
+
}
|
|
979
|
+
return activeIndex;
|
|
980
|
+
}
|
|
981
|
+
function updateActiveIndex(newActiveIndex) {
|
|
982
|
+
const swiper = this;
|
|
983
|
+
const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
|
|
984
|
+
const {
|
|
985
|
+
snapGrid,
|
|
986
|
+
params,
|
|
987
|
+
activeIndex: previousIndex,
|
|
988
|
+
realIndex: previousRealIndex,
|
|
989
|
+
snapIndex: previousSnapIndex
|
|
990
|
+
} = swiper;
|
|
991
|
+
let activeIndex = newActiveIndex;
|
|
992
|
+
let snapIndex;
|
|
993
|
+
const getVirtualRealIndex = aIndex => {
|
|
994
|
+
let realIndex = aIndex - swiper.virtual.slidesBefore;
|
|
995
|
+
if (realIndex < 0) {
|
|
996
|
+
realIndex = swiper.virtual.slides.length + realIndex;
|
|
997
|
+
}
|
|
998
|
+
if (realIndex >= swiper.virtual.slides.length) {
|
|
999
|
+
realIndex -= swiper.virtual.slides.length;
|
|
1000
|
+
}
|
|
1001
|
+
return realIndex;
|
|
1002
|
+
};
|
|
1003
|
+
if (typeof activeIndex === 'undefined') {
|
|
1004
|
+
activeIndex = getActiveIndexByTranslate(swiper);
|
|
1005
|
+
}
|
|
1006
|
+
if (snapGrid.indexOf(translate) >= 0) {
|
|
1007
|
+
snapIndex = snapGrid.indexOf(translate);
|
|
1008
|
+
} else {
|
|
1009
|
+
const skip = Math.min(params.slidesPerGroupSkip, activeIndex);
|
|
1010
|
+
snapIndex = skip + Math.floor((activeIndex - skip) / params.slidesPerGroup);
|
|
1011
|
+
}
|
|
1012
|
+
if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;
|
|
1013
|
+
if (activeIndex === previousIndex && !swiper.params.loop) {
|
|
1014
|
+
if (snapIndex !== previousSnapIndex) {
|
|
1015
|
+
swiper.snapIndex = snapIndex;
|
|
1016
|
+
swiper.emit('snapIndexChange');
|
|
1017
|
+
}
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
if (activeIndex === previousIndex && swiper.params.loop && swiper.virtual && swiper.params.virtual.enabled) {
|
|
1021
|
+
swiper.realIndex = getVirtualRealIndex(activeIndex);
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
|
|
1025
|
+
|
|
1026
|
+
// Get real index
|
|
1027
|
+
let realIndex;
|
|
1028
|
+
if (swiper.virtual && params.virtual.enabled && params.loop) {
|
|
1029
|
+
realIndex = getVirtualRealIndex(activeIndex);
|
|
1030
|
+
} else if (gridEnabled) {
|
|
1031
|
+
const firstSlideInColumn = swiper.slides.find(slideEl => slideEl.column === activeIndex);
|
|
1032
|
+
let activeSlideIndex = parseInt(firstSlideInColumn.getAttribute('data-swiper-slide-index'), 10);
|
|
1033
|
+
if (Number.isNaN(activeSlideIndex)) {
|
|
1034
|
+
activeSlideIndex = Math.max(swiper.slides.indexOf(firstSlideInColumn), 0);
|
|
1035
|
+
}
|
|
1036
|
+
realIndex = Math.floor(activeSlideIndex / params.grid.rows);
|
|
1037
|
+
} else if (swiper.slides[activeIndex]) {
|
|
1038
|
+
const slideIndex = swiper.slides[activeIndex].getAttribute('data-swiper-slide-index');
|
|
1039
|
+
if (slideIndex) {
|
|
1040
|
+
realIndex = parseInt(slideIndex, 10);
|
|
1041
|
+
} else {
|
|
1042
|
+
realIndex = activeIndex;
|
|
1043
|
+
}
|
|
1044
|
+
} else {
|
|
1045
|
+
realIndex = activeIndex;
|
|
1046
|
+
}
|
|
1047
|
+
Object.assign(swiper, {
|
|
1048
|
+
previousSnapIndex,
|
|
1049
|
+
snapIndex,
|
|
1050
|
+
previousRealIndex,
|
|
1051
|
+
realIndex,
|
|
1052
|
+
previousIndex,
|
|
1053
|
+
activeIndex
|
|
1054
|
+
});
|
|
1055
|
+
if (swiper.initialized) {
|
|
1056
|
+
preload(swiper);
|
|
1057
|
+
}
|
|
1058
|
+
swiper.emit('activeIndexChange');
|
|
1059
|
+
swiper.emit('snapIndexChange');
|
|
1060
|
+
if (swiper.initialized || swiper.params.runCallbacksOnInit) {
|
|
1061
|
+
if (previousRealIndex !== realIndex) {
|
|
1062
|
+
swiper.emit('realIndexChange');
|
|
1063
|
+
}
|
|
1064
|
+
swiper.emit('slideChange');
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
function updateClickedSlide(el, path) {
|
|
1069
|
+
const swiper = this;
|
|
1070
|
+
const params = swiper.params;
|
|
1071
|
+
let slide = el.closest(`.${params.slideClass}, swiper-slide`);
|
|
1072
|
+
if (!slide && swiper.isElement && path && path.length > 1 && path.includes(el)) {
|
|
1073
|
+
[...path.slice(path.indexOf(el) + 1, path.length)].forEach(pathEl => {
|
|
1074
|
+
if (!slide && pathEl.matches && pathEl.matches(`.${params.slideClass}, swiper-slide`)) {
|
|
1075
|
+
slide = pathEl;
|
|
1076
|
+
}
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
let slideFound = false;
|
|
1080
|
+
let slideIndex;
|
|
1081
|
+
if (slide) {
|
|
1082
|
+
for (let i = 0; i < swiper.slides.length; i += 1) {
|
|
1083
|
+
if (swiper.slides[i] === slide) {
|
|
1084
|
+
slideFound = true;
|
|
1085
|
+
slideIndex = i;
|
|
1086
|
+
break;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
if (slide && slideFound) {
|
|
1091
|
+
swiper.clickedSlide = slide;
|
|
1092
|
+
if (swiper.virtual && swiper.params.virtual.enabled) {
|
|
1093
|
+
swiper.clickedIndex = parseInt(slide.getAttribute('data-swiper-slide-index'), 10);
|
|
1094
|
+
} else {
|
|
1095
|
+
swiper.clickedIndex = slideIndex;
|
|
1096
|
+
}
|
|
1097
|
+
} else {
|
|
1098
|
+
swiper.clickedSlide = undefined;
|
|
1099
|
+
swiper.clickedIndex = undefined;
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
if (params.slideToClickedSlide && swiper.clickedIndex !== undefined && swiper.clickedIndex !== swiper.activeIndex) {
|
|
1103
|
+
swiper.slideToClickedSlide();
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
var update = {
|
|
1108
|
+
updateSize,
|
|
1109
|
+
updateSlides,
|
|
1110
|
+
updateAutoHeight,
|
|
1111
|
+
updateSlidesOffset,
|
|
1112
|
+
updateSlidesProgress,
|
|
1113
|
+
updateProgress,
|
|
1114
|
+
updateSlidesClasses,
|
|
1115
|
+
updateActiveIndex,
|
|
1116
|
+
updateClickedSlide
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
function getSwiperTranslate(axis) {
|
|
1120
|
+
if (axis === void 0) {
|
|
1121
|
+
axis = this.isHorizontal() ? 'x' : 'y';
|
|
1122
|
+
}
|
|
1123
|
+
const swiper = this;
|
|
1124
|
+
const {
|
|
1125
|
+
params,
|
|
1126
|
+
rtlTranslate: rtl,
|
|
1127
|
+
translate,
|
|
1128
|
+
wrapperEl
|
|
1129
|
+
} = swiper;
|
|
1130
|
+
if (params.virtualTranslate) {
|
|
1131
|
+
return rtl ? -translate : translate;
|
|
1132
|
+
}
|
|
1133
|
+
if (params.cssMode) {
|
|
1134
|
+
return translate;
|
|
1135
|
+
}
|
|
1136
|
+
let currentTranslate = getTranslate(wrapperEl, axis);
|
|
1137
|
+
currentTranslate += swiper.cssOverflowAdjustment();
|
|
1138
|
+
if (rtl) currentTranslate = -currentTranslate;
|
|
1139
|
+
return currentTranslate || 0;
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
function setTranslate(translate, byController) {
|
|
1143
|
+
const swiper = this;
|
|
1144
|
+
const {
|
|
1145
|
+
rtlTranslate: rtl,
|
|
1146
|
+
params,
|
|
1147
|
+
wrapperEl,
|
|
1148
|
+
progress
|
|
1149
|
+
} = swiper;
|
|
1150
|
+
let x = 0;
|
|
1151
|
+
let y = 0;
|
|
1152
|
+
const z = 0;
|
|
1153
|
+
if (swiper.isHorizontal()) {
|
|
1154
|
+
x = rtl ? -translate : translate;
|
|
1155
|
+
} else {
|
|
1156
|
+
y = translate;
|
|
1157
|
+
}
|
|
1158
|
+
if (params.roundLengths) {
|
|
1159
|
+
x = Math.floor(x);
|
|
1160
|
+
y = Math.floor(y);
|
|
1161
|
+
}
|
|
1162
|
+
swiper.previousTranslate = swiper.translate;
|
|
1163
|
+
swiper.translate = swiper.isHorizontal() ? x : y;
|
|
1164
|
+
if (params.cssMode) {
|
|
1165
|
+
wrapperEl[swiper.isHorizontal() ? 'scrollLeft' : 'scrollTop'] = swiper.isHorizontal() ? -x : -y;
|
|
1166
|
+
} else if (!params.virtualTranslate) {
|
|
1167
|
+
if (swiper.isHorizontal()) {
|
|
1168
|
+
x -= swiper.cssOverflowAdjustment();
|
|
1169
|
+
} else {
|
|
1170
|
+
y -= swiper.cssOverflowAdjustment();
|
|
1171
|
+
}
|
|
1172
|
+
wrapperEl.style.transform = `translate3d(${x}px, ${y}px, ${z}px)`;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
// Check if we need to update progress
|
|
1176
|
+
let newProgress;
|
|
1177
|
+
const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
|
|
1178
|
+
if (translatesDiff === 0) {
|
|
1179
|
+
newProgress = 0;
|
|
1180
|
+
} else {
|
|
1181
|
+
newProgress = (translate - swiper.minTranslate()) / translatesDiff;
|
|
1182
|
+
}
|
|
1183
|
+
if (newProgress !== progress) {
|
|
1184
|
+
swiper.updateProgress(translate);
|
|
1185
|
+
}
|
|
1186
|
+
swiper.emit('setTranslate', swiper.translate, byController);
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
function minTranslate() {
|
|
1190
|
+
return -this.snapGrid[0];
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
function maxTranslate() {
|
|
1194
|
+
return -this.snapGrid[this.snapGrid.length - 1];
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
function translateTo(translate, speed, runCallbacks, translateBounds, internal) {
|
|
1198
|
+
if (translate === void 0) {
|
|
1199
|
+
translate = 0;
|
|
1200
|
+
}
|
|
1201
|
+
if (speed === void 0) {
|
|
1202
|
+
speed = this.params.speed;
|
|
1203
|
+
}
|
|
1204
|
+
if (runCallbacks === void 0) {
|
|
1205
|
+
runCallbacks = true;
|
|
1206
|
+
}
|
|
1207
|
+
if (translateBounds === void 0) {
|
|
1208
|
+
translateBounds = true;
|
|
1209
|
+
}
|
|
1210
|
+
const swiper = this;
|
|
1211
|
+
const {
|
|
1212
|
+
params,
|
|
1213
|
+
wrapperEl
|
|
1214
|
+
} = swiper;
|
|
1215
|
+
if (swiper.animating && params.preventInteractionOnTransition) {
|
|
1216
|
+
return false;
|
|
1217
|
+
}
|
|
1218
|
+
const minTranslate = swiper.minTranslate();
|
|
1219
|
+
const maxTranslate = swiper.maxTranslate();
|
|
1220
|
+
let newTranslate;
|
|
1221
|
+
if (translateBounds && translate > minTranslate) newTranslate = minTranslate;else if (translateBounds && translate < maxTranslate) newTranslate = maxTranslate;else newTranslate = translate;
|
|
1222
|
+
|
|
1223
|
+
// Update progress
|
|
1224
|
+
swiper.updateProgress(newTranslate);
|
|
1225
|
+
if (params.cssMode) {
|
|
1226
|
+
const isH = swiper.isHorizontal();
|
|
1227
|
+
if (speed === 0) {
|
|
1228
|
+
wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = -newTranslate;
|
|
1229
|
+
} else {
|
|
1230
|
+
if (!swiper.support.smoothScroll) {
|
|
1231
|
+
animateCSSModeScroll({
|
|
1232
|
+
swiper,
|
|
1233
|
+
targetPosition: -newTranslate,
|
|
1234
|
+
side: isH ? 'left' : 'top'
|
|
1235
|
+
});
|
|
1236
|
+
return true;
|
|
1237
|
+
}
|
|
1238
|
+
wrapperEl.scrollTo({
|
|
1239
|
+
[isH ? 'left' : 'top']: -newTranslate,
|
|
1240
|
+
behavior: 'smooth'
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
return true;
|
|
1244
|
+
}
|
|
1245
|
+
if (speed === 0) {
|
|
1246
|
+
swiper.setTransition(0);
|
|
1247
|
+
swiper.setTranslate(newTranslate);
|
|
1248
|
+
if (runCallbacks) {
|
|
1249
|
+
swiper.emit('beforeTransitionStart', speed, internal);
|
|
1250
|
+
swiper.emit('transitionEnd');
|
|
1251
|
+
}
|
|
1252
|
+
} else {
|
|
1253
|
+
swiper.setTransition(speed);
|
|
1254
|
+
swiper.setTranslate(newTranslate);
|
|
1255
|
+
if (runCallbacks) {
|
|
1256
|
+
swiper.emit('beforeTransitionStart', speed, internal);
|
|
1257
|
+
swiper.emit('transitionStart');
|
|
1258
|
+
}
|
|
1259
|
+
if (!swiper.animating) {
|
|
1260
|
+
swiper.animating = true;
|
|
1261
|
+
if (!swiper.onTranslateToWrapperTransitionEnd) {
|
|
1262
|
+
swiper.onTranslateToWrapperTransitionEnd = function transitionEnd(e) {
|
|
1263
|
+
if (!swiper || swiper.destroyed) return;
|
|
1264
|
+
if (e.target !== this) return;
|
|
1265
|
+
swiper.wrapperEl.removeEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd);
|
|
1266
|
+
swiper.onTranslateToWrapperTransitionEnd = null;
|
|
1267
|
+
delete swiper.onTranslateToWrapperTransitionEnd;
|
|
1268
|
+
swiper.animating = false;
|
|
1269
|
+
if (runCallbacks) {
|
|
1270
|
+
swiper.emit('transitionEnd');
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
swiper.wrapperEl.addEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd);
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
return true;
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
var translate = {
|
|
1281
|
+
getTranslate: getSwiperTranslate,
|
|
1282
|
+
setTranslate,
|
|
1283
|
+
minTranslate,
|
|
1284
|
+
maxTranslate,
|
|
1285
|
+
translateTo
|
|
1286
|
+
};
|
|
1287
|
+
|
|
1288
|
+
function setTransition(duration, byController) {
|
|
1289
|
+
const swiper = this;
|
|
1290
|
+
if (!swiper.params.cssMode) {
|
|
1291
|
+
swiper.wrapperEl.style.transitionDuration = `${duration}ms`;
|
|
1292
|
+
swiper.wrapperEl.style.transitionDelay = duration === 0 ? `0ms` : '';
|
|
1293
|
+
}
|
|
1294
|
+
swiper.emit('setTransition', duration, byController);
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
function transitionEmit(_ref) {
|
|
1298
|
+
let {
|
|
1299
|
+
swiper,
|
|
1300
|
+
runCallbacks,
|
|
1301
|
+
direction,
|
|
1302
|
+
step
|
|
1303
|
+
} = _ref;
|
|
1304
|
+
const {
|
|
1305
|
+
activeIndex,
|
|
1306
|
+
previousIndex
|
|
1307
|
+
} = swiper;
|
|
1308
|
+
let dir = direction;
|
|
1309
|
+
if (!dir) {
|
|
1310
|
+
if (activeIndex > previousIndex) dir = 'next';else if (activeIndex < previousIndex) dir = 'prev';else dir = 'reset';
|
|
1311
|
+
}
|
|
1312
|
+
swiper.emit(`transition${step}`);
|
|
1313
|
+
if (runCallbacks && dir === 'reset') {
|
|
1314
|
+
swiper.emit(`slideResetTransition${step}`);
|
|
1315
|
+
} else if (runCallbacks && activeIndex !== previousIndex) {
|
|
1316
|
+
swiper.emit(`slideChangeTransition${step}`);
|
|
1317
|
+
if (dir === 'next') {
|
|
1318
|
+
swiper.emit(`slideNextTransition${step}`);
|
|
1319
|
+
} else {
|
|
1320
|
+
swiper.emit(`slidePrevTransition${step}`);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
function transitionStart(runCallbacks, direction) {
|
|
1326
|
+
if (runCallbacks === void 0) {
|
|
1327
|
+
runCallbacks = true;
|
|
1328
|
+
}
|
|
1329
|
+
const swiper = this;
|
|
1330
|
+
const {
|
|
1331
|
+
params
|
|
1332
|
+
} = swiper;
|
|
1333
|
+
if (params.cssMode) return;
|
|
1334
|
+
if (params.autoHeight) {
|
|
1335
|
+
swiper.updateAutoHeight();
|
|
1336
|
+
}
|
|
1337
|
+
transitionEmit({
|
|
1338
|
+
swiper,
|
|
1339
|
+
runCallbacks,
|
|
1340
|
+
direction,
|
|
1341
|
+
step: 'Start'
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
function transitionEnd(runCallbacks, direction) {
|
|
1346
|
+
if (runCallbacks === void 0) {
|
|
1347
|
+
runCallbacks = true;
|
|
1348
|
+
}
|
|
1349
|
+
const swiper = this;
|
|
1350
|
+
const {
|
|
1351
|
+
params
|
|
1352
|
+
} = swiper;
|
|
1353
|
+
swiper.animating = false;
|
|
1354
|
+
if (params.cssMode) return;
|
|
1355
|
+
swiper.setTransition(0);
|
|
1356
|
+
transitionEmit({
|
|
1357
|
+
swiper,
|
|
1358
|
+
runCallbacks,
|
|
1359
|
+
direction,
|
|
1360
|
+
step: 'End'
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
var transition = {
|
|
1365
|
+
setTransition,
|
|
1366
|
+
transitionStart,
|
|
1367
|
+
transitionEnd
|
|
1368
|
+
};
|
|
1369
|
+
|
|
1370
|
+
function slideTo(index, speed, runCallbacks, internal, initial) {
|
|
1371
|
+
if (index === void 0) {
|
|
1372
|
+
index = 0;
|
|
1373
|
+
}
|
|
1374
|
+
if (runCallbacks === void 0) {
|
|
1375
|
+
runCallbacks = true;
|
|
1376
|
+
}
|
|
1377
|
+
if (typeof index === 'string') {
|
|
1378
|
+
index = parseInt(index, 10);
|
|
1379
|
+
}
|
|
1380
|
+
const swiper = this;
|
|
1381
|
+
let slideIndex = index;
|
|
1382
|
+
if (slideIndex < 0) slideIndex = 0;
|
|
1383
|
+
const {
|
|
1384
|
+
params,
|
|
1385
|
+
snapGrid,
|
|
1386
|
+
slidesGrid,
|
|
1387
|
+
previousIndex,
|
|
1388
|
+
activeIndex,
|
|
1389
|
+
rtlTranslate: rtl,
|
|
1390
|
+
wrapperEl,
|
|
1391
|
+
enabled
|
|
1392
|
+
} = swiper;
|
|
1393
|
+
if (!enabled && !internal && !initial || swiper.destroyed || swiper.animating && params.preventInteractionOnTransition) {
|
|
1394
|
+
return false;
|
|
1395
|
+
}
|
|
1396
|
+
if (typeof speed === 'undefined') {
|
|
1397
|
+
speed = swiper.params.speed;
|
|
1398
|
+
}
|
|
1399
|
+
const skip = Math.min(swiper.params.slidesPerGroupSkip, slideIndex);
|
|
1400
|
+
let snapIndex = skip + Math.floor((slideIndex - skip) / swiper.params.slidesPerGroup);
|
|
1401
|
+
if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;
|
|
1402
|
+
const translate = -snapGrid[snapIndex];
|
|
1403
|
+
// Normalize slideIndex
|
|
1404
|
+
if (params.normalizeSlideIndex) {
|
|
1405
|
+
for (let i = 0; i < slidesGrid.length; i += 1) {
|
|
1406
|
+
const normalizedTranslate = -Math.floor(translate * 100);
|
|
1407
|
+
const normalizedGrid = Math.floor(slidesGrid[i] * 100);
|
|
1408
|
+
const normalizedGridNext = Math.floor(slidesGrid[i + 1] * 100);
|
|
1409
|
+
if (typeof slidesGrid[i + 1] !== 'undefined') {
|
|
1410
|
+
if (normalizedTranslate >= normalizedGrid && normalizedTranslate < normalizedGridNext - (normalizedGridNext - normalizedGrid) / 2) {
|
|
1411
|
+
slideIndex = i;
|
|
1412
|
+
} else if (normalizedTranslate >= normalizedGrid && normalizedTranslate < normalizedGridNext) {
|
|
1413
|
+
slideIndex = i + 1;
|
|
1414
|
+
}
|
|
1415
|
+
} else if (normalizedTranslate >= normalizedGrid) {
|
|
1416
|
+
slideIndex = i;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
// Directions locks
|
|
1421
|
+
if (swiper.initialized && slideIndex !== activeIndex) {
|
|
1422
|
+
if (!swiper.allowSlideNext && (rtl ? translate > swiper.translate && translate > swiper.minTranslate() : translate < swiper.translate && translate < swiper.minTranslate())) {
|
|
1423
|
+
return false;
|
|
1424
|
+
}
|
|
1425
|
+
if (!swiper.allowSlidePrev && translate > swiper.translate && translate > swiper.maxTranslate()) {
|
|
1426
|
+
if ((activeIndex || 0) !== slideIndex) {
|
|
1427
|
+
return false;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
if (slideIndex !== (previousIndex || 0) && runCallbacks) {
|
|
1432
|
+
swiper.emit('beforeSlideChangeStart');
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
// Update progress
|
|
1436
|
+
swiper.updateProgress(translate);
|
|
1437
|
+
let direction;
|
|
1438
|
+
if (slideIndex > activeIndex) direction = 'next';else if (slideIndex < activeIndex) direction = 'prev';else direction = 'reset';
|
|
1439
|
+
|
|
1440
|
+
// initial virtual
|
|
1441
|
+
const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
|
|
1442
|
+
const isInitialVirtual = isVirtual && initial;
|
|
1443
|
+
// Update Index
|
|
1444
|
+
if (!isInitialVirtual && (rtl && -translate === swiper.translate || !rtl && translate === swiper.translate)) {
|
|
1445
|
+
swiper.updateActiveIndex(slideIndex);
|
|
1446
|
+
// Update Height
|
|
1447
|
+
if (params.autoHeight) {
|
|
1448
|
+
swiper.updateAutoHeight();
|
|
1449
|
+
}
|
|
1450
|
+
swiper.updateSlidesClasses();
|
|
1451
|
+
if (params.effect !== 'slide') {
|
|
1452
|
+
swiper.setTranslate(translate);
|
|
1453
|
+
}
|
|
1454
|
+
if (direction !== 'reset') {
|
|
1455
|
+
swiper.transitionStart(runCallbacks, direction);
|
|
1456
|
+
swiper.transitionEnd(runCallbacks, direction);
|
|
1457
|
+
}
|
|
1458
|
+
return false;
|
|
1459
|
+
}
|
|
1460
|
+
if (params.cssMode) {
|
|
1461
|
+
const isH = swiper.isHorizontal();
|
|
1462
|
+
const t = rtl ? translate : -translate;
|
|
1463
|
+
if (speed === 0) {
|
|
1464
|
+
if (isVirtual) {
|
|
1465
|
+
swiper.wrapperEl.style.scrollSnapType = 'none';
|
|
1466
|
+
swiper._immediateVirtual = true;
|
|
1467
|
+
}
|
|
1468
|
+
if (isVirtual && !swiper._cssModeVirtualInitialSet && swiper.params.initialSlide > 0) {
|
|
1469
|
+
swiper._cssModeVirtualInitialSet = true;
|
|
1470
|
+
requestAnimationFrame(() => {
|
|
1471
|
+
wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = t;
|
|
1472
|
+
});
|
|
1473
|
+
} else {
|
|
1474
|
+
wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = t;
|
|
1475
|
+
}
|
|
1476
|
+
if (isVirtual) {
|
|
1477
|
+
requestAnimationFrame(() => {
|
|
1478
|
+
swiper.wrapperEl.style.scrollSnapType = '';
|
|
1479
|
+
swiper._immediateVirtual = false;
|
|
1480
|
+
});
|
|
1481
|
+
}
|
|
1482
|
+
} else {
|
|
1483
|
+
if (!swiper.support.smoothScroll) {
|
|
1484
|
+
animateCSSModeScroll({
|
|
1485
|
+
swiper,
|
|
1486
|
+
targetPosition: t,
|
|
1487
|
+
side: isH ? 'left' : 'top'
|
|
1488
|
+
});
|
|
1489
|
+
return true;
|
|
1490
|
+
}
|
|
1491
|
+
wrapperEl.scrollTo({
|
|
1492
|
+
[isH ? 'left' : 'top']: t,
|
|
1493
|
+
behavior: 'smooth'
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
return true;
|
|
1497
|
+
}
|
|
1498
|
+
const browser = getBrowser();
|
|
1499
|
+
const isSafari = browser.isSafari;
|
|
1500
|
+
if (isVirtual && !initial && isSafari && swiper.isElement) {
|
|
1501
|
+
swiper.virtual.update(false, false, slideIndex);
|
|
1502
|
+
}
|
|
1503
|
+
swiper.setTransition(speed);
|
|
1504
|
+
swiper.setTranslate(translate);
|
|
1505
|
+
swiper.updateActiveIndex(slideIndex);
|
|
1506
|
+
swiper.updateSlidesClasses();
|
|
1507
|
+
swiper.emit('beforeTransitionStart', speed, internal);
|
|
1508
|
+
swiper.transitionStart(runCallbacks, direction);
|
|
1509
|
+
if (speed === 0) {
|
|
1510
|
+
swiper.transitionEnd(runCallbacks, direction);
|
|
1511
|
+
} else if (!swiper.animating) {
|
|
1512
|
+
swiper.animating = true;
|
|
1513
|
+
if (!swiper.onSlideToWrapperTransitionEnd) {
|
|
1514
|
+
swiper.onSlideToWrapperTransitionEnd = function transitionEnd(e) {
|
|
1515
|
+
if (!swiper || swiper.destroyed) return;
|
|
1516
|
+
if (e.target !== this) return;
|
|
1517
|
+
swiper.wrapperEl.removeEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
|
|
1518
|
+
swiper.onSlideToWrapperTransitionEnd = null;
|
|
1519
|
+
delete swiper.onSlideToWrapperTransitionEnd;
|
|
1520
|
+
swiper.transitionEnd(runCallbacks, direction);
|
|
1521
|
+
};
|
|
1522
|
+
}
|
|
1523
|
+
swiper.wrapperEl.addEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
|
|
1524
|
+
}
|
|
1525
|
+
return true;
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
function slideToLoop(index, speed, runCallbacks, internal) {
|
|
1529
|
+
if (index === void 0) {
|
|
1530
|
+
index = 0;
|
|
1531
|
+
}
|
|
1532
|
+
if (runCallbacks === void 0) {
|
|
1533
|
+
runCallbacks = true;
|
|
1534
|
+
}
|
|
1535
|
+
if (typeof index === 'string') {
|
|
1536
|
+
const indexAsNumber = parseInt(index, 10);
|
|
1537
|
+
index = indexAsNumber;
|
|
1538
|
+
}
|
|
1539
|
+
const swiper = this;
|
|
1540
|
+
if (swiper.destroyed) return;
|
|
1541
|
+
if (typeof speed === 'undefined') {
|
|
1542
|
+
speed = swiper.params.speed;
|
|
1543
|
+
}
|
|
1544
|
+
const gridEnabled = swiper.grid && swiper.params.grid && swiper.params.grid.rows > 1;
|
|
1545
|
+
let newIndex = index;
|
|
1546
|
+
if (swiper.params.loop) {
|
|
1547
|
+
if (swiper.virtual && swiper.params.virtual.enabled) {
|
|
1548
|
+
// eslint-disable-next-line
|
|
1549
|
+
newIndex = newIndex + swiper.virtual.slidesBefore;
|
|
1550
|
+
} else {
|
|
1551
|
+
let targetSlideIndex;
|
|
1552
|
+
if (gridEnabled) {
|
|
1553
|
+
const slideIndex = newIndex * swiper.params.grid.rows;
|
|
1554
|
+
targetSlideIndex = swiper.slides.find(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === slideIndex).column;
|
|
1555
|
+
} else {
|
|
1556
|
+
targetSlideIndex = swiper.getSlideIndexByData(newIndex);
|
|
1557
|
+
}
|
|
1558
|
+
const cols = gridEnabled ? Math.ceil(swiper.slides.length / swiper.params.grid.rows) : swiper.slides.length;
|
|
1559
|
+
const {
|
|
1560
|
+
centeredSlides
|
|
1561
|
+
} = swiper.params;
|
|
1562
|
+
let slidesPerView = swiper.params.slidesPerView;
|
|
1563
|
+
if (slidesPerView === 'auto') {
|
|
1564
|
+
slidesPerView = swiper.slidesPerViewDynamic();
|
|
1565
|
+
} else {
|
|
1566
|
+
slidesPerView = Math.ceil(parseFloat(swiper.params.slidesPerView, 10));
|
|
1567
|
+
if (centeredSlides && slidesPerView % 2 === 0) {
|
|
1568
|
+
slidesPerView = slidesPerView + 1;
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
let needLoopFix = cols - targetSlideIndex < slidesPerView;
|
|
1572
|
+
if (centeredSlides) {
|
|
1573
|
+
needLoopFix = needLoopFix || targetSlideIndex < Math.ceil(slidesPerView / 2);
|
|
1574
|
+
}
|
|
1575
|
+
if (internal && centeredSlides && swiper.params.slidesPerView !== 'auto' && !gridEnabled) {
|
|
1576
|
+
needLoopFix = false;
|
|
1577
|
+
}
|
|
1578
|
+
if (needLoopFix) {
|
|
1579
|
+
const direction = centeredSlides ? targetSlideIndex < swiper.activeIndex ? 'prev' : 'next' : targetSlideIndex - swiper.activeIndex - 1 < swiper.params.slidesPerView ? 'next' : 'prev';
|
|
1580
|
+
swiper.loopFix({
|
|
1581
|
+
direction,
|
|
1582
|
+
slideTo: true,
|
|
1583
|
+
activeSlideIndex: direction === 'next' ? targetSlideIndex + 1 : targetSlideIndex - cols + 1,
|
|
1584
|
+
slideRealIndex: direction === 'next' ? swiper.realIndex : undefined
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
if (gridEnabled) {
|
|
1588
|
+
const slideIndex = newIndex * swiper.params.grid.rows;
|
|
1589
|
+
newIndex = swiper.slides.find(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === slideIndex).column;
|
|
1590
|
+
} else {
|
|
1591
|
+
newIndex = swiper.getSlideIndexByData(newIndex);
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
requestAnimationFrame(() => {
|
|
1596
|
+
swiper.slideTo(newIndex, speed, runCallbacks, internal);
|
|
1597
|
+
});
|
|
1598
|
+
return swiper;
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
/* eslint no-unused-vars: "off" */
|
|
1602
|
+
function slideNext(speed, runCallbacks, internal) {
|
|
1603
|
+
if (runCallbacks === void 0) {
|
|
1604
|
+
runCallbacks = true;
|
|
1605
|
+
}
|
|
1606
|
+
const swiper = this;
|
|
1607
|
+
const {
|
|
1608
|
+
enabled,
|
|
1609
|
+
params,
|
|
1610
|
+
animating
|
|
1611
|
+
} = swiper;
|
|
1612
|
+
if (!enabled || swiper.destroyed) return swiper;
|
|
1613
|
+
if (typeof speed === 'undefined') {
|
|
1614
|
+
speed = swiper.params.speed;
|
|
1615
|
+
}
|
|
1616
|
+
let perGroup = params.slidesPerGroup;
|
|
1617
|
+
if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
|
|
1618
|
+
perGroup = Math.max(swiper.slidesPerViewDynamic('current', true), 1);
|
|
1619
|
+
}
|
|
1620
|
+
const increment = swiper.activeIndex < params.slidesPerGroupSkip ? 1 : perGroup;
|
|
1621
|
+
const isVirtual = swiper.virtual && params.virtual.enabled;
|
|
1622
|
+
if (params.loop) {
|
|
1623
|
+
if (animating && !isVirtual && params.loopPreventsSliding) return false;
|
|
1624
|
+
|
|
1625
|
+
// Check if loop is disabled
|
|
1626
|
+
const currentSlidesPerView = params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(parseFloat(params.slidesPerView, 10));
|
|
1627
|
+
if (swiper.slides.length >= currentSlidesPerView) {
|
|
1628
|
+
swiper.loopFix({
|
|
1629
|
+
direction: 'next'
|
|
1630
|
+
});
|
|
1631
|
+
// eslint-disable-next-line
|
|
1632
|
+
swiper._clientLeft = swiper.wrapperEl.clientLeft;
|
|
1633
|
+
}
|
|
1634
|
+
if (swiper.activeIndex === swiper.slides.length - 1 && params.cssMode) {
|
|
1635
|
+
requestAnimationFrame(() => {
|
|
1636
|
+
swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal);
|
|
1637
|
+
});
|
|
1638
|
+
return true;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
if (params.rewind && swiper.isEnd) {
|
|
1642
|
+
return swiper.slideTo(0, speed, runCallbacks, internal);
|
|
1643
|
+
}
|
|
1644
|
+
return swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal);
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
/* eslint no-unused-vars: "off" */
|
|
1648
|
+
function slidePrev(speed, runCallbacks, internal) {
|
|
1649
|
+
if (runCallbacks === void 0) {
|
|
1650
|
+
runCallbacks = true;
|
|
1651
|
+
}
|
|
1652
|
+
const swiper = this;
|
|
1653
|
+
const {
|
|
1654
|
+
params,
|
|
1655
|
+
snapGrid,
|
|
1656
|
+
slidesGrid,
|
|
1657
|
+
rtlTranslate,
|
|
1658
|
+
enabled,
|
|
1659
|
+
animating
|
|
1660
|
+
} = swiper;
|
|
1661
|
+
if (!enabled || swiper.destroyed) return swiper;
|
|
1662
|
+
if (typeof speed === 'undefined') {
|
|
1663
|
+
speed = swiper.params.speed;
|
|
1664
|
+
}
|
|
1665
|
+
const isVirtual = swiper.virtual && params.virtual.enabled;
|
|
1666
|
+
if (params.loop) {
|
|
1667
|
+
if (animating && !isVirtual && params.loopPreventsSliding) return false;
|
|
1668
|
+
|
|
1669
|
+
// Check if loop is disabled
|
|
1670
|
+
const currentSlidesPerView = params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(parseFloat(params.slidesPerView, 10));
|
|
1671
|
+
if (swiper.slides.length >= currentSlidesPerView) {
|
|
1672
|
+
swiper.loopFix({
|
|
1673
|
+
direction: 'prev'
|
|
1674
|
+
});
|
|
1675
|
+
// eslint-disable-next-line
|
|
1676
|
+
swiper._clientLeft = swiper.wrapperEl.clientLeft;
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
const translate = rtlTranslate ? swiper.translate : -swiper.translate;
|
|
1680
|
+
function normalize(val) {
|
|
1681
|
+
if (val < 0) return -Math.floor(Math.abs(val));
|
|
1682
|
+
return Math.floor(val);
|
|
1683
|
+
}
|
|
1684
|
+
const normalizedTranslate = normalize(translate);
|
|
1685
|
+
const normalizedSnapGrid = snapGrid.map(val => normalize(val));
|
|
1686
|
+
const isFreeMode = params.freeMode && params.freeMode.enabled;
|
|
1687
|
+
let prevSnap = snapGrid[normalizedSnapGrid.indexOf(normalizedTranslate) - 1];
|
|
1688
|
+
if (typeof prevSnap === 'undefined' && (params.cssMode || isFreeMode)) {
|
|
1689
|
+
let prevSnapIndex;
|
|
1690
|
+
snapGrid.forEach((snap, snapIndex) => {
|
|
1691
|
+
if (normalizedTranslate >= snap) {
|
|
1692
|
+
// prevSnap = snap;
|
|
1693
|
+
prevSnapIndex = snapIndex;
|
|
1694
|
+
}
|
|
1695
|
+
});
|
|
1696
|
+
if (typeof prevSnapIndex !== 'undefined') {
|
|
1697
|
+
prevSnap = isFreeMode ? snapGrid[prevSnapIndex] : snapGrid[prevSnapIndex > 0 ? prevSnapIndex - 1 : prevSnapIndex];
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
let prevIndex = 0;
|
|
1701
|
+
if (typeof prevSnap !== 'undefined') {
|
|
1702
|
+
prevIndex = slidesGrid.indexOf(prevSnap);
|
|
1703
|
+
if (prevIndex < 0) prevIndex = swiper.activeIndex - 1;
|
|
1704
|
+
if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
|
|
1705
|
+
prevIndex = prevIndex - swiper.slidesPerViewDynamic('previous', true) + 1;
|
|
1706
|
+
prevIndex = Math.max(prevIndex, 0);
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
if (params.rewind && swiper.isBeginning) {
|
|
1710
|
+
const lastIndex = swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1;
|
|
1711
|
+
return swiper.slideTo(lastIndex, speed, runCallbacks, internal);
|
|
1712
|
+
} else if (params.loop && swiper.activeIndex === 0 && params.cssMode) {
|
|
1713
|
+
requestAnimationFrame(() => {
|
|
1714
|
+
swiper.slideTo(prevIndex, speed, runCallbacks, internal);
|
|
1715
|
+
});
|
|
1716
|
+
return true;
|
|
1717
|
+
}
|
|
1718
|
+
return swiper.slideTo(prevIndex, speed, runCallbacks, internal);
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
/* eslint no-unused-vars: "off" */
|
|
1722
|
+
function slideReset(speed, runCallbacks, internal) {
|
|
1723
|
+
if (runCallbacks === void 0) {
|
|
1724
|
+
runCallbacks = true;
|
|
1725
|
+
}
|
|
1726
|
+
const swiper = this;
|
|
1727
|
+
if (swiper.destroyed) return;
|
|
1728
|
+
if (typeof speed === 'undefined') {
|
|
1729
|
+
speed = swiper.params.speed;
|
|
1730
|
+
}
|
|
1731
|
+
return swiper.slideTo(swiper.activeIndex, speed, runCallbacks, internal);
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
/* eslint no-unused-vars: "off" */
|
|
1735
|
+
function slideToClosest(speed, runCallbacks, internal, threshold) {
|
|
1736
|
+
if (runCallbacks === void 0) {
|
|
1737
|
+
runCallbacks = true;
|
|
1738
|
+
}
|
|
1739
|
+
if (threshold === void 0) {
|
|
1740
|
+
threshold = 0.5;
|
|
1741
|
+
}
|
|
1742
|
+
const swiper = this;
|
|
1743
|
+
if (swiper.destroyed) return;
|
|
1744
|
+
if (typeof speed === 'undefined') {
|
|
1745
|
+
speed = swiper.params.speed;
|
|
1746
|
+
}
|
|
1747
|
+
let index = swiper.activeIndex;
|
|
1748
|
+
const skip = Math.min(swiper.params.slidesPerGroupSkip, index);
|
|
1749
|
+
const snapIndex = skip + Math.floor((index - skip) / swiper.params.slidesPerGroup);
|
|
1750
|
+
const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
|
|
1751
|
+
if (translate >= swiper.snapGrid[snapIndex]) {
|
|
1752
|
+
// The current translate is on or after the current snap index, so the choice
|
|
1753
|
+
// is between the current index and the one after it.
|
|
1754
|
+
const currentSnap = swiper.snapGrid[snapIndex];
|
|
1755
|
+
const nextSnap = swiper.snapGrid[snapIndex + 1];
|
|
1756
|
+
if (translate - currentSnap > (nextSnap - currentSnap) * threshold) {
|
|
1757
|
+
index += swiper.params.slidesPerGroup;
|
|
1758
|
+
}
|
|
1759
|
+
} else {
|
|
1760
|
+
// The current translate is before the current snap index, so the choice
|
|
1761
|
+
// is between the current index and the one before it.
|
|
1762
|
+
const prevSnap = swiper.snapGrid[snapIndex - 1];
|
|
1763
|
+
const currentSnap = swiper.snapGrid[snapIndex];
|
|
1764
|
+
if (translate - prevSnap <= (currentSnap - prevSnap) * threshold) {
|
|
1765
|
+
index -= swiper.params.slidesPerGroup;
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
index = Math.max(index, 0);
|
|
1769
|
+
index = Math.min(index, swiper.slidesGrid.length - 1);
|
|
1770
|
+
return swiper.slideTo(index, speed, runCallbacks, internal);
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
function slideToClickedSlide() {
|
|
1774
|
+
const swiper = this;
|
|
1775
|
+
if (swiper.destroyed) return;
|
|
1776
|
+
const {
|
|
1777
|
+
params,
|
|
1778
|
+
slidesEl
|
|
1779
|
+
} = swiper;
|
|
1780
|
+
const slidesPerView = params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : params.slidesPerView;
|
|
1781
|
+
let slideToIndex = swiper.getSlideIndexWhenGrid(swiper.clickedIndex);
|
|
1782
|
+
let realIndex;
|
|
1783
|
+
const slideSelector = swiper.isElement ? `swiper-slide` : `.${params.slideClass}`;
|
|
1784
|
+
const isGrid = swiper.grid && swiper.params.grid && swiper.params.grid.rows > 1;
|
|
1785
|
+
if (params.loop) {
|
|
1786
|
+
if (swiper.animating) return;
|
|
1787
|
+
realIndex = parseInt(swiper.clickedSlide.getAttribute('data-swiper-slide-index'), 10);
|
|
1788
|
+
if (params.centeredSlides) {
|
|
1789
|
+
swiper.slideToLoop(realIndex);
|
|
1790
|
+
} else if (slideToIndex > (isGrid ? (swiper.slides.length - slidesPerView) / 2 - (swiper.params.grid.rows - 1) : swiper.slides.length - slidesPerView)) {
|
|
1791
|
+
swiper.loopFix();
|
|
1792
|
+
slideToIndex = swiper.getSlideIndex(elementChildren(slidesEl, `${slideSelector}[data-swiper-slide-index="${realIndex}"]`)[0]);
|
|
1793
|
+
nextTick(() => {
|
|
1794
|
+
swiper.slideTo(slideToIndex);
|
|
1795
|
+
});
|
|
1796
|
+
} else {
|
|
1797
|
+
swiper.slideTo(slideToIndex);
|
|
1798
|
+
}
|
|
1799
|
+
} else {
|
|
1800
|
+
swiper.slideTo(slideToIndex);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
var slide = {
|
|
1805
|
+
slideTo,
|
|
1806
|
+
slideToLoop,
|
|
1807
|
+
slideNext,
|
|
1808
|
+
slidePrev,
|
|
1809
|
+
slideReset,
|
|
1810
|
+
slideToClosest,
|
|
1811
|
+
slideToClickedSlide
|
|
1812
|
+
};
|
|
1813
|
+
|
|
1814
|
+
function loopCreate(slideRealIndex, initial) {
|
|
1815
|
+
const swiper = this;
|
|
1816
|
+
const {
|
|
1817
|
+
params,
|
|
1818
|
+
slidesEl
|
|
1819
|
+
} = swiper;
|
|
1820
|
+
if (!params.loop || swiper.virtual && swiper.params.virtual.enabled) return;
|
|
1821
|
+
const initSlides = () => {
|
|
1822
|
+
const slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`);
|
|
1823
|
+
slides.forEach((el, index) => {
|
|
1824
|
+
el.setAttribute('data-swiper-slide-index', index);
|
|
1825
|
+
});
|
|
1826
|
+
};
|
|
1827
|
+
const clearBlankSlides = () => {
|
|
1828
|
+
const slides = elementChildren(slidesEl, `.${params.slideBlankClass}`);
|
|
1829
|
+
slides.forEach(el => {
|
|
1830
|
+
el.remove();
|
|
1831
|
+
});
|
|
1832
|
+
if (slides.length > 0) {
|
|
1833
|
+
swiper.recalcSlides();
|
|
1834
|
+
swiper.updateSlides();
|
|
1835
|
+
}
|
|
1836
|
+
};
|
|
1837
|
+
const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
|
|
1838
|
+
if (params.loopAddBlankSlides && (params.slidesPerGroup > 1 || gridEnabled)) {
|
|
1839
|
+
clearBlankSlides();
|
|
1840
|
+
}
|
|
1841
|
+
const slidesPerGroup = params.slidesPerGroup * (gridEnabled ? params.grid.rows : 1);
|
|
1842
|
+
const shouldFillGroup = swiper.slides.length % slidesPerGroup !== 0;
|
|
1843
|
+
const shouldFillGrid = gridEnabled && swiper.slides.length % params.grid.rows !== 0;
|
|
1844
|
+
const addBlankSlides = amountOfSlides => {
|
|
1845
|
+
for (let i = 0; i < amountOfSlides; i += 1) {
|
|
1846
|
+
const slideEl = swiper.isElement ? createElement('swiper-slide', [params.slideBlankClass]) : createElement('div', [params.slideClass, params.slideBlankClass]);
|
|
1847
|
+
swiper.slidesEl.append(slideEl);
|
|
1848
|
+
}
|
|
1849
|
+
};
|
|
1850
|
+
if (shouldFillGroup) {
|
|
1851
|
+
if (params.loopAddBlankSlides) {
|
|
1852
|
+
const slidesToAdd = slidesPerGroup - swiper.slides.length % slidesPerGroup;
|
|
1853
|
+
addBlankSlides(slidesToAdd);
|
|
1854
|
+
swiper.recalcSlides();
|
|
1855
|
+
swiper.updateSlides();
|
|
1856
|
+
} else {
|
|
1857
|
+
showWarning('Swiper Loop Warning: The number of slides is not even to slidesPerGroup, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)');
|
|
1858
|
+
}
|
|
1859
|
+
initSlides();
|
|
1860
|
+
} else if (shouldFillGrid) {
|
|
1861
|
+
if (params.loopAddBlankSlides) {
|
|
1862
|
+
const slidesToAdd = params.grid.rows - swiper.slides.length % params.grid.rows;
|
|
1863
|
+
addBlankSlides(slidesToAdd);
|
|
1864
|
+
swiper.recalcSlides();
|
|
1865
|
+
swiper.updateSlides();
|
|
1866
|
+
} else {
|
|
1867
|
+
showWarning('Swiper Loop Warning: The number of slides is not even to grid.rows, loop mode may not function properly. You need to add more slides (or make duplicates, or empty slides)');
|
|
1868
|
+
}
|
|
1869
|
+
initSlides();
|
|
1870
|
+
} else {
|
|
1871
|
+
initSlides();
|
|
1872
|
+
}
|
|
1873
|
+
swiper.loopFix({
|
|
1874
|
+
slideRealIndex,
|
|
1875
|
+
direction: params.centeredSlides ? undefined : 'next',
|
|
1876
|
+
initial
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
function loopFix(_temp) {
|
|
1881
|
+
let {
|
|
1882
|
+
slideRealIndex,
|
|
1883
|
+
slideTo = true,
|
|
1884
|
+
direction,
|
|
1885
|
+
setTranslate,
|
|
1886
|
+
activeSlideIndex,
|
|
1887
|
+
initial,
|
|
1888
|
+
byController,
|
|
1889
|
+
byMousewheel
|
|
1890
|
+
} = _temp === void 0 ? {} : _temp;
|
|
1891
|
+
const swiper = this;
|
|
1892
|
+
if (!swiper.params.loop) return;
|
|
1893
|
+
|
|
1894
|
+
// Disable loop mode if the number of slides is less than slidesPerView
|
|
1895
|
+
const currentSlidesPerView = swiper.params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(parseFloat(swiper.params.slidesPerView, 10));
|
|
1896
|
+
if (swiper.slides.length < currentSlidesPerView) {
|
|
1897
|
+
console.warn('Swiper: Loop mode disabled - slides.length < slidesPerView');
|
|
1898
|
+
return;
|
|
1899
|
+
}
|
|
1900
|
+
swiper.emit('beforeLoopFix');
|
|
1901
|
+
const {
|
|
1902
|
+
slides,
|
|
1903
|
+
allowSlidePrev,
|
|
1904
|
+
allowSlideNext,
|
|
1905
|
+
slidesEl,
|
|
1906
|
+
params
|
|
1907
|
+
} = swiper;
|
|
1908
|
+
const {
|
|
1909
|
+
centeredSlides,
|
|
1910
|
+
initialSlide
|
|
1911
|
+
} = params;
|
|
1912
|
+
swiper.allowSlidePrev = true;
|
|
1913
|
+
swiper.allowSlideNext = true;
|
|
1914
|
+
if (swiper.virtual && params.virtual.enabled) {
|
|
1915
|
+
if (slideTo) {
|
|
1916
|
+
if (!params.centeredSlides && swiper.snapIndex === 0) {
|
|
1917
|
+
swiper.slideTo(swiper.virtual.slides.length, 0, false, true);
|
|
1918
|
+
} else if (params.centeredSlides && swiper.snapIndex < params.slidesPerView) {
|
|
1919
|
+
swiper.slideTo(swiper.virtual.slides.length + swiper.snapIndex, 0, false, true);
|
|
1920
|
+
} else if (swiper.snapIndex === swiper.snapGrid.length - 1) {
|
|
1921
|
+
swiper.slideTo(swiper.virtual.slidesBefore, 0, false, true);
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
swiper.allowSlidePrev = allowSlidePrev;
|
|
1925
|
+
swiper.allowSlideNext = allowSlideNext;
|
|
1926
|
+
swiper.emit('loopFix');
|
|
1927
|
+
return;
|
|
1928
|
+
}
|
|
1929
|
+
let slidesPerView = params.slidesPerView;
|
|
1930
|
+
if (slidesPerView === 'auto') {
|
|
1931
|
+
slidesPerView = swiper.slidesPerViewDynamic();
|
|
1932
|
+
} else {
|
|
1933
|
+
slidesPerView = Math.ceil(parseFloat(params.slidesPerView, 10));
|
|
1934
|
+
if (centeredSlides && slidesPerView % 2 === 0) {
|
|
1935
|
+
slidesPerView = slidesPerView + 1;
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
const slidesPerGroup = params.slidesPerGroupAuto ? slidesPerView : params.slidesPerGroup;
|
|
1939
|
+
let loopedSlides = centeredSlides ? Math.max(slidesPerGroup, Math.ceil(slidesPerView / 2)) : slidesPerGroup;
|
|
1940
|
+
if (loopedSlides % slidesPerGroup !== 0) {
|
|
1941
|
+
loopedSlides += slidesPerGroup - loopedSlides % slidesPerGroup;
|
|
1942
|
+
}
|
|
1943
|
+
loopedSlides += params.loopAdditionalSlides;
|
|
1944
|
+
swiper.loopedSlides = loopedSlides;
|
|
1945
|
+
const gridEnabled = swiper.grid && params.grid && params.grid.rows > 1;
|
|
1946
|
+
if (slides.length < slidesPerView + loopedSlides || swiper.params.effect === 'cards' && slides.length < slidesPerView + loopedSlides * 2) {
|
|
1947
|
+
showWarning('Swiper Loop Warning: The number of slides is not enough for loop mode, it will be disabled or not function properly. You need to add more slides (or make duplicates) or lower the values of slidesPerView and slidesPerGroup parameters');
|
|
1948
|
+
} else if (gridEnabled && params.grid.fill === 'row') {
|
|
1949
|
+
showWarning('Swiper Loop Warning: Loop mode is not compatible with grid.fill = `row`');
|
|
1950
|
+
}
|
|
1951
|
+
const prependSlidesIndexes = [];
|
|
1952
|
+
const appendSlidesIndexes = [];
|
|
1953
|
+
const cols = gridEnabled ? Math.ceil(slides.length / params.grid.rows) : slides.length;
|
|
1954
|
+
const isInitialOverflow = initial && cols - initialSlide < slidesPerView && !centeredSlides;
|
|
1955
|
+
let activeIndex = isInitialOverflow ? initialSlide : swiper.activeIndex;
|
|
1956
|
+
if (typeof activeSlideIndex === 'undefined') {
|
|
1957
|
+
activeSlideIndex = swiper.getSlideIndex(slides.find(el => el.classList.contains(params.slideActiveClass)));
|
|
1958
|
+
} else {
|
|
1959
|
+
activeIndex = activeSlideIndex;
|
|
1960
|
+
}
|
|
1961
|
+
const isNext = direction === 'next' || !direction;
|
|
1962
|
+
const isPrev = direction === 'prev' || !direction;
|
|
1963
|
+
let slidesPrepended = 0;
|
|
1964
|
+
let slidesAppended = 0;
|
|
1965
|
+
const activeColIndex = gridEnabled ? slides[activeSlideIndex].column : activeSlideIndex;
|
|
1966
|
+
const activeColIndexWithShift = activeColIndex + (centeredSlides && typeof setTranslate === 'undefined' ? -slidesPerView / 2 + 0.5 : 0);
|
|
1967
|
+
// prepend last slides before start
|
|
1968
|
+
if (activeColIndexWithShift < loopedSlides) {
|
|
1969
|
+
slidesPrepended = Math.max(loopedSlides - activeColIndexWithShift, slidesPerGroup);
|
|
1970
|
+
for (let i = 0; i < loopedSlides - activeColIndexWithShift; i += 1) {
|
|
1971
|
+
const index = i - Math.floor(i / cols) * cols;
|
|
1972
|
+
if (gridEnabled) {
|
|
1973
|
+
const colIndexToPrepend = cols - index - 1;
|
|
1974
|
+
for (let i = slides.length - 1; i >= 0; i -= 1) {
|
|
1975
|
+
if (slides[i].column === colIndexToPrepend) prependSlidesIndexes.push(i);
|
|
1976
|
+
}
|
|
1977
|
+
// slides.forEach((slide, slideIndex) => {
|
|
1978
|
+
// if (slide.column === colIndexToPrepend) prependSlidesIndexes.push(slideIndex);
|
|
1979
|
+
// });
|
|
1980
|
+
} else {
|
|
1981
|
+
prependSlidesIndexes.push(cols - index - 1);
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
} else if (activeColIndexWithShift + slidesPerView > cols - loopedSlides) {
|
|
1985
|
+
slidesAppended = Math.max(activeColIndexWithShift - (cols - loopedSlides * 2), slidesPerGroup);
|
|
1986
|
+
if (isInitialOverflow) {
|
|
1987
|
+
slidesAppended = Math.max(slidesAppended, slidesPerView - cols + initialSlide + 1);
|
|
1988
|
+
}
|
|
1989
|
+
for (let i = 0; i < slidesAppended; i += 1) {
|
|
1990
|
+
const index = i - Math.floor(i / cols) * cols;
|
|
1991
|
+
if (gridEnabled) {
|
|
1992
|
+
slides.forEach((slide, slideIndex) => {
|
|
1993
|
+
if (slide.column === index) appendSlidesIndexes.push(slideIndex);
|
|
1994
|
+
});
|
|
1995
|
+
} else {
|
|
1996
|
+
appendSlidesIndexes.push(index);
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
swiper.__preventObserver__ = true;
|
|
2001
|
+
requestAnimationFrame(() => {
|
|
2002
|
+
swiper.__preventObserver__ = false;
|
|
2003
|
+
});
|
|
2004
|
+
if (swiper.params.effect === 'cards' && slides.length < slidesPerView + loopedSlides * 2) {
|
|
2005
|
+
if (appendSlidesIndexes.includes(activeSlideIndex)) {
|
|
2006
|
+
appendSlidesIndexes.splice(appendSlidesIndexes.indexOf(activeSlideIndex), 1);
|
|
2007
|
+
}
|
|
2008
|
+
if (prependSlidesIndexes.includes(activeSlideIndex)) {
|
|
2009
|
+
prependSlidesIndexes.splice(prependSlidesIndexes.indexOf(activeSlideIndex), 1);
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
if (isPrev) {
|
|
2013
|
+
prependSlidesIndexes.forEach(index => {
|
|
2014
|
+
slides[index].swiperLoopMoveDOM = true;
|
|
2015
|
+
slidesEl.prepend(slides[index]);
|
|
2016
|
+
slides[index].swiperLoopMoveDOM = false;
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
2019
|
+
if (isNext) {
|
|
2020
|
+
appendSlidesIndexes.forEach(index => {
|
|
2021
|
+
slides[index].swiperLoopMoveDOM = true;
|
|
2022
|
+
slidesEl.append(slides[index]);
|
|
2023
|
+
slides[index].swiperLoopMoveDOM = false;
|
|
2024
|
+
});
|
|
2025
|
+
}
|
|
2026
|
+
swiper.recalcSlides();
|
|
2027
|
+
if (params.slidesPerView === 'auto') {
|
|
2028
|
+
swiper.updateSlides();
|
|
2029
|
+
} else if (gridEnabled && (prependSlidesIndexes.length > 0 && isPrev || appendSlidesIndexes.length > 0 && isNext)) {
|
|
2030
|
+
swiper.slides.forEach((slide, slideIndex) => {
|
|
2031
|
+
swiper.grid.updateSlide(slideIndex, slide, swiper.slides);
|
|
2032
|
+
});
|
|
2033
|
+
}
|
|
2034
|
+
if (params.watchSlidesProgress) {
|
|
2035
|
+
swiper.updateSlidesOffset();
|
|
2036
|
+
}
|
|
2037
|
+
if (slideTo) {
|
|
2038
|
+
if (prependSlidesIndexes.length > 0 && isPrev) {
|
|
2039
|
+
if (typeof slideRealIndex === 'undefined') {
|
|
2040
|
+
const currentSlideTranslate = swiper.slidesGrid[activeIndex];
|
|
2041
|
+
const newSlideTranslate = swiper.slidesGrid[activeIndex + slidesPrepended];
|
|
2042
|
+
const diff = newSlideTranslate - currentSlideTranslate;
|
|
2043
|
+
if (byMousewheel) {
|
|
2044
|
+
swiper.setTranslate(swiper.translate - diff);
|
|
2045
|
+
} else {
|
|
2046
|
+
swiper.slideTo(activeIndex + Math.ceil(slidesPrepended), 0, false, true);
|
|
2047
|
+
if (setTranslate) {
|
|
2048
|
+
swiper.touchEventsData.startTranslate = swiper.touchEventsData.startTranslate - diff;
|
|
2049
|
+
swiper.touchEventsData.currentTranslate = swiper.touchEventsData.currentTranslate - diff;
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
} else {
|
|
2053
|
+
if (setTranslate) {
|
|
2054
|
+
const shift = gridEnabled ? prependSlidesIndexes.length / params.grid.rows : prependSlidesIndexes.length;
|
|
2055
|
+
swiper.slideTo(swiper.activeIndex + shift, 0, false, true);
|
|
2056
|
+
swiper.touchEventsData.currentTranslate = swiper.translate;
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
} else if (appendSlidesIndexes.length > 0 && isNext) {
|
|
2060
|
+
if (typeof slideRealIndex === 'undefined') {
|
|
2061
|
+
const currentSlideTranslate = swiper.slidesGrid[activeIndex];
|
|
2062
|
+
const newSlideTranslate = swiper.slidesGrid[activeIndex - slidesAppended];
|
|
2063
|
+
const diff = newSlideTranslate - currentSlideTranslate;
|
|
2064
|
+
if (byMousewheel) {
|
|
2065
|
+
swiper.setTranslate(swiper.translate - diff);
|
|
2066
|
+
} else {
|
|
2067
|
+
swiper.slideTo(activeIndex - slidesAppended, 0, false, true);
|
|
2068
|
+
if (setTranslate) {
|
|
2069
|
+
swiper.touchEventsData.startTranslate = swiper.touchEventsData.startTranslate - diff;
|
|
2070
|
+
swiper.touchEventsData.currentTranslate = swiper.touchEventsData.currentTranslate - diff;
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
} else {
|
|
2074
|
+
const shift = gridEnabled ? appendSlidesIndexes.length / params.grid.rows : appendSlidesIndexes.length;
|
|
2075
|
+
swiper.slideTo(swiper.activeIndex - shift, 0, false, true);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
swiper.allowSlidePrev = allowSlidePrev;
|
|
2080
|
+
swiper.allowSlideNext = allowSlideNext;
|
|
2081
|
+
if (swiper.controller && swiper.controller.control && !byController) {
|
|
2082
|
+
const loopParams = {
|
|
2083
|
+
slideRealIndex,
|
|
2084
|
+
direction,
|
|
2085
|
+
setTranslate,
|
|
2086
|
+
activeSlideIndex,
|
|
2087
|
+
byController: true
|
|
2088
|
+
};
|
|
2089
|
+
if (Array.isArray(swiper.controller.control)) {
|
|
2090
|
+
swiper.controller.control.forEach(c => {
|
|
2091
|
+
if (!c.destroyed && c.params.loop) c.loopFix({
|
|
2092
|
+
...loopParams,
|
|
2093
|
+
slideTo: c.params.slidesPerView === params.slidesPerView ? slideTo : false
|
|
2094
|
+
});
|
|
2095
|
+
});
|
|
2096
|
+
} else if (swiper.controller.control instanceof swiper.constructor && swiper.controller.control.params.loop) {
|
|
2097
|
+
swiper.controller.control.loopFix({
|
|
2098
|
+
...loopParams,
|
|
2099
|
+
slideTo: swiper.controller.control.params.slidesPerView === params.slidesPerView ? slideTo : false
|
|
2100
|
+
});
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
swiper.emit('loopFix');
|
|
2104
|
+
}
|
|
2105
|
+
|
|
2106
|
+
function loopDestroy() {
|
|
2107
|
+
const swiper = this;
|
|
2108
|
+
const {
|
|
2109
|
+
params,
|
|
2110
|
+
slidesEl
|
|
2111
|
+
} = swiper;
|
|
2112
|
+
if (!params.loop || !slidesEl || swiper.virtual && swiper.params.virtual.enabled) return;
|
|
2113
|
+
swiper.recalcSlides();
|
|
2114
|
+
const newSlidesOrder = [];
|
|
2115
|
+
swiper.slides.forEach(slideEl => {
|
|
2116
|
+
const index = typeof slideEl.swiperSlideIndex === 'undefined' ? slideEl.getAttribute('data-swiper-slide-index') * 1 : slideEl.swiperSlideIndex;
|
|
2117
|
+
newSlidesOrder[index] = slideEl;
|
|
2118
|
+
});
|
|
2119
|
+
swiper.slides.forEach(slideEl => {
|
|
2120
|
+
slideEl.removeAttribute('data-swiper-slide-index');
|
|
2121
|
+
});
|
|
2122
|
+
newSlidesOrder.forEach(slideEl => {
|
|
2123
|
+
slidesEl.append(slideEl);
|
|
2124
|
+
});
|
|
2125
|
+
swiper.recalcSlides();
|
|
2126
|
+
swiper.slideTo(swiper.realIndex, 0);
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
var loop = {
|
|
2130
|
+
loopCreate,
|
|
2131
|
+
loopFix,
|
|
2132
|
+
loopDestroy
|
|
2133
|
+
};
|
|
2134
|
+
|
|
2135
|
+
function setGrabCursor(moving) {
|
|
2136
|
+
const swiper = this;
|
|
2137
|
+
if (!swiper.params.simulateTouch || swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) return;
|
|
2138
|
+
const el = swiper.params.touchEventsTarget === 'container' ? swiper.el : swiper.wrapperEl;
|
|
2139
|
+
if (swiper.isElement) {
|
|
2140
|
+
swiper.__preventObserver__ = true;
|
|
2141
|
+
}
|
|
2142
|
+
el.style.cursor = 'move';
|
|
2143
|
+
el.style.cursor = moving ? 'grabbing' : 'grab';
|
|
2144
|
+
if (swiper.isElement) {
|
|
2145
|
+
requestAnimationFrame(() => {
|
|
2146
|
+
swiper.__preventObserver__ = false;
|
|
2147
|
+
});
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
function unsetGrabCursor() {
|
|
2152
|
+
const swiper = this;
|
|
2153
|
+
if (swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) {
|
|
2154
|
+
return;
|
|
2155
|
+
}
|
|
2156
|
+
if (swiper.isElement) {
|
|
2157
|
+
swiper.__preventObserver__ = true;
|
|
2158
|
+
}
|
|
2159
|
+
swiper[swiper.params.touchEventsTarget === 'container' ? 'el' : 'wrapperEl'].style.cursor = '';
|
|
2160
|
+
if (swiper.isElement) {
|
|
2161
|
+
requestAnimationFrame(() => {
|
|
2162
|
+
swiper.__preventObserver__ = false;
|
|
2163
|
+
});
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
var grabCursor = {
|
|
2168
|
+
setGrabCursor,
|
|
2169
|
+
unsetGrabCursor
|
|
2170
|
+
};
|
|
2171
|
+
|
|
2172
|
+
// Modified from https://stackoverflow.com/questions/54520554/custom-element-getrootnode-closest-function-crossing-multiple-parent-shadowd
|
|
2173
|
+
function closestElement(selector, base) {
|
|
2174
|
+
if (base === void 0) {
|
|
2175
|
+
base = this;
|
|
2176
|
+
}
|
|
2177
|
+
function __closestFrom(el) {
|
|
2178
|
+
if (!el || el === getDocument() || el === getWindow()) return null;
|
|
2179
|
+
if (el.assignedSlot) el = el.assignedSlot;
|
|
2180
|
+
const found = el.closest(selector);
|
|
2181
|
+
if (!found && !el.getRootNode) {
|
|
2182
|
+
return null;
|
|
2183
|
+
}
|
|
2184
|
+
return found || __closestFrom(el.getRootNode().host);
|
|
2185
|
+
}
|
|
2186
|
+
return __closestFrom(base);
|
|
2187
|
+
}
|
|
2188
|
+
function preventEdgeSwipe(swiper, event, startX) {
|
|
2189
|
+
const window = getWindow();
|
|
2190
|
+
const {
|
|
2191
|
+
params
|
|
2192
|
+
} = swiper;
|
|
2193
|
+
const edgeSwipeDetection = params.edgeSwipeDetection;
|
|
2194
|
+
const edgeSwipeThreshold = params.edgeSwipeThreshold;
|
|
2195
|
+
if (edgeSwipeDetection && (startX <= edgeSwipeThreshold || startX >= window.innerWidth - edgeSwipeThreshold)) {
|
|
2196
|
+
if (edgeSwipeDetection === 'prevent') {
|
|
2197
|
+
event.preventDefault();
|
|
2198
|
+
return true;
|
|
2199
|
+
}
|
|
2200
|
+
return false;
|
|
2201
|
+
}
|
|
2202
|
+
return true;
|
|
2203
|
+
}
|
|
2204
|
+
function onTouchStart(event) {
|
|
2205
|
+
const swiper = this;
|
|
2206
|
+
const document = getDocument();
|
|
2207
|
+
let e = event;
|
|
2208
|
+
if (e.originalEvent) e = e.originalEvent;
|
|
2209
|
+
const data = swiper.touchEventsData;
|
|
2210
|
+
if (e.type === 'pointerdown') {
|
|
2211
|
+
if (data.pointerId !== null && data.pointerId !== e.pointerId) {
|
|
2212
|
+
return;
|
|
2213
|
+
}
|
|
2214
|
+
data.pointerId = e.pointerId;
|
|
2215
|
+
} else if (e.type === 'touchstart' && e.targetTouches.length === 1) {
|
|
2216
|
+
data.touchId = e.targetTouches[0].identifier;
|
|
2217
|
+
}
|
|
2218
|
+
if (e.type === 'touchstart') {
|
|
2219
|
+
// don't proceed touch event
|
|
2220
|
+
preventEdgeSwipe(swiper, e, e.targetTouches[0].pageX);
|
|
2221
|
+
return;
|
|
2222
|
+
}
|
|
2223
|
+
const {
|
|
2224
|
+
params,
|
|
2225
|
+
touches,
|
|
2226
|
+
enabled
|
|
2227
|
+
} = swiper;
|
|
2228
|
+
if (!enabled) return;
|
|
2229
|
+
if (!params.simulateTouch && e.pointerType === 'mouse') return;
|
|
2230
|
+
if (swiper.animating && params.preventInteractionOnTransition) {
|
|
2231
|
+
return;
|
|
2232
|
+
}
|
|
2233
|
+
if (!swiper.animating && params.cssMode && params.loop) {
|
|
2234
|
+
swiper.loopFix();
|
|
2235
|
+
}
|
|
2236
|
+
let targetEl = e.target;
|
|
2237
|
+
if (params.touchEventsTarget === 'wrapper') {
|
|
2238
|
+
if (!elementIsChildOf(targetEl, swiper.wrapperEl)) return;
|
|
2239
|
+
}
|
|
2240
|
+
if ('which' in e && e.which === 3) return;
|
|
2241
|
+
if ('button' in e && e.button > 0) return;
|
|
2242
|
+
if (data.isTouched && data.isMoved) return;
|
|
2243
|
+
|
|
2244
|
+
// change target el for shadow root component
|
|
2245
|
+
const swipingClassHasValue = !!params.noSwipingClass && params.noSwipingClass !== '';
|
|
2246
|
+
// eslint-disable-next-line
|
|
2247
|
+
const eventPath = e.composedPath ? e.composedPath() : e.path;
|
|
2248
|
+
if (swipingClassHasValue && e.target && e.target.shadowRoot && eventPath) {
|
|
2249
|
+
targetEl = eventPath[0];
|
|
2250
|
+
}
|
|
2251
|
+
const noSwipingSelector = params.noSwipingSelector ? params.noSwipingSelector : `.${params.noSwipingClass}`;
|
|
2252
|
+
const isTargetShadow = !!(e.target && e.target.shadowRoot);
|
|
2253
|
+
|
|
2254
|
+
// use closestElement for shadow root element to get the actual closest for nested shadow root element
|
|
2255
|
+
if (params.noSwiping && (isTargetShadow ? closestElement(noSwipingSelector, targetEl) : targetEl.closest(noSwipingSelector))) {
|
|
2256
|
+
swiper.allowClick = true;
|
|
2257
|
+
return;
|
|
2258
|
+
}
|
|
2259
|
+
if (params.swipeHandler) {
|
|
2260
|
+
if (!targetEl.closest(params.swipeHandler)) return;
|
|
2261
|
+
}
|
|
2262
|
+
touches.currentX = e.pageX;
|
|
2263
|
+
touches.currentY = e.pageY;
|
|
2264
|
+
const startX = touches.currentX;
|
|
2265
|
+
const startY = touches.currentY;
|
|
2266
|
+
|
|
2267
|
+
// Do NOT start if iOS edge swipe is detected. Otherwise iOS app cannot swipe-to-go-back anymore
|
|
2268
|
+
|
|
2269
|
+
if (!preventEdgeSwipe(swiper, e, startX)) {
|
|
2270
|
+
return;
|
|
2271
|
+
}
|
|
2272
|
+
Object.assign(data, {
|
|
2273
|
+
isTouched: true,
|
|
2274
|
+
isMoved: false,
|
|
2275
|
+
allowTouchCallbacks: true,
|
|
2276
|
+
isScrolling: undefined,
|
|
2277
|
+
startMoving: undefined
|
|
2278
|
+
});
|
|
2279
|
+
touches.startX = startX;
|
|
2280
|
+
touches.startY = startY;
|
|
2281
|
+
data.touchStartTime = now();
|
|
2282
|
+
swiper.allowClick = true;
|
|
2283
|
+
swiper.updateSize();
|
|
2284
|
+
swiper.swipeDirection = undefined;
|
|
2285
|
+
if (params.threshold > 0) data.allowThresholdMove = false;
|
|
2286
|
+
let preventDefault = true;
|
|
2287
|
+
if (targetEl.matches(data.focusableElements)) {
|
|
2288
|
+
preventDefault = false;
|
|
2289
|
+
if (targetEl.nodeName === 'SELECT') {
|
|
2290
|
+
data.isTouched = false;
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
if (document.activeElement && document.activeElement.matches(data.focusableElements) && document.activeElement !== targetEl && (e.pointerType === 'mouse' || e.pointerType !== 'mouse' && !targetEl.matches(data.focusableElements))) {
|
|
2294
|
+
document.activeElement.blur();
|
|
2295
|
+
}
|
|
2296
|
+
const shouldPreventDefault = preventDefault && swiper.allowTouchMove && params.touchStartPreventDefault;
|
|
2297
|
+
if ((params.touchStartForcePreventDefault || shouldPreventDefault) && !targetEl.isContentEditable) {
|
|
2298
|
+
e.preventDefault();
|
|
2299
|
+
}
|
|
2300
|
+
if (params.freeMode && params.freeMode.enabled && swiper.freeMode && swiper.animating && !params.cssMode) {
|
|
2301
|
+
swiper.freeMode.onTouchStart();
|
|
2302
|
+
}
|
|
2303
|
+
swiper.emit('touchStart', e);
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
function onTouchMove(event) {
|
|
2307
|
+
const document = getDocument();
|
|
2308
|
+
const swiper = this;
|
|
2309
|
+
const data = swiper.touchEventsData;
|
|
2310
|
+
const {
|
|
2311
|
+
params,
|
|
2312
|
+
touches,
|
|
2313
|
+
rtlTranslate: rtl,
|
|
2314
|
+
enabled
|
|
2315
|
+
} = swiper;
|
|
2316
|
+
if (!enabled) return;
|
|
2317
|
+
if (!params.simulateTouch && event.pointerType === 'mouse') return;
|
|
2318
|
+
let e = event;
|
|
2319
|
+
if (e.originalEvent) e = e.originalEvent;
|
|
2320
|
+
if (e.type === 'pointermove') {
|
|
2321
|
+
if (data.touchId !== null) return; // return from pointer if we use touch
|
|
2322
|
+
const id = e.pointerId;
|
|
2323
|
+
if (id !== data.pointerId) return;
|
|
2324
|
+
}
|
|
2325
|
+
let targetTouch;
|
|
2326
|
+
if (e.type === 'touchmove') {
|
|
2327
|
+
targetTouch = [...e.changedTouches].find(t => t.identifier === data.touchId);
|
|
2328
|
+
if (!targetTouch || targetTouch.identifier !== data.touchId) return;
|
|
2329
|
+
} else {
|
|
2330
|
+
targetTouch = e;
|
|
2331
|
+
}
|
|
2332
|
+
if (!data.isTouched) {
|
|
2333
|
+
if (data.startMoving && data.isScrolling) {
|
|
2334
|
+
swiper.emit('touchMoveOpposite', e);
|
|
2335
|
+
}
|
|
2336
|
+
return;
|
|
2337
|
+
}
|
|
2338
|
+
const pageX = targetTouch.pageX;
|
|
2339
|
+
const pageY = targetTouch.pageY;
|
|
2340
|
+
if (e.preventedByNestedSwiper) {
|
|
2341
|
+
touches.startX = pageX;
|
|
2342
|
+
touches.startY = pageY;
|
|
2343
|
+
return;
|
|
2344
|
+
}
|
|
2345
|
+
if (!swiper.allowTouchMove) {
|
|
2346
|
+
if (!e.target.matches(data.focusableElements)) {
|
|
2347
|
+
swiper.allowClick = false;
|
|
2348
|
+
}
|
|
2349
|
+
if (data.isTouched) {
|
|
2350
|
+
Object.assign(touches, {
|
|
2351
|
+
startX: pageX,
|
|
2352
|
+
startY: pageY,
|
|
2353
|
+
currentX: pageX,
|
|
2354
|
+
currentY: pageY
|
|
2355
|
+
});
|
|
2356
|
+
data.touchStartTime = now();
|
|
2357
|
+
}
|
|
2358
|
+
return;
|
|
2359
|
+
}
|
|
2360
|
+
if (params.touchReleaseOnEdges && !params.loop) {
|
|
2361
|
+
if (swiper.isVertical()) {
|
|
2362
|
+
// Vertical
|
|
2363
|
+
if (pageY < touches.startY && swiper.translate <= swiper.maxTranslate() || pageY > touches.startY && swiper.translate >= swiper.minTranslate()) {
|
|
2364
|
+
data.isTouched = false;
|
|
2365
|
+
data.isMoved = false;
|
|
2366
|
+
return;
|
|
2367
|
+
}
|
|
2368
|
+
} else if (rtl && (pageX > touches.startX && -swiper.translate <= swiper.maxTranslate() || pageX < touches.startX && -swiper.translate >= swiper.minTranslate())) {
|
|
2369
|
+
return;
|
|
2370
|
+
} else if (!rtl && (pageX < touches.startX && swiper.translate <= swiper.maxTranslate() || pageX > touches.startX && swiper.translate >= swiper.minTranslate())) {
|
|
2371
|
+
return;
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
if (document.activeElement && document.activeElement.matches(data.focusableElements) && document.activeElement !== e.target && e.pointerType !== 'mouse') {
|
|
2375
|
+
document.activeElement.blur();
|
|
2376
|
+
}
|
|
2377
|
+
if (document.activeElement) {
|
|
2378
|
+
if (e.target === document.activeElement && e.target.matches(data.focusableElements)) {
|
|
2379
|
+
data.isMoved = true;
|
|
2380
|
+
swiper.allowClick = false;
|
|
2381
|
+
return;
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
if (data.allowTouchCallbacks) {
|
|
2385
|
+
swiper.emit('touchMove', e);
|
|
2386
|
+
}
|
|
2387
|
+
touches.previousX = touches.currentX;
|
|
2388
|
+
touches.previousY = touches.currentY;
|
|
2389
|
+
touches.currentX = pageX;
|
|
2390
|
+
touches.currentY = pageY;
|
|
2391
|
+
const diffX = touches.currentX - touches.startX;
|
|
2392
|
+
const diffY = touches.currentY - touches.startY;
|
|
2393
|
+
if (swiper.params.threshold && Math.sqrt(diffX ** 2 + diffY ** 2) < swiper.params.threshold) return;
|
|
2394
|
+
if (typeof data.isScrolling === 'undefined') {
|
|
2395
|
+
let touchAngle;
|
|
2396
|
+
if (swiper.isHorizontal() && touches.currentY === touches.startY || swiper.isVertical() && touches.currentX === touches.startX) {
|
|
2397
|
+
data.isScrolling = false;
|
|
2398
|
+
} else {
|
|
2399
|
+
// eslint-disable-next-line
|
|
2400
|
+
if (diffX * diffX + diffY * diffY >= 25) {
|
|
2401
|
+
touchAngle = Math.atan2(Math.abs(diffY), Math.abs(diffX)) * 180 / Math.PI;
|
|
2402
|
+
data.isScrolling = swiper.isHorizontal() ? touchAngle > params.touchAngle : 90 - touchAngle > params.touchAngle;
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
if (data.isScrolling) {
|
|
2407
|
+
swiper.emit('touchMoveOpposite', e);
|
|
2408
|
+
}
|
|
2409
|
+
if (typeof data.startMoving === 'undefined') {
|
|
2410
|
+
if (touches.currentX !== touches.startX || touches.currentY !== touches.startY) {
|
|
2411
|
+
data.startMoving = true;
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
if (data.isScrolling || e.type === 'touchmove' && data.preventTouchMoveFromPointerMove) {
|
|
2415
|
+
data.isTouched = false;
|
|
2416
|
+
return;
|
|
2417
|
+
}
|
|
2418
|
+
if (!data.startMoving) {
|
|
2419
|
+
return;
|
|
2420
|
+
}
|
|
2421
|
+
swiper.allowClick = false;
|
|
2422
|
+
if (!params.cssMode && e.cancelable) {
|
|
2423
|
+
e.preventDefault();
|
|
2424
|
+
}
|
|
2425
|
+
if (params.touchMoveStopPropagation && !params.nested) {
|
|
2426
|
+
e.stopPropagation();
|
|
2427
|
+
}
|
|
2428
|
+
let diff = swiper.isHorizontal() ? diffX : diffY;
|
|
2429
|
+
let touchesDiff = swiper.isHorizontal() ? touches.currentX - touches.previousX : touches.currentY - touches.previousY;
|
|
2430
|
+
if (params.oneWayMovement) {
|
|
2431
|
+
diff = Math.abs(diff) * (rtl ? 1 : -1);
|
|
2432
|
+
touchesDiff = Math.abs(touchesDiff) * (rtl ? 1 : -1);
|
|
2433
|
+
}
|
|
2434
|
+
touches.diff = diff;
|
|
2435
|
+
diff *= params.touchRatio;
|
|
2436
|
+
if (rtl) {
|
|
2437
|
+
diff = -diff;
|
|
2438
|
+
touchesDiff = -touchesDiff;
|
|
2439
|
+
}
|
|
2440
|
+
const prevTouchesDirection = swiper.touchesDirection;
|
|
2441
|
+
swiper.swipeDirection = diff > 0 ? 'prev' : 'next';
|
|
2442
|
+
swiper.touchesDirection = touchesDiff > 0 ? 'prev' : 'next';
|
|
2443
|
+
const isLoop = swiper.params.loop && !params.cssMode;
|
|
2444
|
+
const allowLoopFix = swiper.touchesDirection === 'next' && swiper.allowSlideNext || swiper.touchesDirection === 'prev' && swiper.allowSlidePrev;
|
|
2445
|
+
if (!data.isMoved) {
|
|
2446
|
+
if (isLoop && allowLoopFix) {
|
|
2447
|
+
swiper.loopFix({
|
|
2448
|
+
direction: swiper.swipeDirection
|
|
2449
|
+
});
|
|
2450
|
+
}
|
|
2451
|
+
data.startTranslate = swiper.getTranslate();
|
|
2452
|
+
swiper.setTransition(0);
|
|
2453
|
+
if (swiper.animating) {
|
|
2454
|
+
const evt = new window.CustomEvent('transitionend', {
|
|
2455
|
+
bubbles: true,
|
|
2456
|
+
cancelable: true,
|
|
2457
|
+
detail: {
|
|
2458
|
+
bySwiperTouchMove: true
|
|
2459
|
+
}
|
|
2460
|
+
});
|
|
2461
|
+
swiper.wrapperEl.dispatchEvent(evt);
|
|
2462
|
+
}
|
|
2463
|
+
data.allowMomentumBounce = false;
|
|
2464
|
+
// Grab Cursor
|
|
2465
|
+
if (params.grabCursor && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
|
|
2466
|
+
swiper.setGrabCursor(true);
|
|
2467
|
+
}
|
|
2468
|
+
swiper.emit('sliderFirstMove', e);
|
|
2469
|
+
}
|
|
2470
|
+
let loopFixed;
|
|
2471
|
+
new Date().getTime();
|
|
2472
|
+
if (params._loopSwapReset !== false && data.isMoved && data.allowThresholdMove && prevTouchesDirection !== swiper.touchesDirection && isLoop && allowLoopFix && Math.abs(diff) >= 1) {
|
|
2473
|
+
Object.assign(touches, {
|
|
2474
|
+
startX: pageX,
|
|
2475
|
+
startY: pageY,
|
|
2476
|
+
currentX: pageX,
|
|
2477
|
+
currentY: pageY,
|
|
2478
|
+
startTranslate: data.currentTranslate
|
|
2479
|
+
});
|
|
2480
|
+
data.loopSwapReset = true;
|
|
2481
|
+
data.startTranslate = data.currentTranslate;
|
|
2482
|
+
return;
|
|
2483
|
+
}
|
|
2484
|
+
swiper.emit('sliderMove', e);
|
|
2485
|
+
data.isMoved = true;
|
|
2486
|
+
data.currentTranslate = diff + data.startTranslate;
|
|
2487
|
+
let disableParentSwiper = true;
|
|
2488
|
+
let resistanceRatio = params.resistanceRatio;
|
|
2489
|
+
if (params.touchReleaseOnEdges) {
|
|
2490
|
+
resistanceRatio = 0;
|
|
2491
|
+
}
|
|
2492
|
+
if (diff > 0) {
|
|
2493
|
+
if (isLoop && allowLoopFix && !loopFixed && data.allowThresholdMove && data.currentTranslate > (params.centeredSlides ? swiper.minTranslate() - swiper.slidesSizesGrid[swiper.activeIndex + 1] - (params.slidesPerView !== 'auto' && swiper.slides.length - params.slidesPerView >= 2 ? swiper.slidesSizesGrid[swiper.activeIndex + 1] + swiper.params.spaceBetween : 0) - swiper.params.spaceBetween : swiper.minTranslate())) {
|
|
2494
|
+
swiper.loopFix({
|
|
2495
|
+
direction: 'prev',
|
|
2496
|
+
setTranslate: true,
|
|
2497
|
+
activeSlideIndex: 0
|
|
2498
|
+
});
|
|
2499
|
+
}
|
|
2500
|
+
if (data.currentTranslate > swiper.minTranslate()) {
|
|
2501
|
+
disableParentSwiper = false;
|
|
2502
|
+
if (params.resistance) {
|
|
2503
|
+
data.currentTranslate = swiper.minTranslate() - 1 + (-swiper.minTranslate() + data.startTranslate + diff) ** resistanceRatio;
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
} else if (diff < 0) {
|
|
2507
|
+
if (isLoop && allowLoopFix && !loopFixed && data.allowThresholdMove && data.currentTranslate < (params.centeredSlides ? swiper.maxTranslate() + swiper.slidesSizesGrid[swiper.slidesSizesGrid.length - 1] + swiper.params.spaceBetween + (params.slidesPerView !== 'auto' && swiper.slides.length - params.slidesPerView >= 2 ? swiper.slidesSizesGrid[swiper.slidesSizesGrid.length - 1] + swiper.params.spaceBetween : 0) : swiper.maxTranslate())) {
|
|
2508
|
+
swiper.loopFix({
|
|
2509
|
+
direction: 'next',
|
|
2510
|
+
setTranslate: true,
|
|
2511
|
+
activeSlideIndex: swiper.slides.length - (params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : Math.ceil(parseFloat(params.slidesPerView, 10)))
|
|
2512
|
+
});
|
|
2513
|
+
}
|
|
2514
|
+
if (data.currentTranslate < swiper.maxTranslate()) {
|
|
2515
|
+
disableParentSwiper = false;
|
|
2516
|
+
if (params.resistance) {
|
|
2517
|
+
data.currentTranslate = swiper.maxTranslate() + 1 - (swiper.maxTranslate() - data.startTranslate - diff) ** resistanceRatio;
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
if (disableParentSwiper) {
|
|
2522
|
+
e.preventedByNestedSwiper = true;
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
// Directions locks
|
|
2526
|
+
if (!swiper.allowSlideNext && swiper.swipeDirection === 'next' && data.currentTranslate < data.startTranslate) {
|
|
2527
|
+
data.currentTranslate = data.startTranslate;
|
|
2528
|
+
}
|
|
2529
|
+
if (!swiper.allowSlidePrev && swiper.swipeDirection === 'prev' && data.currentTranslate > data.startTranslate) {
|
|
2530
|
+
data.currentTranslate = data.startTranslate;
|
|
2531
|
+
}
|
|
2532
|
+
if (!swiper.allowSlidePrev && !swiper.allowSlideNext) {
|
|
2533
|
+
data.currentTranslate = data.startTranslate;
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
// Threshold
|
|
2537
|
+
if (params.threshold > 0) {
|
|
2538
|
+
if (Math.abs(diff) > params.threshold || data.allowThresholdMove) {
|
|
2539
|
+
if (!data.allowThresholdMove) {
|
|
2540
|
+
data.allowThresholdMove = true;
|
|
2541
|
+
touches.startX = touches.currentX;
|
|
2542
|
+
touches.startY = touches.currentY;
|
|
2543
|
+
data.currentTranslate = data.startTranslate;
|
|
2544
|
+
touches.diff = swiper.isHorizontal() ? touches.currentX - touches.startX : touches.currentY - touches.startY;
|
|
2545
|
+
return;
|
|
2546
|
+
}
|
|
2547
|
+
} else {
|
|
2548
|
+
data.currentTranslate = data.startTranslate;
|
|
2549
|
+
return;
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
if (!params.followFinger || params.cssMode) return;
|
|
2553
|
+
|
|
2554
|
+
// Update active index in free mode
|
|
2555
|
+
if (params.freeMode && params.freeMode.enabled && swiper.freeMode || params.watchSlidesProgress) {
|
|
2556
|
+
swiper.updateActiveIndex();
|
|
2557
|
+
swiper.updateSlidesClasses();
|
|
2558
|
+
}
|
|
2559
|
+
if (params.freeMode && params.freeMode.enabled && swiper.freeMode) {
|
|
2560
|
+
swiper.freeMode.onTouchMove();
|
|
2561
|
+
}
|
|
2562
|
+
// Update progress
|
|
2563
|
+
swiper.updateProgress(data.currentTranslate);
|
|
2564
|
+
// Update translate
|
|
2565
|
+
swiper.setTranslate(data.currentTranslate);
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2568
|
+
function onTouchEnd(event) {
|
|
2569
|
+
const swiper = this;
|
|
2570
|
+
const data = swiper.touchEventsData;
|
|
2571
|
+
let e = event;
|
|
2572
|
+
if (e.originalEvent) e = e.originalEvent;
|
|
2573
|
+
let targetTouch;
|
|
2574
|
+
const isTouchEvent = e.type === 'touchend' || e.type === 'touchcancel';
|
|
2575
|
+
if (!isTouchEvent) {
|
|
2576
|
+
if (data.touchId !== null) return; // return from pointer if we use touch
|
|
2577
|
+
if (e.pointerId !== data.pointerId) return;
|
|
2578
|
+
targetTouch = e;
|
|
2579
|
+
} else {
|
|
2580
|
+
targetTouch = [...e.changedTouches].find(t => t.identifier === data.touchId);
|
|
2581
|
+
if (!targetTouch || targetTouch.identifier !== data.touchId) return;
|
|
2582
|
+
}
|
|
2583
|
+
if (['pointercancel', 'pointerout', 'pointerleave', 'contextmenu'].includes(e.type)) {
|
|
2584
|
+
const proceed = ['pointercancel', 'contextmenu'].includes(e.type) && (swiper.browser.isSafari || swiper.browser.isWebView);
|
|
2585
|
+
if (!proceed) {
|
|
2586
|
+
return;
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
data.pointerId = null;
|
|
2590
|
+
data.touchId = null;
|
|
2591
|
+
const {
|
|
2592
|
+
params,
|
|
2593
|
+
touches,
|
|
2594
|
+
rtlTranslate: rtl,
|
|
2595
|
+
slidesGrid,
|
|
2596
|
+
enabled
|
|
2597
|
+
} = swiper;
|
|
2598
|
+
if (!enabled) return;
|
|
2599
|
+
if (!params.simulateTouch && e.pointerType === 'mouse') return;
|
|
2600
|
+
if (data.allowTouchCallbacks) {
|
|
2601
|
+
swiper.emit('touchEnd', e);
|
|
2602
|
+
}
|
|
2603
|
+
data.allowTouchCallbacks = false;
|
|
2604
|
+
if (!data.isTouched) {
|
|
2605
|
+
if (data.isMoved && params.grabCursor) {
|
|
2606
|
+
swiper.setGrabCursor(false);
|
|
2607
|
+
}
|
|
2608
|
+
data.isMoved = false;
|
|
2609
|
+
data.startMoving = false;
|
|
2610
|
+
return;
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
// Return Grab Cursor
|
|
2614
|
+
if (params.grabCursor && data.isMoved && data.isTouched && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
|
|
2615
|
+
swiper.setGrabCursor(false);
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2618
|
+
// Time diff
|
|
2619
|
+
const touchEndTime = now();
|
|
2620
|
+
const timeDiff = touchEndTime - data.touchStartTime;
|
|
2621
|
+
|
|
2622
|
+
// Tap, doubleTap, Click
|
|
2623
|
+
if (swiper.allowClick) {
|
|
2624
|
+
const pathTree = e.path || e.composedPath && e.composedPath();
|
|
2625
|
+
swiper.updateClickedSlide(pathTree && pathTree[0] || e.target, pathTree);
|
|
2626
|
+
swiper.emit('tap click', e);
|
|
2627
|
+
if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) {
|
|
2628
|
+
swiper.emit('doubleTap doubleClick', e);
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
data.lastClickTime = now();
|
|
2632
|
+
nextTick(() => {
|
|
2633
|
+
if (!swiper.destroyed) swiper.allowClick = true;
|
|
2634
|
+
});
|
|
2635
|
+
if (!data.isTouched || !data.isMoved || !swiper.swipeDirection || touches.diff === 0 && !data.loopSwapReset || data.currentTranslate === data.startTranslate && !data.loopSwapReset) {
|
|
2636
|
+
data.isTouched = false;
|
|
2637
|
+
data.isMoved = false;
|
|
2638
|
+
data.startMoving = false;
|
|
2639
|
+
return;
|
|
2640
|
+
}
|
|
2641
|
+
data.isTouched = false;
|
|
2642
|
+
data.isMoved = false;
|
|
2643
|
+
data.startMoving = false;
|
|
2644
|
+
let currentPos;
|
|
2645
|
+
if (params.followFinger) {
|
|
2646
|
+
currentPos = rtl ? swiper.translate : -swiper.translate;
|
|
2647
|
+
} else {
|
|
2648
|
+
currentPos = -data.currentTranslate;
|
|
2649
|
+
}
|
|
2650
|
+
if (params.cssMode) {
|
|
2651
|
+
return;
|
|
2652
|
+
}
|
|
2653
|
+
if (params.freeMode && params.freeMode.enabled) {
|
|
2654
|
+
swiper.freeMode.onTouchEnd({
|
|
2655
|
+
currentPos
|
|
2656
|
+
});
|
|
2657
|
+
return;
|
|
2658
|
+
}
|
|
2659
|
+
|
|
2660
|
+
// Find current slide
|
|
2661
|
+
const swipeToLast = currentPos >= -swiper.maxTranslate() && !swiper.params.loop;
|
|
2662
|
+
let stopIndex = 0;
|
|
2663
|
+
let groupSize = swiper.slidesSizesGrid[0];
|
|
2664
|
+
for (let i = 0; i < slidesGrid.length; i += i < params.slidesPerGroupSkip ? 1 : params.slidesPerGroup) {
|
|
2665
|
+
const increment = i < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
|
|
2666
|
+
if (typeof slidesGrid[i + increment] !== 'undefined') {
|
|
2667
|
+
if (swipeToLast || currentPos >= slidesGrid[i] && currentPos < slidesGrid[i + increment]) {
|
|
2668
|
+
stopIndex = i;
|
|
2669
|
+
groupSize = slidesGrid[i + increment] - slidesGrid[i];
|
|
2670
|
+
}
|
|
2671
|
+
} else if (swipeToLast || currentPos >= slidesGrid[i]) {
|
|
2672
|
+
stopIndex = i;
|
|
2673
|
+
groupSize = slidesGrid[slidesGrid.length - 1] - slidesGrid[slidesGrid.length - 2];
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
let rewindFirstIndex = null;
|
|
2677
|
+
let rewindLastIndex = null;
|
|
2678
|
+
if (params.rewind) {
|
|
2679
|
+
if (swiper.isBeginning) {
|
|
2680
|
+
rewindLastIndex = params.virtual && params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1;
|
|
2681
|
+
} else if (swiper.isEnd) {
|
|
2682
|
+
rewindFirstIndex = 0;
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
// Find current slide size
|
|
2686
|
+
const ratio = (currentPos - slidesGrid[stopIndex]) / groupSize;
|
|
2687
|
+
const increment = stopIndex < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
|
|
2688
|
+
if (timeDiff > params.longSwipesMs) {
|
|
2689
|
+
// Long touches
|
|
2690
|
+
if (!params.longSwipes) {
|
|
2691
|
+
swiper.slideTo(swiper.activeIndex);
|
|
2692
|
+
return;
|
|
2693
|
+
}
|
|
2694
|
+
if (swiper.swipeDirection === 'next') {
|
|
2695
|
+
if (ratio >= params.longSwipesRatio) swiper.slideTo(params.rewind && swiper.isEnd ? rewindFirstIndex : stopIndex + increment);else swiper.slideTo(stopIndex);
|
|
2696
|
+
}
|
|
2697
|
+
if (swiper.swipeDirection === 'prev') {
|
|
2698
|
+
if (ratio > 1 - params.longSwipesRatio) {
|
|
2699
|
+
swiper.slideTo(stopIndex + increment);
|
|
2700
|
+
} else if (rewindLastIndex !== null && ratio < 0 && Math.abs(ratio) > params.longSwipesRatio) {
|
|
2701
|
+
swiper.slideTo(rewindLastIndex);
|
|
2702
|
+
} else {
|
|
2703
|
+
swiper.slideTo(stopIndex);
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
} else {
|
|
2707
|
+
// Short swipes
|
|
2708
|
+
if (!params.shortSwipes) {
|
|
2709
|
+
swiper.slideTo(swiper.activeIndex);
|
|
2710
|
+
return;
|
|
2711
|
+
}
|
|
2712
|
+
const isNavButtonTarget = swiper.navigation && (e.target === swiper.navigation.nextEl || e.target === swiper.navigation.prevEl);
|
|
2713
|
+
if (!isNavButtonTarget) {
|
|
2714
|
+
if (swiper.swipeDirection === 'next') {
|
|
2715
|
+
swiper.slideTo(rewindFirstIndex !== null ? rewindFirstIndex : stopIndex + increment);
|
|
2716
|
+
}
|
|
2717
|
+
if (swiper.swipeDirection === 'prev') {
|
|
2718
|
+
swiper.slideTo(rewindLastIndex !== null ? rewindLastIndex : stopIndex);
|
|
2719
|
+
}
|
|
2720
|
+
} else if (e.target === swiper.navigation.nextEl) {
|
|
2721
|
+
swiper.slideTo(stopIndex + increment);
|
|
2722
|
+
} else {
|
|
2723
|
+
swiper.slideTo(stopIndex);
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2728
|
+
function onResize() {
|
|
2729
|
+
const swiper = this;
|
|
2730
|
+
const {
|
|
2731
|
+
params,
|
|
2732
|
+
el
|
|
2733
|
+
} = swiper;
|
|
2734
|
+
if (el && el.offsetWidth === 0) return;
|
|
2735
|
+
|
|
2736
|
+
// Breakpoints
|
|
2737
|
+
if (params.breakpoints) {
|
|
2738
|
+
swiper.setBreakpoint();
|
|
2739
|
+
}
|
|
2740
|
+
|
|
2741
|
+
// Save locks
|
|
2742
|
+
const {
|
|
2743
|
+
allowSlideNext,
|
|
2744
|
+
allowSlidePrev,
|
|
2745
|
+
snapGrid
|
|
2746
|
+
} = swiper;
|
|
2747
|
+
const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
|
|
2748
|
+
|
|
2749
|
+
// Disable locks on resize
|
|
2750
|
+
swiper.allowSlideNext = true;
|
|
2751
|
+
swiper.allowSlidePrev = true;
|
|
2752
|
+
swiper.updateSize();
|
|
2753
|
+
swiper.updateSlides();
|
|
2754
|
+
swiper.updateSlidesClasses();
|
|
2755
|
+
const isVirtualLoop = isVirtual && params.loop;
|
|
2756
|
+
if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !swiper.isBeginning && !swiper.params.centeredSlides && !isVirtualLoop) {
|
|
2757
|
+
swiper.slideTo(swiper.slides.length - 1, 0, false, true);
|
|
2758
|
+
} else {
|
|
2759
|
+
if (swiper.params.loop && !isVirtual) {
|
|
2760
|
+
swiper.slideToLoop(swiper.realIndex, 0, false, true);
|
|
2761
|
+
} else {
|
|
2762
|
+
swiper.slideTo(swiper.activeIndex, 0, false, true);
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) {
|
|
2766
|
+
clearTimeout(swiper.autoplay.resizeTimeout);
|
|
2767
|
+
swiper.autoplay.resizeTimeout = setTimeout(() => {
|
|
2768
|
+
if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) {
|
|
2769
|
+
swiper.autoplay.resume();
|
|
2770
|
+
}
|
|
2771
|
+
}, 500);
|
|
2772
|
+
}
|
|
2773
|
+
// Return locks after resize
|
|
2774
|
+
swiper.allowSlidePrev = allowSlidePrev;
|
|
2775
|
+
swiper.allowSlideNext = allowSlideNext;
|
|
2776
|
+
if (swiper.params.watchOverflow && snapGrid !== swiper.snapGrid) {
|
|
2777
|
+
swiper.checkOverflow();
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2781
|
+
function onClick(e) {
|
|
2782
|
+
const swiper = this;
|
|
2783
|
+
if (!swiper.enabled) return;
|
|
2784
|
+
if (!swiper.allowClick) {
|
|
2785
|
+
if (swiper.params.preventClicks) e.preventDefault();
|
|
2786
|
+
if (swiper.params.preventClicksPropagation && swiper.animating) {
|
|
2787
|
+
e.stopPropagation();
|
|
2788
|
+
e.stopImmediatePropagation();
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
|
|
2793
|
+
function onScroll() {
|
|
2794
|
+
const swiper = this;
|
|
2795
|
+
const {
|
|
2796
|
+
wrapperEl,
|
|
2797
|
+
rtlTranslate,
|
|
2798
|
+
enabled
|
|
2799
|
+
} = swiper;
|
|
2800
|
+
if (!enabled) return;
|
|
2801
|
+
swiper.previousTranslate = swiper.translate;
|
|
2802
|
+
if (swiper.isHorizontal()) {
|
|
2803
|
+
swiper.translate = -wrapperEl.scrollLeft;
|
|
2804
|
+
} else {
|
|
2805
|
+
swiper.translate = -wrapperEl.scrollTop;
|
|
2806
|
+
}
|
|
2807
|
+
// eslint-disable-next-line
|
|
2808
|
+
if (swiper.translate === 0) swiper.translate = 0;
|
|
2809
|
+
swiper.updateActiveIndex();
|
|
2810
|
+
swiper.updateSlidesClasses();
|
|
2811
|
+
let newProgress;
|
|
2812
|
+
const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
|
|
2813
|
+
if (translatesDiff === 0) {
|
|
2814
|
+
newProgress = 0;
|
|
2815
|
+
} else {
|
|
2816
|
+
newProgress = (swiper.translate - swiper.minTranslate()) / translatesDiff;
|
|
2817
|
+
}
|
|
2818
|
+
if (newProgress !== swiper.progress) {
|
|
2819
|
+
swiper.updateProgress(rtlTranslate ? -swiper.translate : swiper.translate);
|
|
2820
|
+
}
|
|
2821
|
+
swiper.emit('setTranslate', swiper.translate, false);
|
|
2822
|
+
}
|
|
2823
|
+
|
|
2824
|
+
function onLoad(e) {
|
|
2825
|
+
const swiper = this;
|
|
2826
|
+
processLazyPreloader(swiper, e.target);
|
|
2827
|
+
if (swiper.params.cssMode || swiper.params.slidesPerView !== 'auto' && !swiper.params.autoHeight) {
|
|
2828
|
+
return;
|
|
2829
|
+
}
|
|
2830
|
+
swiper.update();
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2833
|
+
function onDocumentTouchStart() {
|
|
2834
|
+
const swiper = this;
|
|
2835
|
+
if (swiper.documentTouchHandlerProceeded) return;
|
|
2836
|
+
swiper.documentTouchHandlerProceeded = true;
|
|
2837
|
+
if (swiper.params.touchReleaseOnEdges) {
|
|
2838
|
+
swiper.el.style.touchAction = 'auto';
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
|
|
2842
|
+
const events = (swiper, method) => {
|
|
2843
|
+
const document = getDocument();
|
|
2844
|
+
const {
|
|
2845
|
+
params,
|
|
2846
|
+
el,
|
|
2847
|
+
wrapperEl,
|
|
2848
|
+
device
|
|
2849
|
+
} = swiper;
|
|
2850
|
+
const capture = !!params.nested;
|
|
2851
|
+
const domMethod = method === 'on' ? 'addEventListener' : 'removeEventListener';
|
|
2852
|
+
const swiperMethod = method;
|
|
2853
|
+
if (!el || typeof el === 'string') return;
|
|
2854
|
+
|
|
2855
|
+
// Touch Events
|
|
2856
|
+
document[domMethod]('touchstart', swiper.onDocumentTouchStart, {
|
|
2857
|
+
passive: false,
|
|
2858
|
+
capture
|
|
2859
|
+
});
|
|
2860
|
+
el[domMethod]('touchstart', swiper.onTouchStart, {
|
|
2861
|
+
passive: false
|
|
2862
|
+
});
|
|
2863
|
+
el[domMethod]('pointerdown', swiper.onTouchStart, {
|
|
2864
|
+
passive: false
|
|
2865
|
+
});
|
|
2866
|
+
document[domMethod]('touchmove', swiper.onTouchMove, {
|
|
2867
|
+
passive: false,
|
|
2868
|
+
capture
|
|
2869
|
+
});
|
|
2870
|
+
document[domMethod]('pointermove', swiper.onTouchMove, {
|
|
2871
|
+
passive: false,
|
|
2872
|
+
capture
|
|
2873
|
+
});
|
|
2874
|
+
document[domMethod]('touchend', swiper.onTouchEnd, {
|
|
2875
|
+
passive: true
|
|
2876
|
+
});
|
|
2877
|
+
document[domMethod]('pointerup', swiper.onTouchEnd, {
|
|
2878
|
+
passive: true
|
|
2879
|
+
});
|
|
2880
|
+
document[domMethod]('pointercancel', swiper.onTouchEnd, {
|
|
2881
|
+
passive: true
|
|
2882
|
+
});
|
|
2883
|
+
document[domMethod]('touchcancel', swiper.onTouchEnd, {
|
|
2884
|
+
passive: true
|
|
2885
|
+
});
|
|
2886
|
+
document[domMethod]('pointerout', swiper.onTouchEnd, {
|
|
2887
|
+
passive: true
|
|
2888
|
+
});
|
|
2889
|
+
document[domMethod]('pointerleave', swiper.onTouchEnd, {
|
|
2890
|
+
passive: true
|
|
2891
|
+
});
|
|
2892
|
+
document[domMethod]('contextmenu', swiper.onTouchEnd, {
|
|
2893
|
+
passive: true
|
|
2894
|
+
});
|
|
2895
|
+
|
|
2896
|
+
// Prevent Links Clicks
|
|
2897
|
+
if (params.preventClicks || params.preventClicksPropagation) {
|
|
2898
|
+
el[domMethod]('click', swiper.onClick, true);
|
|
2899
|
+
}
|
|
2900
|
+
if (params.cssMode) {
|
|
2901
|
+
wrapperEl[domMethod]('scroll', swiper.onScroll);
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2904
|
+
// Resize handler
|
|
2905
|
+
if (params.updateOnWindowResize) {
|
|
2906
|
+
swiper[swiperMethod](device.ios || device.android ? 'resize orientationchange observerUpdate' : 'resize observerUpdate', onResize, true);
|
|
2907
|
+
} else {
|
|
2908
|
+
swiper[swiperMethod]('observerUpdate', onResize, true);
|
|
2909
|
+
}
|
|
2910
|
+
|
|
2911
|
+
// Images loader
|
|
2912
|
+
el[domMethod]('load', swiper.onLoad, {
|
|
2913
|
+
capture: true
|
|
2914
|
+
});
|
|
2915
|
+
};
|
|
2916
|
+
function attachEvents() {
|
|
2917
|
+
const swiper = this;
|
|
2918
|
+
const {
|
|
2919
|
+
params
|
|
2920
|
+
} = swiper;
|
|
2921
|
+
swiper.onTouchStart = onTouchStart.bind(swiper);
|
|
2922
|
+
swiper.onTouchMove = onTouchMove.bind(swiper);
|
|
2923
|
+
swiper.onTouchEnd = onTouchEnd.bind(swiper);
|
|
2924
|
+
swiper.onDocumentTouchStart = onDocumentTouchStart.bind(swiper);
|
|
2925
|
+
if (params.cssMode) {
|
|
2926
|
+
swiper.onScroll = onScroll.bind(swiper);
|
|
2927
|
+
}
|
|
2928
|
+
swiper.onClick = onClick.bind(swiper);
|
|
2929
|
+
swiper.onLoad = onLoad.bind(swiper);
|
|
2930
|
+
events(swiper, 'on');
|
|
2931
|
+
}
|
|
2932
|
+
function detachEvents() {
|
|
2933
|
+
const swiper = this;
|
|
2934
|
+
events(swiper, 'off');
|
|
2935
|
+
}
|
|
2936
|
+
var events$1 = {
|
|
2937
|
+
attachEvents,
|
|
2938
|
+
detachEvents
|
|
2939
|
+
};
|
|
2940
|
+
|
|
2941
|
+
const isGridEnabled = (swiper, params) => {
|
|
2942
|
+
return swiper.grid && params.grid && params.grid.rows > 1;
|
|
2943
|
+
};
|
|
2944
|
+
function setBreakpoint() {
|
|
2945
|
+
const swiper = this;
|
|
2946
|
+
const {
|
|
2947
|
+
realIndex,
|
|
2948
|
+
initialized,
|
|
2949
|
+
params,
|
|
2950
|
+
el
|
|
2951
|
+
} = swiper;
|
|
2952
|
+
const breakpoints = params.breakpoints;
|
|
2953
|
+
if (!breakpoints || breakpoints && Object.keys(breakpoints).length === 0) return;
|
|
2954
|
+
const document = getDocument();
|
|
2955
|
+
|
|
2956
|
+
// Get breakpoint for window/container width and update parameters
|
|
2957
|
+
const breakpointsBase = params.breakpointsBase === 'window' || !params.breakpointsBase ? params.breakpointsBase : 'container';
|
|
2958
|
+
const breakpointContainer = ['window', 'container'].includes(params.breakpointsBase) || !params.breakpointsBase ? swiper.el : document.querySelector(params.breakpointsBase);
|
|
2959
|
+
const breakpoint = swiper.getBreakpoint(breakpoints, breakpointsBase, breakpointContainer);
|
|
2960
|
+
if (!breakpoint || swiper.currentBreakpoint === breakpoint) return;
|
|
2961
|
+
const breakpointOnlyParams = breakpoint in breakpoints ? breakpoints[breakpoint] : undefined;
|
|
2962
|
+
const breakpointParams = breakpointOnlyParams || swiper.originalParams;
|
|
2963
|
+
const wasMultiRow = isGridEnabled(swiper, params);
|
|
2964
|
+
const isMultiRow = isGridEnabled(swiper, breakpointParams);
|
|
2965
|
+
const wasGrabCursor = swiper.params.grabCursor;
|
|
2966
|
+
const isGrabCursor = breakpointParams.grabCursor;
|
|
2967
|
+
const wasEnabled = params.enabled;
|
|
2968
|
+
if (wasMultiRow && !isMultiRow) {
|
|
2969
|
+
el.classList.remove(`${params.containerModifierClass}grid`, `${params.containerModifierClass}grid-column`);
|
|
2970
|
+
swiper.emitContainerClasses();
|
|
2971
|
+
} else if (!wasMultiRow && isMultiRow) {
|
|
2972
|
+
el.classList.add(`${params.containerModifierClass}grid`);
|
|
2973
|
+
if (breakpointParams.grid.fill && breakpointParams.grid.fill === 'column' || !breakpointParams.grid.fill && params.grid.fill === 'column') {
|
|
2974
|
+
el.classList.add(`${params.containerModifierClass}grid-column`);
|
|
2975
|
+
}
|
|
2976
|
+
swiper.emitContainerClasses();
|
|
2977
|
+
}
|
|
2978
|
+
if (wasGrabCursor && !isGrabCursor) {
|
|
2979
|
+
swiper.unsetGrabCursor();
|
|
2980
|
+
} else if (!wasGrabCursor && isGrabCursor) {
|
|
2981
|
+
swiper.setGrabCursor();
|
|
2982
|
+
}
|
|
2983
|
+
|
|
2984
|
+
// Toggle navigation, pagination, scrollbar
|
|
2985
|
+
['navigation', 'pagination', 'scrollbar'].forEach(prop => {
|
|
2986
|
+
if (typeof breakpointParams[prop] === 'undefined') return;
|
|
2987
|
+
const wasModuleEnabled = params[prop] && params[prop].enabled;
|
|
2988
|
+
const isModuleEnabled = breakpointParams[prop] && breakpointParams[prop].enabled;
|
|
2989
|
+
if (wasModuleEnabled && !isModuleEnabled) {
|
|
2990
|
+
swiper[prop].disable();
|
|
2991
|
+
}
|
|
2992
|
+
if (!wasModuleEnabled && isModuleEnabled) {
|
|
2993
|
+
swiper[prop].enable();
|
|
2994
|
+
}
|
|
2995
|
+
});
|
|
2996
|
+
const directionChanged = breakpointParams.direction && breakpointParams.direction !== params.direction;
|
|
2997
|
+
const needsReLoop = params.loop && (breakpointParams.slidesPerView !== params.slidesPerView || directionChanged);
|
|
2998
|
+
const wasLoop = params.loop;
|
|
2999
|
+
if (directionChanged && initialized) {
|
|
3000
|
+
swiper.changeDirection();
|
|
3001
|
+
}
|
|
3002
|
+
extend(swiper.params, breakpointParams);
|
|
3003
|
+
const isEnabled = swiper.params.enabled;
|
|
3004
|
+
const hasLoop = swiper.params.loop;
|
|
3005
|
+
Object.assign(swiper, {
|
|
3006
|
+
allowTouchMove: swiper.params.allowTouchMove,
|
|
3007
|
+
allowSlideNext: swiper.params.allowSlideNext,
|
|
3008
|
+
allowSlidePrev: swiper.params.allowSlidePrev
|
|
3009
|
+
});
|
|
3010
|
+
if (wasEnabled && !isEnabled) {
|
|
3011
|
+
swiper.disable();
|
|
3012
|
+
} else if (!wasEnabled && isEnabled) {
|
|
3013
|
+
swiper.enable();
|
|
3014
|
+
}
|
|
3015
|
+
swiper.currentBreakpoint = breakpoint;
|
|
3016
|
+
swiper.emit('_beforeBreakpoint', breakpointParams);
|
|
3017
|
+
if (initialized) {
|
|
3018
|
+
if (needsReLoop) {
|
|
3019
|
+
swiper.loopDestroy();
|
|
3020
|
+
swiper.loopCreate(realIndex);
|
|
3021
|
+
swiper.updateSlides();
|
|
3022
|
+
} else if (!wasLoop && hasLoop) {
|
|
3023
|
+
swiper.loopCreate(realIndex);
|
|
3024
|
+
swiper.updateSlides();
|
|
3025
|
+
} else if (wasLoop && !hasLoop) {
|
|
3026
|
+
swiper.loopDestroy();
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
swiper.emit('breakpoint', breakpointParams);
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
function getBreakpoint(breakpoints, base, containerEl) {
|
|
3033
|
+
if (base === void 0) {
|
|
3034
|
+
base = 'window';
|
|
3035
|
+
}
|
|
3036
|
+
if (!breakpoints || base === 'container' && !containerEl) return undefined;
|
|
3037
|
+
let breakpoint = false;
|
|
3038
|
+
const window = getWindow();
|
|
3039
|
+
const currentHeight = base === 'window' ? window.innerHeight : containerEl.clientHeight;
|
|
3040
|
+
const points = Object.keys(breakpoints).map(point => {
|
|
3041
|
+
if (typeof point === 'string' && point.indexOf('@') === 0) {
|
|
3042
|
+
const minRatio = parseFloat(point.substr(1));
|
|
3043
|
+
const value = currentHeight * minRatio;
|
|
3044
|
+
return {
|
|
3045
|
+
value,
|
|
3046
|
+
point
|
|
3047
|
+
};
|
|
3048
|
+
}
|
|
3049
|
+
return {
|
|
3050
|
+
value: point,
|
|
3051
|
+
point
|
|
3052
|
+
};
|
|
3053
|
+
});
|
|
3054
|
+
points.sort((a, b) => parseInt(a.value, 10) - parseInt(b.value, 10));
|
|
3055
|
+
for (let i = 0; i < points.length; i += 1) {
|
|
3056
|
+
const {
|
|
3057
|
+
point,
|
|
3058
|
+
value
|
|
3059
|
+
} = points[i];
|
|
3060
|
+
if (base === 'window') {
|
|
3061
|
+
if (window.matchMedia(`(min-width: ${value}px)`).matches) {
|
|
3062
|
+
breakpoint = point;
|
|
3063
|
+
}
|
|
3064
|
+
} else if (value <= containerEl.clientWidth) {
|
|
3065
|
+
breakpoint = point;
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
return breakpoint || 'max';
|
|
3069
|
+
}
|
|
3070
|
+
|
|
3071
|
+
var breakpoints = {
|
|
3072
|
+
setBreakpoint,
|
|
3073
|
+
getBreakpoint
|
|
3074
|
+
};
|
|
3075
|
+
|
|
3076
|
+
function prepareClasses(entries, prefix) {
|
|
3077
|
+
const resultClasses = [];
|
|
3078
|
+
entries.forEach(item => {
|
|
3079
|
+
if (typeof item === 'object') {
|
|
3080
|
+
Object.keys(item).forEach(classNames => {
|
|
3081
|
+
if (item[classNames]) {
|
|
3082
|
+
resultClasses.push(prefix + classNames);
|
|
3083
|
+
}
|
|
3084
|
+
});
|
|
3085
|
+
} else if (typeof item === 'string') {
|
|
3086
|
+
resultClasses.push(prefix + item);
|
|
3087
|
+
}
|
|
3088
|
+
});
|
|
3089
|
+
return resultClasses;
|
|
3090
|
+
}
|
|
3091
|
+
function addClasses() {
|
|
3092
|
+
const swiper = this;
|
|
3093
|
+
const {
|
|
3094
|
+
classNames,
|
|
3095
|
+
params,
|
|
3096
|
+
rtl,
|
|
3097
|
+
el,
|
|
3098
|
+
device
|
|
3099
|
+
} = swiper;
|
|
3100
|
+
// prettier-ignore
|
|
3101
|
+
const suffixes = prepareClasses(['initialized', params.direction, {
|
|
3102
|
+
'free-mode': swiper.params.freeMode && params.freeMode.enabled
|
|
3103
|
+
}, {
|
|
3104
|
+
'autoheight': params.autoHeight
|
|
3105
|
+
}, {
|
|
3106
|
+
'rtl': rtl
|
|
3107
|
+
}, {
|
|
3108
|
+
'grid': params.grid && params.grid.rows > 1
|
|
3109
|
+
}, {
|
|
3110
|
+
'grid-column': params.grid && params.grid.rows > 1 && params.grid.fill === 'column'
|
|
3111
|
+
}, {
|
|
3112
|
+
'android': device.android
|
|
3113
|
+
}, {
|
|
3114
|
+
'ios': device.ios
|
|
3115
|
+
}, {
|
|
3116
|
+
'css-mode': params.cssMode
|
|
3117
|
+
}, {
|
|
3118
|
+
'centered': params.cssMode && params.centeredSlides
|
|
3119
|
+
}, {
|
|
3120
|
+
'watch-progress': params.watchSlidesProgress
|
|
3121
|
+
}], params.containerModifierClass);
|
|
3122
|
+
classNames.push(...suffixes);
|
|
3123
|
+
el.classList.add(...classNames);
|
|
3124
|
+
swiper.emitContainerClasses();
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
function removeClasses() {
|
|
3128
|
+
const swiper = this;
|
|
3129
|
+
const {
|
|
3130
|
+
el,
|
|
3131
|
+
classNames
|
|
3132
|
+
} = swiper;
|
|
3133
|
+
if (!el || typeof el === 'string') return;
|
|
3134
|
+
el.classList.remove(...classNames);
|
|
3135
|
+
swiper.emitContainerClasses();
|
|
3136
|
+
}
|
|
3137
|
+
|
|
3138
|
+
var classes = {
|
|
3139
|
+
addClasses,
|
|
3140
|
+
removeClasses
|
|
3141
|
+
};
|
|
3142
|
+
|
|
3143
|
+
function checkOverflow() {
|
|
3144
|
+
const swiper = this;
|
|
3145
|
+
const {
|
|
3146
|
+
isLocked: wasLocked,
|
|
3147
|
+
params
|
|
3148
|
+
} = swiper;
|
|
3149
|
+
const {
|
|
3150
|
+
slidesOffsetBefore
|
|
3151
|
+
} = params;
|
|
3152
|
+
if (slidesOffsetBefore) {
|
|
3153
|
+
const lastSlideIndex = swiper.slides.length - 1;
|
|
3154
|
+
const lastSlideRightEdge = swiper.slidesGrid[lastSlideIndex] + swiper.slidesSizesGrid[lastSlideIndex] + slidesOffsetBefore * 2;
|
|
3155
|
+
swiper.isLocked = swiper.size > lastSlideRightEdge;
|
|
3156
|
+
} else {
|
|
3157
|
+
swiper.isLocked = swiper.snapGrid.length === 1;
|
|
3158
|
+
}
|
|
3159
|
+
if (params.allowSlideNext === true) {
|
|
3160
|
+
swiper.allowSlideNext = !swiper.isLocked;
|
|
3161
|
+
}
|
|
3162
|
+
if (params.allowSlidePrev === true) {
|
|
3163
|
+
swiper.allowSlidePrev = !swiper.isLocked;
|
|
3164
|
+
}
|
|
3165
|
+
if (wasLocked && wasLocked !== swiper.isLocked) {
|
|
3166
|
+
swiper.isEnd = false;
|
|
3167
|
+
}
|
|
3168
|
+
if (wasLocked !== swiper.isLocked) {
|
|
3169
|
+
swiper.emit(swiper.isLocked ? 'lock' : 'unlock');
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
var checkOverflow$1 = {
|
|
3173
|
+
checkOverflow
|
|
3174
|
+
};
|
|
3175
|
+
|
|
3176
|
+
var defaults = {
|
|
3177
|
+
init: true,
|
|
3178
|
+
direction: 'horizontal',
|
|
3179
|
+
oneWayMovement: false,
|
|
3180
|
+
swiperElementNodeName: 'SWIPER-CONTAINER',
|
|
3181
|
+
touchEventsTarget: 'wrapper',
|
|
3182
|
+
initialSlide: 0,
|
|
3183
|
+
speed: 300,
|
|
3184
|
+
cssMode: false,
|
|
3185
|
+
updateOnWindowResize: true,
|
|
3186
|
+
resizeObserver: true,
|
|
3187
|
+
nested: false,
|
|
3188
|
+
createElements: false,
|
|
3189
|
+
eventsPrefix: 'swiper',
|
|
3190
|
+
enabled: true,
|
|
3191
|
+
focusableElements: 'input, select, option, textarea, button, video, label',
|
|
3192
|
+
// Overrides
|
|
3193
|
+
width: null,
|
|
3194
|
+
height: null,
|
|
3195
|
+
//
|
|
3196
|
+
preventInteractionOnTransition: false,
|
|
3197
|
+
// ssr
|
|
3198
|
+
userAgent: null,
|
|
3199
|
+
url: null,
|
|
3200
|
+
// To support iOS's swipe-to-go-back gesture (when being used in-app).
|
|
3201
|
+
edgeSwipeDetection: false,
|
|
3202
|
+
edgeSwipeThreshold: 20,
|
|
3203
|
+
// Autoheight
|
|
3204
|
+
autoHeight: false,
|
|
3205
|
+
// Set wrapper width
|
|
3206
|
+
setWrapperSize: false,
|
|
3207
|
+
// Virtual Translate
|
|
3208
|
+
virtualTranslate: false,
|
|
3209
|
+
// Effects
|
|
3210
|
+
effect: 'slide',
|
|
3211
|
+
// 'slide' or 'fade' or 'cube' or 'coverflow' or 'flip'
|
|
3212
|
+
|
|
3213
|
+
// Breakpoints
|
|
3214
|
+
breakpoints: undefined,
|
|
3215
|
+
breakpointsBase: 'window',
|
|
3216
|
+
// Slides grid
|
|
3217
|
+
spaceBetween: 0,
|
|
3218
|
+
slidesPerView: 1,
|
|
3219
|
+
slidesPerGroup: 1,
|
|
3220
|
+
slidesPerGroupSkip: 0,
|
|
3221
|
+
slidesPerGroupAuto: false,
|
|
3222
|
+
centeredSlides: false,
|
|
3223
|
+
centeredSlidesBounds: false,
|
|
3224
|
+
slidesOffsetBefore: 0,
|
|
3225
|
+
// in px
|
|
3226
|
+
slidesOffsetAfter: 0,
|
|
3227
|
+
// in px
|
|
3228
|
+
normalizeSlideIndex: true,
|
|
3229
|
+
centerInsufficientSlides: false,
|
|
3230
|
+
// Disable swiper and hide navigation when container not overflow
|
|
3231
|
+
watchOverflow: true,
|
|
3232
|
+
// Round length
|
|
3233
|
+
roundLengths: false,
|
|
3234
|
+
// Touches
|
|
3235
|
+
touchRatio: 1,
|
|
3236
|
+
touchAngle: 45,
|
|
3237
|
+
simulateTouch: true,
|
|
3238
|
+
shortSwipes: true,
|
|
3239
|
+
longSwipes: true,
|
|
3240
|
+
longSwipesRatio: 0.5,
|
|
3241
|
+
longSwipesMs: 300,
|
|
3242
|
+
followFinger: true,
|
|
3243
|
+
allowTouchMove: true,
|
|
3244
|
+
threshold: 5,
|
|
3245
|
+
touchMoveStopPropagation: false,
|
|
3246
|
+
touchStartPreventDefault: true,
|
|
3247
|
+
touchStartForcePreventDefault: false,
|
|
3248
|
+
touchReleaseOnEdges: false,
|
|
3249
|
+
// Unique Navigation Elements
|
|
3250
|
+
uniqueNavElements: true,
|
|
3251
|
+
// Resistance
|
|
3252
|
+
resistance: true,
|
|
3253
|
+
resistanceRatio: 0.85,
|
|
3254
|
+
// Progress
|
|
3255
|
+
watchSlidesProgress: false,
|
|
3256
|
+
// Cursor
|
|
3257
|
+
grabCursor: false,
|
|
3258
|
+
// Clicks
|
|
3259
|
+
preventClicks: true,
|
|
3260
|
+
preventClicksPropagation: true,
|
|
3261
|
+
slideToClickedSlide: false,
|
|
3262
|
+
// loop
|
|
3263
|
+
loop: false,
|
|
3264
|
+
loopAddBlankSlides: true,
|
|
3265
|
+
loopAdditionalSlides: 0,
|
|
3266
|
+
loopPreventsSliding: true,
|
|
3267
|
+
// rewind
|
|
3268
|
+
rewind: false,
|
|
3269
|
+
// Swiping/no swiping
|
|
3270
|
+
allowSlidePrev: true,
|
|
3271
|
+
allowSlideNext: true,
|
|
3272
|
+
swipeHandler: null,
|
|
3273
|
+
// '.swipe-handler',
|
|
3274
|
+
noSwiping: true,
|
|
3275
|
+
noSwipingClass: 'swiper-no-swiping',
|
|
3276
|
+
noSwipingSelector: null,
|
|
3277
|
+
// Passive Listeners
|
|
3278
|
+
passiveListeners: true,
|
|
3279
|
+
maxBackfaceHiddenSlides: 10,
|
|
3280
|
+
// NS
|
|
3281
|
+
containerModifierClass: 'swiper-',
|
|
3282
|
+
// NEW
|
|
3283
|
+
slideClass: 'swiper-slide',
|
|
3284
|
+
slideBlankClass: 'swiper-slide-blank',
|
|
3285
|
+
slideActiveClass: 'swiper-slide-active',
|
|
3286
|
+
slideVisibleClass: 'swiper-slide-visible',
|
|
3287
|
+
slideFullyVisibleClass: 'swiper-slide-fully-visible',
|
|
3288
|
+
slideNextClass: 'swiper-slide-next',
|
|
3289
|
+
slidePrevClass: 'swiper-slide-prev',
|
|
3290
|
+
wrapperClass: 'swiper-wrapper',
|
|
3291
|
+
lazyPreloaderClass: 'swiper-lazy-preloader',
|
|
3292
|
+
lazyPreloadPrevNext: 0,
|
|
3293
|
+
// Callbacks
|
|
3294
|
+
runCallbacksOnInit: true,
|
|
3295
|
+
// Internals
|
|
3296
|
+
_emitClasses: false
|
|
3297
|
+
};
|
|
3298
|
+
|
|
3299
|
+
function moduleExtendParams(params, allModulesParams) {
|
|
3300
|
+
return function extendParams(obj) {
|
|
3301
|
+
if (obj === void 0) {
|
|
3302
|
+
obj = {};
|
|
3303
|
+
}
|
|
3304
|
+
const moduleParamName = Object.keys(obj)[0];
|
|
3305
|
+
const moduleParams = obj[moduleParamName];
|
|
3306
|
+
if (typeof moduleParams !== 'object' || moduleParams === null) {
|
|
3307
|
+
extend(allModulesParams, obj);
|
|
3308
|
+
return;
|
|
3309
|
+
}
|
|
3310
|
+
if (params[moduleParamName] === true) {
|
|
3311
|
+
params[moduleParamName] = {
|
|
3312
|
+
enabled: true
|
|
3313
|
+
};
|
|
3314
|
+
}
|
|
3315
|
+
if (moduleParamName === 'navigation' && params[moduleParamName] && params[moduleParamName].enabled && !params[moduleParamName].prevEl && !params[moduleParamName].nextEl) {
|
|
3316
|
+
params[moduleParamName].auto = true;
|
|
3317
|
+
}
|
|
3318
|
+
if (['pagination', 'scrollbar'].indexOf(moduleParamName) >= 0 && params[moduleParamName] && params[moduleParamName].enabled && !params[moduleParamName].el) {
|
|
3319
|
+
params[moduleParamName].auto = true;
|
|
3320
|
+
}
|
|
3321
|
+
if (!(moduleParamName in params && 'enabled' in moduleParams)) {
|
|
3322
|
+
extend(allModulesParams, obj);
|
|
3323
|
+
return;
|
|
3324
|
+
}
|
|
3325
|
+
if (typeof params[moduleParamName] === 'object' && !('enabled' in params[moduleParamName])) {
|
|
3326
|
+
params[moduleParamName].enabled = true;
|
|
3327
|
+
}
|
|
3328
|
+
if (!params[moduleParamName]) params[moduleParamName] = {
|
|
3329
|
+
enabled: false
|
|
3330
|
+
};
|
|
3331
|
+
extend(allModulesParams, obj);
|
|
3332
|
+
};
|
|
3333
|
+
}
|
|
3334
|
+
|
|
3335
|
+
/* eslint no-param-reassign: "off" */
|
|
3336
|
+
const prototypes = {
|
|
3337
|
+
eventsEmitter,
|
|
3338
|
+
update,
|
|
3339
|
+
translate,
|
|
3340
|
+
transition,
|
|
3341
|
+
slide,
|
|
3342
|
+
loop,
|
|
3343
|
+
grabCursor,
|
|
3344
|
+
events: events$1,
|
|
3345
|
+
breakpoints,
|
|
3346
|
+
checkOverflow: checkOverflow$1,
|
|
3347
|
+
classes
|
|
3348
|
+
};
|
|
3349
|
+
const extendedDefaults = {};
|
|
3350
|
+
class Swiper {
|
|
3351
|
+
constructor() {
|
|
3352
|
+
let el;
|
|
3353
|
+
let params;
|
|
3354
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3355
|
+
args[_key] = arguments[_key];
|
|
3356
|
+
}
|
|
3357
|
+
if (args.length === 1 && args[0].constructor && Object.prototype.toString.call(args[0]).slice(8, -1) === 'Object') {
|
|
3358
|
+
params = args[0];
|
|
3359
|
+
} else {
|
|
3360
|
+
[el, params] = args;
|
|
3361
|
+
}
|
|
3362
|
+
if (!params) params = {};
|
|
3363
|
+
params = extend({}, params);
|
|
3364
|
+
if (el && !params.el) params.el = el;
|
|
3365
|
+
const document = getDocument();
|
|
3366
|
+
if (params.el && typeof params.el === 'string' && document.querySelectorAll(params.el).length > 1) {
|
|
3367
|
+
const swipers = [];
|
|
3368
|
+
document.querySelectorAll(params.el).forEach(containerEl => {
|
|
3369
|
+
const newParams = extend({}, params, {
|
|
3370
|
+
el: containerEl
|
|
3371
|
+
});
|
|
3372
|
+
swipers.push(new Swiper(newParams));
|
|
3373
|
+
});
|
|
3374
|
+
// eslint-disable-next-line no-constructor-return
|
|
3375
|
+
return swipers;
|
|
3376
|
+
}
|
|
3377
|
+
|
|
3378
|
+
// Swiper Instance
|
|
3379
|
+
const swiper = this;
|
|
3380
|
+
swiper.__swiper__ = true;
|
|
3381
|
+
swiper.support = getSupport();
|
|
3382
|
+
swiper.device = getDevice({
|
|
3383
|
+
userAgent: params.userAgent
|
|
3384
|
+
});
|
|
3385
|
+
swiper.browser = getBrowser();
|
|
3386
|
+
swiper.eventsListeners = {};
|
|
3387
|
+
swiper.eventsAnyListeners = [];
|
|
3388
|
+
swiper.modules = [...swiper.__modules__];
|
|
3389
|
+
if (params.modules && Array.isArray(params.modules)) {
|
|
3390
|
+
swiper.modules.push(...params.modules);
|
|
3391
|
+
}
|
|
3392
|
+
const allModulesParams = {};
|
|
3393
|
+
swiper.modules.forEach(mod => {
|
|
3394
|
+
mod({
|
|
3395
|
+
params,
|
|
3396
|
+
swiper,
|
|
3397
|
+
extendParams: moduleExtendParams(params, allModulesParams),
|
|
3398
|
+
on: swiper.on.bind(swiper),
|
|
3399
|
+
once: swiper.once.bind(swiper),
|
|
3400
|
+
off: swiper.off.bind(swiper),
|
|
3401
|
+
emit: swiper.emit.bind(swiper)
|
|
3402
|
+
});
|
|
3403
|
+
});
|
|
3404
|
+
|
|
3405
|
+
// Extend defaults with modules params
|
|
3406
|
+
const swiperParams = extend({}, defaults, allModulesParams);
|
|
3407
|
+
|
|
3408
|
+
// Extend defaults with passed params
|
|
3409
|
+
swiper.params = extend({}, swiperParams, extendedDefaults, params);
|
|
3410
|
+
swiper.originalParams = extend({}, swiper.params);
|
|
3411
|
+
swiper.passedParams = extend({}, params);
|
|
3412
|
+
|
|
3413
|
+
// add event listeners
|
|
3414
|
+
if (swiper.params && swiper.params.on) {
|
|
3415
|
+
Object.keys(swiper.params.on).forEach(eventName => {
|
|
3416
|
+
swiper.on(eventName, swiper.params.on[eventName]);
|
|
3417
|
+
});
|
|
3418
|
+
}
|
|
3419
|
+
if (swiper.params && swiper.params.onAny) {
|
|
3420
|
+
swiper.onAny(swiper.params.onAny);
|
|
3421
|
+
}
|
|
3422
|
+
|
|
3423
|
+
// Extend Swiper
|
|
3424
|
+
Object.assign(swiper, {
|
|
3425
|
+
enabled: swiper.params.enabled,
|
|
3426
|
+
el,
|
|
3427
|
+
// Classes
|
|
3428
|
+
classNames: [],
|
|
3429
|
+
// Slides
|
|
3430
|
+
slides: [],
|
|
3431
|
+
slidesGrid: [],
|
|
3432
|
+
snapGrid: [],
|
|
3433
|
+
slidesSizesGrid: [],
|
|
3434
|
+
// isDirection
|
|
3435
|
+
isHorizontal() {
|
|
3436
|
+
return swiper.params.direction === 'horizontal';
|
|
3437
|
+
},
|
|
3438
|
+
isVertical() {
|
|
3439
|
+
return swiper.params.direction === 'vertical';
|
|
3440
|
+
},
|
|
3441
|
+
// Indexes
|
|
3442
|
+
activeIndex: 0,
|
|
3443
|
+
realIndex: 0,
|
|
3444
|
+
//
|
|
3445
|
+
isBeginning: true,
|
|
3446
|
+
isEnd: false,
|
|
3447
|
+
// Props
|
|
3448
|
+
translate: 0,
|
|
3449
|
+
previousTranslate: 0,
|
|
3450
|
+
progress: 0,
|
|
3451
|
+
velocity: 0,
|
|
3452
|
+
animating: false,
|
|
3453
|
+
cssOverflowAdjustment() {
|
|
3454
|
+
// Returns 0 unless `translate` is > 2**23
|
|
3455
|
+
// Should be subtracted from css values to prevent overflow
|
|
3456
|
+
return Math.trunc(this.translate / 2 ** 23) * 2 ** 23;
|
|
3457
|
+
},
|
|
3458
|
+
// Locks
|
|
3459
|
+
allowSlideNext: swiper.params.allowSlideNext,
|
|
3460
|
+
allowSlidePrev: swiper.params.allowSlidePrev,
|
|
3461
|
+
// Touch Events
|
|
3462
|
+
touchEventsData: {
|
|
3463
|
+
isTouched: undefined,
|
|
3464
|
+
isMoved: undefined,
|
|
3465
|
+
allowTouchCallbacks: undefined,
|
|
3466
|
+
touchStartTime: undefined,
|
|
3467
|
+
isScrolling: undefined,
|
|
3468
|
+
currentTranslate: undefined,
|
|
3469
|
+
startTranslate: undefined,
|
|
3470
|
+
allowThresholdMove: undefined,
|
|
3471
|
+
// Form elements to match
|
|
3472
|
+
focusableElements: swiper.params.focusableElements,
|
|
3473
|
+
// Last click time
|
|
3474
|
+
lastClickTime: 0,
|
|
3475
|
+
clickTimeout: undefined,
|
|
3476
|
+
// Velocities
|
|
3477
|
+
velocities: [],
|
|
3478
|
+
allowMomentumBounce: undefined,
|
|
3479
|
+
startMoving: undefined,
|
|
3480
|
+
pointerId: null,
|
|
3481
|
+
touchId: null
|
|
3482
|
+
},
|
|
3483
|
+
// Clicks
|
|
3484
|
+
allowClick: true,
|
|
3485
|
+
// Touches
|
|
3486
|
+
allowTouchMove: swiper.params.allowTouchMove,
|
|
3487
|
+
touches: {
|
|
3488
|
+
startX: 0,
|
|
3489
|
+
startY: 0,
|
|
3490
|
+
currentX: 0,
|
|
3491
|
+
currentY: 0,
|
|
3492
|
+
diff: 0
|
|
3493
|
+
},
|
|
3494
|
+
// Images
|
|
3495
|
+
imagesToLoad: [],
|
|
3496
|
+
imagesLoaded: 0
|
|
3497
|
+
});
|
|
3498
|
+
swiper.emit('_swiper');
|
|
3499
|
+
|
|
3500
|
+
// Init
|
|
3501
|
+
if (swiper.params.init) {
|
|
3502
|
+
swiper.init();
|
|
3503
|
+
}
|
|
3504
|
+
|
|
3505
|
+
// Return app instance
|
|
3506
|
+
// eslint-disable-next-line no-constructor-return
|
|
3507
|
+
return swiper;
|
|
3508
|
+
}
|
|
3509
|
+
getDirectionLabel(property) {
|
|
3510
|
+
if (this.isHorizontal()) {
|
|
3511
|
+
return property;
|
|
3512
|
+
}
|
|
3513
|
+
// prettier-ignore
|
|
3514
|
+
return {
|
|
3515
|
+
'width': 'height',
|
|
3516
|
+
'margin-top': 'margin-left',
|
|
3517
|
+
'margin-bottom ': 'margin-right',
|
|
3518
|
+
'margin-left': 'margin-top',
|
|
3519
|
+
'margin-right': 'margin-bottom',
|
|
3520
|
+
'padding-left': 'padding-top',
|
|
3521
|
+
'padding-right': 'padding-bottom',
|
|
3522
|
+
'marginRight': 'marginBottom'
|
|
3523
|
+
}[property];
|
|
3524
|
+
}
|
|
3525
|
+
getSlideIndex(slideEl) {
|
|
3526
|
+
const {
|
|
3527
|
+
slidesEl,
|
|
3528
|
+
params
|
|
3529
|
+
} = this;
|
|
3530
|
+
const slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`);
|
|
3531
|
+
const firstSlideIndex = elementIndex(slides[0]);
|
|
3532
|
+
return elementIndex(slideEl) - firstSlideIndex;
|
|
3533
|
+
}
|
|
3534
|
+
getSlideIndexByData(index) {
|
|
3535
|
+
return this.getSlideIndex(this.slides.find(slideEl => slideEl.getAttribute('data-swiper-slide-index') * 1 === index));
|
|
3536
|
+
}
|
|
3537
|
+
getSlideIndexWhenGrid(index) {
|
|
3538
|
+
if (this.grid && this.params.grid && this.params.grid.rows > 1) {
|
|
3539
|
+
if (this.params.grid.fill === 'column') {
|
|
3540
|
+
index = Math.floor(index / this.params.grid.rows);
|
|
3541
|
+
} else if (this.params.grid.fill === 'row') {
|
|
3542
|
+
index = index % Math.ceil(this.slides.length / this.params.grid.rows);
|
|
3543
|
+
}
|
|
3544
|
+
}
|
|
3545
|
+
return index;
|
|
3546
|
+
}
|
|
3547
|
+
recalcSlides() {
|
|
3548
|
+
const swiper = this;
|
|
3549
|
+
const {
|
|
3550
|
+
slidesEl,
|
|
3551
|
+
params
|
|
3552
|
+
} = swiper;
|
|
3553
|
+
swiper.slides = elementChildren(slidesEl, `.${params.slideClass}, swiper-slide`);
|
|
3554
|
+
}
|
|
3555
|
+
enable() {
|
|
3556
|
+
const swiper = this;
|
|
3557
|
+
if (swiper.enabled) return;
|
|
3558
|
+
swiper.enabled = true;
|
|
3559
|
+
if (swiper.params.grabCursor) {
|
|
3560
|
+
swiper.setGrabCursor();
|
|
3561
|
+
}
|
|
3562
|
+
swiper.emit('enable');
|
|
3563
|
+
}
|
|
3564
|
+
disable() {
|
|
3565
|
+
const swiper = this;
|
|
3566
|
+
if (!swiper.enabled) return;
|
|
3567
|
+
swiper.enabled = false;
|
|
3568
|
+
if (swiper.params.grabCursor) {
|
|
3569
|
+
swiper.unsetGrabCursor();
|
|
3570
|
+
}
|
|
3571
|
+
swiper.emit('disable');
|
|
3572
|
+
}
|
|
3573
|
+
setProgress(progress, speed) {
|
|
3574
|
+
const swiper = this;
|
|
3575
|
+
progress = Math.min(Math.max(progress, 0), 1);
|
|
3576
|
+
const min = swiper.minTranslate();
|
|
3577
|
+
const max = swiper.maxTranslate();
|
|
3578
|
+
const current = (max - min) * progress + min;
|
|
3579
|
+
swiper.translateTo(current, typeof speed === 'undefined' ? 0 : speed);
|
|
3580
|
+
swiper.updateActiveIndex();
|
|
3581
|
+
swiper.updateSlidesClasses();
|
|
3582
|
+
}
|
|
3583
|
+
emitContainerClasses() {
|
|
3584
|
+
const swiper = this;
|
|
3585
|
+
if (!swiper.params._emitClasses || !swiper.el) return;
|
|
3586
|
+
const cls = swiper.el.className.split(' ').filter(className => {
|
|
3587
|
+
return className.indexOf('swiper') === 0 || className.indexOf(swiper.params.containerModifierClass) === 0;
|
|
3588
|
+
});
|
|
3589
|
+
swiper.emit('_containerClasses', cls.join(' '));
|
|
3590
|
+
}
|
|
3591
|
+
getSlideClasses(slideEl) {
|
|
3592
|
+
const swiper = this;
|
|
3593
|
+
if (swiper.destroyed) return '';
|
|
3594
|
+
return slideEl.className.split(' ').filter(className => {
|
|
3595
|
+
return className.indexOf('swiper-slide') === 0 || className.indexOf(swiper.params.slideClass) === 0;
|
|
3596
|
+
}).join(' ');
|
|
3597
|
+
}
|
|
3598
|
+
emitSlidesClasses() {
|
|
3599
|
+
const swiper = this;
|
|
3600
|
+
if (!swiper.params._emitClasses || !swiper.el) return;
|
|
3601
|
+
const updates = [];
|
|
3602
|
+
swiper.slides.forEach(slideEl => {
|
|
3603
|
+
const classNames = swiper.getSlideClasses(slideEl);
|
|
3604
|
+
updates.push({
|
|
3605
|
+
slideEl,
|
|
3606
|
+
classNames
|
|
3607
|
+
});
|
|
3608
|
+
swiper.emit('_slideClass', slideEl, classNames);
|
|
3609
|
+
});
|
|
3610
|
+
swiper.emit('_slideClasses', updates);
|
|
3611
|
+
}
|
|
3612
|
+
slidesPerViewDynamic(view, exact) {
|
|
3613
|
+
if (view === void 0) {
|
|
3614
|
+
view = 'current';
|
|
3615
|
+
}
|
|
3616
|
+
if (exact === void 0) {
|
|
3617
|
+
exact = false;
|
|
3618
|
+
}
|
|
3619
|
+
const swiper = this;
|
|
3620
|
+
const {
|
|
3621
|
+
params,
|
|
3622
|
+
slides,
|
|
3623
|
+
slidesGrid,
|
|
3624
|
+
slidesSizesGrid,
|
|
3625
|
+
size: swiperSize,
|
|
3626
|
+
activeIndex
|
|
3627
|
+
} = swiper;
|
|
3628
|
+
let spv = 1;
|
|
3629
|
+
if (typeof params.slidesPerView === 'number') return params.slidesPerView;
|
|
3630
|
+
if (params.centeredSlides) {
|
|
3631
|
+
let slideSize = slides[activeIndex] ? Math.ceil(slides[activeIndex].swiperSlideSize) : 0;
|
|
3632
|
+
let breakLoop;
|
|
3633
|
+
for (let i = activeIndex + 1; i < slides.length; i += 1) {
|
|
3634
|
+
if (slides[i] && !breakLoop) {
|
|
3635
|
+
slideSize += Math.ceil(slides[i].swiperSlideSize);
|
|
3636
|
+
spv += 1;
|
|
3637
|
+
if (slideSize > swiperSize) breakLoop = true;
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3640
|
+
for (let i = activeIndex - 1; i >= 0; i -= 1) {
|
|
3641
|
+
if (slides[i] && !breakLoop) {
|
|
3642
|
+
slideSize += slides[i].swiperSlideSize;
|
|
3643
|
+
spv += 1;
|
|
3644
|
+
if (slideSize > swiperSize) breakLoop = true;
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3647
|
+
} else {
|
|
3648
|
+
// eslint-disable-next-line
|
|
3649
|
+
if (view === 'current') {
|
|
3650
|
+
for (let i = activeIndex + 1; i < slides.length; i += 1) {
|
|
3651
|
+
const slideInView = exact ? slidesGrid[i] + slidesSizesGrid[i] - slidesGrid[activeIndex] < swiperSize : slidesGrid[i] - slidesGrid[activeIndex] < swiperSize;
|
|
3652
|
+
if (slideInView) {
|
|
3653
|
+
spv += 1;
|
|
3654
|
+
}
|
|
3655
|
+
}
|
|
3656
|
+
} else {
|
|
3657
|
+
// previous
|
|
3658
|
+
for (let i = activeIndex - 1; i >= 0; i -= 1) {
|
|
3659
|
+
const slideInView = slidesGrid[activeIndex] - slidesGrid[i] < swiperSize;
|
|
3660
|
+
if (slideInView) {
|
|
3661
|
+
spv += 1;
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
}
|
|
3665
|
+
}
|
|
3666
|
+
return spv;
|
|
3667
|
+
}
|
|
3668
|
+
update() {
|
|
3669
|
+
const swiper = this;
|
|
3670
|
+
if (!swiper || swiper.destroyed) return;
|
|
3671
|
+
const {
|
|
3672
|
+
snapGrid,
|
|
3673
|
+
params
|
|
3674
|
+
} = swiper;
|
|
3675
|
+
// Breakpoints
|
|
3676
|
+
if (params.breakpoints) {
|
|
3677
|
+
swiper.setBreakpoint();
|
|
3678
|
+
}
|
|
3679
|
+
[...swiper.el.querySelectorAll('[loading="lazy"]')].forEach(imageEl => {
|
|
3680
|
+
if (imageEl.complete) {
|
|
3681
|
+
processLazyPreloader(swiper, imageEl);
|
|
3682
|
+
}
|
|
3683
|
+
});
|
|
3684
|
+
swiper.updateSize();
|
|
3685
|
+
swiper.updateSlides();
|
|
3686
|
+
swiper.updateProgress();
|
|
3687
|
+
swiper.updateSlidesClasses();
|
|
3688
|
+
function setTranslate() {
|
|
3689
|
+
const translateValue = swiper.rtlTranslate ? swiper.translate * -1 : swiper.translate;
|
|
3690
|
+
const newTranslate = Math.min(Math.max(translateValue, swiper.maxTranslate()), swiper.minTranslate());
|
|
3691
|
+
swiper.setTranslate(newTranslate);
|
|
3692
|
+
swiper.updateActiveIndex();
|
|
3693
|
+
swiper.updateSlidesClasses();
|
|
3694
|
+
}
|
|
3695
|
+
let translated;
|
|
3696
|
+
if (params.freeMode && params.freeMode.enabled && !params.cssMode) {
|
|
3697
|
+
setTranslate();
|
|
3698
|
+
if (params.autoHeight) {
|
|
3699
|
+
swiper.updateAutoHeight();
|
|
3700
|
+
}
|
|
3701
|
+
} else {
|
|
3702
|
+
if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !params.centeredSlides) {
|
|
3703
|
+
const slides = swiper.virtual && params.virtual.enabled ? swiper.virtual.slides : swiper.slides;
|
|
3704
|
+
translated = swiper.slideTo(slides.length - 1, 0, false, true);
|
|
3705
|
+
} else {
|
|
3706
|
+
translated = swiper.slideTo(swiper.activeIndex, 0, false, true);
|
|
3707
|
+
}
|
|
3708
|
+
if (!translated) {
|
|
3709
|
+
setTranslate();
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
if (params.watchOverflow && snapGrid !== swiper.snapGrid) {
|
|
3713
|
+
swiper.checkOverflow();
|
|
3714
|
+
}
|
|
3715
|
+
swiper.emit('update');
|
|
3716
|
+
}
|
|
3717
|
+
changeDirection(newDirection, needUpdate) {
|
|
3718
|
+
if (needUpdate === void 0) {
|
|
3719
|
+
needUpdate = true;
|
|
3720
|
+
}
|
|
3721
|
+
const swiper = this;
|
|
3722
|
+
const currentDirection = swiper.params.direction;
|
|
3723
|
+
if (!newDirection) {
|
|
3724
|
+
// eslint-disable-next-line
|
|
3725
|
+
newDirection = currentDirection === 'horizontal' ? 'vertical' : 'horizontal';
|
|
3726
|
+
}
|
|
3727
|
+
if (newDirection === currentDirection || newDirection !== 'horizontal' && newDirection !== 'vertical') {
|
|
3728
|
+
return swiper;
|
|
3729
|
+
}
|
|
3730
|
+
swiper.el.classList.remove(`${swiper.params.containerModifierClass}${currentDirection}`);
|
|
3731
|
+
swiper.el.classList.add(`${swiper.params.containerModifierClass}${newDirection}`);
|
|
3732
|
+
swiper.emitContainerClasses();
|
|
3733
|
+
swiper.params.direction = newDirection;
|
|
3734
|
+
swiper.slides.forEach(slideEl => {
|
|
3735
|
+
if (newDirection === 'vertical') {
|
|
3736
|
+
slideEl.style.width = '';
|
|
3737
|
+
} else {
|
|
3738
|
+
slideEl.style.height = '';
|
|
3739
|
+
}
|
|
3740
|
+
});
|
|
3741
|
+
swiper.emit('changeDirection');
|
|
3742
|
+
if (needUpdate) swiper.update();
|
|
3743
|
+
return swiper;
|
|
3744
|
+
}
|
|
3745
|
+
changeLanguageDirection(direction) {
|
|
3746
|
+
const swiper = this;
|
|
3747
|
+
if (swiper.rtl && direction === 'rtl' || !swiper.rtl && direction === 'ltr') return;
|
|
3748
|
+
swiper.rtl = direction === 'rtl';
|
|
3749
|
+
swiper.rtlTranslate = swiper.params.direction === 'horizontal' && swiper.rtl;
|
|
3750
|
+
if (swiper.rtl) {
|
|
3751
|
+
swiper.el.classList.add(`${swiper.params.containerModifierClass}rtl`);
|
|
3752
|
+
swiper.el.dir = 'rtl';
|
|
3753
|
+
} else {
|
|
3754
|
+
swiper.el.classList.remove(`${swiper.params.containerModifierClass}rtl`);
|
|
3755
|
+
swiper.el.dir = 'ltr';
|
|
3756
|
+
}
|
|
3757
|
+
swiper.update();
|
|
3758
|
+
}
|
|
3759
|
+
mount(element) {
|
|
3760
|
+
const swiper = this;
|
|
3761
|
+
if (swiper.mounted) return true;
|
|
3762
|
+
|
|
3763
|
+
// Find el
|
|
3764
|
+
let el = element || swiper.params.el;
|
|
3765
|
+
if (typeof el === 'string') {
|
|
3766
|
+
el = document.querySelector(el);
|
|
3767
|
+
}
|
|
3768
|
+
if (!el) {
|
|
3769
|
+
return false;
|
|
3770
|
+
}
|
|
3771
|
+
el.swiper = swiper;
|
|
3772
|
+
if (el.parentNode && el.parentNode.host && el.parentNode.host.nodeName === swiper.params.swiperElementNodeName.toUpperCase()) {
|
|
3773
|
+
swiper.isElement = true;
|
|
3774
|
+
}
|
|
3775
|
+
const getWrapperSelector = () => {
|
|
3776
|
+
return `.${(swiper.params.wrapperClass || '').trim().split(' ').join('.')}`;
|
|
3777
|
+
};
|
|
3778
|
+
const getWrapper = () => {
|
|
3779
|
+
if (el && el.shadowRoot && el.shadowRoot.querySelector) {
|
|
3780
|
+
const res = el.shadowRoot.querySelector(getWrapperSelector());
|
|
3781
|
+
// Children needs to return slot items
|
|
3782
|
+
return res;
|
|
3783
|
+
}
|
|
3784
|
+
return elementChildren(el, getWrapperSelector())[0];
|
|
3785
|
+
};
|
|
3786
|
+
// Find Wrapper
|
|
3787
|
+
let wrapperEl = getWrapper();
|
|
3788
|
+
if (!wrapperEl && swiper.params.createElements) {
|
|
3789
|
+
wrapperEl = createElement('div', swiper.params.wrapperClass);
|
|
3790
|
+
el.append(wrapperEl);
|
|
3791
|
+
elementChildren(el, `.${swiper.params.slideClass}`).forEach(slideEl => {
|
|
3792
|
+
wrapperEl.append(slideEl);
|
|
3793
|
+
});
|
|
3794
|
+
}
|
|
3795
|
+
Object.assign(swiper, {
|
|
3796
|
+
el,
|
|
3797
|
+
wrapperEl,
|
|
3798
|
+
slidesEl: swiper.isElement && !el.parentNode.host.slideSlots ? el.parentNode.host : wrapperEl,
|
|
3799
|
+
hostEl: swiper.isElement ? el.parentNode.host : el,
|
|
3800
|
+
mounted: true,
|
|
3801
|
+
// RTL
|
|
3802
|
+
rtl: el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl',
|
|
3803
|
+
rtlTranslate: swiper.params.direction === 'horizontal' && (el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl'),
|
|
3804
|
+
wrongRTL: elementStyle(wrapperEl, 'display') === '-webkit-box'
|
|
3805
|
+
});
|
|
3806
|
+
return true;
|
|
3807
|
+
}
|
|
3808
|
+
init(el) {
|
|
3809
|
+
const swiper = this;
|
|
3810
|
+
if (swiper.initialized) return swiper;
|
|
3811
|
+
const mounted = swiper.mount(el);
|
|
3812
|
+
if (mounted === false) return swiper;
|
|
3813
|
+
swiper.emit('beforeInit');
|
|
3814
|
+
|
|
3815
|
+
// Set breakpoint
|
|
3816
|
+
if (swiper.params.breakpoints) {
|
|
3817
|
+
swiper.setBreakpoint();
|
|
3818
|
+
}
|
|
3819
|
+
|
|
3820
|
+
// Add Classes
|
|
3821
|
+
swiper.addClasses();
|
|
3822
|
+
|
|
3823
|
+
// Update size
|
|
3824
|
+
swiper.updateSize();
|
|
3825
|
+
|
|
3826
|
+
// Update slides
|
|
3827
|
+
swiper.updateSlides();
|
|
3828
|
+
if (swiper.params.watchOverflow) {
|
|
3829
|
+
swiper.checkOverflow();
|
|
3830
|
+
}
|
|
3831
|
+
|
|
3832
|
+
// Set Grab Cursor
|
|
3833
|
+
if (swiper.params.grabCursor && swiper.enabled) {
|
|
3834
|
+
swiper.setGrabCursor();
|
|
3835
|
+
}
|
|
3836
|
+
|
|
3837
|
+
// Slide To Initial Slide
|
|
3838
|
+
if (swiper.params.loop && swiper.virtual && swiper.params.virtual.enabled) {
|
|
3839
|
+
swiper.slideTo(swiper.params.initialSlide + swiper.virtual.slidesBefore, 0, swiper.params.runCallbacksOnInit, false, true);
|
|
3840
|
+
} else {
|
|
3841
|
+
swiper.slideTo(swiper.params.initialSlide, 0, swiper.params.runCallbacksOnInit, false, true);
|
|
3842
|
+
}
|
|
3843
|
+
|
|
3844
|
+
// Create loop
|
|
3845
|
+
if (swiper.params.loop) {
|
|
3846
|
+
swiper.loopCreate(undefined, true);
|
|
3847
|
+
}
|
|
3848
|
+
|
|
3849
|
+
// Attach events
|
|
3850
|
+
swiper.attachEvents();
|
|
3851
|
+
const lazyElements = [...swiper.el.querySelectorAll('[loading="lazy"]')];
|
|
3852
|
+
if (swiper.isElement) {
|
|
3853
|
+
lazyElements.push(...swiper.hostEl.querySelectorAll('[loading="lazy"]'));
|
|
3854
|
+
}
|
|
3855
|
+
lazyElements.forEach(imageEl => {
|
|
3856
|
+
if (imageEl.complete) {
|
|
3857
|
+
processLazyPreloader(swiper, imageEl);
|
|
3858
|
+
} else {
|
|
3859
|
+
imageEl.addEventListener('load', e => {
|
|
3860
|
+
processLazyPreloader(swiper, e.target);
|
|
3861
|
+
});
|
|
3862
|
+
}
|
|
3863
|
+
});
|
|
3864
|
+
preload(swiper);
|
|
3865
|
+
|
|
3866
|
+
// Init Flag
|
|
3867
|
+
swiper.initialized = true;
|
|
3868
|
+
preload(swiper);
|
|
3869
|
+
|
|
3870
|
+
// Emit
|
|
3871
|
+
swiper.emit('init');
|
|
3872
|
+
swiper.emit('afterInit');
|
|
3873
|
+
return swiper;
|
|
3874
|
+
}
|
|
3875
|
+
destroy(deleteInstance, cleanStyles) {
|
|
3876
|
+
if (deleteInstance === void 0) {
|
|
3877
|
+
deleteInstance = true;
|
|
3878
|
+
}
|
|
3879
|
+
if (cleanStyles === void 0) {
|
|
3880
|
+
cleanStyles = true;
|
|
3881
|
+
}
|
|
3882
|
+
const swiper = this;
|
|
3883
|
+
const {
|
|
3884
|
+
params,
|
|
3885
|
+
el,
|
|
3886
|
+
wrapperEl,
|
|
3887
|
+
slides
|
|
3888
|
+
} = swiper;
|
|
3889
|
+
if (typeof swiper.params === 'undefined' || swiper.destroyed) {
|
|
3890
|
+
return null;
|
|
3891
|
+
}
|
|
3892
|
+
swiper.emit('beforeDestroy');
|
|
3893
|
+
|
|
3894
|
+
// Init Flag
|
|
3895
|
+
swiper.initialized = false;
|
|
3896
|
+
|
|
3897
|
+
// Detach events
|
|
3898
|
+
swiper.detachEvents();
|
|
3899
|
+
|
|
3900
|
+
// Destroy loop
|
|
3901
|
+
if (params.loop) {
|
|
3902
|
+
swiper.loopDestroy();
|
|
3903
|
+
}
|
|
3904
|
+
|
|
3905
|
+
// Cleanup styles
|
|
3906
|
+
if (cleanStyles) {
|
|
3907
|
+
swiper.removeClasses();
|
|
3908
|
+
if (el && typeof el !== 'string') {
|
|
3909
|
+
el.removeAttribute('style');
|
|
3910
|
+
}
|
|
3911
|
+
if (wrapperEl) {
|
|
3912
|
+
wrapperEl.removeAttribute('style');
|
|
3913
|
+
}
|
|
3914
|
+
if (slides && slides.length) {
|
|
3915
|
+
slides.forEach(slideEl => {
|
|
3916
|
+
slideEl.classList.remove(params.slideVisibleClass, params.slideFullyVisibleClass, params.slideActiveClass, params.slideNextClass, params.slidePrevClass);
|
|
3917
|
+
slideEl.removeAttribute('style');
|
|
3918
|
+
slideEl.removeAttribute('data-swiper-slide-index');
|
|
3919
|
+
});
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
swiper.emit('destroy');
|
|
3923
|
+
|
|
3924
|
+
// Detach emitter events
|
|
3925
|
+
Object.keys(swiper.eventsListeners).forEach(eventName => {
|
|
3926
|
+
swiper.off(eventName);
|
|
3927
|
+
});
|
|
3928
|
+
if (deleteInstance !== false) {
|
|
3929
|
+
if (swiper.el && typeof swiper.el !== 'string') {
|
|
3930
|
+
swiper.el.swiper = null;
|
|
3931
|
+
}
|
|
3932
|
+
deleteProps(swiper);
|
|
3933
|
+
}
|
|
3934
|
+
swiper.destroyed = true;
|
|
3935
|
+
return null;
|
|
3936
|
+
}
|
|
3937
|
+
static extendDefaults(newDefaults) {
|
|
3938
|
+
extend(extendedDefaults, newDefaults);
|
|
3939
|
+
}
|
|
3940
|
+
static get extendedDefaults() {
|
|
3941
|
+
return extendedDefaults;
|
|
3942
|
+
}
|
|
3943
|
+
static get defaults() {
|
|
3944
|
+
return defaults;
|
|
3945
|
+
}
|
|
3946
|
+
static installModule(mod) {
|
|
3947
|
+
if (!Swiper.prototype.__modules__) Swiper.prototype.__modules__ = [];
|
|
3948
|
+
const modules = Swiper.prototype.__modules__;
|
|
3949
|
+
if (typeof mod === 'function' && modules.indexOf(mod) < 0) {
|
|
3950
|
+
modules.push(mod);
|
|
3951
|
+
}
|
|
3952
|
+
}
|
|
3953
|
+
static use(module) {
|
|
3954
|
+
if (Array.isArray(module)) {
|
|
3955
|
+
module.forEach(m => Swiper.installModule(m));
|
|
3956
|
+
return Swiper;
|
|
3957
|
+
}
|
|
3958
|
+
Swiper.installModule(module);
|
|
3959
|
+
return Swiper;
|
|
3960
|
+
}
|
|
3961
|
+
}
|
|
3962
|
+
Object.keys(prototypes).forEach(prototypeGroup => {
|
|
3963
|
+
Object.keys(prototypes[prototypeGroup]).forEach(protoMethod => {
|
|
3964
|
+
Swiper.prototype[protoMethod] = prototypes[prototypeGroup][protoMethod];
|
|
3965
|
+
});
|
|
3966
|
+
});
|
|
3967
|
+
Swiper.use([Resize, Observer]);
|
|
3968
|
+
|
|
3969
|
+
export { Swiper as S, defaults as d };
|