1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | (function (global, factory) {
|
14 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
15 | typeof define === 'function' && define.amd ? define(factory) :
|
16 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Swiper = factory());
|
17 | })(this, (function () { 'use strict';
|
18 |
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | function isObject$1(obj) {
|
33 | return obj !== null && typeof obj === 'object' && 'constructor' in obj && obj.constructor === Object;
|
34 | }
|
35 |
|
36 | function extend$1(target, src) {
|
37 | if (target === void 0) {
|
38 | target = {};
|
39 | }
|
40 |
|
41 | if (src === void 0) {
|
42 | src = {};
|
43 | }
|
44 |
|
45 | Object.keys(src).forEach(key => {
|
46 | if (typeof target[key] === 'undefined') target[key] = src[key];else if (isObject$1(src[key]) && isObject$1(target[key]) && Object.keys(src[key]).length > 0) {
|
47 | extend$1(target[key], src[key]);
|
48 | }
|
49 | });
|
50 | }
|
51 |
|
52 | const ssrDocument = {
|
53 | body: {},
|
54 |
|
55 | addEventListener() {},
|
56 |
|
57 | removeEventListener() {},
|
58 |
|
59 | activeElement: {
|
60 | blur() {},
|
61 |
|
62 | nodeName: ''
|
63 | },
|
64 |
|
65 | querySelector() {
|
66 | return null;
|
67 | },
|
68 |
|
69 | querySelectorAll() {
|
70 | return [];
|
71 | },
|
72 |
|
73 | getElementById() {
|
74 | return null;
|
75 | },
|
76 |
|
77 | createEvent() {
|
78 | return {
|
79 | initEvent() {}
|
80 |
|
81 | };
|
82 | },
|
83 |
|
84 | createElement() {
|
85 | return {
|
86 | children: [],
|
87 | childNodes: [],
|
88 | style: {},
|
89 |
|
90 | setAttribute() {},
|
91 |
|
92 | getElementsByTagName() {
|
93 | return [];
|
94 | }
|
95 |
|
96 | };
|
97 | },
|
98 |
|
99 | createElementNS() {
|
100 | return {};
|
101 | },
|
102 |
|
103 | importNode() {
|
104 | return null;
|
105 | },
|
106 |
|
107 | location: {
|
108 | hash: '',
|
109 | host: '',
|
110 | hostname: '',
|
111 | href: '',
|
112 | origin: '',
|
113 | pathname: '',
|
114 | protocol: '',
|
115 | search: ''
|
116 | }
|
117 | };
|
118 |
|
119 | function getDocument() {
|
120 | const doc = typeof document !== 'undefined' ? document : {};
|
121 | extend$1(doc, ssrDocument);
|
122 | return doc;
|
123 | }
|
124 |
|
125 | const ssrWindow = {
|
126 | document: ssrDocument,
|
127 | navigator: {
|
128 | userAgent: ''
|
129 | },
|
130 | location: {
|
131 | hash: '',
|
132 | host: '',
|
133 | hostname: '',
|
134 | href: '',
|
135 | origin: '',
|
136 | pathname: '',
|
137 | protocol: '',
|
138 | search: ''
|
139 | },
|
140 | history: {
|
141 | replaceState() {},
|
142 |
|
143 | pushState() {},
|
144 |
|
145 | go() {},
|
146 |
|
147 | back() {}
|
148 |
|
149 | },
|
150 | CustomEvent: function CustomEvent() {
|
151 | return this;
|
152 | },
|
153 |
|
154 | addEventListener() {},
|
155 |
|
156 | removeEventListener() {},
|
157 |
|
158 | getComputedStyle() {
|
159 | return {
|
160 | getPropertyValue() {
|
161 | return '';
|
162 | }
|
163 |
|
164 | };
|
165 | },
|
166 |
|
167 | Image() {},
|
168 |
|
169 | Date() {},
|
170 |
|
171 | screen: {},
|
172 |
|
173 | setTimeout() {},
|
174 |
|
175 | clearTimeout() {},
|
176 |
|
177 | matchMedia() {
|
178 | return {};
|
179 | },
|
180 |
|
181 | requestAnimationFrame(callback) {
|
182 | if (typeof setTimeout === 'undefined') {
|
183 | callback();
|
184 | return null;
|
185 | }
|
186 |
|
187 | return setTimeout(callback, 0);
|
188 | },
|
189 |
|
190 | cancelAnimationFrame(id) {
|
191 | if (typeof setTimeout === 'undefined') {
|
192 | return;
|
193 | }
|
194 |
|
195 | clearTimeout(id);
|
196 | }
|
197 |
|
198 | };
|
199 |
|
200 | function getWindow() {
|
201 | const win = typeof window !== 'undefined' ? window : {};
|
202 | extend$1(win, ssrWindow);
|
203 | return win;
|
204 | }
|
205 |
|
206 | |
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 | function makeReactive(obj) {
|
220 | const proto = obj.__proto__;
|
221 | Object.defineProperty(obj, '__proto__', {
|
222 | get() {
|
223 | return proto;
|
224 | },
|
225 |
|
226 | set(value) {
|
227 | proto.__proto__ = value;
|
228 | }
|
229 |
|
230 | });
|
231 | }
|
232 |
|
233 | class Dom7 extends Array {
|
234 | constructor(items) {
|
235 | if (typeof items === 'number') {
|
236 | super(items);
|
237 | } else {
|
238 | super(...(items || []));
|
239 | makeReactive(this);
|
240 | }
|
241 | }
|
242 |
|
243 | }
|
244 |
|
245 | function arrayFlat(arr) {
|
246 | if (arr === void 0) {
|
247 | arr = [];
|
248 | }
|
249 |
|
250 | const res = [];
|
251 | arr.forEach(el => {
|
252 | if (Array.isArray(el)) {
|
253 | res.push(...arrayFlat(el));
|
254 | } else {
|
255 | res.push(el);
|
256 | }
|
257 | });
|
258 | return res;
|
259 | }
|
260 |
|
261 | function arrayFilter(arr, callback) {
|
262 | return Array.prototype.filter.call(arr, callback);
|
263 | }
|
264 |
|
265 | function arrayUnique(arr) {
|
266 | const uniqueArray = [];
|
267 |
|
268 | for (let i = 0; i < arr.length; i += 1) {
|
269 | if (uniqueArray.indexOf(arr[i]) === -1) uniqueArray.push(arr[i]);
|
270 | }
|
271 |
|
272 | return uniqueArray;
|
273 | }
|
274 |
|
275 |
|
276 | function qsa(selector, context) {
|
277 | if (typeof selector !== 'string') {
|
278 | return [selector];
|
279 | }
|
280 |
|
281 | const a = [];
|
282 | const res = context.querySelectorAll(selector);
|
283 |
|
284 | for (let i = 0; i < res.length; i += 1) {
|
285 | a.push(res[i]);
|
286 | }
|
287 |
|
288 | return a;
|
289 | }
|
290 |
|
291 | function $(selector, context) {
|
292 | const window = getWindow();
|
293 | const document = getDocument();
|
294 | let arr = [];
|
295 |
|
296 | if (!context && selector instanceof Dom7) {
|
297 | return selector;
|
298 | }
|
299 |
|
300 | if (!selector) {
|
301 | return new Dom7(arr);
|
302 | }
|
303 |
|
304 | if (typeof selector === 'string') {
|
305 | const html = selector.trim();
|
306 |
|
307 | if (html.indexOf('<') >= 0 && html.indexOf('>') >= 0) {
|
308 | let toCreate = 'div';
|
309 | if (html.indexOf('<li') === 0) toCreate = 'ul';
|
310 | if (html.indexOf('<tr') === 0) toCreate = 'tbody';
|
311 | if (html.indexOf('<td') === 0 || html.indexOf('<th') === 0) toCreate = 'tr';
|
312 | if (html.indexOf('<tbody') === 0) toCreate = 'table';
|
313 | if (html.indexOf('<option') === 0) toCreate = 'select';
|
314 | const tempParent = document.createElement(toCreate);
|
315 | tempParent.innerHTML = html;
|
316 |
|
317 | for (let i = 0; i < tempParent.childNodes.length; i += 1) {
|
318 | arr.push(tempParent.childNodes[i]);
|
319 | }
|
320 | } else {
|
321 | arr = qsa(selector.trim(), context || document);
|
322 | }
|
323 |
|
324 | } else if (selector.nodeType || selector === window || selector === document) {
|
325 | arr.push(selector);
|
326 | } else if (Array.isArray(selector)) {
|
327 | if (selector instanceof Dom7) return selector;
|
328 | arr = selector;
|
329 | }
|
330 |
|
331 | return new Dom7(arrayUnique(arr));
|
332 | }
|
333 |
|
334 | $.fn = Dom7.prototype;
|
335 |
|
336 | function addClass() {
|
337 | for (var _len = arguments.length, classes = new Array(_len), _key = 0; _key < _len; _key++) {
|
338 | classes[_key] = arguments[_key];
|
339 | }
|
340 |
|
341 | const classNames = arrayFlat(classes.map(c => c.split(' ')));
|
342 | this.forEach(el => {
|
343 | el.classList.add(...classNames);
|
344 | });
|
345 | return this;
|
346 | }
|
347 |
|
348 | function removeClass() {
|
349 | for (var _len2 = arguments.length, classes = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
350 | classes[_key2] = arguments[_key2];
|
351 | }
|
352 |
|
353 | const classNames = arrayFlat(classes.map(c => c.split(' ')));
|
354 | this.forEach(el => {
|
355 | el.classList.remove(...classNames);
|
356 | });
|
357 | return this;
|
358 | }
|
359 |
|
360 | function toggleClass() {
|
361 | for (var _len3 = arguments.length, classes = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
362 | classes[_key3] = arguments[_key3];
|
363 | }
|
364 |
|
365 | const classNames = arrayFlat(classes.map(c => c.split(' ')));
|
366 | this.forEach(el => {
|
367 | classNames.forEach(className => {
|
368 | el.classList.toggle(className);
|
369 | });
|
370 | });
|
371 | }
|
372 |
|
373 | function hasClass() {
|
374 | for (var _len4 = arguments.length, classes = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
375 | classes[_key4] = arguments[_key4];
|
376 | }
|
377 |
|
378 | const classNames = arrayFlat(classes.map(c => c.split(' ')));
|
379 | return arrayFilter(this, el => {
|
380 | return classNames.filter(className => el.classList.contains(className)).length > 0;
|
381 | }).length > 0;
|
382 | }
|
383 |
|
384 | function attr(attrs, value) {
|
385 | if (arguments.length === 1 && typeof attrs === 'string') {
|
386 |
|
387 | if (this[0]) return this[0].getAttribute(attrs);
|
388 | return undefined;
|
389 | }
|
390 |
|
391 |
|
392 | for (let i = 0; i < this.length; i += 1) {
|
393 | if (arguments.length === 2) {
|
394 |
|
395 | this[i].setAttribute(attrs, value);
|
396 | } else {
|
397 |
|
398 | for (const attrName in attrs) {
|
399 | this[i][attrName] = attrs[attrName];
|
400 | this[i].setAttribute(attrName, attrs[attrName]);
|
401 | }
|
402 | }
|
403 | }
|
404 |
|
405 | return this;
|
406 | }
|
407 |
|
408 | function removeAttr(attr) {
|
409 | for (let i = 0; i < this.length; i += 1) {
|
410 | this[i].removeAttribute(attr);
|
411 | }
|
412 |
|
413 | return this;
|
414 | }
|
415 |
|
416 | function transform(transform) {
|
417 | for (let i = 0; i < this.length; i += 1) {
|
418 | this[i].style.transform = transform;
|
419 | }
|
420 |
|
421 | return this;
|
422 | }
|
423 |
|
424 | function transition$1(duration) {
|
425 | for (let i = 0; i < this.length; i += 1) {
|
426 | this[i].style.transitionDuration = typeof duration !== 'string' ? `${duration}ms` : duration;
|
427 | }
|
428 |
|
429 | return this;
|
430 | }
|
431 |
|
432 | function on() {
|
433 | for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
434 | args[_key5] = arguments[_key5];
|
435 | }
|
436 |
|
437 | let [eventType, targetSelector, listener, capture] = args;
|
438 |
|
439 | if (typeof args[1] === 'function') {
|
440 | [eventType, listener, capture] = args;
|
441 | targetSelector = undefined;
|
442 | }
|
443 |
|
444 | if (!capture) capture = false;
|
445 |
|
446 | function handleLiveEvent(e) {
|
447 | const target = e.target;
|
448 | if (!target) return;
|
449 | const eventData = e.target.dom7EventData || [];
|
450 |
|
451 | if (eventData.indexOf(e) < 0) {
|
452 | eventData.unshift(e);
|
453 | }
|
454 |
|
455 | if ($(target).is(targetSelector)) listener.apply(target, eventData);else {
|
456 | const parents = $(target).parents();
|
457 |
|
458 | for (let k = 0; k < parents.length; k += 1) {
|
459 | if ($(parents[k]).is(targetSelector)) listener.apply(parents[k], eventData);
|
460 | }
|
461 | }
|
462 | }
|
463 |
|
464 | function handleEvent(e) {
|
465 | const eventData = e && e.target ? e.target.dom7EventData || [] : [];
|
466 |
|
467 | if (eventData.indexOf(e) < 0) {
|
468 | eventData.unshift(e);
|
469 | }
|
470 |
|
471 | listener.apply(this, eventData);
|
472 | }
|
473 |
|
474 | const events = eventType.split(' ');
|
475 | let j;
|
476 |
|
477 | for (let i = 0; i < this.length; i += 1) {
|
478 | const el = this[i];
|
479 |
|
480 | if (!targetSelector) {
|
481 | for (j = 0; j < events.length; j += 1) {
|
482 | const event = events[j];
|
483 | if (!el.dom7Listeners) el.dom7Listeners = {};
|
484 | if (!el.dom7Listeners[event]) el.dom7Listeners[event] = [];
|
485 | el.dom7Listeners[event].push({
|
486 | listener,
|
487 | proxyListener: handleEvent
|
488 | });
|
489 | el.addEventListener(event, handleEvent, capture);
|
490 | }
|
491 | } else {
|
492 |
|
493 | for (j = 0; j < events.length; j += 1) {
|
494 | const event = events[j];
|
495 | if (!el.dom7LiveListeners) el.dom7LiveListeners = {};
|
496 | if (!el.dom7LiveListeners[event]) el.dom7LiveListeners[event] = [];
|
497 | el.dom7LiveListeners[event].push({
|
498 | listener,
|
499 | proxyListener: handleLiveEvent
|
500 | });
|
501 | el.addEventListener(event, handleLiveEvent, capture);
|
502 | }
|
503 | }
|
504 | }
|
505 |
|
506 | return this;
|
507 | }
|
508 |
|
509 | function off() {
|
510 | for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
511 | args[_key6] = arguments[_key6];
|
512 | }
|
513 |
|
514 | let [eventType, targetSelector, listener, capture] = args;
|
515 |
|
516 | if (typeof args[1] === 'function') {
|
517 | [eventType, listener, capture] = args;
|
518 | targetSelector = undefined;
|
519 | }
|
520 |
|
521 | if (!capture) capture = false;
|
522 | const events = eventType.split(' ');
|
523 |
|
524 | for (let i = 0; i < events.length; i += 1) {
|
525 | const event = events[i];
|
526 |
|
527 | for (let j = 0; j < this.length; j += 1) {
|
528 | const el = this[j];
|
529 | let handlers;
|
530 |
|
531 | if (!targetSelector && el.dom7Listeners) {
|
532 | handlers = el.dom7Listeners[event];
|
533 | } else if (targetSelector && el.dom7LiveListeners) {
|
534 | handlers = el.dom7LiveListeners[event];
|
535 | }
|
536 |
|
537 | if (handlers && handlers.length) {
|
538 | for (let k = handlers.length - 1; k >= 0; k -= 1) {
|
539 | const handler = handlers[k];
|
540 |
|
541 | if (listener && handler.listener === listener) {
|
542 | el.removeEventListener(event, handler.proxyListener, capture);
|
543 | handlers.splice(k, 1);
|
544 | } else if (listener && handler.listener && handler.listener.dom7proxy && handler.listener.dom7proxy === listener) {
|
545 | el.removeEventListener(event, handler.proxyListener, capture);
|
546 | handlers.splice(k, 1);
|
547 | } else if (!listener) {
|
548 | el.removeEventListener(event, handler.proxyListener, capture);
|
549 | handlers.splice(k, 1);
|
550 | }
|
551 | }
|
552 | }
|
553 | }
|
554 | }
|
555 |
|
556 | return this;
|
557 | }
|
558 |
|
559 | function trigger() {
|
560 | const window = getWindow();
|
561 |
|
562 | for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
|
563 | args[_key9] = arguments[_key9];
|
564 | }
|
565 |
|
566 | const events = args[0].split(' ');
|
567 | const eventData = args[1];
|
568 |
|
569 | for (let i = 0; i < events.length; i += 1) {
|
570 | const event = events[i];
|
571 |
|
572 | for (let j = 0; j < this.length; j += 1) {
|
573 | const el = this[j];
|
574 |
|
575 | if (window.CustomEvent) {
|
576 | const evt = new window.CustomEvent(event, {
|
577 | detail: eventData,
|
578 | bubbles: true,
|
579 | cancelable: true
|
580 | });
|
581 | el.dom7EventData = args.filter((data, dataIndex) => dataIndex > 0);
|
582 | el.dispatchEvent(evt);
|
583 | el.dom7EventData = [];
|
584 | delete el.dom7EventData;
|
585 | }
|
586 | }
|
587 | }
|
588 |
|
589 | return this;
|
590 | }
|
591 |
|
592 | function transitionEnd$1(callback) {
|
593 | const dom = this;
|
594 |
|
595 | function fireCallBack(e) {
|
596 | if (e.target !== this) return;
|
597 | callback.call(this, e);
|
598 | dom.off('transitionend', fireCallBack);
|
599 | }
|
600 |
|
601 | if (callback) {
|
602 | dom.on('transitionend', fireCallBack);
|
603 | }
|
604 |
|
605 | return this;
|
606 | }
|
607 |
|
608 | function outerWidth(includeMargins) {
|
609 | if (this.length > 0) {
|
610 | if (includeMargins) {
|
611 | const styles = this.styles();
|
612 | return this[0].offsetWidth + parseFloat(styles.getPropertyValue('margin-right')) + parseFloat(styles.getPropertyValue('margin-left'));
|
613 | }
|
614 |
|
615 | return this[0].offsetWidth;
|
616 | }
|
617 |
|
618 | return null;
|
619 | }
|
620 |
|
621 | function outerHeight(includeMargins) {
|
622 | if (this.length > 0) {
|
623 | if (includeMargins) {
|
624 | const styles = this.styles();
|
625 | return this[0].offsetHeight + parseFloat(styles.getPropertyValue('margin-top')) + parseFloat(styles.getPropertyValue('margin-bottom'));
|
626 | }
|
627 |
|
628 | return this[0].offsetHeight;
|
629 | }
|
630 |
|
631 | return null;
|
632 | }
|
633 |
|
634 | function offset() {
|
635 | if (this.length > 0) {
|
636 | const window = getWindow();
|
637 | const document = getDocument();
|
638 | const el = this[0];
|
639 | const box = el.getBoundingClientRect();
|
640 | const body = document.body;
|
641 | const clientTop = el.clientTop || body.clientTop || 0;
|
642 | const clientLeft = el.clientLeft || body.clientLeft || 0;
|
643 | const scrollTop = el === window ? window.scrollY : el.scrollTop;
|
644 | const scrollLeft = el === window ? window.scrollX : el.scrollLeft;
|
645 | return {
|
646 | top: box.top + scrollTop - clientTop,
|
647 | left: box.left + scrollLeft - clientLeft
|
648 | };
|
649 | }
|
650 |
|
651 | return null;
|
652 | }
|
653 |
|
654 | function styles() {
|
655 | const window = getWindow();
|
656 | if (this[0]) return window.getComputedStyle(this[0], null);
|
657 | return {};
|
658 | }
|
659 |
|
660 | function css(props, value) {
|
661 | const window = getWindow();
|
662 | let i;
|
663 |
|
664 | if (arguments.length === 1) {
|
665 | if (typeof props === 'string') {
|
666 |
|
667 | if (this[0]) return window.getComputedStyle(this[0], null).getPropertyValue(props);
|
668 | } else {
|
669 |
|
670 | for (i = 0; i < this.length; i += 1) {
|
671 | for (const prop in props) {
|
672 | this[i].style[prop] = props[prop];
|
673 | }
|
674 | }
|
675 |
|
676 | return this;
|
677 | }
|
678 | }
|
679 |
|
680 | if (arguments.length === 2 && typeof props === 'string') {
|
681 |
|
682 | for (i = 0; i < this.length; i += 1) {
|
683 | this[i].style[props] = value;
|
684 | }
|
685 |
|
686 | return this;
|
687 | }
|
688 |
|
689 | return this;
|
690 | }
|
691 |
|
692 | function each(callback) {
|
693 | if (!callback) return this;
|
694 | this.forEach((el, index) => {
|
695 | callback.apply(el, [el, index]);
|
696 | });
|
697 | return this;
|
698 | }
|
699 |
|
700 | function filter(callback) {
|
701 | const result = arrayFilter(this, callback);
|
702 | return $(result);
|
703 | }
|
704 |
|
705 | function html(html) {
|
706 | if (typeof html === 'undefined') {
|
707 | return this[0] ? this[0].innerHTML : null;
|
708 | }
|
709 |
|
710 | for (let i = 0; i < this.length; i += 1) {
|
711 | this[i].innerHTML = html;
|
712 | }
|
713 |
|
714 | return this;
|
715 | }
|
716 |
|
717 | function text(text) {
|
718 | if (typeof text === 'undefined') {
|
719 | return this[0] ? this[0].textContent.trim() : null;
|
720 | }
|
721 |
|
722 | for (let i = 0; i < this.length; i += 1) {
|
723 | this[i].textContent = text;
|
724 | }
|
725 |
|
726 | return this;
|
727 | }
|
728 |
|
729 | function is(selector) {
|
730 | const window = getWindow();
|
731 | const document = getDocument();
|
732 | const el = this[0];
|
733 | let compareWith;
|
734 | let i;
|
735 | if (!el || typeof selector === 'undefined') return false;
|
736 |
|
737 | if (typeof selector === 'string') {
|
738 | if (el.matches) return el.matches(selector);
|
739 | if (el.webkitMatchesSelector) return el.webkitMatchesSelector(selector);
|
740 | if (el.msMatchesSelector) return el.msMatchesSelector(selector);
|
741 | compareWith = $(selector);
|
742 |
|
743 | for (i = 0; i < compareWith.length; i += 1) {
|
744 | if (compareWith[i] === el) return true;
|
745 | }
|
746 |
|
747 | return false;
|
748 | }
|
749 |
|
750 | if (selector === document) {
|
751 | return el === document;
|
752 | }
|
753 |
|
754 | if (selector === window) {
|
755 | return el === window;
|
756 | }
|
757 |
|
758 | if (selector.nodeType || selector instanceof Dom7) {
|
759 | compareWith = selector.nodeType ? [selector] : selector;
|
760 |
|
761 | for (i = 0; i < compareWith.length; i += 1) {
|
762 | if (compareWith[i] === el) return true;
|
763 | }
|
764 |
|
765 | return false;
|
766 | }
|
767 |
|
768 | return false;
|
769 | }
|
770 |
|
771 | function index() {
|
772 | let child = this[0];
|
773 | let i;
|
774 |
|
775 | if (child) {
|
776 | i = 0;
|
777 |
|
778 | while ((child = child.previousSibling) !== null) {
|
779 | if (child.nodeType === 1) i += 1;
|
780 | }
|
781 |
|
782 | return i;
|
783 | }
|
784 |
|
785 | return undefined;
|
786 | }
|
787 |
|
788 | function eq(index) {
|
789 | if (typeof index === 'undefined') return this;
|
790 | const length = this.length;
|
791 |
|
792 | if (index > length - 1) {
|
793 | return $([]);
|
794 | }
|
795 |
|
796 | if (index < 0) {
|
797 | const returnIndex = length + index;
|
798 | if (returnIndex < 0) return $([]);
|
799 | return $([this[returnIndex]]);
|
800 | }
|
801 |
|
802 | return $([this[index]]);
|
803 | }
|
804 |
|
805 | function append() {
|
806 | let newChild;
|
807 | const document = getDocument();
|
808 |
|
809 | for (let k = 0; k < arguments.length; k += 1) {
|
810 | newChild = k < 0 || arguments.length <= k ? undefined : arguments[k];
|
811 |
|
812 | for (let i = 0; i < this.length; i += 1) {
|
813 | if (typeof newChild === 'string') {
|
814 | const tempDiv = document.createElement('div');
|
815 | tempDiv.innerHTML = newChild;
|
816 |
|
817 | while (tempDiv.firstChild) {
|
818 | this[i].appendChild(tempDiv.firstChild);
|
819 | }
|
820 | } else if (newChild instanceof Dom7) {
|
821 | for (let j = 0; j < newChild.length; j += 1) {
|
822 | this[i].appendChild(newChild[j]);
|
823 | }
|
824 | } else {
|
825 | this[i].appendChild(newChild);
|
826 | }
|
827 | }
|
828 | }
|
829 |
|
830 | return this;
|
831 | }
|
832 |
|
833 | function prepend(newChild) {
|
834 | const document = getDocument();
|
835 | let i;
|
836 | let j;
|
837 |
|
838 | for (i = 0; i < this.length; i += 1) {
|
839 | if (typeof newChild === 'string') {
|
840 | const tempDiv = document.createElement('div');
|
841 | tempDiv.innerHTML = newChild;
|
842 |
|
843 | for (j = tempDiv.childNodes.length - 1; j >= 0; j -= 1) {
|
844 | this[i].insertBefore(tempDiv.childNodes[j], this[i].childNodes[0]);
|
845 | }
|
846 | } else if (newChild instanceof Dom7) {
|
847 | for (j = 0; j < newChild.length; j += 1) {
|
848 | this[i].insertBefore(newChild[j], this[i].childNodes[0]);
|
849 | }
|
850 | } else {
|
851 | this[i].insertBefore(newChild, this[i].childNodes[0]);
|
852 | }
|
853 | }
|
854 |
|
855 | return this;
|
856 | }
|
857 |
|
858 | function next(selector) {
|
859 | if (this.length > 0) {
|
860 | if (selector) {
|
861 | if (this[0].nextElementSibling && $(this[0].nextElementSibling).is(selector)) {
|
862 | return $([this[0].nextElementSibling]);
|
863 | }
|
864 |
|
865 | return $([]);
|
866 | }
|
867 |
|
868 | if (this[0].nextElementSibling) return $([this[0].nextElementSibling]);
|
869 | return $([]);
|
870 | }
|
871 |
|
872 | return $([]);
|
873 | }
|
874 |
|
875 | function nextAll(selector) {
|
876 | const nextEls = [];
|
877 | let el = this[0];
|
878 | if (!el) return $([]);
|
879 |
|
880 | while (el.nextElementSibling) {
|
881 | const next = el.nextElementSibling;
|
882 |
|
883 | if (selector) {
|
884 | if ($(next).is(selector)) nextEls.push(next);
|
885 | } else nextEls.push(next);
|
886 |
|
887 | el = next;
|
888 | }
|
889 |
|
890 | return $(nextEls);
|
891 | }
|
892 |
|
893 | function prev(selector) {
|
894 | if (this.length > 0) {
|
895 | const el = this[0];
|
896 |
|
897 | if (selector) {
|
898 | if (el.previousElementSibling && $(el.previousElementSibling).is(selector)) {
|
899 | return $([el.previousElementSibling]);
|
900 | }
|
901 |
|
902 | return $([]);
|
903 | }
|
904 |
|
905 | if (el.previousElementSibling) return $([el.previousElementSibling]);
|
906 | return $([]);
|
907 | }
|
908 |
|
909 | return $([]);
|
910 | }
|
911 |
|
912 | function prevAll(selector) {
|
913 | const prevEls = [];
|
914 | let el = this[0];
|
915 | if (!el) return $([]);
|
916 |
|
917 | while (el.previousElementSibling) {
|
918 | const prev = el.previousElementSibling;
|
919 |
|
920 | if (selector) {
|
921 | if ($(prev).is(selector)) prevEls.push(prev);
|
922 | } else prevEls.push(prev);
|
923 |
|
924 | el = prev;
|
925 | }
|
926 |
|
927 | return $(prevEls);
|
928 | }
|
929 |
|
930 | function parent(selector) {
|
931 | const parents = [];
|
932 |
|
933 | for (let i = 0; i < this.length; i += 1) {
|
934 | if (this[i].parentNode !== null) {
|
935 | if (selector) {
|
936 | if ($(this[i].parentNode).is(selector)) parents.push(this[i].parentNode);
|
937 | } else {
|
938 | parents.push(this[i].parentNode);
|
939 | }
|
940 | }
|
941 | }
|
942 |
|
943 | return $(parents);
|
944 | }
|
945 |
|
946 | function parents(selector) {
|
947 | const parents = [];
|
948 |
|
949 | for (let i = 0; i < this.length; i += 1) {
|
950 | let parent = this[i].parentNode;
|
951 |
|
952 | while (parent) {
|
953 | if (selector) {
|
954 | if ($(parent).is(selector)) parents.push(parent);
|
955 | } else {
|
956 | parents.push(parent);
|
957 | }
|
958 |
|
959 | parent = parent.parentNode;
|
960 | }
|
961 | }
|
962 |
|
963 | return $(parents);
|
964 | }
|
965 |
|
966 | function closest(selector) {
|
967 | let closest = this;
|
968 |
|
969 | if (typeof selector === 'undefined') {
|
970 | return $([]);
|
971 | }
|
972 |
|
973 | if (!closest.is(selector)) {
|
974 | closest = closest.parents(selector).eq(0);
|
975 | }
|
976 |
|
977 | return closest;
|
978 | }
|
979 |
|
980 | function find(selector) {
|
981 | const foundElements = [];
|
982 |
|
983 | for (let i = 0; i < this.length; i += 1) {
|
984 | const found = this[i].querySelectorAll(selector);
|
985 |
|
986 | for (let j = 0; j < found.length; j += 1) {
|
987 | foundElements.push(found[j]);
|
988 | }
|
989 | }
|
990 |
|
991 | return $(foundElements);
|
992 | }
|
993 |
|
994 | function children(selector) {
|
995 | const children = [];
|
996 |
|
997 | for (let i = 0; i < this.length; i += 1) {
|
998 | const childNodes = this[i].children;
|
999 |
|
1000 | for (let j = 0; j < childNodes.length; j += 1) {
|
1001 | if (!selector || $(childNodes[j]).is(selector)) {
|
1002 | children.push(childNodes[j]);
|
1003 | }
|
1004 | }
|
1005 | }
|
1006 |
|
1007 | return $(children);
|
1008 | }
|
1009 |
|
1010 | function remove() {
|
1011 | for (let i = 0; i < this.length; i += 1) {
|
1012 | if (this[i].parentNode) this[i].parentNode.removeChild(this[i]);
|
1013 | }
|
1014 |
|
1015 | return this;
|
1016 | }
|
1017 |
|
1018 | const Methods = {
|
1019 | addClass,
|
1020 | removeClass,
|
1021 | hasClass,
|
1022 | toggleClass,
|
1023 | attr,
|
1024 | removeAttr,
|
1025 | transform,
|
1026 | transition: transition$1,
|
1027 | on,
|
1028 | off,
|
1029 | trigger,
|
1030 | transitionEnd: transitionEnd$1,
|
1031 | outerWidth,
|
1032 | outerHeight,
|
1033 | styles,
|
1034 | offset,
|
1035 | css,
|
1036 | each,
|
1037 | html,
|
1038 | text,
|
1039 | is,
|
1040 | index,
|
1041 | eq,
|
1042 | append,
|
1043 | prepend,
|
1044 | next,
|
1045 | nextAll,
|
1046 | prev,
|
1047 | prevAll,
|
1048 | parent,
|
1049 | parents,
|
1050 | closest,
|
1051 | find,
|
1052 | children,
|
1053 | filter,
|
1054 | remove
|
1055 | };
|
1056 | Object.keys(Methods).forEach(methodName => {
|
1057 | Object.defineProperty($.fn, methodName, {
|
1058 | value: Methods[methodName],
|
1059 | writable: true
|
1060 | });
|
1061 | });
|
1062 |
|
1063 | function deleteProps(obj) {
|
1064 | const object = obj;
|
1065 | Object.keys(object).forEach(key => {
|
1066 | try {
|
1067 | object[key] = null;
|
1068 | } catch (e) {
|
1069 | }
|
1070 |
|
1071 | try {
|
1072 | delete object[key];
|
1073 | } catch (e) {
|
1074 | }
|
1075 | });
|
1076 | }
|
1077 |
|
1078 | function nextTick(callback, delay) {
|
1079 | if (delay === void 0) {
|
1080 | delay = 0;
|
1081 | }
|
1082 |
|
1083 | return setTimeout(callback, delay);
|
1084 | }
|
1085 |
|
1086 | function now() {
|
1087 | return Date.now();
|
1088 | }
|
1089 |
|
1090 | function getComputedStyle$1(el) {
|
1091 | const window = getWindow();
|
1092 | let style;
|
1093 |
|
1094 | if (window.getComputedStyle) {
|
1095 | style = window.getComputedStyle(el, null);
|
1096 | }
|
1097 |
|
1098 | if (!style && el.currentStyle) {
|
1099 | style = el.currentStyle;
|
1100 | }
|
1101 |
|
1102 | if (!style) {
|
1103 | style = el.style;
|
1104 | }
|
1105 |
|
1106 | return style;
|
1107 | }
|
1108 |
|
1109 | function getTranslate(el, axis) {
|
1110 | if (axis === void 0) {
|
1111 | axis = 'x';
|
1112 | }
|
1113 |
|
1114 | const window = getWindow();
|
1115 | let matrix;
|
1116 | let curTransform;
|
1117 | let transformMatrix;
|
1118 | const curStyle = getComputedStyle$1(el);
|
1119 |
|
1120 | if (window.WebKitCSSMatrix) {
|
1121 | curTransform = curStyle.transform || curStyle.webkitTransform;
|
1122 |
|
1123 | if (curTransform.split(',').length > 6) {
|
1124 | curTransform = curTransform.split(', ').map(a => a.replace(',', '.')).join(', ');
|
1125 | }
|
1126 |
|
1127 |
|
1128 |
|
1129 | transformMatrix = new window.WebKitCSSMatrix(curTransform === 'none' ? '' : curTransform);
|
1130 | } else {
|
1131 | transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
|
1132 | matrix = transformMatrix.toString().split(',');
|
1133 | }
|
1134 |
|
1135 | if (axis === 'x') {
|
1136 |
|
1137 | if (window.WebKitCSSMatrix) curTransform = transformMatrix.m41;
|
1138 | else if (matrix.length === 16) curTransform = parseFloat(matrix[12]);
|
1139 | else curTransform = parseFloat(matrix[4]);
|
1140 | }
|
1141 |
|
1142 | if (axis === 'y') {
|
1143 |
|
1144 | if (window.WebKitCSSMatrix) curTransform = transformMatrix.m42;
|
1145 | else if (matrix.length === 16) curTransform = parseFloat(matrix[13]);
|
1146 | else curTransform = parseFloat(matrix[5]);
|
1147 | }
|
1148 |
|
1149 | return curTransform || 0;
|
1150 | }
|
1151 |
|
1152 | function isObject(o) {
|
1153 | return typeof o === 'object' && o !== null && o.constructor && Object.prototype.toString.call(o).slice(8, -1) === 'Object';
|
1154 | }
|
1155 |
|
1156 | function isNode(node) {
|
1157 |
|
1158 | if (typeof window !== 'undefined' && typeof window.HTMLElement !== 'undefined') {
|
1159 | return node instanceof HTMLElement;
|
1160 | }
|
1161 |
|
1162 | return node && (node.nodeType === 1 || node.nodeType === 11);
|
1163 | }
|
1164 |
|
1165 | function extend() {
|
1166 | const to = Object(arguments.length <= 0 ? undefined : arguments[0]);
|
1167 | const noExtend = ['__proto__', 'constructor', 'prototype'];
|
1168 |
|
1169 | for (let i = 1; i < arguments.length; i += 1) {
|
1170 | const nextSource = i < 0 || arguments.length <= i ? undefined : arguments[i];
|
1171 |
|
1172 | if (nextSource !== undefined && nextSource !== null && !isNode(nextSource)) {
|
1173 | const keysArray = Object.keys(Object(nextSource)).filter(key => noExtend.indexOf(key) < 0);
|
1174 |
|
1175 | for (let nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex += 1) {
|
1176 | const nextKey = keysArray[nextIndex];
|
1177 | const desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
|
1178 |
|
1179 | if (desc !== undefined && desc.enumerable) {
|
1180 | if (isObject(to[nextKey]) && isObject(nextSource[nextKey])) {
|
1181 | if (nextSource[nextKey].__swiper__) {
|
1182 | to[nextKey] = nextSource[nextKey];
|
1183 | } else {
|
1184 | extend(to[nextKey], nextSource[nextKey]);
|
1185 | }
|
1186 | } else if (!isObject(to[nextKey]) && isObject(nextSource[nextKey])) {
|
1187 | to[nextKey] = {};
|
1188 |
|
1189 | if (nextSource[nextKey].__swiper__) {
|
1190 | to[nextKey] = nextSource[nextKey];
|
1191 | } else {
|
1192 | extend(to[nextKey], nextSource[nextKey]);
|
1193 | }
|
1194 | } else {
|
1195 | to[nextKey] = nextSource[nextKey];
|
1196 | }
|
1197 | }
|
1198 | }
|
1199 | }
|
1200 | }
|
1201 |
|
1202 | return to;
|
1203 | }
|
1204 |
|
1205 | function setCSSProperty(el, varName, varValue) {
|
1206 | el.style.setProperty(varName, varValue);
|
1207 | }
|
1208 |
|
1209 | function animateCSSModeScroll(_ref) {
|
1210 | let {
|
1211 | swiper,
|
1212 | targetPosition,
|
1213 | side
|
1214 | } = _ref;
|
1215 | const window = getWindow();
|
1216 | const startPosition = -swiper.translate;
|
1217 | let startTime = null;
|
1218 | let time;
|
1219 | const duration = swiper.params.speed;
|
1220 | swiper.wrapperEl.style.scrollSnapType = 'none';
|
1221 | window.cancelAnimationFrame(swiper.cssModeFrameID);
|
1222 | const dir = targetPosition > startPosition ? 'next' : 'prev';
|
1223 |
|
1224 | const isOutOfBound = (current, target) => {
|
1225 | return dir === 'next' && current >= target || dir === 'prev' && current <= target;
|
1226 | };
|
1227 |
|
1228 | const animate = () => {
|
1229 | time = new Date().getTime();
|
1230 |
|
1231 | if (startTime === null) {
|
1232 | startTime = time;
|
1233 | }
|
1234 |
|
1235 | const progress = Math.max(Math.min((time - startTime) / duration, 1), 0);
|
1236 | const easeProgress = 0.5 - Math.cos(progress * Math.PI) / 2;
|
1237 | let currentPosition = startPosition + easeProgress * (targetPosition - startPosition);
|
1238 |
|
1239 | if (isOutOfBound(currentPosition, targetPosition)) {
|
1240 | currentPosition = targetPosition;
|
1241 | }
|
1242 |
|
1243 | swiper.wrapperEl.scrollTo({
|
1244 | [side]: currentPosition
|
1245 | });
|
1246 |
|
1247 | if (isOutOfBound(currentPosition, targetPosition)) {
|
1248 | swiper.wrapperEl.style.overflow = 'hidden';
|
1249 | swiper.wrapperEl.style.scrollSnapType = '';
|
1250 | setTimeout(() => {
|
1251 | swiper.wrapperEl.style.overflow = '';
|
1252 | swiper.wrapperEl.scrollTo({
|
1253 | [side]: currentPosition
|
1254 | });
|
1255 | });
|
1256 | window.cancelAnimationFrame(swiper.cssModeFrameID);
|
1257 | return;
|
1258 | }
|
1259 |
|
1260 | swiper.cssModeFrameID = window.requestAnimationFrame(animate);
|
1261 | };
|
1262 |
|
1263 | animate();
|
1264 | }
|
1265 |
|
1266 | let support;
|
1267 |
|
1268 | function calcSupport() {
|
1269 | const window = getWindow();
|
1270 | const document = getDocument();
|
1271 | return {
|
1272 | smoothScroll: document.documentElement && 'scrollBehavior' in document.documentElement.style,
|
1273 | touch: !!('ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch),
|
1274 | passiveListener: function checkPassiveListener() {
|
1275 | let supportsPassive = false;
|
1276 |
|
1277 | try {
|
1278 | const opts = Object.defineProperty({}, 'passive', {
|
1279 |
|
1280 | get() {
|
1281 | supportsPassive = true;
|
1282 | }
|
1283 |
|
1284 | });
|
1285 | window.addEventListener('testPassiveListener', null, opts);
|
1286 | } catch (e) {
|
1287 | }
|
1288 |
|
1289 | return supportsPassive;
|
1290 | }(),
|
1291 | gestures: function checkGestures() {
|
1292 | return 'ongesturestart' in window;
|
1293 | }()
|
1294 | };
|
1295 | }
|
1296 |
|
1297 | function getSupport() {
|
1298 | if (!support) {
|
1299 | support = calcSupport();
|
1300 | }
|
1301 |
|
1302 | return support;
|
1303 | }
|
1304 |
|
1305 | let deviceCached;
|
1306 |
|
1307 | function calcDevice(_temp) {
|
1308 | let {
|
1309 | userAgent
|
1310 | } = _temp === void 0 ? {} : _temp;
|
1311 | const support = getSupport();
|
1312 | const window = getWindow();
|
1313 | const platform = window.navigator.platform;
|
1314 | const ua = userAgent || window.navigator.userAgent;
|
1315 | const device = {
|
1316 | ios: false,
|
1317 | android: false
|
1318 | };
|
1319 | const screenWidth = window.screen.width;
|
1320 | const screenHeight = window.screen.height;
|
1321 | const android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
|
1322 |
|
1323 | let ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
|
1324 | const ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
|
1325 | const iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/);
|
1326 | const windows = platform === 'Win32';
|
1327 | let macos = platform === 'MacIntel';
|
1328 |
|
1329 | const iPadScreens = ['1024x1366', '1366x1024', '834x1194', '1194x834', '834x1112', '1112x834', '768x1024', '1024x768', '820x1180', '1180x820', '810x1080', '1080x810'];
|
1330 |
|
1331 | if (!ipad && macos && support.touch && iPadScreens.indexOf(`${screenWidth}x${screenHeight}`) >= 0) {
|
1332 | ipad = ua.match(/(Version)\/([\d.]+)/);
|
1333 | if (!ipad) ipad = [0, 1, '13_0_0'];
|
1334 | macos = false;
|
1335 | }
|
1336 |
|
1337 |
|
1338 | if (android && !windows) {
|
1339 | device.os = 'android';
|
1340 | device.android = true;
|
1341 | }
|
1342 |
|
1343 | if (ipad || iphone || ipod) {
|
1344 | device.os = 'ios';
|
1345 | device.ios = true;
|
1346 | }
|
1347 |
|
1348 |
|
1349 | return device;
|
1350 | }
|
1351 |
|
1352 | function getDevice(overrides) {
|
1353 | if (overrides === void 0) {
|
1354 | overrides = {};
|
1355 | }
|
1356 |
|
1357 | if (!deviceCached) {
|
1358 | deviceCached = calcDevice(overrides);
|
1359 | }
|
1360 |
|
1361 | return deviceCached;
|
1362 | }
|
1363 |
|
1364 | let browser;
|
1365 |
|
1366 | function calcBrowser() {
|
1367 | const window = getWindow();
|
1368 |
|
1369 | function isSafari() {
|
1370 | const ua = window.navigator.userAgent.toLowerCase();
|
1371 | return ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0;
|
1372 | }
|
1373 |
|
1374 | return {
|
1375 | isSafari: isSafari(),
|
1376 | isWebView: /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(window.navigator.userAgent)
|
1377 | };
|
1378 | }
|
1379 |
|
1380 | function getBrowser() {
|
1381 | if (!browser) {
|
1382 | browser = calcBrowser();
|
1383 | }
|
1384 |
|
1385 | return browser;
|
1386 | }
|
1387 |
|
1388 | function Resize(_ref) {
|
1389 | let {
|
1390 | swiper,
|
1391 | on,
|
1392 | emit
|
1393 | } = _ref;
|
1394 | const window = getWindow();
|
1395 | let observer = null;
|
1396 | let animationFrame = null;
|
1397 |
|
1398 | const resizeHandler = () => {
|
1399 | if (!swiper || swiper.destroyed || !swiper.initialized) return;
|
1400 | emit('beforeResize');
|
1401 | emit('resize');
|
1402 | };
|
1403 |
|
1404 | const createObserver = () => {
|
1405 | if (!swiper || swiper.destroyed || !swiper.initialized) return;
|
1406 | observer = new ResizeObserver(entries => {
|
1407 | animationFrame = window.requestAnimationFrame(() => {
|
1408 | const {
|
1409 | width,
|
1410 | height
|
1411 | } = swiper;
|
1412 | let newWidth = width;
|
1413 | let newHeight = height;
|
1414 | entries.forEach(_ref2 => {
|
1415 | let {
|
1416 | contentBoxSize,
|
1417 | contentRect,
|
1418 | target
|
1419 | } = _ref2;
|
1420 | if (target && target !== swiper.el) return;
|
1421 | newWidth = contentRect ? contentRect.width : (contentBoxSize[0] || contentBoxSize).inlineSize;
|
1422 | newHeight = contentRect ? contentRect.height : (contentBoxSize[0] || contentBoxSize).blockSize;
|
1423 | });
|
1424 |
|
1425 | if (newWidth !== width || newHeight !== height) {
|
1426 | resizeHandler();
|
1427 | }
|
1428 | });
|
1429 | });
|
1430 | observer.observe(swiper.el);
|
1431 | };
|
1432 |
|
1433 | const removeObserver = () => {
|
1434 | if (animationFrame) {
|
1435 | window.cancelAnimationFrame(animationFrame);
|
1436 | }
|
1437 |
|
1438 | if (observer && observer.unobserve && swiper.el) {
|
1439 | observer.unobserve(swiper.el);
|
1440 | observer = null;
|
1441 | }
|
1442 | };
|
1443 |
|
1444 | const orientationChangeHandler = () => {
|
1445 | if (!swiper || swiper.destroyed || !swiper.initialized) return;
|
1446 | emit('orientationchange');
|
1447 | };
|
1448 |
|
1449 | on('init', () => {
|
1450 | if (swiper.params.resizeObserver && typeof window.ResizeObserver !== 'undefined') {
|
1451 | createObserver();
|
1452 | return;
|
1453 | }
|
1454 |
|
1455 | window.addEventListener('resize', resizeHandler);
|
1456 | window.addEventListener('orientationchange', orientationChangeHandler);
|
1457 | });
|
1458 | on('destroy', () => {
|
1459 | removeObserver();
|
1460 | window.removeEventListener('resize', resizeHandler);
|
1461 | window.removeEventListener('orientationchange', orientationChangeHandler);
|
1462 | });
|
1463 | }
|
1464 |
|
1465 | function Observer(_ref) {
|
1466 | let {
|
1467 | swiper,
|
1468 | extendParams,
|
1469 | on,
|
1470 | emit
|
1471 | } = _ref;
|
1472 | const observers = [];
|
1473 | const window = getWindow();
|
1474 |
|
1475 | const attach = function (target, options) {
|
1476 | if (options === void 0) {
|
1477 | options = {};
|
1478 | }
|
1479 |
|
1480 | const ObserverFunc = window.MutationObserver || window.WebkitMutationObserver;
|
1481 | const observer = new ObserverFunc(mutations => {
|
1482 |
|
1483 |
|
1484 |
|
1485 | if (mutations.length === 1) {
|
1486 | emit('observerUpdate', mutations[0]);
|
1487 | return;
|
1488 | }
|
1489 |
|
1490 | const observerUpdate = function observerUpdate() {
|
1491 | emit('observerUpdate', mutations[0]);
|
1492 | };
|
1493 |
|
1494 | if (window.requestAnimationFrame) {
|
1495 | window.requestAnimationFrame(observerUpdate);
|
1496 | } else {
|
1497 | window.setTimeout(observerUpdate, 0);
|
1498 | }
|
1499 | });
|
1500 | observer.observe(target, {
|
1501 | attributes: typeof options.attributes === 'undefined' ? true : options.attributes,
|
1502 | childList: typeof options.childList === 'undefined' ? true : options.childList,
|
1503 | characterData: typeof options.characterData === 'undefined' ? true : options.characterData
|
1504 | });
|
1505 | observers.push(observer);
|
1506 | };
|
1507 |
|
1508 | const init = () => {
|
1509 | if (!swiper.params.observer) return;
|
1510 |
|
1511 | if (swiper.params.observeParents) {
|
1512 | const containerParents = swiper.$el.parents();
|
1513 |
|
1514 | for (let i = 0; i < containerParents.length; i += 1) {
|
1515 | attach(containerParents[i]);
|
1516 | }
|
1517 | }
|
1518 |
|
1519 |
|
1520 | attach(swiper.$el[0], {
|
1521 | childList: swiper.params.observeSlideChildren
|
1522 | });
|
1523 |
|
1524 | attach(swiper.$wrapperEl[0], {
|
1525 | attributes: false
|
1526 | });
|
1527 | };
|
1528 |
|
1529 | const destroy = () => {
|
1530 | observers.forEach(observer => {
|
1531 | observer.disconnect();
|
1532 | });
|
1533 | observers.splice(0, observers.length);
|
1534 | };
|
1535 |
|
1536 | extendParams({
|
1537 | observer: false,
|
1538 | observeParents: false,
|
1539 | observeSlideChildren: false
|
1540 | });
|
1541 | on('init', init);
|
1542 | on('destroy', destroy);
|
1543 | }
|
1544 |
|
1545 |
|
1546 | var eventsEmitter = {
|
1547 | on(events, handler, priority) {
|
1548 | const self = this;
|
1549 | if (typeof handler !== 'function') return self;
|
1550 | const method = priority ? 'unshift' : 'push';
|
1551 | events.split(' ').forEach(event => {
|
1552 | if (!self.eventsListeners[event]) self.eventsListeners[event] = [];
|
1553 | self.eventsListeners[event][method](handler);
|
1554 | });
|
1555 | return self;
|
1556 | },
|
1557 |
|
1558 | once(events, handler, priority) {
|
1559 | const self = this;
|
1560 | if (typeof handler !== 'function') return self;
|
1561 |
|
1562 | function onceHandler() {
|
1563 | self.off(events, onceHandler);
|
1564 |
|
1565 | if (onceHandler.__emitterProxy) {
|
1566 | delete onceHandler.__emitterProxy;
|
1567 | }
|
1568 |
|
1569 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
1570 | args[_key] = arguments[_key];
|
1571 | }
|
1572 |
|
1573 | handler.apply(self, args);
|
1574 | }
|
1575 |
|
1576 | onceHandler.__emitterProxy = handler;
|
1577 | return self.on(events, onceHandler, priority);
|
1578 | },
|
1579 |
|
1580 | onAny(handler, priority) {
|
1581 | const self = this;
|
1582 | if (typeof handler !== 'function') return self;
|
1583 | const method = priority ? 'unshift' : 'push';
|
1584 |
|
1585 | if (self.eventsAnyListeners.indexOf(handler) < 0) {
|
1586 | self.eventsAnyListeners[method](handler);
|
1587 | }
|
1588 |
|
1589 | return self;
|
1590 | },
|
1591 |
|
1592 | offAny(handler) {
|
1593 | const self = this;
|
1594 | if (!self.eventsAnyListeners) return self;
|
1595 | const index = self.eventsAnyListeners.indexOf(handler);
|
1596 |
|
1597 | if (index >= 0) {
|
1598 | self.eventsAnyListeners.splice(index, 1);
|
1599 | }
|
1600 |
|
1601 | return self;
|
1602 | },
|
1603 |
|
1604 | off(events, handler) {
|
1605 | const self = this;
|
1606 | if (!self.eventsListeners) return self;
|
1607 | events.split(' ').forEach(event => {
|
1608 | if (typeof handler === 'undefined') {
|
1609 | self.eventsListeners[event] = [];
|
1610 | } else if (self.eventsListeners[event]) {
|
1611 | self.eventsListeners[event].forEach((eventHandler, index) => {
|
1612 | if (eventHandler === handler || eventHandler.__emitterProxy && eventHandler.__emitterProxy === handler) {
|
1613 | self.eventsListeners[event].splice(index, 1);
|
1614 | }
|
1615 | });
|
1616 | }
|
1617 | });
|
1618 | return self;
|
1619 | },
|
1620 |
|
1621 | emit() {
|
1622 | const self = this;
|
1623 | if (!self.eventsListeners) return self;
|
1624 | let events;
|
1625 | let data;
|
1626 | let context;
|
1627 |
|
1628 | for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
1629 | args[_key2] = arguments[_key2];
|
1630 | }
|
1631 |
|
1632 | if (typeof args[0] === 'string' || Array.isArray(args[0])) {
|
1633 | events = args[0];
|
1634 | data = args.slice(1, args.length);
|
1635 | context = self;
|
1636 | } else {
|
1637 | events = args[0].events;
|
1638 | data = args[0].data;
|
1639 | context = args[0].context || self;
|
1640 | }
|
1641 |
|
1642 | data.unshift(context);
|
1643 | const eventsArray = Array.isArray(events) ? events : events.split(' ');
|
1644 | eventsArray.forEach(event => {
|
1645 | if (self.eventsAnyListeners && self.eventsAnyListeners.length) {
|
1646 | self.eventsAnyListeners.forEach(eventHandler => {
|
1647 | eventHandler.apply(context, [event, ...data]);
|
1648 | });
|
1649 | }
|
1650 |
|
1651 | if (self.eventsListeners && self.eventsListeners[event]) {
|
1652 | self.eventsListeners[event].forEach(eventHandler => {
|
1653 | eventHandler.apply(context, data);
|
1654 | });
|
1655 | }
|
1656 | });
|
1657 | return self;
|
1658 | }
|
1659 |
|
1660 | };
|
1661 |
|
1662 | function updateSize() {
|
1663 | const swiper = this;
|
1664 | let width;
|
1665 | let height;
|
1666 | const $el = swiper.$el;
|
1667 |
|
1668 | if (typeof swiper.params.width !== 'undefined' && swiper.params.width !== null) {
|
1669 | width = swiper.params.width;
|
1670 | } else {
|
1671 | width = $el[0].clientWidth;
|
1672 | }
|
1673 |
|
1674 | if (typeof swiper.params.height !== 'undefined' && swiper.params.height !== null) {
|
1675 | height = swiper.params.height;
|
1676 | } else {
|
1677 | height = $el[0].clientHeight;
|
1678 | }
|
1679 |
|
1680 | if (width === 0 && swiper.isHorizontal() || height === 0 && swiper.isVertical()) {
|
1681 | return;
|
1682 | }
|
1683 |
|
1684 |
|
1685 | width = width - parseInt($el.css('padding-left') || 0, 10) - parseInt($el.css('padding-right') || 0, 10);
|
1686 | height = height - parseInt($el.css('padding-top') || 0, 10) - parseInt($el.css('padding-bottom') || 0, 10);
|
1687 | if (Number.isNaN(width)) width = 0;
|
1688 | if (Number.isNaN(height)) height = 0;
|
1689 | Object.assign(swiper, {
|
1690 | width,
|
1691 | height,
|
1692 | size: swiper.isHorizontal() ? width : height
|
1693 | });
|
1694 | }
|
1695 |
|
1696 | function updateSlides() {
|
1697 | const swiper = this;
|
1698 |
|
1699 | function getDirectionLabel(property) {
|
1700 | if (swiper.isHorizontal()) {
|
1701 | return property;
|
1702 | }
|
1703 |
|
1704 |
|
1705 | return {
|
1706 | 'width': 'height',
|
1707 | 'margin-top': 'margin-left',
|
1708 | 'margin-bottom ': 'margin-right',
|
1709 | 'margin-left': 'margin-top',
|
1710 | 'margin-right': 'margin-bottom',
|
1711 | 'padding-left': 'padding-top',
|
1712 | 'padding-right': 'padding-bottom',
|
1713 | 'marginRight': 'marginBottom'
|
1714 | }[property];
|
1715 | }
|
1716 |
|
1717 | function getDirectionPropertyValue(node, label) {
|
1718 | return parseFloat(node.getPropertyValue(getDirectionLabel(label)) || 0);
|
1719 | }
|
1720 |
|
1721 | const params = swiper.params;
|
1722 | const {
|
1723 | $wrapperEl,
|
1724 | size: swiperSize,
|
1725 | rtlTranslate: rtl,
|
1726 | wrongRTL
|
1727 | } = swiper;
|
1728 | const isVirtual = swiper.virtual && params.virtual.enabled;
|
1729 | const previousSlidesLength = isVirtual ? swiper.virtual.slides.length : swiper.slides.length;
|
1730 | const slides = $wrapperEl.children(`.${swiper.params.slideClass}`);
|
1731 | const slidesLength = isVirtual ? swiper.virtual.slides.length : slides.length;
|
1732 | let snapGrid = [];
|
1733 | const slidesGrid = [];
|
1734 | const slidesSizesGrid = [];
|
1735 | let offsetBefore = params.slidesOffsetBefore;
|
1736 |
|
1737 | if (typeof offsetBefore === 'function') {
|
1738 | offsetBefore = params.slidesOffsetBefore.call(swiper);
|
1739 | }
|
1740 |
|
1741 | let offsetAfter = params.slidesOffsetAfter;
|
1742 |
|
1743 | if (typeof offsetAfter === 'function') {
|
1744 | offsetAfter = params.slidesOffsetAfter.call(swiper);
|
1745 | }
|
1746 |
|
1747 | const previousSnapGridLength = swiper.snapGrid.length;
|
1748 | const previousSlidesGridLength = swiper.slidesGrid.length;
|
1749 | let spaceBetween = params.spaceBetween;
|
1750 | let slidePosition = -offsetBefore;
|
1751 | let prevSlideSize = 0;
|
1752 | let index = 0;
|
1753 |
|
1754 | if (typeof swiperSize === 'undefined') {
|
1755 | return;
|
1756 | }
|
1757 |
|
1758 | if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
|
1759 | spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * swiperSize;
|
1760 | }
|
1761 |
|
1762 | swiper.virtualSize = -spaceBetween;
|
1763 |
|
1764 | if (rtl) slides.css({
|
1765 | marginLeft: '',
|
1766 | marginBottom: '',
|
1767 | marginTop: ''
|
1768 | });else slides.css({
|
1769 | marginRight: '',
|
1770 | marginBottom: '',
|
1771 | marginTop: ''
|
1772 | });
|
1773 |
|
1774 | if (params.centeredSlides && params.cssMode) {
|
1775 | setCSSProperty(swiper.wrapperEl, '--swiper-centered-offset-before', '');
|
1776 | setCSSProperty(swiper.wrapperEl, '--swiper-centered-offset-after', '');
|
1777 | }
|
1778 |
|
1779 | const gridEnabled = params.grid && params.grid.rows > 1 && swiper.grid;
|
1780 |
|
1781 | if (gridEnabled) {
|
1782 | swiper.grid.initSlides(slidesLength);
|
1783 | }
|
1784 |
|
1785 |
|
1786 | let slideSize;
|
1787 | const shouldResetSlideSize = params.slidesPerView === 'auto' && params.breakpoints && Object.keys(params.breakpoints).filter(key => {
|
1788 | return typeof params.breakpoints[key].slidesPerView !== 'undefined';
|
1789 | }).length > 0;
|
1790 |
|
1791 | for (let i = 0; i < slidesLength; i += 1) {
|
1792 | slideSize = 0;
|
1793 | const slide = slides.eq(i);
|
1794 |
|
1795 | if (gridEnabled) {
|
1796 | swiper.grid.updateSlide(i, slide, slidesLength, getDirectionLabel);
|
1797 | }
|
1798 |
|
1799 | if (slide.css('display') === 'none') continue;
|
1800 |
|
1801 | if (params.slidesPerView === 'auto') {
|
1802 | if (shouldResetSlideSize) {
|
1803 | slides[i].style[getDirectionLabel('width')] = ``;
|
1804 | }
|
1805 |
|
1806 | const slideStyles = getComputedStyle(slide[0]);
|
1807 | const currentTransform = slide[0].style.transform;
|
1808 | const currentWebKitTransform = slide[0].style.webkitTransform;
|
1809 |
|
1810 | if (currentTransform) {
|
1811 | slide[0].style.transform = 'none';
|
1812 | }
|
1813 |
|
1814 | if (currentWebKitTransform) {
|
1815 | slide[0].style.webkitTransform = 'none';
|
1816 | }
|
1817 |
|
1818 | if (params.roundLengths) {
|
1819 | slideSize = swiper.isHorizontal() ? slide.outerWidth(true) : slide.outerHeight(true);
|
1820 | } else {
|
1821 |
|
1822 | const width = getDirectionPropertyValue(slideStyles, 'width');
|
1823 | const paddingLeft = getDirectionPropertyValue(slideStyles, 'padding-left');
|
1824 | const paddingRight = getDirectionPropertyValue(slideStyles, 'padding-right');
|
1825 | const marginLeft = getDirectionPropertyValue(slideStyles, 'margin-left');
|
1826 | const marginRight = getDirectionPropertyValue(slideStyles, 'margin-right');
|
1827 | const boxSizing = slideStyles.getPropertyValue('box-sizing');
|
1828 |
|
1829 | if (boxSizing && boxSizing === 'border-box') {
|
1830 | slideSize = width + marginLeft + marginRight;
|
1831 | } else {
|
1832 | const {
|
1833 | clientWidth,
|
1834 | offsetWidth
|
1835 | } = slide[0];
|
1836 | slideSize = width + paddingLeft + paddingRight + marginLeft + marginRight + (offsetWidth - clientWidth);
|
1837 | }
|
1838 | }
|
1839 |
|
1840 | if (currentTransform) {
|
1841 | slide[0].style.transform = currentTransform;
|
1842 | }
|
1843 |
|
1844 | if (currentWebKitTransform) {
|
1845 | slide[0].style.webkitTransform = currentWebKitTransform;
|
1846 | }
|
1847 |
|
1848 | if (params.roundLengths) slideSize = Math.floor(slideSize);
|
1849 | } else {
|
1850 | slideSize = (swiperSize - (params.slidesPerView - 1) * spaceBetween) / params.slidesPerView;
|
1851 | if (params.roundLengths) slideSize = Math.floor(slideSize);
|
1852 |
|
1853 | if (slides[i]) {
|
1854 | slides[i].style[getDirectionLabel('width')] = `${slideSize}px`;
|
1855 | }
|
1856 | }
|
1857 |
|
1858 | if (slides[i]) {
|
1859 | slides[i].swiperSlideSize = slideSize;
|
1860 | }
|
1861 |
|
1862 | slidesSizesGrid.push(slideSize);
|
1863 |
|
1864 | if (params.centeredSlides) {
|
1865 | slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween;
|
1866 | if (prevSlideSize === 0 && i !== 0) slidePosition = slidePosition - swiperSize / 2 - spaceBetween;
|
1867 | if (i === 0) slidePosition = slidePosition - swiperSize / 2 - spaceBetween;
|
1868 | if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0;
|
1869 | if (params.roundLengths) slidePosition = Math.floor(slidePosition);
|
1870 | if (index % params.slidesPerGroup === 0) snapGrid.push(slidePosition);
|
1871 | slidesGrid.push(slidePosition);
|
1872 | } else {
|
1873 | if (params.roundLengths) slidePosition = Math.floor(slidePosition);
|
1874 | if ((index - Math.min(swiper.params.slidesPerGroupSkip, index)) % swiper.params.slidesPerGroup === 0) snapGrid.push(slidePosition);
|
1875 | slidesGrid.push(slidePosition);
|
1876 | slidePosition = slidePosition + slideSize + spaceBetween;
|
1877 | }
|
1878 |
|
1879 | swiper.virtualSize += slideSize + spaceBetween;
|
1880 | prevSlideSize = slideSize;
|
1881 | index += 1;
|
1882 | }
|
1883 |
|
1884 | swiper.virtualSize = Math.max(swiper.virtualSize, swiperSize) + offsetAfter;
|
1885 |
|
1886 | if (rtl && wrongRTL && (params.effect === 'slide' || params.effect === 'coverflow')) {
|
1887 | $wrapperEl.css({
|
1888 | width: `${swiper.virtualSize + params.spaceBetween}px`
|
1889 | });
|
1890 | }
|
1891 |
|
1892 | if (params.setWrapperSize) {
|
1893 | $wrapperEl.css({
|
1894 | [getDirectionLabel('width')]: `${swiper.virtualSize + params.spaceBetween}px`
|
1895 | });
|
1896 | }
|
1897 |
|
1898 | if (gridEnabled) {
|
1899 | swiper.grid.updateWrapperSize(slideSize, snapGrid, getDirectionLabel);
|
1900 | }
|
1901 |
|
1902 |
|
1903 | if (!params.centeredSlides) {
|
1904 | const newSlidesGrid = [];
|
1905 |
|
1906 | for (let i = 0; i < snapGrid.length; i += 1) {
|
1907 | let slidesGridItem = snapGrid[i];
|
1908 | if (params.roundLengths) slidesGridItem = Math.floor(slidesGridItem);
|
1909 |
|
1910 | if (snapGrid[i] <= swiper.virtualSize - swiperSize) {
|
1911 | newSlidesGrid.push(slidesGridItem);
|
1912 | }
|
1913 | }
|
1914 |
|
1915 | snapGrid = newSlidesGrid;
|
1916 |
|
1917 | if (Math.floor(swiper.virtualSize - swiperSize) - Math.floor(snapGrid[snapGrid.length - 1]) > 1) {
|
1918 | snapGrid.push(swiper.virtualSize - swiperSize);
|
1919 | }
|
1920 | }
|
1921 |
|
1922 | if (snapGrid.length === 0) snapGrid = [0];
|
1923 |
|
1924 | if (params.spaceBetween !== 0) {
|
1925 | const key = swiper.isHorizontal() && rtl ? 'marginLeft' : getDirectionLabel('marginRight');
|
1926 | slides.filter((_, slideIndex) => {
|
1927 | if (!params.cssMode) return true;
|
1928 |
|
1929 | if (slideIndex === slides.length - 1) {
|
1930 | return false;
|
1931 | }
|
1932 |
|
1933 | return true;
|
1934 | }).css({
|
1935 | [key]: `${spaceBetween}px`
|
1936 | });
|
1937 | }
|
1938 |
|
1939 | if (params.centeredSlides && params.centeredSlidesBounds) {
|
1940 | let allSlidesSize = 0;
|
1941 | slidesSizesGrid.forEach(slideSizeValue => {
|
1942 | allSlidesSize += slideSizeValue + (params.spaceBetween ? params.spaceBetween : 0);
|
1943 | });
|
1944 | allSlidesSize -= params.spaceBetween;
|
1945 | const maxSnap = allSlidesSize - swiperSize;
|
1946 | snapGrid = snapGrid.map(snap => {
|
1947 | if (snap < 0) return -offsetBefore;
|
1948 | if (snap > maxSnap) return maxSnap + offsetAfter;
|
1949 | return snap;
|
1950 | });
|
1951 | }
|
1952 |
|
1953 | if (params.centerInsufficientSlides) {
|
1954 | let allSlidesSize = 0;
|
1955 | slidesSizesGrid.forEach(slideSizeValue => {
|
1956 | allSlidesSize += slideSizeValue + (params.spaceBetween ? params.spaceBetween : 0);
|
1957 | });
|
1958 | allSlidesSize -= params.spaceBetween;
|
1959 |
|
1960 | if (allSlidesSize < swiperSize) {
|
1961 | const allSlidesOffset = (swiperSize - allSlidesSize) / 2;
|
1962 | snapGrid.forEach((snap, snapIndex) => {
|
1963 | snapGrid[snapIndex] = snap - allSlidesOffset;
|
1964 | });
|
1965 | slidesGrid.forEach((snap, snapIndex) => {
|
1966 | slidesGrid[snapIndex] = snap + allSlidesOffset;
|
1967 | });
|
1968 | }
|
1969 | }
|
1970 |
|
1971 | Object.assign(swiper, {
|
1972 | slides,
|
1973 | snapGrid,
|
1974 | slidesGrid,
|
1975 | slidesSizesGrid
|
1976 | });
|
1977 |
|
1978 | if (params.centeredSlides && params.cssMode && !params.centeredSlidesBounds) {
|
1979 | setCSSProperty(swiper.wrapperEl, '--swiper-centered-offset-before', `${-snapGrid[0]}px`);
|
1980 | setCSSProperty(swiper.wrapperEl, '--swiper-centered-offset-after', `${swiper.size / 2 - slidesSizesGrid[slidesSizesGrid.length - 1] / 2}px`);
|
1981 | const addToSnapGrid = -swiper.snapGrid[0];
|
1982 | const addToSlidesGrid = -swiper.slidesGrid[0];
|
1983 | swiper.snapGrid = swiper.snapGrid.map(v => v + addToSnapGrid);
|
1984 | swiper.slidesGrid = swiper.slidesGrid.map(v => v + addToSlidesGrid);
|
1985 | }
|
1986 |
|
1987 | if (slidesLength !== previousSlidesLength) {
|
1988 | swiper.emit('slidesLengthChange');
|
1989 | }
|
1990 |
|
1991 | if (snapGrid.length !== previousSnapGridLength) {
|
1992 | if (swiper.params.watchOverflow) swiper.checkOverflow();
|
1993 | swiper.emit('snapGridLengthChange');
|
1994 | }
|
1995 |
|
1996 | if (slidesGrid.length !== previousSlidesGridLength) {
|
1997 | swiper.emit('slidesGridLengthChange');
|
1998 | }
|
1999 |
|
2000 | if (params.watchSlidesProgress) {
|
2001 | swiper.updateSlidesOffset();
|
2002 | }
|
2003 |
|
2004 | if (!isVirtual && !params.cssMode && (params.effect === 'slide' || params.effect === 'fade')) {
|
2005 | const backFaceHiddenClass = `${params.containerModifierClass}backface-hidden`;
|
2006 | const hasClassBackfaceClassAdded = swiper.$el.hasClass(backFaceHiddenClass);
|
2007 |
|
2008 | if (slidesLength <= params.maxBackfaceHiddenSlides) {
|
2009 | if (!hasClassBackfaceClassAdded) swiper.$el.addClass(backFaceHiddenClass);
|
2010 | } else if (hasClassBackfaceClassAdded) {
|
2011 | swiper.$el.removeClass(backFaceHiddenClass);
|
2012 | }
|
2013 | }
|
2014 | }
|
2015 |
|
2016 | function updateAutoHeight(speed) {
|
2017 | const swiper = this;
|
2018 | const activeSlides = [];
|
2019 | const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
|
2020 | let newHeight = 0;
|
2021 | let i;
|
2022 |
|
2023 | if (typeof speed === 'number') {
|
2024 | swiper.setTransition(speed);
|
2025 | } else if (speed === true) {
|
2026 | swiper.setTransition(swiper.params.speed);
|
2027 | }
|
2028 |
|
2029 | const getSlideByIndex = index => {
|
2030 | if (isVirtual) {
|
2031 | return swiper.slides.filter(el => parseInt(el.getAttribute('data-swiper-slide-index'), 10) === index)[0];
|
2032 | }
|
2033 |
|
2034 | return swiper.slides.eq(index)[0];
|
2035 | };
|
2036 |
|
2037 |
|
2038 | if (swiper.params.slidesPerView !== 'auto' && swiper.params.slidesPerView > 1) {
|
2039 | if (swiper.params.centeredSlides) {
|
2040 | swiper.visibleSlides.each(slide => {
|
2041 | activeSlides.push(slide);
|
2042 | });
|
2043 | } else {
|
2044 | for (i = 0; i < Math.ceil(swiper.params.slidesPerView); i += 1) {
|
2045 | const index = swiper.activeIndex + i;
|
2046 | if (index > swiper.slides.length && !isVirtual) break;
|
2047 | activeSlides.push(getSlideByIndex(index));
|
2048 | }
|
2049 | }
|
2050 | } else {
|
2051 | activeSlides.push(getSlideByIndex(swiper.activeIndex));
|
2052 | }
|
2053 |
|
2054 |
|
2055 | for (i = 0; i < activeSlides.length; i += 1) {
|
2056 | if (typeof activeSlides[i] !== 'undefined') {
|
2057 | const height = activeSlides[i].offsetHeight;
|
2058 | newHeight = height > newHeight ? height : newHeight;
|
2059 | }
|
2060 | }
|
2061 |
|
2062 |
|
2063 | if (newHeight || newHeight === 0) swiper.$wrapperEl.css('height', `${newHeight}px`);
|
2064 | }
|
2065 |
|
2066 | function updateSlidesOffset() {
|
2067 | const swiper = this;
|
2068 | const slides = swiper.slides;
|
2069 |
|
2070 | for (let i = 0; i < slides.length; i += 1) {
|
2071 | slides[i].swiperSlideOffset = swiper.isHorizontal() ? slides[i].offsetLeft : slides[i].offsetTop;
|
2072 | }
|
2073 | }
|
2074 |
|
2075 | function updateSlidesProgress(translate) {
|
2076 | if (translate === void 0) {
|
2077 | translate = this && this.translate || 0;
|
2078 | }
|
2079 |
|
2080 | const swiper = this;
|
2081 | const params = swiper.params;
|
2082 | const {
|
2083 | slides,
|
2084 | rtlTranslate: rtl,
|
2085 | snapGrid
|
2086 | } = swiper;
|
2087 | if (slides.length === 0) return;
|
2088 | if (typeof slides[0].swiperSlideOffset === 'undefined') swiper.updateSlidesOffset();
|
2089 | let offsetCenter = -translate;
|
2090 | if (rtl) offsetCenter = translate;
|
2091 |
|
2092 | slides.removeClass(params.slideVisibleClass);
|
2093 | swiper.visibleSlidesIndexes = [];
|
2094 | swiper.visibleSlides = [];
|
2095 |
|
2096 | for (let i = 0; i < slides.length; i += 1) {
|
2097 | const slide = slides[i];
|
2098 | let slideOffset = slide.swiperSlideOffset;
|
2099 |
|
2100 | if (params.cssMode && params.centeredSlides) {
|
2101 | slideOffset -= slides[0].swiperSlideOffset;
|
2102 | }
|
2103 |
|
2104 | const slideProgress = (offsetCenter + (params.centeredSlides ? swiper.minTranslate() : 0) - slideOffset) / (slide.swiperSlideSize + params.spaceBetween);
|
2105 | const originalSlideProgress = (offsetCenter - snapGrid[0] + (params.centeredSlides ? swiper.minTranslate() : 0) - slideOffset) / (slide.swiperSlideSize + params.spaceBetween);
|
2106 | const slideBefore = -(offsetCenter - slideOffset);
|
2107 | const slideAfter = slideBefore + swiper.slidesSizesGrid[i];
|
2108 | const isVisible = slideBefore >= 0 && slideBefore < swiper.size - 1 || slideAfter > 1 && slideAfter <= swiper.size || slideBefore <= 0 && slideAfter >= swiper.size;
|
2109 |
|
2110 | if (isVisible) {
|
2111 | swiper.visibleSlides.push(slide);
|
2112 | swiper.visibleSlidesIndexes.push(i);
|
2113 | slides.eq(i).addClass(params.slideVisibleClass);
|
2114 | }
|
2115 |
|
2116 | slide.progress = rtl ? -slideProgress : slideProgress;
|
2117 | slide.originalProgress = rtl ? -originalSlideProgress : originalSlideProgress;
|
2118 | }
|
2119 |
|
2120 | swiper.visibleSlides = $(swiper.visibleSlides);
|
2121 | }
|
2122 |
|
2123 | function updateProgress(translate) {
|
2124 | const swiper = this;
|
2125 |
|
2126 | if (typeof translate === 'undefined') {
|
2127 | const multiplier = swiper.rtlTranslate ? -1 : 1;
|
2128 |
|
2129 | translate = swiper && swiper.translate && swiper.translate * multiplier || 0;
|
2130 | }
|
2131 |
|
2132 | const params = swiper.params;
|
2133 | const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
|
2134 | let {
|
2135 | progress,
|
2136 | isBeginning,
|
2137 | isEnd
|
2138 | } = swiper;
|
2139 | const wasBeginning = isBeginning;
|
2140 | const wasEnd = isEnd;
|
2141 |
|
2142 | if (translatesDiff === 0) {
|
2143 | progress = 0;
|
2144 | isBeginning = true;
|
2145 | isEnd = true;
|
2146 | } else {
|
2147 | progress = (translate - swiper.minTranslate()) / translatesDiff;
|
2148 | isBeginning = progress <= 0;
|
2149 | isEnd = progress >= 1;
|
2150 | }
|
2151 |
|
2152 | Object.assign(swiper, {
|
2153 | progress,
|
2154 | isBeginning,
|
2155 | isEnd
|
2156 | });
|
2157 | if (params.watchSlidesProgress || params.centeredSlides && params.autoHeight) swiper.updateSlidesProgress(translate);
|
2158 |
|
2159 | if (isBeginning && !wasBeginning) {
|
2160 | swiper.emit('reachBeginning toEdge');
|
2161 | }
|
2162 |
|
2163 | if (isEnd && !wasEnd) {
|
2164 | swiper.emit('reachEnd toEdge');
|
2165 | }
|
2166 |
|
2167 | if (wasBeginning && !isBeginning || wasEnd && !isEnd) {
|
2168 | swiper.emit('fromEdge');
|
2169 | }
|
2170 |
|
2171 | swiper.emit('progress', progress);
|
2172 | }
|
2173 |
|
2174 | function updateSlidesClasses() {
|
2175 | const swiper = this;
|
2176 | const {
|
2177 | slides,
|
2178 | params,
|
2179 | $wrapperEl,
|
2180 | activeIndex,
|
2181 | realIndex
|
2182 | } = swiper;
|
2183 | const isVirtual = swiper.virtual && params.virtual.enabled;
|
2184 | slides.removeClass(`${params.slideActiveClass} ${params.slideNextClass} ${params.slidePrevClass} ${params.slideDuplicateActiveClass} ${params.slideDuplicateNextClass} ${params.slideDuplicatePrevClass}`);
|
2185 | let activeSlide;
|
2186 |
|
2187 | if (isVirtual) {
|
2188 | activeSlide = swiper.$wrapperEl.find(`.${params.slideClass}[data-swiper-slide-index="${activeIndex}"]`);
|
2189 | } else {
|
2190 | activeSlide = slides.eq(activeIndex);
|
2191 | }
|
2192 |
|
2193 |
|
2194 | activeSlide.addClass(params.slideActiveClass);
|
2195 |
|
2196 | if (params.loop) {
|
2197 |
|
2198 | if (activeSlide.hasClass(params.slideDuplicateClass)) {
|
2199 | $wrapperEl.children(`.${params.slideClass}:not(.${params.slideDuplicateClass})[data-swiper-slide-index="${realIndex}"]`).addClass(params.slideDuplicateActiveClass);
|
2200 | } else {
|
2201 | $wrapperEl.children(`.${params.slideClass}.${params.slideDuplicateClass}[data-swiper-slide-index="${realIndex}"]`).addClass(params.slideDuplicateActiveClass);
|
2202 | }
|
2203 | }
|
2204 |
|
2205 |
|
2206 | let nextSlide = activeSlide.nextAll(`.${params.slideClass}`).eq(0).addClass(params.slideNextClass);
|
2207 |
|
2208 | if (params.loop && nextSlide.length === 0) {
|
2209 | nextSlide = slides.eq(0);
|
2210 | nextSlide.addClass(params.slideNextClass);
|
2211 | }
|
2212 |
|
2213 |
|
2214 | let prevSlide = activeSlide.prevAll(`.${params.slideClass}`).eq(0).addClass(params.slidePrevClass);
|
2215 |
|
2216 | if (params.loop && prevSlide.length === 0) {
|
2217 | prevSlide = slides.eq(-1);
|
2218 | prevSlide.addClass(params.slidePrevClass);
|
2219 | }
|
2220 |
|
2221 | if (params.loop) {
|
2222 |
|
2223 | if (nextSlide.hasClass(params.slideDuplicateClass)) {
|
2224 | $wrapperEl.children(`.${params.slideClass}:not(.${params.slideDuplicateClass})[data-swiper-slide-index="${nextSlide.attr('data-swiper-slide-index')}"]`).addClass(params.slideDuplicateNextClass);
|
2225 | } else {
|
2226 | $wrapperEl.children(`.${params.slideClass}.${params.slideDuplicateClass}[data-swiper-slide-index="${nextSlide.attr('data-swiper-slide-index')}"]`).addClass(params.slideDuplicateNextClass);
|
2227 | }
|
2228 |
|
2229 | if (prevSlide.hasClass(params.slideDuplicateClass)) {
|
2230 | $wrapperEl.children(`.${params.slideClass}:not(.${params.slideDuplicateClass})[data-swiper-slide-index="${prevSlide.attr('data-swiper-slide-index')}"]`).addClass(params.slideDuplicatePrevClass);
|
2231 | } else {
|
2232 | $wrapperEl.children(`.${params.slideClass}.${params.slideDuplicateClass}[data-swiper-slide-index="${prevSlide.attr('data-swiper-slide-index')}"]`).addClass(params.slideDuplicatePrevClass);
|
2233 | }
|
2234 | }
|
2235 |
|
2236 | swiper.emitSlidesClasses();
|
2237 | }
|
2238 |
|
2239 | function updateActiveIndex(newActiveIndex) {
|
2240 | const swiper = this;
|
2241 | const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
|
2242 | const {
|
2243 | slidesGrid,
|
2244 | snapGrid,
|
2245 | params,
|
2246 | activeIndex: previousIndex,
|
2247 | realIndex: previousRealIndex,
|
2248 | snapIndex: previousSnapIndex
|
2249 | } = swiper;
|
2250 | let activeIndex = newActiveIndex;
|
2251 | let snapIndex;
|
2252 |
|
2253 | if (typeof activeIndex === 'undefined') {
|
2254 | for (let i = 0; i < slidesGrid.length; i += 1) {
|
2255 | if (typeof slidesGrid[i + 1] !== 'undefined') {
|
2256 | if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1] - (slidesGrid[i + 1] - slidesGrid[i]) / 2) {
|
2257 | activeIndex = i;
|
2258 | } else if (translate >= slidesGrid[i] && translate < slidesGrid[i + 1]) {
|
2259 | activeIndex = i + 1;
|
2260 | }
|
2261 | } else if (translate >= slidesGrid[i]) {
|
2262 | activeIndex = i;
|
2263 | }
|
2264 | }
|
2265 |
|
2266 |
|
2267 | if (params.normalizeSlideIndex) {
|
2268 | if (activeIndex < 0 || typeof activeIndex === 'undefined') activeIndex = 0;
|
2269 | }
|
2270 | }
|
2271 |
|
2272 | if (snapGrid.indexOf(translate) >= 0) {
|
2273 | snapIndex = snapGrid.indexOf(translate);
|
2274 | } else {
|
2275 | const skip = Math.min(params.slidesPerGroupSkip, activeIndex);
|
2276 | snapIndex = skip + Math.floor((activeIndex - skip) / params.slidesPerGroup);
|
2277 | }
|
2278 |
|
2279 | if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;
|
2280 |
|
2281 | if (activeIndex === previousIndex) {
|
2282 | if (snapIndex !== previousSnapIndex) {
|
2283 | swiper.snapIndex = snapIndex;
|
2284 | swiper.emit('snapIndexChange');
|
2285 | }
|
2286 |
|
2287 | return;
|
2288 | }
|
2289 |
|
2290 |
|
2291 | const realIndex = parseInt(swiper.slides.eq(activeIndex).attr('data-swiper-slide-index') || activeIndex, 10);
|
2292 | Object.assign(swiper, {
|
2293 | snapIndex,
|
2294 | realIndex,
|
2295 | previousIndex,
|
2296 | activeIndex
|
2297 | });
|
2298 | swiper.emit('activeIndexChange');
|
2299 | swiper.emit('snapIndexChange');
|
2300 |
|
2301 | if (previousRealIndex !== realIndex) {
|
2302 | swiper.emit('realIndexChange');
|
2303 | }
|
2304 |
|
2305 | if (swiper.initialized || swiper.params.runCallbacksOnInit) {
|
2306 | swiper.emit('slideChange');
|
2307 | }
|
2308 | }
|
2309 |
|
2310 | function updateClickedSlide(e) {
|
2311 | const swiper = this;
|
2312 | const params = swiper.params;
|
2313 | const slide = $(e).closest(`.${params.slideClass}`)[0];
|
2314 | let slideFound = false;
|
2315 | let slideIndex;
|
2316 |
|
2317 | if (slide) {
|
2318 | for (let i = 0; i < swiper.slides.length; i += 1) {
|
2319 | if (swiper.slides[i] === slide) {
|
2320 | slideFound = true;
|
2321 | slideIndex = i;
|
2322 | break;
|
2323 | }
|
2324 | }
|
2325 | }
|
2326 |
|
2327 | if (slide && slideFound) {
|
2328 | swiper.clickedSlide = slide;
|
2329 |
|
2330 | if (swiper.virtual && swiper.params.virtual.enabled) {
|
2331 | swiper.clickedIndex = parseInt($(slide).attr('data-swiper-slide-index'), 10);
|
2332 | } else {
|
2333 | swiper.clickedIndex = slideIndex;
|
2334 | }
|
2335 | } else {
|
2336 | swiper.clickedSlide = undefined;
|
2337 | swiper.clickedIndex = undefined;
|
2338 | return;
|
2339 | }
|
2340 |
|
2341 | if (params.slideToClickedSlide && swiper.clickedIndex !== undefined && swiper.clickedIndex !== swiper.activeIndex) {
|
2342 | swiper.slideToClickedSlide();
|
2343 | }
|
2344 | }
|
2345 |
|
2346 | var update = {
|
2347 | updateSize,
|
2348 | updateSlides,
|
2349 | updateAutoHeight,
|
2350 | updateSlidesOffset,
|
2351 | updateSlidesProgress,
|
2352 | updateProgress,
|
2353 | updateSlidesClasses,
|
2354 | updateActiveIndex,
|
2355 | updateClickedSlide
|
2356 | };
|
2357 |
|
2358 | function getSwiperTranslate(axis) {
|
2359 | if (axis === void 0) {
|
2360 | axis = this.isHorizontal() ? 'x' : 'y';
|
2361 | }
|
2362 |
|
2363 | const swiper = this;
|
2364 | const {
|
2365 | params,
|
2366 | rtlTranslate: rtl,
|
2367 | translate,
|
2368 | $wrapperEl
|
2369 | } = swiper;
|
2370 |
|
2371 | if (params.virtualTranslate) {
|
2372 | return rtl ? -translate : translate;
|
2373 | }
|
2374 |
|
2375 | if (params.cssMode) {
|
2376 | return translate;
|
2377 | }
|
2378 |
|
2379 | let currentTranslate = getTranslate($wrapperEl[0], axis);
|
2380 | if (rtl) currentTranslate = -currentTranslate;
|
2381 | return currentTranslate || 0;
|
2382 | }
|
2383 |
|
2384 | function setTranslate(translate, byController) {
|
2385 | const swiper = this;
|
2386 | const {
|
2387 | rtlTranslate: rtl,
|
2388 | params,
|
2389 | $wrapperEl,
|
2390 | wrapperEl,
|
2391 | progress
|
2392 | } = swiper;
|
2393 | let x = 0;
|
2394 | let y = 0;
|
2395 | const z = 0;
|
2396 |
|
2397 | if (swiper.isHorizontal()) {
|
2398 | x = rtl ? -translate : translate;
|
2399 | } else {
|
2400 | y = translate;
|
2401 | }
|
2402 |
|
2403 | if (params.roundLengths) {
|
2404 | x = Math.floor(x);
|
2405 | y = Math.floor(y);
|
2406 | }
|
2407 |
|
2408 | if (params.cssMode) {
|
2409 | wrapperEl[swiper.isHorizontal() ? 'scrollLeft' : 'scrollTop'] = swiper.isHorizontal() ? -x : -y;
|
2410 | } else if (!params.virtualTranslate) {
|
2411 | $wrapperEl.transform(`translate3d(${x}px, ${y}px, ${z}px)`);
|
2412 | }
|
2413 |
|
2414 | swiper.previousTranslate = swiper.translate;
|
2415 | swiper.translate = swiper.isHorizontal() ? x : y;
|
2416 |
|
2417 | let newProgress;
|
2418 | const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
|
2419 |
|
2420 | if (translatesDiff === 0) {
|
2421 | newProgress = 0;
|
2422 | } else {
|
2423 | newProgress = (translate - swiper.minTranslate()) / translatesDiff;
|
2424 | }
|
2425 |
|
2426 | if (newProgress !== progress) {
|
2427 | swiper.updateProgress(translate);
|
2428 | }
|
2429 |
|
2430 | swiper.emit('setTranslate', swiper.translate, byController);
|
2431 | }
|
2432 |
|
2433 | function minTranslate() {
|
2434 | return -this.snapGrid[0];
|
2435 | }
|
2436 |
|
2437 | function maxTranslate() {
|
2438 | return -this.snapGrid[this.snapGrid.length - 1];
|
2439 | }
|
2440 |
|
2441 | function translateTo(translate, speed, runCallbacks, translateBounds, internal) {
|
2442 | if (translate === void 0) {
|
2443 | translate = 0;
|
2444 | }
|
2445 |
|
2446 | if (speed === void 0) {
|
2447 | speed = this.params.speed;
|
2448 | }
|
2449 |
|
2450 | if (runCallbacks === void 0) {
|
2451 | runCallbacks = true;
|
2452 | }
|
2453 |
|
2454 | if (translateBounds === void 0) {
|
2455 | translateBounds = true;
|
2456 | }
|
2457 |
|
2458 | const swiper = this;
|
2459 | const {
|
2460 | params,
|
2461 | wrapperEl
|
2462 | } = swiper;
|
2463 |
|
2464 | if (swiper.animating && params.preventInteractionOnTransition) {
|
2465 | return false;
|
2466 | }
|
2467 |
|
2468 | const minTranslate = swiper.minTranslate();
|
2469 | const maxTranslate = swiper.maxTranslate();
|
2470 | let newTranslate;
|
2471 | if (translateBounds && translate > minTranslate) newTranslate = minTranslate;else if (translateBounds && translate < maxTranslate) newTranslate = maxTranslate;else newTranslate = translate;
|
2472 |
|
2473 | swiper.updateProgress(newTranslate);
|
2474 |
|
2475 | if (params.cssMode) {
|
2476 | const isH = swiper.isHorizontal();
|
2477 |
|
2478 | if (speed === 0) {
|
2479 | wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = -newTranslate;
|
2480 | } else {
|
2481 | if (!swiper.support.smoothScroll) {
|
2482 | animateCSSModeScroll({
|
2483 | swiper,
|
2484 | targetPosition: -newTranslate,
|
2485 | side: isH ? 'left' : 'top'
|
2486 | });
|
2487 | return true;
|
2488 | }
|
2489 |
|
2490 | wrapperEl.scrollTo({
|
2491 | [isH ? 'left' : 'top']: -newTranslate,
|
2492 | behavior: 'smooth'
|
2493 | });
|
2494 | }
|
2495 |
|
2496 | return true;
|
2497 | }
|
2498 |
|
2499 | if (speed === 0) {
|
2500 | swiper.setTransition(0);
|
2501 | swiper.setTranslate(newTranslate);
|
2502 |
|
2503 | if (runCallbacks) {
|
2504 | swiper.emit('beforeTransitionStart', speed, internal);
|
2505 | swiper.emit('transitionEnd');
|
2506 | }
|
2507 | } else {
|
2508 | swiper.setTransition(speed);
|
2509 | swiper.setTranslate(newTranslate);
|
2510 |
|
2511 | if (runCallbacks) {
|
2512 | swiper.emit('beforeTransitionStart', speed, internal);
|
2513 | swiper.emit('transitionStart');
|
2514 | }
|
2515 |
|
2516 | if (!swiper.animating) {
|
2517 | swiper.animating = true;
|
2518 |
|
2519 | if (!swiper.onTranslateToWrapperTransitionEnd) {
|
2520 | swiper.onTranslateToWrapperTransitionEnd = function transitionEnd(e) {
|
2521 | if (!swiper || swiper.destroyed) return;
|
2522 | if (e.target !== this) return;
|
2523 | swiper.$wrapperEl[0].removeEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd);
|
2524 | swiper.$wrapperEl[0].removeEventListener('webkitTransitionEnd', swiper.onTranslateToWrapperTransitionEnd);
|
2525 | swiper.onTranslateToWrapperTransitionEnd = null;
|
2526 | delete swiper.onTranslateToWrapperTransitionEnd;
|
2527 |
|
2528 | if (runCallbacks) {
|
2529 | swiper.emit('transitionEnd');
|
2530 | }
|
2531 | };
|
2532 | }
|
2533 |
|
2534 | swiper.$wrapperEl[0].addEventListener('transitionend', swiper.onTranslateToWrapperTransitionEnd);
|
2535 | swiper.$wrapperEl[0].addEventListener('webkitTransitionEnd', swiper.onTranslateToWrapperTransitionEnd);
|
2536 | }
|
2537 | }
|
2538 |
|
2539 | return true;
|
2540 | }
|
2541 |
|
2542 | var translate = {
|
2543 | getTranslate: getSwiperTranslate,
|
2544 | setTranslate,
|
2545 | minTranslate,
|
2546 | maxTranslate,
|
2547 | translateTo
|
2548 | };
|
2549 |
|
2550 | function setTransition(duration, byController) {
|
2551 | const swiper = this;
|
2552 |
|
2553 | if (!swiper.params.cssMode) {
|
2554 | swiper.$wrapperEl.transition(duration);
|
2555 | }
|
2556 |
|
2557 | swiper.emit('setTransition', duration, byController);
|
2558 | }
|
2559 |
|
2560 | function transitionEmit(_ref) {
|
2561 | let {
|
2562 | swiper,
|
2563 | runCallbacks,
|
2564 | direction,
|
2565 | step
|
2566 | } = _ref;
|
2567 | const {
|
2568 | activeIndex,
|
2569 | previousIndex
|
2570 | } = swiper;
|
2571 | let dir = direction;
|
2572 |
|
2573 | if (!dir) {
|
2574 | if (activeIndex > previousIndex) dir = 'next';else if (activeIndex < previousIndex) dir = 'prev';else dir = 'reset';
|
2575 | }
|
2576 |
|
2577 | swiper.emit(`transition${step}`);
|
2578 |
|
2579 | if (runCallbacks && activeIndex !== previousIndex) {
|
2580 | if (dir === 'reset') {
|
2581 | swiper.emit(`slideResetTransition${step}`);
|
2582 | return;
|
2583 | }
|
2584 |
|
2585 | swiper.emit(`slideChangeTransition${step}`);
|
2586 |
|
2587 | if (dir === 'next') {
|
2588 | swiper.emit(`slideNextTransition${step}`);
|
2589 | } else {
|
2590 | swiper.emit(`slidePrevTransition${step}`);
|
2591 | }
|
2592 | }
|
2593 | }
|
2594 |
|
2595 | function transitionStart(runCallbacks, direction) {
|
2596 | if (runCallbacks === void 0) {
|
2597 | runCallbacks = true;
|
2598 | }
|
2599 |
|
2600 | const swiper = this;
|
2601 | const {
|
2602 | params
|
2603 | } = swiper;
|
2604 | if (params.cssMode) return;
|
2605 |
|
2606 | if (params.autoHeight) {
|
2607 | swiper.updateAutoHeight();
|
2608 | }
|
2609 |
|
2610 | transitionEmit({
|
2611 | swiper,
|
2612 | runCallbacks,
|
2613 | direction,
|
2614 | step: 'Start'
|
2615 | });
|
2616 | }
|
2617 |
|
2618 | function transitionEnd(runCallbacks, direction) {
|
2619 | if (runCallbacks === void 0) {
|
2620 | runCallbacks = true;
|
2621 | }
|
2622 |
|
2623 | const swiper = this;
|
2624 | const {
|
2625 | params
|
2626 | } = swiper;
|
2627 | swiper.animating = false;
|
2628 | if (params.cssMode) return;
|
2629 | swiper.setTransition(0);
|
2630 | transitionEmit({
|
2631 | swiper,
|
2632 | runCallbacks,
|
2633 | direction,
|
2634 | step: 'End'
|
2635 | });
|
2636 | }
|
2637 |
|
2638 | var transition = {
|
2639 | setTransition,
|
2640 | transitionStart,
|
2641 | transitionEnd
|
2642 | };
|
2643 |
|
2644 | function slideTo(index, speed, runCallbacks, internal, initial) {
|
2645 | if (index === void 0) {
|
2646 | index = 0;
|
2647 | }
|
2648 |
|
2649 | if (speed === void 0) {
|
2650 | speed = this.params.speed;
|
2651 | }
|
2652 |
|
2653 | if (runCallbacks === void 0) {
|
2654 | runCallbacks = true;
|
2655 | }
|
2656 |
|
2657 | if (typeof index !== 'number' && typeof index !== 'string') {
|
2658 | throw new Error(`The 'index' argument cannot have type other than 'number' or 'string'. [${typeof index}] given.`);
|
2659 | }
|
2660 |
|
2661 | if (typeof index === 'string') {
|
2662 | |
2663 |
|
2664 |
|
2665 |
|
2666 | const indexAsNumber = parseInt(index, 10);
|
2667 | |
2668 |
|
2669 |
|
2670 |
|
2671 |
|
2672 |
|
2673 | const isValidNumber = isFinite(indexAsNumber);
|
2674 |
|
2675 | if (!isValidNumber) {
|
2676 | throw new Error(`The passed-in 'index' (string) couldn't be converted to 'number'. [${index}] given.`);
|
2677 | }
|
2678 |
|
2679 |
|
2680 |
|
2681 | index = indexAsNumber;
|
2682 | }
|
2683 |
|
2684 | const swiper = this;
|
2685 | let slideIndex = index;
|
2686 | if (slideIndex < 0) slideIndex = 0;
|
2687 | const {
|
2688 | params,
|
2689 | snapGrid,
|
2690 | slidesGrid,
|
2691 | previousIndex,
|
2692 | activeIndex,
|
2693 | rtlTranslate: rtl,
|
2694 | wrapperEl,
|
2695 | enabled
|
2696 | } = swiper;
|
2697 |
|
2698 | if (swiper.animating && params.preventInteractionOnTransition || !enabled && !internal && !initial) {
|
2699 | return false;
|
2700 | }
|
2701 |
|
2702 | const skip = Math.min(swiper.params.slidesPerGroupSkip, slideIndex);
|
2703 | let snapIndex = skip + Math.floor((slideIndex - skip) / swiper.params.slidesPerGroup);
|
2704 | if (snapIndex >= snapGrid.length) snapIndex = snapGrid.length - 1;
|
2705 |
|
2706 | if ((activeIndex || params.initialSlide || 0) === (previousIndex || 0) && runCallbacks) {
|
2707 | swiper.emit('beforeSlideChangeStart');
|
2708 | }
|
2709 |
|
2710 | const translate = -snapGrid[snapIndex];
|
2711 |
|
2712 | swiper.updateProgress(translate);
|
2713 |
|
2714 | if (params.normalizeSlideIndex) {
|
2715 | for (let i = 0; i < slidesGrid.length; i += 1) {
|
2716 | const normalizedTranslate = -Math.floor(translate * 100);
|
2717 | const normalizedGrid = Math.floor(slidesGrid[i] * 100);
|
2718 | const normalizedGridNext = Math.floor(slidesGrid[i + 1] * 100);
|
2719 |
|
2720 | if (typeof slidesGrid[i + 1] !== 'undefined') {
|
2721 | if (normalizedTranslate >= normalizedGrid && normalizedTranslate < normalizedGridNext - (normalizedGridNext - normalizedGrid) / 2) {
|
2722 | slideIndex = i;
|
2723 | } else if (normalizedTranslate >= normalizedGrid && normalizedTranslate < normalizedGridNext) {
|
2724 | slideIndex = i + 1;
|
2725 | }
|
2726 | } else if (normalizedTranslate >= normalizedGrid) {
|
2727 | slideIndex = i;
|
2728 | }
|
2729 | }
|
2730 | }
|
2731 |
|
2732 |
|
2733 | if (swiper.initialized && slideIndex !== activeIndex) {
|
2734 | if (!swiper.allowSlideNext && translate < swiper.translate && translate < swiper.minTranslate()) {
|
2735 | return false;
|
2736 | }
|
2737 |
|
2738 | if (!swiper.allowSlidePrev && translate > swiper.translate && translate > swiper.maxTranslate()) {
|
2739 | if ((activeIndex || 0) !== slideIndex) return false;
|
2740 | }
|
2741 | }
|
2742 |
|
2743 | let direction;
|
2744 | if (slideIndex > activeIndex) direction = 'next';else if (slideIndex < activeIndex) direction = 'prev';else direction = 'reset';
|
2745 |
|
2746 | if (rtl && -translate === swiper.translate || !rtl && translate === swiper.translate) {
|
2747 | swiper.updateActiveIndex(slideIndex);
|
2748 |
|
2749 | if (params.autoHeight) {
|
2750 | swiper.updateAutoHeight();
|
2751 | }
|
2752 |
|
2753 | swiper.updateSlidesClasses();
|
2754 |
|
2755 | if (params.effect !== 'slide') {
|
2756 | swiper.setTranslate(translate);
|
2757 | }
|
2758 |
|
2759 | if (direction !== 'reset') {
|
2760 | swiper.transitionStart(runCallbacks, direction);
|
2761 | swiper.transitionEnd(runCallbacks, direction);
|
2762 | }
|
2763 |
|
2764 | return false;
|
2765 | }
|
2766 |
|
2767 | if (params.cssMode) {
|
2768 | const isH = swiper.isHorizontal();
|
2769 | const t = rtl ? translate : -translate;
|
2770 |
|
2771 | if (speed === 0) {
|
2772 | const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
|
2773 |
|
2774 | if (isVirtual) {
|
2775 | swiper.wrapperEl.style.scrollSnapType = 'none';
|
2776 | swiper._immediateVirtual = true;
|
2777 | }
|
2778 |
|
2779 | wrapperEl[isH ? 'scrollLeft' : 'scrollTop'] = t;
|
2780 |
|
2781 | if (isVirtual) {
|
2782 | requestAnimationFrame(() => {
|
2783 | swiper.wrapperEl.style.scrollSnapType = '';
|
2784 | swiper._swiperImmediateVirtual = false;
|
2785 | });
|
2786 | }
|
2787 | } else {
|
2788 | if (!swiper.support.smoothScroll) {
|
2789 | animateCSSModeScroll({
|
2790 | swiper,
|
2791 | targetPosition: t,
|
2792 | side: isH ? 'left' : 'top'
|
2793 | });
|
2794 | return true;
|
2795 | }
|
2796 |
|
2797 | wrapperEl.scrollTo({
|
2798 | [isH ? 'left' : 'top']: t,
|
2799 | behavior: 'smooth'
|
2800 | });
|
2801 | }
|
2802 |
|
2803 | return true;
|
2804 | }
|
2805 |
|
2806 | swiper.setTransition(speed);
|
2807 | swiper.setTranslate(translate);
|
2808 | swiper.updateActiveIndex(slideIndex);
|
2809 | swiper.updateSlidesClasses();
|
2810 | swiper.emit('beforeTransitionStart', speed, internal);
|
2811 | swiper.transitionStart(runCallbacks, direction);
|
2812 |
|
2813 | if (speed === 0) {
|
2814 | swiper.transitionEnd(runCallbacks, direction);
|
2815 | } else if (!swiper.animating) {
|
2816 | swiper.animating = true;
|
2817 |
|
2818 | if (!swiper.onSlideToWrapperTransitionEnd) {
|
2819 | swiper.onSlideToWrapperTransitionEnd = function transitionEnd(e) {
|
2820 | if (!swiper || swiper.destroyed) return;
|
2821 | if (e.target !== this) return;
|
2822 | swiper.$wrapperEl[0].removeEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
|
2823 | swiper.$wrapperEl[0].removeEventListener('webkitTransitionEnd', swiper.onSlideToWrapperTransitionEnd);
|
2824 | swiper.onSlideToWrapperTransitionEnd = null;
|
2825 | delete swiper.onSlideToWrapperTransitionEnd;
|
2826 | swiper.transitionEnd(runCallbacks, direction);
|
2827 | };
|
2828 | }
|
2829 |
|
2830 | swiper.$wrapperEl[0].addEventListener('transitionend', swiper.onSlideToWrapperTransitionEnd);
|
2831 | swiper.$wrapperEl[0].addEventListener('webkitTransitionEnd', swiper.onSlideToWrapperTransitionEnd);
|
2832 | }
|
2833 |
|
2834 | return true;
|
2835 | }
|
2836 |
|
2837 | function slideToLoop(index, speed, runCallbacks, internal) {
|
2838 | if (index === void 0) {
|
2839 | index = 0;
|
2840 | }
|
2841 |
|
2842 | if (speed === void 0) {
|
2843 | speed = this.params.speed;
|
2844 | }
|
2845 |
|
2846 | if (runCallbacks === void 0) {
|
2847 | runCallbacks = true;
|
2848 | }
|
2849 |
|
2850 | const swiper = this;
|
2851 | let newIndex = index;
|
2852 |
|
2853 | if (swiper.params.loop) {
|
2854 | newIndex += swiper.loopedSlides;
|
2855 | }
|
2856 |
|
2857 | return swiper.slideTo(newIndex, speed, runCallbacks, internal);
|
2858 | }
|
2859 |
|
2860 |
|
2861 | function slideNext(speed, runCallbacks, internal) {
|
2862 | if (speed === void 0) {
|
2863 | speed = this.params.speed;
|
2864 | }
|
2865 |
|
2866 | if (runCallbacks === void 0) {
|
2867 | runCallbacks = true;
|
2868 | }
|
2869 |
|
2870 | const swiper = this;
|
2871 | const {
|
2872 | animating,
|
2873 | enabled,
|
2874 | params
|
2875 | } = swiper;
|
2876 | if (!enabled) return swiper;
|
2877 | let perGroup = params.slidesPerGroup;
|
2878 |
|
2879 | if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
|
2880 | perGroup = Math.max(swiper.slidesPerViewDynamic('current', true), 1);
|
2881 | }
|
2882 |
|
2883 | const increment = swiper.activeIndex < params.slidesPerGroupSkip ? 1 : perGroup;
|
2884 |
|
2885 | if (params.loop) {
|
2886 | if (animating && params.loopPreventsSlide) return false;
|
2887 | swiper.loopFix();
|
2888 |
|
2889 | swiper._clientLeft = swiper.$wrapperEl[0].clientLeft;
|
2890 | }
|
2891 |
|
2892 | if (params.rewind && swiper.isEnd) {
|
2893 | return swiper.slideTo(0, speed, runCallbacks, internal);
|
2894 | }
|
2895 |
|
2896 | return swiper.slideTo(swiper.activeIndex + increment, speed, runCallbacks, internal);
|
2897 | }
|
2898 |
|
2899 |
|
2900 | function slidePrev(speed, runCallbacks, internal) {
|
2901 | if (speed === void 0) {
|
2902 | speed = this.params.speed;
|
2903 | }
|
2904 |
|
2905 | if (runCallbacks === void 0) {
|
2906 | runCallbacks = true;
|
2907 | }
|
2908 |
|
2909 | const swiper = this;
|
2910 | const {
|
2911 | params,
|
2912 | animating,
|
2913 | snapGrid,
|
2914 | slidesGrid,
|
2915 | rtlTranslate,
|
2916 | enabled
|
2917 | } = swiper;
|
2918 | if (!enabled) return swiper;
|
2919 |
|
2920 | if (params.loop) {
|
2921 | if (animating && params.loopPreventsSlide) return false;
|
2922 | swiper.loopFix();
|
2923 |
|
2924 | swiper._clientLeft = swiper.$wrapperEl[0].clientLeft;
|
2925 | }
|
2926 |
|
2927 | const translate = rtlTranslate ? swiper.translate : -swiper.translate;
|
2928 |
|
2929 | function normalize(val) {
|
2930 | if (val < 0) return -Math.floor(Math.abs(val));
|
2931 | return Math.floor(val);
|
2932 | }
|
2933 |
|
2934 | const normalizedTranslate = normalize(translate);
|
2935 | const normalizedSnapGrid = snapGrid.map(val => normalize(val));
|
2936 | let prevSnap = snapGrid[normalizedSnapGrid.indexOf(normalizedTranslate) - 1];
|
2937 |
|
2938 | if (typeof prevSnap === 'undefined' && params.cssMode) {
|
2939 | let prevSnapIndex;
|
2940 | snapGrid.forEach((snap, snapIndex) => {
|
2941 | if (normalizedTranslate >= snap) {
|
2942 |
|
2943 | prevSnapIndex = snapIndex;
|
2944 | }
|
2945 | });
|
2946 |
|
2947 | if (typeof prevSnapIndex !== 'undefined') {
|
2948 | prevSnap = snapGrid[prevSnapIndex > 0 ? prevSnapIndex - 1 : prevSnapIndex];
|
2949 | }
|
2950 | }
|
2951 |
|
2952 | let prevIndex = 0;
|
2953 |
|
2954 | if (typeof prevSnap !== 'undefined') {
|
2955 | prevIndex = slidesGrid.indexOf(prevSnap);
|
2956 | if (prevIndex < 0) prevIndex = swiper.activeIndex - 1;
|
2957 |
|
2958 | if (params.slidesPerView === 'auto' && params.slidesPerGroup === 1 && params.slidesPerGroupAuto) {
|
2959 | prevIndex = prevIndex - swiper.slidesPerViewDynamic('previous', true) + 1;
|
2960 | prevIndex = Math.max(prevIndex, 0);
|
2961 | }
|
2962 | }
|
2963 |
|
2964 | if (params.rewind && swiper.isBeginning) {
|
2965 | const lastIndex = swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1;
|
2966 | return swiper.slideTo(lastIndex, speed, runCallbacks, internal);
|
2967 | }
|
2968 |
|
2969 | return swiper.slideTo(prevIndex, speed, runCallbacks, internal);
|
2970 | }
|
2971 |
|
2972 |
|
2973 | function slideReset(speed, runCallbacks, internal) {
|
2974 | if (speed === void 0) {
|
2975 | speed = this.params.speed;
|
2976 | }
|
2977 |
|
2978 | if (runCallbacks === void 0) {
|
2979 | runCallbacks = true;
|
2980 | }
|
2981 |
|
2982 | const swiper = this;
|
2983 | return swiper.slideTo(swiper.activeIndex, speed, runCallbacks, internal);
|
2984 | }
|
2985 |
|
2986 |
|
2987 | function slideToClosest(speed, runCallbacks, internal, threshold) {
|
2988 | if (speed === void 0) {
|
2989 | speed = this.params.speed;
|
2990 | }
|
2991 |
|
2992 | if (runCallbacks === void 0) {
|
2993 | runCallbacks = true;
|
2994 | }
|
2995 |
|
2996 | if (threshold === void 0) {
|
2997 | threshold = 0.5;
|
2998 | }
|
2999 |
|
3000 | const swiper = this;
|
3001 | let index = swiper.activeIndex;
|
3002 | const skip = Math.min(swiper.params.slidesPerGroupSkip, index);
|
3003 | const snapIndex = skip + Math.floor((index - skip) / swiper.params.slidesPerGroup);
|
3004 | const translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;
|
3005 |
|
3006 | if (translate >= swiper.snapGrid[snapIndex]) {
|
3007 |
|
3008 |
|
3009 | const currentSnap = swiper.snapGrid[snapIndex];
|
3010 | const nextSnap = swiper.snapGrid[snapIndex + 1];
|
3011 |
|
3012 | if (translate - currentSnap > (nextSnap - currentSnap) * threshold) {
|
3013 | index += swiper.params.slidesPerGroup;
|
3014 | }
|
3015 | } else {
|
3016 |
|
3017 |
|
3018 | const prevSnap = swiper.snapGrid[snapIndex - 1];
|
3019 | const currentSnap = swiper.snapGrid[snapIndex];
|
3020 |
|
3021 | if (translate - prevSnap <= (currentSnap - prevSnap) * threshold) {
|
3022 | index -= swiper.params.slidesPerGroup;
|
3023 | }
|
3024 | }
|
3025 |
|
3026 | index = Math.max(index, 0);
|
3027 | index = Math.min(index, swiper.slidesGrid.length - 1);
|
3028 | return swiper.slideTo(index, speed, runCallbacks, internal);
|
3029 | }
|
3030 |
|
3031 | function slideToClickedSlide() {
|
3032 | const swiper = this;
|
3033 | const {
|
3034 | params,
|
3035 | $wrapperEl
|
3036 | } = swiper;
|
3037 | const slidesPerView = params.slidesPerView === 'auto' ? swiper.slidesPerViewDynamic() : params.slidesPerView;
|
3038 | let slideToIndex = swiper.clickedIndex;
|
3039 | let realIndex;
|
3040 |
|
3041 | if (params.loop) {
|
3042 | if (swiper.animating) return;
|
3043 | realIndex = parseInt($(swiper.clickedSlide).attr('data-swiper-slide-index'), 10);
|
3044 |
|
3045 | if (params.centeredSlides) {
|
3046 | if (slideToIndex < swiper.loopedSlides - slidesPerView / 2 || slideToIndex > swiper.slides.length - swiper.loopedSlides + slidesPerView / 2) {
|
3047 | swiper.loopFix();
|
3048 | slideToIndex = $wrapperEl.children(`.${params.slideClass}[data-swiper-slide-index="${realIndex}"]:not(.${params.slideDuplicateClass})`).eq(0).index();
|
3049 | nextTick(() => {
|
3050 | swiper.slideTo(slideToIndex);
|
3051 | });
|
3052 | } else {
|
3053 | swiper.slideTo(slideToIndex);
|
3054 | }
|
3055 | } else if (slideToIndex > swiper.slides.length - slidesPerView) {
|
3056 | swiper.loopFix();
|
3057 | slideToIndex = $wrapperEl.children(`.${params.slideClass}[data-swiper-slide-index="${realIndex}"]:not(.${params.slideDuplicateClass})`).eq(0).index();
|
3058 | nextTick(() => {
|
3059 | swiper.slideTo(slideToIndex);
|
3060 | });
|
3061 | } else {
|
3062 | swiper.slideTo(slideToIndex);
|
3063 | }
|
3064 | } else {
|
3065 | swiper.slideTo(slideToIndex);
|
3066 | }
|
3067 | }
|
3068 |
|
3069 | var slide = {
|
3070 | slideTo,
|
3071 | slideToLoop,
|
3072 | slideNext,
|
3073 | slidePrev,
|
3074 | slideReset,
|
3075 | slideToClosest,
|
3076 | slideToClickedSlide
|
3077 | };
|
3078 |
|
3079 | function loopCreate() {
|
3080 | const swiper = this;
|
3081 | const document = getDocument();
|
3082 | const {
|
3083 | params,
|
3084 | $wrapperEl
|
3085 | } = swiper;
|
3086 |
|
3087 | const $selector = $wrapperEl.children().length > 0 ? $($wrapperEl.children()[0].parentNode) : $wrapperEl;
|
3088 | $selector.children(`.${params.slideClass}.${params.slideDuplicateClass}`).remove();
|
3089 | let slides = $selector.children(`.${params.slideClass}`);
|
3090 |
|
3091 | if (params.loopFillGroupWithBlank) {
|
3092 | const blankSlidesNum = params.slidesPerGroup - slides.length % params.slidesPerGroup;
|
3093 |
|
3094 | if (blankSlidesNum !== params.slidesPerGroup) {
|
3095 | for (let i = 0; i < blankSlidesNum; i += 1) {
|
3096 | const blankNode = $(document.createElement('div')).addClass(`${params.slideClass} ${params.slideBlankClass}`);
|
3097 | $selector.append(blankNode);
|
3098 | }
|
3099 |
|
3100 | slides = $selector.children(`.${params.slideClass}`);
|
3101 | }
|
3102 | }
|
3103 |
|
3104 | if (params.slidesPerView === 'auto' && !params.loopedSlides) params.loopedSlides = slides.length;
|
3105 | swiper.loopedSlides = Math.ceil(parseFloat(params.loopedSlides || params.slidesPerView, 10));
|
3106 | swiper.loopedSlides += params.loopAdditionalSlides;
|
3107 |
|
3108 | if (swiper.loopedSlides > slides.length) {
|
3109 | swiper.loopedSlides = slides.length;
|
3110 | }
|
3111 |
|
3112 | const prependSlides = [];
|
3113 | const appendSlides = [];
|
3114 | slides.each((el, index) => {
|
3115 | const slide = $(el);
|
3116 |
|
3117 | if (index < swiper.loopedSlides) {
|
3118 | appendSlides.push(el);
|
3119 | }
|
3120 |
|
3121 | if (index < slides.length && index >= slides.length - swiper.loopedSlides) {
|
3122 | prependSlides.push(el);
|
3123 | }
|
3124 |
|
3125 | slide.attr('data-swiper-slide-index', index);
|
3126 | });
|
3127 |
|
3128 | for (let i = 0; i < appendSlides.length; i += 1) {
|
3129 | $selector.append($(appendSlides[i].cloneNode(true)).addClass(params.slideDuplicateClass));
|
3130 | }
|
3131 |
|
3132 | for (let i = prependSlides.length - 1; i >= 0; i -= 1) {
|
3133 | $selector.prepend($(prependSlides[i].cloneNode(true)).addClass(params.slideDuplicateClass));
|
3134 | }
|
3135 | }
|
3136 |
|
3137 | function loopFix() {
|
3138 | const swiper = this;
|
3139 | swiper.emit('beforeLoopFix');
|
3140 | const {
|
3141 | activeIndex,
|
3142 | slides,
|
3143 | loopedSlides,
|
3144 | allowSlidePrev,
|
3145 | allowSlideNext,
|
3146 | snapGrid,
|
3147 | rtlTranslate: rtl
|
3148 | } = swiper;
|
3149 | let newIndex;
|
3150 | swiper.allowSlidePrev = true;
|
3151 | swiper.allowSlideNext = true;
|
3152 | const snapTranslate = -snapGrid[activeIndex];
|
3153 | const diff = snapTranslate - swiper.getTranslate();
|
3154 |
|
3155 | if (activeIndex < loopedSlides) {
|
3156 | newIndex = slides.length - loopedSlides * 3 + activeIndex;
|
3157 | newIndex += loopedSlides;
|
3158 | const slideChanged = swiper.slideTo(newIndex, 0, false, true);
|
3159 |
|
3160 | if (slideChanged && diff !== 0) {
|
3161 | swiper.setTranslate((rtl ? -swiper.translate : swiper.translate) - diff);
|
3162 | }
|
3163 | } else if (activeIndex >= slides.length - loopedSlides) {
|
3164 |
|
3165 | newIndex = -slides.length + activeIndex + loopedSlides;
|
3166 | newIndex += loopedSlides;
|
3167 | const slideChanged = swiper.slideTo(newIndex, 0, false, true);
|
3168 |
|
3169 | if (slideChanged && diff !== 0) {
|
3170 | swiper.setTranslate((rtl ? -swiper.translate : swiper.translate) - diff);
|
3171 | }
|
3172 | }
|
3173 |
|
3174 | swiper.allowSlidePrev = allowSlidePrev;
|
3175 | swiper.allowSlideNext = allowSlideNext;
|
3176 | swiper.emit('loopFix');
|
3177 | }
|
3178 |
|
3179 | function loopDestroy() {
|
3180 | const swiper = this;
|
3181 | const {
|
3182 | $wrapperEl,
|
3183 | params,
|
3184 | slides
|
3185 | } = swiper;
|
3186 | $wrapperEl.children(`.${params.slideClass}.${params.slideDuplicateClass},.${params.slideClass}.${params.slideBlankClass}`).remove();
|
3187 | slides.removeAttr('data-swiper-slide-index');
|
3188 | }
|
3189 |
|
3190 | var loop = {
|
3191 | loopCreate,
|
3192 | loopFix,
|
3193 | loopDestroy
|
3194 | };
|
3195 |
|
3196 | function setGrabCursor(moving) {
|
3197 | const swiper = this;
|
3198 | if (swiper.support.touch || !swiper.params.simulateTouch || swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) return;
|
3199 | const el = swiper.params.touchEventsTarget === 'container' ? swiper.el : swiper.wrapperEl;
|
3200 | el.style.cursor = 'move';
|
3201 | el.style.cursor = moving ? '-webkit-grabbing' : '-webkit-grab';
|
3202 | el.style.cursor = moving ? '-moz-grabbin' : '-moz-grab';
|
3203 | el.style.cursor = moving ? 'grabbing' : 'grab';
|
3204 | }
|
3205 |
|
3206 | function unsetGrabCursor() {
|
3207 | const swiper = this;
|
3208 |
|
3209 | if (swiper.support.touch || swiper.params.watchOverflow && swiper.isLocked || swiper.params.cssMode) {
|
3210 | return;
|
3211 | }
|
3212 |
|
3213 | swiper[swiper.params.touchEventsTarget === 'container' ? 'el' : 'wrapperEl'].style.cursor = '';
|
3214 | }
|
3215 |
|
3216 | var grabCursor = {
|
3217 | setGrabCursor,
|
3218 | unsetGrabCursor
|
3219 | };
|
3220 |
|
3221 | function closestElement(selector, base) {
|
3222 | if (base === void 0) {
|
3223 | base = this;
|
3224 | }
|
3225 |
|
3226 | function __closestFrom(el) {
|
3227 | if (!el || el === getDocument() || el === getWindow()) return null;
|
3228 | if (el.assignedSlot) el = el.assignedSlot;
|
3229 | const found = el.closest(selector);
|
3230 | return found || __closestFrom(el.getRootNode().host);
|
3231 | }
|
3232 |
|
3233 | return __closestFrom(base);
|
3234 | }
|
3235 |
|
3236 | function onTouchStart(event) {
|
3237 | const swiper = this;
|
3238 | const document = getDocument();
|
3239 | const window = getWindow();
|
3240 | const data = swiper.touchEventsData;
|
3241 | const {
|
3242 | params,
|
3243 | touches,
|
3244 | enabled
|
3245 | } = swiper;
|
3246 | if (!enabled) return;
|
3247 |
|
3248 | if (swiper.animating && params.preventInteractionOnTransition) {
|
3249 | return;
|
3250 | }
|
3251 |
|
3252 | if (!swiper.animating && params.cssMode && params.loop) {
|
3253 | swiper.loopFix();
|
3254 | }
|
3255 |
|
3256 | let e = event;
|
3257 | if (e.originalEvent) e = e.originalEvent;
|
3258 | let $targetEl = $(e.target);
|
3259 |
|
3260 | if (params.touchEventsTarget === 'wrapper') {
|
3261 | if (!$targetEl.closest(swiper.wrapperEl).length) return;
|
3262 | }
|
3263 |
|
3264 | data.isTouchEvent = e.type === 'touchstart';
|
3265 | if (!data.isTouchEvent && 'which' in e && e.which === 3) return;
|
3266 | if (!data.isTouchEvent && 'button' in e && e.button > 0) return;
|
3267 | if (data.isTouched && data.isMoved) return;
|
3268 |
|
3269 | const swipingClassHasValue = !!params.noSwipingClass && params.noSwipingClass !== '';
|
3270 |
|
3271 | if (swipingClassHasValue && e.target && e.target.shadowRoot && event.path && event.path[0]) {
|
3272 | $targetEl = $(event.path[0]);
|
3273 | }
|
3274 |
|
3275 | const noSwipingSelector = params.noSwipingSelector ? params.noSwipingSelector : `.${params.noSwipingClass}`;
|
3276 | const isTargetShadow = !!(e.target && e.target.shadowRoot);
|
3277 |
|
3278 | if (params.noSwiping && (isTargetShadow ? closestElement(noSwipingSelector, e.target) : $targetEl.closest(noSwipingSelector)[0])) {
|
3279 | swiper.allowClick = true;
|
3280 | return;
|
3281 | }
|
3282 |
|
3283 | if (params.swipeHandler) {
|
3284 | if (!$targetEl.closest(params.swipeHandler)[0]) return;
|
3285 | }
|
3286 |
|
3287 | touches.currentX = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
|
3288 | touches.currentY = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
|
3289 | const startX = touches.currentX;
|
3290 | const startY = touches.currentY;
|
3291 |
|
3292 | const edgeSwipeDetection = params.edgeSwipeDetection || params.iOSEdgeSwipeDetection;
|
3293 | const edgeSwipeThreshold = params.edgeSwipeThreshold || params.iOSEdgeSwipeThreshold;
|
3294 |
|
3295 | if (edgeSwipeDetection && (startX <= edgeSwipeThreshold || startX >= window.innerWidth - edgeSwipeThreshold)) {
|
3296 | if (edgeSwipeDetection === 'prevent') {
|
3297 | event.preventDefault();
|
3298 | } else {
|
3299 | return;
|
3300 | }
|
3301 | }
|
3302 |
|
3303 | Object.assign(data, {
|
3304 | isTouched: true,
|
3305 | isMoved: false,
|
3306 | allowTouchCallbacks: true,
|
3307 | isScrolling: undefined,
|
3308 | startMoving: undefined
|
3309 | });
|
3310 | touches.startX = startX;
|
3311 | touches.startY = startY;
|
3312 | data.touchStartTime = now();
|
3313 | swiper.allowClick = true;
|
3314 | swiper.updateSize();
|
3315 | swiper.swipeDirection = undefined;
|
3316 | if (params.threshold > 0) data.allowThresholdMove = false;
|
3317 |
|
3318 | if (e.type !== 'touchstart') {
|
3319 | let preventDefault = true;
|
3320 |
|
3321 | if ($targetEl.is(data.focusableElements)) {
|
3322 | preventDefault = false;
|
3323 |
|
3324 | if ($targetEl[0].nodeName === 'SELECT') {
|
3325 | data.isTouched = false;
|
3326 | }
|
3327 | }
|
3328 |
|
3329 | if (document.activeElement && $(document.activeElement).is(data.focusableElements) && document.activeElement !== $targetEl[0]) {
|
3330 | document.activeElement.blur();
|
3331 | }
|
3332 |
|
3333 | const shouldPreventDefault = preventDefault && swiper.allowTouchMove && params.touchStartPreventDefault;
|
3334 |
|
3335 | if ((params.touchStartForcePreventDefault || shouldPreventDefault) && !$targetEl[0].isContentEditable) {
|
3336 | e.preventDefault();
|
3337 | }
|
3338 | }
|
3339 |
|
3340 | if (swiper.params.freeMode && swiper.params.freeMode.enabled && swiper.freeMode && swiper.animating && !params.cssMode) {
|
3341 | swiper.freeMode.onTouchStart();
|
3342 | }
|
3343 |
|
3344 | swiper.emit('touchStart', e);
|
3345 | }
|
3346 |
|
3347 | function onTouchMove(event) {
|
3348 | const document = getDocument();
|
3349 | const swiper = this;
|
3350 | const data = swiper.touchEventsData;
|
3351 | const {
|
3352 | params,
|
3353 | touches,
|
3354 | rtlTranslate: rtl,
|
3355 | enabled
|
3356 | } = swiper;
|
3357 | if (!enabled) return;
|
3358 | let e = event;
|
3359 | if (e.originalEvent) e = e.originalEvent;
|
3360 |
|
3361 | if (!data.isTouched) {
|
3362 | if (data.startMoving && data.isScrolling) {
|
3363 | swiper.emit('touchMoveOpposite', e);
|
3364 | }
|
3365 |
|
3366 | return;
|
3367 | }
|
3368 |
|
3369 | if (data.isTouchEvent && e.type !== 'touchmove') return;
|
3370 | const targetTouch = e.type === 'touchmove' && e.targetTouches && (e.targetTouches[0] || e.changedTouches[0]);
|
3371 | const pageX = e.type === 'touchmove' ? targetTouch.pageX : e.pageX;
|
3372 | const pageY = e.type === 'touchmove' ? targetTouch.pageY : e.pageY;
|
3373 |
|
3374 | if (e.preventedByNestedSwiper) {
|
3375 | touches.startX = pageX;
|
3376 | touches.startY = pageY;
|
3377 | return;
|
3378 | }
|
3379 |
|
3380 | if (!swiper.allowTouchMove) {
|
3381 | if (!$(e.target).is(data.focusableElements)) {
|
3382 | swiper.allowClick = false;
|
3383 | }
|
3384 |
|
3385 | if (data.isTouched) {
|
3386 | Object.assign(touches, {
|
3387 | startX: pageX,
|
3388 | startY: pageY,
|
3389 | currentX: pageX,
|
3390 | currentY: pageY
|
3391 | });
|
3392 | data.touchStartTime = now();
|
3393 | }
|
3394 |
|
3395 | return;
|
3396 | }
|
3397 |
|
3398 | if (data.isTouchEvent && params.touchReleaseOnEdges && !params.loop) {
|
3399 | if (swiper.isVertical()) {
|
3400 |
|
3401 | if (pageY < touches.startY && swiper.translate <= swiper.maxTranslate() || pageY > touches.startY && swiper.translate >= swiper.minTranslate()) {
|
3402 | data.isTouched = false;
|
3403 | data.isMoved = false;
|
3404 | return;
|
3405 | }
|
3406 | } else if (pageX < touches.startX && swiper.translate <= swiper.maxTranslate() || pageX > touches.startX && swiper.translate >= swiper.minTranslate()) {
|
3407 | return;
|
3408 | }
|
3409 | }
|
3410 |
|
3411 | if (data.isTouchEvent && document.activeElement) {
|
3412 | if (e.target === document.activeElement && $(e.target).is(data.focusableElements)) {
|
3413 | data.isMoved = true;
|
3414 | swiper.allowClick = false;
|
3415 | return;
|
3416 | }
|
3417 | }
|
3418 |
|
3419 | if (data.allowTouchCallbacks) {
|
3420 | swiper.emit('touchMove', e);
|
3421 | }
|
3422 |
|
3423 | if (e.targetTouches && e.targetTouches.length > 1) return;
|
3424 | touches.currentX = pageX;
|
3425 | touches.currentY = pageY;
|
3426 | const diffX = touches.currentX - touches.startX;
|
3427 | const diffY = touches.currentY - touches.startY;
|
3428 | if (swiper.params.threshold && Math.sqrt(diffX ** 2 + diffY ** 2) < swiper.params.threshold) return;
|
3429 |
|
3430 | if (typeof data.isScrolling === 'undefined') {
|
3431 | let touchAngle;
|
3432 |
|
3433 | if (swiper.isHorizontal() && touches.currentY === touches.startY || swiper.isVertical() && touches.currentX === touches.startX) {
|
3434 | data.isScrolling = false;
|
3435 | } else {
|
3436 |
|
3437 | if (diffX * diffX + diffY * diffY >= 25) {
|
3438 | touchAngle = Math.atan2(Math.abs(diffY), Math.abs(diffX)) * 180 / Math.PI;
|
3439 | data.isScrolling = swiper.isHorizontal() ? touchAngle > params.touchAngle : 90 - touchAngle > params.touchAngle;
|
3440 | }
|
3441 | }
|
3442 | }
|
3443 |
|
3444 | if (data.isScrolling) {
|
3445 | swiper.emit('touchMoveOpposite', e);
|
3446 | }
|
3447 |
|
3448 | if (typeof data.startMoving === 'undefined') {
|
3449 | if (touches.currentX !== touches.startX || touches.currentY !== touches.startY) {
|
3450 | data.startMoving = true;
|
3451 | }
|
3452 | }
|
3453 |
|
3454 | if (data.isScrolling) {
|
3455 | data.isTouched = false;
|
3456 | return;
|
3457 | }
|
3458 |
|
3459 | if (!data.startMoving) {
|
3460 | return;
|
3461 | }
|
3462 |
|
3463 | swiper.allowClick = false;
|
3464 |
|
3465 | if (!params.cssMode && e.cancelable) {
|
3466 | e.preventDefault();
|
3467 | }
|
3468 |
|
3469 | if (params.touchMoveStopPropagation && !params.nested) {
|
3470 | e.stopPropagation();
|
3471 | }
|
3472 |
|
3473 | if (!data.isMoved) {
|
3474 | if (params.loop && !params.cssMode) {
|
3475 | swiper.loopFix();
|
3476 | }
|
3477 |
|
3478 | data.startTranslate = swiper.getTranslate();
|
3479 | swiper.setTransition(0);
|
3480 |
|
3481 | if (swiper.animating) {
|
3482 | swiper.$wrapperEl.trigger('webkitTransitionEnd transitionend');
|
3483 | }
|
3484 |
|
3485 | data.allowMomentumBounce = false;
|
3486 |
|
3487 | if (params.grabCursor && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
|
3488 | swiper.setGrabCursor(true);
|
3489 | }
|
3490 |
|
3491 | swiper.emit('sliderFirstMove', e);
|
3492 | }
|
3493 |
|
3494 | swiper.emit('sliderMove', e);
|
3495 | data.isMoved = true;
|
3496 | let diff = swiper.isHorizontal() ? diffX : diffY;
|
3497 | touches.diff = diff;
|
3498 | diff *= params.touchRatio;
|
3499 | if (rtl) diff = -diff;
|
3500 | swiper.swipeDirection = diff > 0 ? 'prev' : 'next';
|
3501 | data.currentTranslate = diff + data.startTranslate;
|
3502 | let disableParentSwiper = true;
|
3503 | let resistanceRatio = params.resistanceRatio;
|
3504 |
|
3505 | if (params.touchReleaseOnEdges) {
|
3506 | resistanceRatio = 0;
|
3507 | }
|
3508 |
|
3509 | if (diff > 0 && data.currentTranslate > swiper.minTranslate()) {
|
3510 | disableParentSwiper = false;
|
3511 | if (params.resistance) data.currentTranslate = swiper.minTranslate() - 1 + (-swiper.minTranslate() + data.startTranslate + diff) ** resistanceRatio;
|
3512 | } else if (diff < 0 && data.currentTranslate < swiper.maxTranslate()) {
|
3513 | disableParentSwiper = false;
|
3514 | if (params.resistance) data.currentTranslate = swiper.maxTranslate() + 1 - (swiper.maxTranslate() - data.startTranslate - diff) ** resistanceRatio;
|
3515 | }
|
3516 |
|
3517 | if (disableParentSwiper) {
|
3518 | e.preventedByNestedSwiper = true;
|
3519 | }
|
3520 |
|
3521 |
|
3522 | if (!swiper.allowSlideNext && swiper.swipeDirection === 'next' && data.currentTranslate < data.startTranslate) {
|
3523 | data.currentTranslate = data.startTranslate;
|
3524 | }
|
3525 |
|
3526 | if (!swiper.allowSlidePrev && swiper.swipeDirection === 'prev' && data.currentTranslate > data.startTranslate) {
|
3527 | data.currentTranslate = data.startTranslate;
|
3528 | }
|
3529 |
|
3530 | if (!swiper.allowSlidePrev && !swiper.allowSlideNext) {
|
3531 | data.currentTranslate = data.startTranslate;
|
3532 | }
|
3533 |
|
3534 |
|
3535 | if (params.threshold > 0) {
|
3536 | if (Math.abs(diff) > params.threshold || data.allowThresholdMove) {
|
3537 | if (!data.allowThresholdMove) {
|
3538 | data.allowThresholdMove = true;
|
3539 | touches.startX = touches.currentX;
|
3540 | touches.startY = touches.currentY;
|
3541 | data.currentTranslate = data.startTranslate;
|
3542 | touches.diff = swiper.isHorizontal() ? touches.currentX - touches.startX : touches.currentY - touches.startY;
|
3543 | return;
|
3544 | }
|
3545 | } else {
|
3546 | data.currentTranslate = data.startTranslate;
|
3547 | return;
|
3548 | }
|
3549 | }
|
3550 |
|
3551 | if (!params.followFinger || params.cssMode) return;
|
3552 |
|
3553 | if (params.freeMode && params.freeMode.enabled && swiper.freeMode || params.watchSlidesProgress) {
|
3554 | swiper.updateActiveIndex();
|
3555 | swiper.updateSlidesClasses();
|
3556 | }
|
3557 |
|
3558 | if (swiper.params.freeMode && params.freeMode.enabled && swiper.freeMode) {
|
3559 | swiper.freeMode.onTouchMove();
|
3560 | }
|
3561 |
|
3562 |
|
3563 | swiper.updateProgress(data.currentTranslate);
|
3564 |
|
3565 | swiper.setTranslate(data.currentTranslate);
|
3566 | }
|
3567 |
|
3568 | function onTouchEnd(event) {
|
3569 | const swiper = this;
|
3570 | const data = swiper.touchEventsData;
|
3571 | const {
|
3572 | params,
|
3573 | touches,
|
3574 | rtlTranslate: rtl,
|
3575 | slidesGrid,
|
3576 | enabled
|
3577 | } = swiper;
|
3578 | if (!enabled) return;
|
3579 | let e = event;
|
3580 | if (e.originalEvent) e = e.originalEvent;
|
3581 |
|
3582 | if (data.allowTouchCallbacks) {
|
3583 | swiper.emit('touchEnd', e);
|
3584 | }
|
3585 |
|
3586 | data.allowTouchCallbacks = false;
|
3587 |
|
3588 | if (!data.isTouched) {
|
3589 | if (data.isMoved && params.grabCursor) {
|
3590 | swiper.setGrabCursor(false);
|
3591 | }
|
3592 |
|
3593 | data.isMoved = false;
|
3594 | data.startMoving = false;
|
3595 | return;
|
3596 | }
|
3597 |
|
3598 |
|
3599 | if (params.grabCursor && data.isMoved && data.isTouched && (swiper.allowSlideNext === true || swiper.allowSlidePrev === true)) {
|
3600 | swiper.setGrabCursor(false);
|
3601 | }
|
3602 |
|
3603 |
|
3604 | const touchEndTime = now();
|
3605 | const timeDiff = touchEndTime - data.touchStartTime;
|
3606 |
|
3607 | if (swiper.allowClick) {
|
3608 | const pathTree = e.path || e.composedPath && e.composedPath();
|
3609 | swiper.updateClickedSlide(pathTree && pathTree[0] || e.target);
|
3610 | swiper.emit('tap click', e);
|
3611 |
|
3612 | if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) {
|
3613 | swiper.emit('doubleTap doubleClick', e);
|
3614 | }
|
3615 | }
|
3616 |
|
3617 | data.lastClickTime = now();
|
3618 | nextTick(() => {
|
3619 | if (!swiper.destroyed) swiper.allowClick = true;
|
3620 | });
|
3621 |
|
3622 | if (!data.isTouched || !data.isMoved || !swiper.swipeDirection || touches.diff === 0 || data.currentTranslate === data.startTranslate) {
|
3623 | data.isTouched = false;
|
3624 | data.isMoved = false;
|
3625 | data.startMoving = false;
|
3626 | return;
|
3627 | }
|
3628 |
|
3629 | data.isTouched = false;
|
3630 | data.isMoved = false;
|
3631 | data.startMoving = false;
|
3632 | let currentPos;
|
3633 |
|
3634 | if (params.followFinger) {
|
3635 | currentPos = rtl ? swiper.translate : -swiper.translate;
|
3636 | } else {
|
3637 | currentPos = -data.currentTranslate;
|
3638 | }
|
3639 |
|
3640 | if (params.cssMode) {
|
3641 | return;
|
3642 | }
|
3643 |
|
3644 | if (swiper.params.freeMode && params.freeMode.enabled) {
|
3645 | swiper.freeMode.onTouchEnd({
|
3646 | currentPos
|
3647 | });
|
3648 | return;
|
3649 | }
|
3650 |
|
3651 |
|
3652 | let stopIndex = 0;
|
3653 | let groupSize = swiper.slidesSizesGrid[0];
|
3654 |
|
3655 | for (let i = 0; i < slidesGrid.length; i += i < params.slidesPerGroupSkip ? 1 : params.slidesPerGroup) {
|
3656 | const increment = i < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
|
3657 |
|
3658 | if (typeof slidesGrid[i + increment] !== 'undefined') {
|
3659 | if (currentPos >= slidesGrid[i] && currentPos < slidesGrid[i + increment]) {
|
3660 | stopIndex = i;
|
3661 | groupSize = slidesGrid[i + increment] - slidesGrid[i];
|
3662 | }
|
3663 | } else if (currentPos >= slidesGrid[i]) {
|
3664 | stopIndex = i;
|
3665 | groupSize = slidesGrid[slidesGrid.length - 1] - slidesGrid[slidesGrid.length - 2];
|
3666 | }
|
3667 | }
|
3668 |
|
3669 | let rewindFirstIndex = null;
|
3670 | let rewindLastIndex = null;
|
3671 |
|
3672 | if (params.rewind) {
|
3673 | if (swiper.isBeginning) {
|
3674 | rewindLastIndex = swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual ? swiper.virtual.slides.length - 1 : swiper.slides.length - 1;
|
3675 | } else if (swiper.isEnd) {
|
3676 | rewindFirstIndex = 0;
|
3677 | }
|
3678 | }
|
3679 |
|
3680 |
|
3681 | const ratio = (currentPos - slidesGrid[stopIndex]) / groupSize;
|
3682 | const increment = stopIndex < params.slidesPerGroupSkip - 1 ? 1 : params.slidesPerGroup;
|
3683 |
|
3684 | if (timeDiff > params.longSwipesMs) {
|
3685 |
|
3686 | if (!params.longSwipes) {
|
3687 | swiper.slideTo(swiper.activeIndex);
|
3688 | return;
|
3689 | }
|
3690 |
|
3691 | if (swiper.swipeDirection === 'next') {
|
3692 | if (ratio >= params.longSwipesRatio) swiper.slideTo(params.rewind && swiper.isEnd ? rewindFirstIndex : stopIndex + increment);else swiper.slideTo(stopIndex);
|
3693 | }
|
3694 |
|
3695 | if (swiper.swipeDirection === 'prev') {
|
3696 | if (ratio > 1 - params.longSwipesRatio) {
|
3697 | swiper.slideTo(stopIndex + increment);
|
3698 | } else if (rewindLastIndex !== null && ratio < 0 && Math.abs(ratio) > params.longSwipesRatio) {
|
3699 | swiper.slideTo(rewindLastIndex);
|
3700 | } else {
|
3701 | swiper.slideTo(stopIndex);
|
3702 | }
|
3703 | }
|
3704 | } else {
|
3705 |
|
3706 | if (!params.shortSwipes) {
|
3707 | swiper.slideTo(swiper.activeIndex);
|
3708 | return;
|
3709 | }
|
3710 |
|
3711 | const isNavButtonTarget = swiper.navigation && (e.target === swiper.navigation.nextEl || e.target === swiper.navigation.prevEl);
|
3712 |
|
3713 | if (!isNavButtonTarget) {
|
3714 | if (swiper.swipeDirection === 'next') {
|
3715 | swiper.slideTo(rewindFirstIndex !== null ? rewindFirstIndex : stopIndex + increment);
|
3716 | }
|
3717 |
|
3718 | if (swiper.swipeDirection === 'prev') {
|
3719 | swiper.slideTo(rewindLastIndex !== null ? rewindLastIndex : stopIndex);
|
3720 | }
|
3721 | } else if (e.target === swiper.navigation.nextEl) {
|
3722 | swiper.slideTo(stopIndex + increment);
|
3723 | } else {
|
3724 | swiper.slideTo(stopIndex);
|
3725 | }
|
3726 | }
|
3727 | }
|
3728 |
|
3729 | function onResize() {
|
3730 | const swiper = this;
|
3731 | const {
|
3732 | params,
|
3733 | el
|
3734 | } = swiper;
|
3735 | if (el && el.offsetWidth === 0) return;
|
3736 |
|
3737 | if (params.breakpoints) {
|
3738 | swiper.setBreakpoint();
|
3739 | }
|
3740 |
|
3741 |
|
3742 | const {
|
3743 | allowSlideNext,
|
3744 | allowSlidePrev,
|
3745 | snapGrid
|
3746 | } = swiper;
|
3747 |
|
3748 | swiper.allowSlideNext = true;
|
3749 | swiper.allowSlidePrev = true;
|
3750 | swiper.updateSize();
|
3751 | swiper.updateSlides();
|
3752 | swiper.updateSlidesClasses();
|
3753 |
|
3754 | if ((params.slidesPerView === 'auto' || params.slidesPerView > 1) && swiper.isEnd && !swiper.isBeginning && !swiper.params.centeredSlides) {
|
3755 | swiper.slideTo(swiper.slides.length - 1, 0, false, true);
|
3756 | } else {
|
3757 | swiper.slideTo(swiper.activeIndex, 0, false, true);
|
3758 | }
|
3759 |
|
3760 | if (swiper.autoplay && swiper.autoplay.running && swiper.autoplay.paused) {
|
3761 | swiper.autoplay.run();
|
3762 | }
|
3763 |
|
3764 |
|
3765 | swiper.allowSlidePrev = allowSlidePrev;
|
3766 | swiper.allowSlideNext = allowSlideNext;
|
3767 |
|
3768 | if (swiper.params.watchOverflow && snapGrid !== swiper.snapGrid) {
|
3769 | swiper.checkOverflow();
|
3770 | }
|
3771 | }
|
3772 |
|
3773 | function onClick(e) {
|
3774 | const swiper = this;
|
3775 | if (!swiper.enabled) return;
|
3776 |
|
3777 | if (!swiper.allowClick) {
|
3778 | if (swiper.params.preventClicks) e.preventDefault();
|
3779 |
|
3780 | if (swiper.params.preventClicksPropagation && swiper.animating) {
|
3781 | e.stopPropagation();
|
3782 | e.stopImmediatePropagation();
|
3783 | }
|
3784 | }
|
3785 | }
|
3786 |
|
3787 | function onScroll() {
|
3788 | const swiper = this;
|
3789 | const {
|
3790 | wrapperEl,
|
3791 | rtlTranslate,
|
3792 | enabled
|
3793 | } = swiper;
|
3794 | if (!enabled) return;
|
3795 | swiper.previousTranslate = swiper.translate;
|
3796 |
|
3797 | if (swiper.isHorizontal()) {
|
3798 | swiper.translate = -wrapperEl.scrollLeft;
|
3799 | } else {
|
3800 | swiper.translate = -wrapperEl.scrollTop;
|
3801 | }
|
3802 |
|
3803 |
|
3804 | if (swiper.translate === -0) swiper.translate = 0;
|
3805 | swiper.updateActiveIndex();
|
3806 | swiper.updateSlidesClasses();
|
3807 | let newProgress;
|
3808 | const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
|
3809 |
|
3810 | if (translatesDiff === 0) {
|
3811 | newProgress = 0;
|
3812 | } else {
|
3813 | newProgress = (swiper.translate - swiper.minTranslate()) / translatesDiff;
|
3814 | }
|
3815 |
|
3816 | if (newProgress !== swiper.progress) {
|
3817 | swiper.updateProgress(rtlTranslate ? -swiper.translate : swiper.translate);
|
3818 | }
|
3819 |
|
3820 | swiper.emit('setTranslate', swiper.translate, false);
|
3821 | }
|
3822 |
|
3823 | let dummyEventAttached = false;
|
3824 |
|
3825 | function dummyEventListener() {}
|
3826 |
|
3827 | const events = (swiper, method) => {
|
3828 | const document = getDocument();
|
3829 | const {
|
3830 | params,
|
3831 | touchEvents,
|
3832 | el,
|
3833 | wrapperEl,
|
3834 | device,
|
3835 | support
|
3836 | } = swiper;
|
3837 | const capture = !!params.nested;
|
3838 | const domMethod = method === 'on' ? 'addEventListener' : 'removeEventListener';
|
3839 | const swiperMethod = method;
|
3840 |
|
3841 | if (!support.touch) {
|
3842 | el[domMethod](touchEvents.start, swiper.onTouchStart, false);
|
3843 | document[domMethod](touchEvents.move, swiper.onTouchMove, capture);
|
3844 | document[domMethod](touchEvents.end, swiper.onTouchEnd, false);
|
3845 | } else {
|
3846 | const passiveListener = touchEvents.start === 'touchstart' && support.passiveListener && params.passiveListeners ? {
|
3847 | passive: true,
|
3848 | capture: false
|
3849 | } : false;
|
3850 | el[domMethod](touchEvents.start, swiper.onTouchStart, passiveListener);
|
3851 | el[domMethod](touchEvents.move, swiper.onTouchMove, support.passiveListener ? {
|
3852 | passive: false,
|
3853 | capture
|
3854 | } : capture);
|
3855 | el[domMethod](touchEvents.end, swiper.onTouchEnd, passiveListener);
|
3856 |
|
3857 | if (touchEvents.cancel) {
|
3858 | el[domMethod](touchEvents.cancel, swiper.onTouchEnd, passiveListener);
|
3859 | }
|
3860 | }
|
3861 |
|
3862 |
|
3863 | if (params.preventClicks || params.preventClicksPropagation) {
|
3864 | el[domMethod]('click', swiper.onClick, true);
|
3865 | }
|
3866 |
|
3867 | if (params.cssMode) {
|
3868 | wrapperEl[domMethod]('scroll', swiper.onScroll);
|
3869 | }
|
3870 |
|
3871 |
|
3872 | if (params.updateOnWindowResize) {
|
3873 | swiper[swiperMethod](device.ios || device.android ? 'resize orientationchange observerUpdate' : 'resize observerUpdate', onResize, true);
|
3874 | } else {
|
3875 | swiper[swiperMethod]('observerUpdate', onResize, true);
|
3876 | }
|
3877 | };
|
3878 |
|
3879 | function attachEvents() {
|
3880 | const swiper = this;
|
3881 | const document = getDocument();
|
3882 | const {
|
3883 | params,
|
3884 | support
|
3885 | } = swiper;
|
3886 | swiper.onTouchStart = onTouchStart.bind(swiper);
|
3887 | swiper.onTouchMove = onTouchMove.bind(swiper);
|
3888 | swiper.onTouchEnd = onTouchEnd.bind(swiper);
|
3889 |
|
3890 | if (params.cssMode) {
|
3891 | swiper.onScroll = onScroll.bind(swiper);
|
3892 | }
|
3893 |
|
3894 | swiper.onClick = onClick.bind(swiper);
|
3895 |
|
3896 | if (support.touch && !dummyEventAttached) {
|
3897 | document.addEventListener('touchstart', dummyEventListener);
|
3898 | dummyEventAttached = true;
|
3899 | }
|
3900 |
|
3901 | events(swiper, 'on');
|
3902 | }
|
3903 |
|
3904 | function detachEvents() {
|
3905 | const swiper = this;
|
3906 | events(swiper, 'off');
|
3907 | }
|
3908 |
|
3909 | var events$1 = {
|
3910 | attachEvents,
|
3911 | detachEvents
|
3912 | };
|
3913 |
|
3914 | const isGridEnabled = (swiper, params) => {
|
3915 | return swiper.grid && params.grid && params.grid.rows > 1;
|
3916 | };
|
3917 |
|
3918 | function setBreakpoint() {
|
3919 | const swiper = this;
|
3920 | const {
|
3921 | activeIndex,
|
3922 | initialized,
|
3923 | loopedSlides = 0,
|
3924 | params,
|
3925 | $el
|
3926 | } = swiper;
|
3927 | const breakpoints = params.breakpoints;
|
3928 | if (!breakpoints || breakpoints && Object.keys(breakpoints).length === 0) return;
|
3929 |
|
3930 | const breakpoint = swiper.getBreakpoint(breakpoints, swiper.params.breakpointsBase, swiper.el);
|
3931 | if (!breakpoint || swiper.currentBreakpoint === breakpoint) return;
|
3932 | const breakpointOnlyParams = breakpoint in breakpoints ? breakpoints[breakpoint] : undefined;
|
3933 | const breakpointParams = breakpointOnlyParams || swiper.originalParams;
|
3934 | const wasMultiRow = isGridEnabled(swiper, params);
|
3935 | const isMultiRow = isGridEnabled(swiper, breakpointParams);
|
3936 | const wasEnabled = params.enabled;
|
3937 |
|
3938 | if (wasMultiRow && !isMultiRow) {
|
3939 | $el.removeClass(`${params.containerModifierClass}grid ${params.containerModifierClass}grid-column`);
|
3940 | swiper.emitContainerClasses();
|
3941 | } else if (!wasMultiRow && isMultiRow) {
|
3942 | $el.addClass(`${params.containerModifierClass}grid`);
|
3943 |
|
3944 | if (breakpointParams.grid.fill && breakpointParams.grid.fill === 'column' || !breakpointParams.grid.fill && params.grid.fill === 'column') {
|
3945 | $el.addClass(`${params.containerModifierClass}grid-column`);
|
3946 | }
|
3947 |
|
3948 | swiper.emitContainerClasses();
|
3949 | }
|
3950 |
|
3951 | const directionChanged = breakpointParams.direction && breakpointParams.direction !== params.direction;
|
3952 | const needsReLoop = params.loop && (breakpointParams.slidesPerView !== params.slidesPerView || directionChanged);
|
3953 |
|
3954 | if (directionChanged && initialized) {
|
3955 | swiper.changeDirection();
|
3956 | }
|
3957 |
|
3958 | extend(swiper.params, breakpointParams);
|
3959 | const isEnabled = swiper.params.enabled;
|
3960 | Object.assign(swiper, {
|
3961 | allowTouchMove: swiper.params.allowTouchMove,
|
3962 | allowSlideNext: swiper.params.allowSlideNext,
|
3963 | allowSlidePrev: swiper.params.allowSlidePrev
|
3964 | });
|
3965 |
|
3966 | if (wasEnabled && !isEnabled) {
|
3967 | swiper.disable();
|
3968 | } else if (!wasEnabled && isEnabled) {
|
3969 | swiper.enable();
|
3970 | }
|
3971 |
|
3972 | swiper.currentBreakpoint = breakpoint;
|
3973 | swiper.emit('_beforeBreakpoint', breakpointParams);
|
3974 |
|
3975 | if (needsReLoop && initialized) {
|
3976 | swiper.loopDestroy();
|
3977 | swiper.loopCreate();
|
3978 | swiper.updateSlides();
|
3979 | swiper.slideTo(activeIndex - loopedSlides + swiper.loopedSlides, 0, false);
|
3980 | }
|
3981 |
|
3982 | swiper.emit('breakpoint', breakpointParams);
|
3983 | }
|
3984 |
|
3985 | function getBreakpoint(breakpoints, base, containerEl) {
|
3986 | if (base === void 0) {
|
3987 | base = 'window';
|
3988 | }
|
3989 |
|
3990 | if (!breakpoints || base === 'container' && !containerEl) return undefined;
|
3991 | let breakpoint = false;
|
3992 | const window = getWindow();
|
3993 | const currentHeight = base === 'window' ? window.innerHeight : containerEl.clientHeight;
|
3994 | const points = Object.keys(breakpoints).map(point => {
|
3995 | if (typeof point === 'string' && point.indexOf('@') === 0) {
|
3996 | const minRatio = parseFloat(point.substr(1));
|
3997 | const value = currentHeight * minRatio;
|
3998 | return {
|
3999 | value,
|
4000 | point
|
4001 | };
|
4002 | }
|
4003 |
|
4004 | return {
|
4005 | value: point,
|
4006 | point
|
4007 | };
|
4008 | });
|
4009 | points.sort((a, b) => parseInt(a.value, 10) - parseInt(b.value, 10));
|
4010 |
|
4011 | for (let i = 0; i < points.length; i += 1) {
|
4012 | const {
|
4013 | point,
|
4014 | value
|
4015 | } = points[i];
|
4016 |
|
4017 | if (base === 'window') {
|
4018 | if (window.matchMedia(`(min-width: ${value}px)`).matches) {
|
4019 | breakpoint = point;
|
4020 | }
|
4021 | } else if (value <= containerEl.clientWidth) {
|
4022 | breakpoint = point;
|
4023 | }
|
4024 | }
|
4025 |
|
4026 | return breakpoint || 'max';
|
4027 | }
|
4028 |
|
4029 | var breakpoints = {
|
4030 | setBreakpoint,
|
4031 | getBreakpoint
|
4032 | };
|
4033 |
|
4034 | function prepareClasses(entries, prefix) {
|
4035 | const resultClasses = [];
|
4036 | entries.forEach(item => {
|
4037 | if (typeof item === 'object') {
|
4038 | Object.keys(item).forEach(classNames => {
|
4039 | if (item[classNames]) {
|
4040 | resultClasses.push(prefix + classNames);
|
4041 | }
|
4042 | });
|
4043 | } else if (typeof item === 'string') {
|
4044 | resultClasses.push(prefix + item);
|
4045 | }
|
4046 | });
|
4047 | return resultClasses;
|
4048 | }
|
4049 |
|
4050 | function addClasses() {
|
4051 | const swiper = this;
|
4052 | const {
|
4053 | classNames,
|
4054 | params,
|
4055 | rtl,
|
4056 | $el,
|
4057 | device,
|
4058 | support
|
4059 | } = swiper;
|
4060 |
|
4061 | const suffixes = prepareClasses(['initialized', params.direction, {
|
4062 | 'pointer-events': !support.touch
|
4063 | }, {
|
4064 | 'free-mode': swiper.params.freeMode && params.freeMode.enabled
|
4065 | }, {
|
4066 | 'autoheight': params.autoHeight
|
4067 | }, {
|
4068 | 'rtl': rtl
|
4069 | }, {
|
4070 | 'grid': params.grid && params.grid.rows > 1
|
4071 | }, {
|
4072 | 'grid-column': params.grid && params.grid.rows > 1 && params.grid.fill === 'column'
|
4073 | }, {
|
4074 | 'android': device.android
|
4075 | }, {
|
4076 | 'ios': device.ios
|
4077 | }, {
|
4078 | 'css-mode': params.cssMode
|
4079 | }, {
|
4080 | 'centered': params.cssMode && params.centeredSlides
|
4081 | }], params.containerModifierClass);
|
4082 | classNames.push(...suffixes);
|
4083 | $el.addClass([...classNames].join(' '));
|
4084 | swiper.emitContainerClasses();
|
4085 | }
|
4086 |
|
4087 | function removeClasses() {
|
4088 | const swiper = this;
|
4089 | const {
|
4090 | $el,
|
4091 | classNames
|
4092 | } = swiper;
|
4093 | $el.removeClass(classNames.join(' '));
|
4094 | swiper.emitContainerClasses();
|
4095 | }
|
4096 |
|
4097 | var classes = {
|
4098 | addClasses,
|
4099 | removeClasses
|
4100 | };
|
4101 |
|
4102 | function loadImage(imageEl, src, srcset, sizes, checkForComplete, callback) {
|
4103 | const window = getWindow();
|
4104 | let image;
|
4105 |
|
4106 | function onReady() {
|
4107 | if (callback) callback();
|
4108 | }
|
4109 |
|
4110 | const isPicture = $(imageEl).parent('picture')[0];
|
4111 |
|
4112 | if (!isPicture && (!imageEl.complete || !checkForComplete)) {
|
4113 | if (src) {
|
4114 | image = new window.Image();
|
4115 | image.onload = onReady;
|
4116 | image.onerror = onReady;
|
4117 |
|
4118 | if (sizes) {
|
4119 | image.sizes = sizes;
|
4120 | }
|
4121 |
|
4122 | if (srcset) {
|
4123 | image.srcset = srcset;
|
4124 | }
|
4125 |
|
4126 | if (src) {
|
4127 | image.src = src;
|
4128 | }
|
4129 | } else {
|
4130 | onReady();
|
4131 | }
|
4132 | } else {
|
4133 |
|
4134 | onReady();
|
4135 | }
|
4136 | }
|
4137 |
|
4138 | function preloadImages() {
|
4139 | const swiper = this;
|
4140 | swiper.imagesToLoad = swiper.$el.find('img');
|
4141 |
|
4142 | function onReady() {
|
4143 | if (typeof swiper === 'undefined' || swiper === null || !swiper || swiper.destroyed) return;
|
4144 | if (swiper.imagesLoaded !== undefined) swiper.imagesLoaded += 1;
|
4145 |
|
4146 | if (swiper.imagesLoaded === swiper.imagesToLoad.length) {
|
4147 | if (swiper.params.updateOnImagesReady) swiper.update();
|
4148 | swiper.emit('imagesReady');
|
4149 | }
|
4150 | }
|
4151 |
|
4152 | for (let i = 0; i < swiper.imagesToLoad.length; i += 1) {
|
4153 | const imageEl = swiper.imagesToLoad[i];
|
4154 | swiper.loadImage(imageEl, imageEl.currentSrc || imageEl.getAttribute('src'), imageEl.srcset || imageEl.getAttribute('srcset'), imageEl.sizes || imageEl.getAttribute('sizes'), true, onReady);
|
4155 | }
|
4156 | }
|
4157 |
|
4158 | var images = {
|
4159 | loadImage,
|
4160 | preloadImages
|
4161 | };
|
4162 |
|
4163 | function checkOverflow() {
|
4164 | const swiper = this;
|
4165 | const {
|
4166 | isLocked: wasLocked,
|
4167 | params
|
4168 | } = swiper;
|
4169 | const {
|
4170 | slidesOffsetBefore
|
4171 | } = params;
|
4172 |
|
4173 | if (slidesOffsetBefore) {
|
4174 | const lastSlideIndex = swiper.slides.length - 1;
|
4175 | const lastSlideRightEdge = swiper.slidesGrid[lastSlideIndex] + swiper.slidesSizesGrid[lastSlideIndex] + slidesOffsetBefore * 2;
|
4176 | swiper.isLocked = swiper.size > lastSlideRightEdge;
|
4177 | } else {
|
4178 | swiper.isLocked = swiper.snapGrid.length === 1;
|
4179 | }
|
4180 |
|
4181 | if (params.allowSlideNext === true) {
|
4182 | swiper.allowSlideNext = !swiper.isLocked;
|
4183 | }
|
4184 |
|
4185 | if (params.allowSlidePrev === true) {
|
4186 | swiper.allowSlidePrev = !swiper.isLocked;
|
4187 | }
|
4188 |
|
4189 | if (wasLocked && wasLocked !== swiper.isLocked) {
|
4190 | swiper.isEnd = false;
|
4191 | }
|
4192 |
|
4193 | if (wasLocked !== swiper.isLocked) {
|
4194 | swiper.emit(swiper.isLocked ? 'lock' : 'unlock');
|
4195 | }
|
4196 | }
|
4197 |
|
4198 | var checkOverflow$1 = {
|
4199 | checkOverflow
|
4200 | };
|
4201 |
|
4202 | var defaults = {
|
4203 | init: true,
|
4204 | direction: 'horizontal',
|
4205 | touchEventsTarget: 'wrapper',
|
4206 | initialSlide: 0,
|
4207 | speed: 300,
|
4208 | cssMode: false,
|
4209 | updateOnWindowResize: true,
|
4210 | resizeObserver: true,
|
4211 | nested: false,
|
4212 | createElements: false,
|
4213 | enabled: true,
|
4214 | focusableElements: 'input, select, option, textarea, button, video, label',
|
4215 |
|
4216 | width: null,
|
4217 | height: null,
|
4218 |
|
4219 | preventInteractionOnTransition: false,
|
4220 |
|
4221 | userAgent: null,
|
4222 | url: null,
|
4223 |
|
4224 | edgeSwipeDetection: false,
|
4225 | edgeSwipeThreshold: 20,
|
4226 |
|
4227 | autoHeight: false,
|
4228 |
|
4229 | setWrapperSize: false,
|
4230 |
|
4231 | virtualTranslate: false,
|
4232 |
|
4233 | effect: 'slide',
|
4234 |
|
4235 |
|
4236 | breakpoints: undefined,
|
4237 | breakpointsBase: 'window',
|
4238 |
|
4239 | spaceBetween: 0,
|
4240 | slidesPerView: 1,
|
4241 | slidesPerGroup: 1,
|
4242 | slidesPerGroupSkip: 0,
|
4243 | slidesPerGroupAuto: false,
|
4244 | centeredSlides: false,
|
4245 | centeredSlidesBounds: false,
|
4246 | slidesOffsetBefore: 0,
|
4247 |
|
4248 | slidesOffsetAfter: 0,
|
4249 |
|
4250 | normalizeSlideIndex: true,
|
4251 | centerInsufficientSlides: false,
|
4252 |
|
4253 | watchOverflow: true,
|
4254 |
|
4255 | roundLengths: false,
|
4256 |
|
4257 | touchRatio: 1,
|
4258 | touchAngle: 45,
|
4259 | simulateTouch: true,
|
4260 | shortSwipes: true,
|
4261 | longSwipes: true,
|
4262 | longSwipesRatio: 0.5,
|
4263 | longSwipesMs: 300,
|
4264 | followFinger: true,
|
4265 | allowTouchMove: true,
|
4266 | threshold: 0,
|
4267 | touchMoveStopPropagation: false,
|
4268 | touchStartPreventDefault: true,
|
4269 | touchStartForcePreventDefault: false,
|
4270 | touchReleaseOnEdges: false,
|
4271 |
|
4272 | uniqueNavElements: true,
|
4273 |
|
4274 | resistance: true,
|
4275 | resistanceRatio: 0.85,
|
4276 |
|
4277 | watchSlidesProgress: false,
|
4278 |
|
4279 | grabCursor: false,
|
4280 |
|
4281 | preventClicks: true,
|
4282 | preventClicksPropagation: true,
|
4283 | slideToClickedSlide: false,
|
4284 |
|
4285 | preloadImages: true,
|
4286 | updateOnImagesReady: true,
|
4287 |
|
4288 | loop: false,
|
4289 | loopAdditionalSlides: 0,
|
4290 | loopedSlides: null,
|
4291 | loopFillGroupWithBlank: false,
|
4292 | loopPreventsSlide: true,
|
4293 |
|
4294 | rewind: false,
|
4295 |
|
4296 | allowSlidePrev: true,
|
4297 | allowSlideNext: true,
|
4298 | swipeHandler: null,
|
4299 |
|
4300 | noSwiping: true,
|
4301 | noSwipingClass: 'swiper-no-swiping',
|
4302 | noSwipingSelector: null,
|
4303 |
|
4304 | passiveListeners: true,
|
4305 | maxBackfaceHiddenSlides: 10,
|
4306 |
|
4307 | containerModifierClass: 'swiper-',
|
4308 |
|
4309 | slideClass: 'swiper-slide',
|
4310 | slideBlankClass: 'swiper-slide-invisible-blank',
|
4311 | slideActiveClass: 'swiper-slide-active',
|
4312 | slideDuplicateActiveClass: 'swiper-slide-duplicate-active',
|
4313 | slideVisibleClass: 'swiper-slide-visible',
|
4314 | slideDuplicateClass: 'swiper-slide-duplicate',
|
4315 | slideNextClass: 'swiper-slide-next',
|
4316 | slideDuplicateNextClass: 'swiper-slide-duplicate-next',
|
4317 | slidePrevClass: 'swiper-slide-prev',
|
4318 | slideDuplicatePrevClass: 'swiper-slide-duplicate-prev',
|
4319 | wrapperClass: 'swiper-wrapper',
|
4320 |
|
4321 | runCallbacksOnInit: true,
|
4322 |
|
4323 | _emitClasses: false
|
4324 | };
|
4325 |
|
4326 | function moduleExtendParams(params, allModulesParams) {
|
4327 | return function extendParams(obj) {
|
4328 | if (obj === void 0) {
|
4329 | obj = {};
|
4330 | }
|
4331 |
|
4332 | const moduleParamName = Object.keys(obj)[0];
|
4333 | const moduleParams = obj[moduleParamName];
|
4334 |
|
4335 | if (typeof moduleParams !== 'object' || moduleParams === null) {
|
4336 | extend(allModulesParams, obj);
|
4337 | return;
|
4338 | }
|
4339 |
|
4340 | if (['navigation', 'pagination', 'scrollbar'].indexOf(moduleParamName) >= 0 && params[moduleParamName] === true) {
|
4341 | params[moduleParamName] = {
|
4342 | auto: true
|
4343 | };
|
4344 | }
|
4345 |
|
4346 | if (!(moduleParamName in params && 'enabled' in moduleParams)) {
|
4347 | extend(allModulesParams, obj);
|
4348 | return;
|
4349 | }
|
4350 |
|
4351 | if (params[moduleParamName] === true) {
|
4352 | params[moduleParamName] = {
|
4353 | enabled: true
|
4354 | };
|
4355 | }
|
4356 |
|
4357 | if (typeof params[moduleParamName] === 'object' && !('enabled' in params[moduleParamName])) {
|
4358 | params[moduleParamName].enabled = true;
|
4359 | }
|
4360 |
|
4361 | if (!params[moduleParamName]) params[moduleParamName] = {
|
4362 | enabled: false
|
4363 | };
|
4364 | extend(allModulesParams, obj);
|
4365 | };
|
4366 | }
|
4367 |
|
4368 |
|
4369 | const prototypes = {
|
4370 | eventsEmitter,
|
4371 | update,
|
4372 | translate,
|
4373 | transition,
|
4374 | slide,
|
4375 | loop,
|
4376 | grabCursor,
|
4377 | events: events$1,
|
4378 | breakpoints,
|
4379 | checkOverflow: checkOverflow$1,
|
4380 | classes,
|
4381 | images
|
4382 | };
|
4383 | const extendedDefaults = {};
|
4384 |
|
4385 | class Swiper {
|
4386 | constructor() {
|
4387 | let el;
|
4388 | let params;
|
4389 |
|
4390 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
4391 | args[_key] = arguments[_key];
|
4392 | }
|
4393 |
|
4394 | if (args.length === 1 && args[0].constructor && Object.prototype.toString.call(args[0]).slice(8, -1) === 'Object') {
|
4395 | params = args[0];
|
4396 | } else {
|
4397 | [el, params] = args;
|
4398 | }
|
4399 |
|
4400 | if (!params) params = {};
|
4401 | params = extend({}, params);
|
4402 | if (el && !params.el) params.el = el;
|
4403 |
|
4404 | if (params.el && $(params.el).length > 1) {
|
4405 | const swipers = [];
|
4406 | $(params.el).each(containerEl => {
|
4407 | const newParams = extend({}, params, {
|
4408 | el: containerEl
|
4409 | });
|
4410 | swipers.push(new Swiper(newParams));
|
4411 | });
|
4412 | return swipers;
|
4413 | }
|
4414 |
|
4415 |
|
4416 | const swiper = this;
|
4417 | swiper.__swiper__ = true;
|
4418 | swiper.support = getSupport();
|
4419 | swiper.device = getDevice({
|
4420 | userAgent: params.userAgent
|
4421 | });
|
4422 | swiper.browser = getBrowser();
|
4423 | swiper.eventsListeners = {};
|
4424 | swiper.eventsAnyListeners = [];
|
4425 | swiper.modules = [...swiper.__modules__];
|
4426 |
|
4427 | if (params.modules && Array.isArray(params.modules)) {
|
4428 | swiper.modules.push(...params.modules);
|
4429 | }
|
4430 |
|
4431 | const allModulesParams = {};
|
4432 | swiper.modules.forEach(mod => {
|
4433 | mod({
|
4434 | swiper,
|
4435 | extendParams: moduleExtendParams(params, allModulesParams),
|
4436 | on: swiper.on.bind(swiper),
|
4437 | once: swiper.once.bind(swiper),
|
4438 | off: swiper.off.bind(swiper),
|
4439 | emit: swiper.emit.bind(swiper)
|
4440 | });
|
4441 | });
|
4442 |
|
4443 | const swiperParams = extend({}, defaults, allModulesParams);
|
4444 |
|
4445 | swiper.params = extend({}, swiperParams, extendedDefaults, params);
|
4446 | swiper.originalParams = extend({}, swiper.params);
|
4447 | swiper.passedParams = extend({}, params);
|
4448 |
|
4449 | if (swiper.params && swiper.params.on) {
|
4450 | Object.keys(swiper.params.on).forEach(eventName => {
|
4451 | swiper.on(eventName, swiper.params.on[eventName]);
|
4452 | });
|
4453 | }
|
4454 |
|
4455 | if (swiper.params && swiper.params.onAny) {
|
4456 | swiper.onAny(swiper.params.onAny);
|
4457 | }
|
4458 |
|
4459 |
|
4460 | swiper.$ = $;
|
4461 |
|
4462 | Object.assign(swiper, {
|
4463 | enabled: swiper.params.enabled,
|
4464 | el,
|
4465 |
|
4466 | classNames: [],
|
4467 |
|
4468 | slides: $(),
|
4469 | slidesGrid: [],
|
4470 | snapGrid: [],
|
4471 | slidesSizesGrid: [],
|
4472 |
|
4473 |
|
4474 | isHorizontal() {
|
4475 | return swiper.params.direction === 'horizontal';
|
4476 | },
|
4477 |
|
4478 | isVertical() {
|
4479 | return swiper.params.direction === 'vertical';
|
4480 | },
|
4481 |
|
4482 |
|
4483 | activeIndex: 0,
|
4484 | realIndex: 0,
|
4485 |
|
4486 | isBeginning: true,
|
4487 | isEnd: false,
|
4488 |
|
4489 | translate: 0,
|
4490 | previousTranslate: 0,
|
4491 | progress: 0,
|
4492 | velocity: 0,
|
4493 | animating: false,
|
4494 |
|
4495 | allowSlideNext: swiper.params.allowSlideNext,
|
4496 | allowSlidePrev: swiper.params.allowSlidePrev,
|
4497 |
|
4498 | touchEvents: function touchEvents() {
|
4499 | const touch = ['touchstart', 'touchmove', 'touchend', 'touchcancel'];
|
4500 | const desktop = ['pointerdown', 'pointermove', 'pointerup'];
|
4501 | swiper.touchEventsTouch = {
|
4502 | start: touch[0],
|
4503 | move: touch[1],
|
4504 | end: touch[2],
|
4505 | cancel: touch[3]
|
4506 | };
|
4507 | swiper.touchEventsDesktop = {
|
4508 | start: desktop[0],
|
4509 | move: desktop[1],
|
4510 | end: desktop[2]
|
4511 | };
|
4512 | return swiper.support.touch || !swiper.params.simulateTouch ? swiper.touchEventsTouch : swiper.touchEventsDesktop;
|
4513 | }(),
|
4514 | touchEventsData: {
|
4515 | isTouched: undefined,
|
4516 | isMoved: undefined,
|
4517 | allowTouchCallbacks: undefined,
|
4518 | touchStartTime: undefined,
|
4519 | isScrolling: undefined,
|
4520 | currentTranslate: undefined,
|
4521 | startTranslate: undefined,
|
4522 | allowThresholdMove: undefined,
|
4523 |
|
4524 | focusableElements: swiper.params.focusableElements,
|
4525 |
|
4526 | lastClickTime: now(),
|
4527 | clickTimeout: undefined,
|
4528 |
|
4529 | velocities: [],
|
4530 | allowMomentumBounce: undefined,
|
4531 | isTouchEvent: undefined,
|
4532 | startMoving: undefined
|
4533 | },
|
4534 |
|
4535 | allowClick: true,
|
4536 |
|
4537 | allowTouchMove: swiper.params.allowTouchMove,
|
4538 | touches: {
|
4539 | startX: 0,
|
4540 | startY: 0,
|
4541 | currentX: 0,
|
4542 | currentY: 0,
|
4543 | diff: 0
|
4544 | },
|
4545 |
|
4546 | imagesToLoad: [],
|
4547 | imagesLoaded: 0
|
4548 | });
|
4549 | swiper.emit('_swiper');
|
4550 |
|
4551 | if (swiper.params.init) {
|
4552 | swiper.init();
|
4553 | }
|
4554 |
|
4555 |
|
4556 | return swiper;
|
4557 | }
|
4558 |
|
4559 | enable() {
|
4560 | const swiper = this;
|
4561 | if (swiper.enabled) return;
|
4562 | swiper.enabled = true;
|
4563 |
|
4564 | if (swiper.params.grabCursor) {
|
4565 | swiper.setGrabCursor();
|
4566 | }
|
4567 |
|
4568 | swiper.emit('enable');
|
4569 | }
|
4570 |
|
4571 | disable() {
|
4572 | const swiper = this;
|
4573 | if (!swiper.enabled) return;
|
4574 | swiper.enabled = false;
|
4575 |
|
4576 | if (swiper.params.grabCursor) {
|
4577 | swiper.unsetGrabCursor();
|
4578 | }
|
4579 |
|
4580 | swiper.emit('disable');
|
4581 | }
|
4582 |
|
4583 | setProgress(progress, speed) {
|
4584 | const swiper = this;
|
4585 | progress = Math.min(Math.max(progress, 0), 1);
|
4586 | const min = swiper.minTranslate();
|
4587 | const max = swiper.maxTranslate();
|
4588 | const current = (max - min) * progress + min;
|
4589 | swiper.translateTo(current, typeof speed === 'undefined' ? 0 : speed);
|
4590 | swiper.updateActiveIndex();
|
4591 | swiper.updateSlidesClasses();
|
4592 | }
|
4593 |
|
4594 | emitContainerClasses() {
|
4595 | const swiper = this;
|
4596 | if (!swiper.params._emitClasses || !swiper.el) return;
|
4597 | const cls = swiper.el.className.split(' ').filter(className => {
|
4598 | return className.indexOf('swiper') === 0 || className.indexOf(swiper.params.containerModifierClass) === 0;
|
4599 | });
|
4600 | swiper.emit('_containerClasses', cls.join(' '));
|
4601 | }
|
4602 |
|
4603 | getSlideClasses(slideEl) {
|
4604 | const swiper = this;
|
4605 | return slideEl.className.split(' ').filter(className => {
|
4606 | return className.indexOf('swiper-slide') === 0 || className.indexOf(swiper.params.slideClass) === 0;
|
4607 | }).join(' ');
|
4608 | }
|
4609 |
|
4610 | emitSlidesClasses() {
|
4611 | const swiper = this;
|
4612 | if (!swiper.params._emitClasses || !swiper.el) return;
|
4613 | const updates = [];
|
4614 | swiper.slides.each(slideEl => {
|
4615 | const classNames = swiper.getSlideClasses(slideEl);
|
4616 | updates.push({
|
4617 | slideEl,
|
4618 | classNames
|
4619 | });
|
4620 | swiper.emit('_slideClass', slideEl, classNames);
|
4621 | });
|
4622 | swiper.emit('_slideClasses', updates);
|
4623 | }
|
4624 |
|
4625 | slidesPerViewDynamic(view, exact) {
|
4626 | if (view === void 0) {
|
4627 | view = 'current';
|
4628 | }
|
4629 |
|
4630 | if (exact === void 0) {
|
4631 | exact = false;
|
4632 | }
|
4633 |
|
4634 | const swiper = this;
|
4635 | const {
|
4636 | params,
|
4637 | slides,
|
4638 | slidesGrid,
|
4639 | slidesSizesGrid,
|
4640 | size: swiperSize,
|
4641 | activeIndex
|
4642 | } = swiper;
|
4643 | let spv = 1;
|
4644 |
|
4645 | if (params.centeredSlides) {
|
4646 | let slideSize = slides[activeIndex].swiperSlideSize;
|
4647 | let breakLoop;
|
4648 |
|
4649 | for (let i = activeIndex + 1; i < slides.length; i += 1) {
|
4650 | if (slides[i] && !breakLoop) {
|
4651 | slideSize += slides[i].swiperSlideSize;
|
4652 | spv += 1;
|
4653 | if (slideSize > swiperSize) breakLoop = true;
|
4654 | }
|
4655 | }
|
4656 |
|
4657 | for (let i = activeIndex - 1; i >= 0; i -= 1) {
|
4658 | if (slides[i] && !breakLoop) {
|
4659 | slideSize += slides[i].swiperSlideSize;
|
4660 | spv += 1;
|
4661 | if (slideSize > swiperSize) breakLoop = true;
|
4662 | }
|
4663 | }
|
4664 | } else {
|
4665 |
|
4666 | if (view === 'current') {
|
4667 | for (let i = activeIndex + 1; i < slides.length; i += 1) {
|
4668 | const slideInView = exact ? slidesGrid[i] + slidesSizesGrid[i] - slidesGrid[activeIndex] < swiperSize : slidesGrid[i] - slidesGrid[activeIndex] < swiperSize;
|
4669 |
|
4670 | if (slideInView) {
|
4671 | spv += 1;
|
4672 | }
|
4673 | }
|
4674 | } else {
|
4675 |
|
4676 | for (let i = activeIndex - 1; i >= 0; i -= 1) {
|
4677 | const slideInView = slidesGrid[activeIndex] - slidesGrid[i] < swiperSize;
|
4678 |
|
4679 | if (slideInView) {
|
4680 | spv += 1;
|
4681 | }
|
4682 | }
|
4683 | }
|
4684 | }
|
4685 |
|
4686 | return spv;
|
4687 | }
|
4688 |
|
4689 | update() {
|
4690 | const swiper = this;
|
4691 | if (!swiper || swiper.destroyed) return;
|
4692 | const {
|
4693 | snapGrid,
|
4694 | params
|
4695 | } = swiper;
|
4696 |
|
4697 | if (params.breakpoints) {
|
4698 | swiper.setBreakpoint();
|
4699 | }
|
4700 |
|
4701 | swiper.updateSize();
|
4702 | swiper.updateSlides();
|
4703 | swiper.updateProgress();
|
4704 | swiper.updateSlidesClasses();
|
4705 |
|
4706 | function setTranslate() {
|
4707 | const translateValue = swiper.rtlTranslate ? swiper.translate * -1 : swiper.translate;
|
4708 | const newTranslate = Math.min(Math.max(translateValue, swiper.maxTranslate()), swiper.minTranslate());
|
4709 | swiper.setTranslate(newTranslate);
|
4710 | swiper.updateActiveIndex();
|
4711 | swiper.updateSlidesClasses();
|
4712 | }
|
4713 |
|
4714 | let translated;
|
4715 |
|
4716 | if (swiper.params.freeMode && swiper.params.freeMode.enabled) {
|
4717 | setTranslate();
|
4718 |
|
4719 | if (swiper.params.autoHeight) {
|
4720 | swiper.updateAutoHeight();
|
4721 | }
|
4722 | } else {
|
4723 | if ((swiper.params.slidesPerView === 'auto' || swiper.params.slidesPerView > 1) && swiper.isEnd && !swiper.params.centeredSlides) {
|
4724 | translated = swiper.slideTo(swiper.slides.length - 1, 0, false, true);
|
4725 | } else {
|
4726 | translated = swiper.slideTo(swiper.activeIndex, 0, false, true);
|
4727 | }
|
4728 |
|
4729 | if (!translated) {
|
4730 | setTranslate();
|
4731 | }
|
4732 | }
|
4733 |
|
4734 | if (params.watchOverflow && snapGrid !== swiper.snapGrid) {
|
4735 | swiper.checkOverflow();
|
4736 | }
|
4737 |
|
4738 | swiper.emit('update');
|
4739 | }
|
4740 |
|
4741 | changeDirection(newDirection, needUpdate) {
|
4742 | if (needUpdate === void 0) {
|
4743 | needUpdate = true;
|
4744 | }
|
4745 |
|
4746 | const swiper = this;
|
4747 | const currentDirection = swiper.params.direction;
|
4748 |
|
4749 | if (!newDirection) {
|
4750 |
|
4751 | newDirection = currentDirection === 'horizontal' ? 'vertical' : 'horizontal';
|
4752 | }
|
4753 |
|
4754 | if (newDirection === currentDirection || newDirection !== 'horizontal' && newDirection !== 'vertical') {
|
4755 | return swiper;
|
4756 | }
|
4757 |
|
4758 | swiper.$el.removeClass(`${swiper.params.containerModifierClass}${currentDirection}`).addClass(`${swiper.params.containerModifierClass}${newDirection}`);
|
4759 | swiper.emitContainerClasses();
|
4760 | swiper.params.direction = newDirection;
|
4761 | swiper.slides.each(slideEl => {
|
4762 | if (newDirection === 'vertical') {
|
4763 | slideEl.style.width = '';
|
4764 | } else {
|
4765 | slideEl.style.height = '';
|
4766 | }
|
4767 | });
|
4768 | swiper.emit('changeDirection');
|
4769 | if (needUpdate) swiper.update();
|
4770 | return swiper;
|
4771 | }
|
4772 |
|
4773 | mount(el) {
|
4774 | const swiper = this;
|
4775 | if (swiper.mounted) return true;
|
4776 |
|
4777 | const $el = $(el || swiper.params.el);
|
4778 | el = $el[0];
|
4779 |
|
4780 | if (!el) {
|
4781 | return false;
|
4782 | }
|
4783 |
|
4784 | el.swiper = swiper;
|
4785 |
|
4786 | const getWrapperSelector = () => {
|
4787 | return `.${(swiper.params.wrapperClass || '').trim().split(' ').join('.')}`;
|
4788 | };
|
4789 |
|
4790 | const getWrapper = () => {
|
4791 | if (el && el.shadowRoot && el.shadowRoot.querySelector) {
|
4792 | const res = $(el.shadowRoot.querySelector(getWrapperSelector()));
|
4793 |
|
4794 | res.children = options => $el.children(options);
|
4795 |
|
4796 | return res;
|
4797 | }
|
4798 |
|
4799 | return $el.children(getWrapperSelector());
|
4800 | };
|
4801 |
|
4802 |
|
4803 | let $wrapperEl = getWrapper();
|
4804 |
|
4805 | if ($wrapperEl.length === 0 && swiper.params.createElements) {
|
4806 | const document = getDocument();
|
4807 | const wrapper = document.createElement('div');
|
4808 | $wrapperEl = $(wrapper);
|
4809 | wrapper.className = swiper.params.wrapperClass;
|
4810 | $el.append(wrapper);
|
4811 | $el.children(`.${swiper.params.slideClass}`).each(slideEl => {
|
4812 | $wrapperEl.append(slideEl);
|
4813 | });
|
4814 | }
|
4815 |
|
4816 | Object.assign(swiper, {
|
4817 | $el,
|
4818 | el,
|
4819 | $wrapperEl,
|
4820 | wrapperEl: $wrapperEl[0],
|
4821 | mounted: true,
|
4822 |
|
4823 | rtl: el.dir.toLowerCase() === 'rtl' || $el.css('direction') === 'rtl',
|
4824 | rtlTranslate: swiper.params.direction === 'horizontal' && (el.dir.toLowerCase() === 'rtl' || $el.css('direction') === 'rtl'),
|
4825 | wrongRTL: $wrapperEl.css('display') === '-webkit-box'
|
4826 | });
|
4827 | return true;
|
4828 | }
|
4829 |
|
4830 | init(el) {
|
4831 | const swiper = this;
|
4832 | if (swiper.initialized) return swiper;
|
4833 | const mounted = swiper.mount(el);
|
4834 | if (mounted === false) return swiper;
|
4835 | swiper.emit('beforeInit');
|
4836 |
|
4837 | if (swiper.params.breakpoints) {
|
4838 | swiper.setBreakpoint();
|
4839 | }
|
4840 |
|
4841 |
|
4842 | swiper.addClasses();
|
4843 |
|
4844 | if (swiper.params.loop) {
|
4845 | swiper.loopCreate();
|
4846 | }
|
4847 |
|
4848 |
|
4849 | swiper.updateSize();
|
4850 |
|
4851 | swiper.updateSlides();
|
4852 |
|
4853 | if (swiper.params.watchOverflow) {
|
4854 | swiper.checkOverflow();
|
4855 | }
|
4856 |
|
4857 |
|
4858 | if (swiper.params.grabCursor && swiper.enabled) {
|
4859 | swiper.setGrabCursor();
|
4860 | }
|
4861 |
|
4862 | if (swiper.params.preloadImages) {
|
4863 | swiper.preloadImages();
|
4864 | }
|
4865 |
|
4866 |
|
4867 | if (swiper.params.loop) {
|
4868 | swiper.slideTo(swiper.params.initialSlide + swiper.loopedSlides, 0, swiper.params.runCallbacksOnInit, false, true);
|
4869 | } else {
|
4870 | swiper.slideTo(swiper.params.initialSlide, 0, swiper.params.runCallbacksOnInit, false, true);
|
4871 | }
|
4872 |
|
4873 |
|
4874 | swiper.attachEvents();
|
4875 |
|
4876 | swiper.initialized = true;
|
4877 |
|
4878 | swiper.emit('init');
|
4879 | swiper.emit('afterInit');
|
4880 | return swiper;
|
4881 | }
|
4882 |
|
4883 | destroy(deleteInstance, cleanStyles) {
|
4884 | if (deleteInstance === void 0) {
|
4885 | deleteInstance = true;
|
4886 | }
|
4887 |
|
4888 | if (cleanStyles === void 0) {
|
4889 | cleanStyles = true;
|
4890 | }
|
4891 |
|
4892 | const swiper = this;
|
4893 | const {
|
4894 | params,
|
4895 | $el,
|
4896 | $wrapperEl,
|
4897 | slides
|
4898 | } = swiper;
|
4899 |
|
4900 | if (typeof swiper.params === 'undefined' || swiper.destroyed) {
|
4901 | return null;
|
4902 | }
|
4903 |
|
4904 | swiper.emit('beforeDestroy');
|
4905 |
|
4906 | swiper.initialized = false;
|
4907 |
|
4908 | swiper.detachEvents();
|
4909 |
|
4910 | if (params.loop) {
|
4911 | swiper.loopDestroy();
|
4912 | }
|
4913 |
|
4914 |
|
4915 | if (cleanStyles) {
|
4916 | swiper.removeClasses();
|
4917 | $el.removeAttr('style');
|
4918 | $wrapperEl.removeAttr('style');
|
4919 |
|
4920 | if (slides && slides.length) {
|
4921 | slides.removeClass([params.slideVisibleClass, params.slideActiveClass, params.slideNextClass, params.slidePrevClass].join(' ')).removeAttr('style').removeAttr('data-swiper-slide-index');
|
4922 | }
|
4923 | }
|
4924 |
|
4925 | swiper.emit('destroy');
|
4926 |
|
4927 | Object.keys(swiper.eventsListeners).forEach(eventName => {
|
4928 | swiper.off(eventName);
|
4929 | });
|
4930 |
|
4931 | if (deleteInstance !== false) {
|
4932 | swiper.$el[0].swiper = null;
|
4933 | deleteProps(swiper);
|
4934 | }
|
4935 |
|
4936 | swiper.destroyed = true;
|
4937 | return null;
|
4938 | }
|
4939 |
|
4940 | static extendDefaults(newDefaults) {
|
4941 | extend(extendedDefaults, newDefaults);
|
4942 | }
|
4943 |
|
4944 | static get extendedDefaults() {
|
4945 | return extendedDefaults;
|
4946 | }
|
4947 |
|
4948 | static get defaults() {
|
4949 | return defaults;
|
4950 | }
|
4951 |
|
4952 | static installModule(mod) {
|
4953 | if (!Swiper.prototype.__modules__) Swiper.prototype.__modules__ = [];
|
4954 | const modules = Swiper.prototype.__modules__;
|
4955 |
|
4956 | if (typeof mod === 'function' && modules.indexOf(mod) < 0) {
|
4957 | modules.push(mod);
|
4958 | }
|
4959 | }
|
4960 |
|
4961 | static use(module) {
|
4962 | if (Array.isArray(module)) {
|
4963 | module.forEach(m => Swiper.installModule(m));
|
4964 | return Swiper;
|
4965 | }
|
4966 |
|
4967 | Swiper.installModule(module);
|
4968 | return Swiper;
|
4969 | }
|
4970 |
|
4971 | }
|
4972 |
|
4973 | Object.keys(prototypes).forEach(prototypeGroup => {
|
4974 | Object.keys(prototypes[prototypeGroup]).forEach(protoMethod => {
|
4975 | Swiper.prototype[protoMethod] = prototypes[prototypeGroup][protoMethod];
|
4976 | });
|
4977 | });
|
4978 | Swiper.use([Resize, Observer]);
|
4979 |
|
4980 | function Virtual(_ref) {
|
4981 | let {
|
4982 | swiper,
|
4983 | extendParams,
|
4984 | on
|
4985 | } = _ref;
|
4986 | extendParams({
|
4987 | virtual: {
|
4988 | enabled: false,
|
4989 | slides: [],
|
4990 | cache: true,
|
4991 | renderSlide: null,
|
4992 | renderExternal: null,
|
4993 | renderExternalUpdate: true,
|
4994 | addSlidesBefore: 0,
|
4995 | addSlidesAfter: 0
|
4996 | }
|
4997 | });
|
4998 | let cssModeTimeout;
|
4999 | swiper.virtual = {
|
5000 | cache: {},
|
5001 | from: undefined,
|
5002 | to: undefined,
|
5003 | slides: [],
|
5004 | offset: 0,
|
5005 | slidesGrid: []
|
5006 | };
|
5007 |
|
5008 | function renderSlide(slide, index) {
|
5009 | const params = swiper.params.virtual;
|
5010 |
|
5011 | if (params.cache && swiper.virtual.cache[index]) {
|
5012 | return swiper.virtual.cache[index];
|
5013 | }
|
5014 |
|
5015 | const $slideEl = params.renderSlide ? $(params.renderSlide.call(swiper, slide, index)) : $(`<div class="${swiper.params.slideClass}" data-swiper-slide-index="${index}">${slide}</div>`);
|
5016 | if (!$slideEl.attr('data-swiper-slide-index')) $slideEl.attr('data-swiper-slide-index', index);
|
5017 | if (params.cache) swiper.virtual.cache[index] = $slideEl;
|
5018 | return $slideEl;
|
5019 | }
|
5020 |
|
5021 | function update(force) {
|
5022 | const {
|
5023 | slidesPerView,
|
5024 | slidesPerGroup,
|
5025 | centeredSlides
|
5026 | } = swiper.params;
|
5027 | const {
|
5028 | addSlidesBefore,
|
5029 | addSlidesAfter
|
5030 | } = swiper.params.virtual;
|
5031 | const {
|
5032 | from: previousFrom,
|
5033 | to: previousTo,
|
5034 | slides,
|
5035 | slidesGrid: previousSlidesGrid,
|
5036 | offset: previousOffset
|
5037 | } = swiper.virtual;
|
5038 |
|
5039 | if (!swiper.params.cssMode) {
|
5040 | swiper.updateActiveIndex();
|
5041 | }
|
5042 |
|
5043 | const activeIndex = swiper.activeIndex || 0;
|
5044 | let offsetProp;
|
5045 | if (swiper.rtlTranslate) offsetProp = 'right';else offsetProp = swiper.isHorizontal() ? 'left' : 'top';
|
5046 | let slidesAfter;
|
5047 | let slidesBefore;
|
5048 |
|
5049 | if (centeredSlides) {
|
5050 | slidesAfter = Math.floor(slidesPerView / 2) + slidesPerGroup + addSlidesAfter;
|
5051 | slidesBefore = Math.floor(slidesPerView / 2) + slidesPerGroup + addSlidesBefore;
|
5052 | } else {
|
5053 | slidesAfter = slidesPerView + (slidesPerGroup - 1) + addSlidesAfter;
|
5054 | slidesBefore = slidesPerGroup + addSlidesBefore;
|
5055 | }
|
5056 |
|
5057 | const from = Math.max((activeIndex || 0) - slidesBefore, 0);
|
5058 | const to = Math.min((activeIndex || 0) + slidesAfter, slides.length - 1);
|
5059 | const offset = (swiper.slidesGrid[from] || 0) - (swiper.slidesGrid[0] || 0);
|
5060 | Object.assign(swiper.virtual, {
|
5061 | from,
|
5062 | to,
|
5063 | offset,
|
5064 | slidesGrid: swiper.slidesGrid
|
5065 | });
|
5066 |
|
5067 | function onRendered() {
|
5068 | swiper.updateSlides();
|
5069 | swiper.updateProgress();
|
5070 | swiper.updateSlidesClasses();
|
5071 |
|
5072 | if (swiper.lazy && swiper.params.lazy.enabled) {
|
5073 | swiper.lazy.load();
|
5074 | }
|
5075 | }
|
5076 |
|
5077 | if (previousFrom === from && previousTo === to && !force) {
|
5078 | if (swiper.slidesGrid !== previousSlidesGrid && offset !== previousOffset) {
|
5079 | swiper.slides.css(offsetProp, `${offset}px`);
|
5080 | }
|
5081 |
|
5082 | swiper.updateProgress();
|
5083 | return;
|
5084 | }
|
5085 |
|
5086 | if (swiper.params.virtual.renderExternal) {
|
5087 | swiper.params.virtual.renderExternal.call(swiper, {
|
5088 | offset,
|
5089 | from,
|
5090 | to,
|
5091 | slides: function getSlides() {
|
5092 | const slidesToRender = [];
|
5093 |
|
5094 | for (let i = from; i <= to; i += 1) {
|
5095 | slidesToRender.push(slides[i]);
|
5096 | }
|
5097 |
|
5098 | return slidesToRender;
|
5099 | }()
|
5100 | });
|
5101 |
|
5102 | if (swiper.params.virtual.renderExternalUpdate) {
|
5103 | onRendered();
|
5104 | }
|
5105 |
|
5106 | return;
|
5107 | }
|
5108 |
|
5109 | const prependIndexes = [];
|
5110 | const appendIndexes = [];
|
5111 |
|
5112 | if (force) {
|
5113 | swiper.$wrapperEl.find(`.${swiper.params.slideClass}`).remove();
|
5114 | } else {
|
5115 | for (let i = previousFrom; i <= previousTo; i += 1) {
|
5116 | if (i < from || i > to) {
|
5117 | swiper.$wrapperEl.find(`.${swiper.params.slideClass}[data-swiper-slide-index="${i}"]`).remove();
|
5118 | }
|
5119 | }
|
5120 | }
|
5121 |
|
5122 | for (let i = 0; i < slides.length; i += 1) {
|
5123 | if (i >= from && i <= to) {
|
5124 | if (typeof previousTo === 'undefined' || force) {
|
5125 | appendIndexes.push(i);
|
5126 | } else {
|
5127 | if (i > previousTo) appendIndexes.push(i);
|
5128 | if (i < previousFrom) prependIndexes.push(i);
|
5129 | }
|
5130 | }
|
5131 | }
|
5132 |
|
5133 | appendIndexes.forEach(index => {
|
5134 | swiper.$wrapperEl.append(renderSlide(slides[index], index));
|
5135 | });
|
5136 | prependIndexes.sort((a, b) => b - a).forEach(index => {
|
5137 | swiper.$wrapperEl.prepend(renderSlide(slides[index], index));
|
5138 | });
|
5139 | swiper.$wrapperEl.children('.swiper-slide').css(offsetProp, `${offset}px`);
|
5140 | onRendered();
|
5141 | }
|
5142 |
|
5143 | function appendSlide(slides) {
|
5144 | if (typeof slides === 'object' && 'length' in slides) {
|
5145 | for (let i = 0; i < slides.length; i += 1) {
|
5146 | if (slides[i]) swiper.virtual.slides.push(slides[i]);
|
5147 | }
|
5148 | } else {
|
5149 | swiper.virtual.slides.push(slides);
|
5150 | }
|
5151 |
|
5152 | update(true);
|
5153 | }
|
5154 |
|
5155 | function prependSlide(slides) {
|
5156 | const activeIndex = swiper.activeIndex;
|
5157 | let newActiveIndex = activeIndex + 1;
|
5158 | let numberOfNewSlides = 1;
|
5159 |
|
5160 | if (Array.isArray(slides)) {
|
5161 | for (let i = 0; i < slides.length; i += 1) {
|
5162 | if (slides[i]) swiper.virtual.slides.unshift(slides[i]);
|
5163 | }
|
5164 |
|
5165 | newActiveIndex = activeIndex + slides.length;
|
5166 | numberOfNewSlides = slides.length;
|
5167 | } else {
|
5168 | swiper.virtual.slides.unshift(slides);
|
5169 | }
|
5170 |
|
5171 | if (swiper.params.virtual.cache) {
|
5172 | const cache = swiper.virtual.cache;
|
5173 | const newCache = {};
|
5174 | Object.keys(cache).forEach(cachedIndex => {
|
5175 | const $cachedEl = cache[cachedIndex];
|
5176 | const cachedElIndex = $cachedEl.attr('data-swiper-slide-index');
|
5177 |
|
5178 | if (cachedElIndex) {
|
5179 | $cachedEl.attr('data-swiper-slide-index', parseInt(cachedElIndex, 10) + numberOfNewSlides);
|
5180 | }
|
5181 |
|
5182 | newCache[parseInt(cachedIndex, 10) + numberOfNewSlides] = $cachedEl;
|
5183 | });
|
5184 | swiper.virtual.cache = newCache;
|
5185 | }
|
5186 |
|
5187 | update(true);
|
5188 | swiper.slideTo(newActiveIndex, 0);
|
5189 | }
|
5190 |
|
5191 | function removeSlide(slidesIndexes) {
|
5192 | if (typeof slidesIndexes === 'undefined' || slidesIndexes === null) return;
|
5193 | let activeIndex = swiper.activeIndex;
|
5194 |
|
5195 | if (Array.isArray(slidesIndexes)) {
|
5196 | for (let i = slidesIndexes.length - 1; i >= 0; i -= 1) {
|
5197 | swiper.virtual.slides.splice(slidesIndexes[i], 1);
|
5198 |
|
5199 | if (swiper.params.virtual.cache) {
|
5200 | delete swiper.virtual.cache[slidesIndexes[i]];
|
5201 | }
|
5202 |
|
5203 | if (slidesIndexes[i] < activeIndex) activeIndex -= 1;
|
5204 | activeIndex = Math.max(activeIndex, 0);
|
5205 | }
|
5206 | } else {
|
5207 | swiper.virtual.slides.splice(slidesIndexes, 1);
|
5208 |
|
5209 | if (swiper.params.virtual.cache) {
|
5210 | delete swiper.virtual.cache[slidesIndexes];
|
5211 | }
|
5212 |
|
5213 | if (slidesIndexes < activeIndex) activeIndex -= 1;
|
5214 | activeIndex = Math.max(activeIndex, 0);
|
5215 | }
|
5216 |
|
5217 | update(true);
|
5218 | swiper.slideTo(activeIndex, 0);
|
5219 | }
|
5220 |
|
5221 | function removeAllSlides() {
|
5222 | swiper.virtual.slides = [];
|
5223 |
|
5224 | if (swiper.params.virtual.cache) {
|
5225 | swiper.virtual.cache = {};
|
5226 | }
|
5227 |
|
5228 | update(true);
|
5229 | swiper.slideTo(0, 0);
|
5230 | }
|
5231 |
|
5232 | on('beforeInit', () => {
|
5233 | if (!swiper.params.virtual.enabled) return;
|
5234 | swiper.virtual.slides = swiper.params.virtual.slides;
|
5235 | swiper.classNames.push(`${swiper.params.containerModifierClass}virtual`);
|
5236 | swiper.params.watchSlidesProgress = true;
|
5237 | swiper.originalParams.watchSlidesProgress = true;
|
5238 |
|
5239 | if (!swiper.params.initialSlide) {
|
5240 | update();
|
5241 | }
|
5242 | });
|
5243 | on('setTranslate', () => {
|
5244 | if (!swiper.params.virtual.enabled) return;
|
5245 |
|
5246 | if (swiper.params.cssMode && !swiper._immediateVirtual) {
|
5247 | clearTimeout(cssModeTimeout);
|
5248 | cssModeTimeout = setTimeout(() => {
|
5249 | update();
|
5250 | }, 100);
|
5251 | } else {
|
5252 | update();
|
5253 | }
|
5254 | });
|
5255 | on('init update resize', () => {
|
5256 | if (!swiper.params.virtual.enabled) return;
|
5257 |
|
5258 | if (swiper.params.cssMode) {
|
5259 | setCSSProperty(swiper.wrapperEl, '--swiper-virtual-size', `${swiper.virtualSize}px`);
|
5260 | }
|
5261 | });
|
5262 | Object.assign(swiper.virtual, {
|
5263 | appendSlide,
|
5264 | prependSlide,
|
5265 | removeSlide,
|
5266 | removeAllSlides,
|
5267 | update
|
5268 | });
|
5269 | }
|
5270 |
|
5271 |
|
5272 | function Keyboard(_ref) {
|
5273 | let {
|
5274 | swiper,
|
5275 | extendParams,
|
5276 | on,
|
5277 | emit
|
5278 | } = _ref;
|
5279 | const document = getDocument();
|
5280 | const window = getWindow();
|
5281 | swiper.keyboard = {
|
5282 | enabled: false
|
5283 | };
|
5284 | extendParams({
|
5285 | keyboard: {
|
5286 | enabled: false,
|
5287 | onlyInViewport: true,
|
5288 | pageUpDown: true
|
5289 | }
|
5290 | });
|
5291 |
|
5292 | function handle(event) {
|
5293 | if (!swiper.enabled) return;
|
5294 | const {
|
5295 | rtlTranslate: rtl
|
5296 | } = swiper;
|
5297 | let e = event;
|
5298 | if (e.originalEvent) e = e.originalEvent;
|
5299 |
|
5300 | const kc = e.keyCode || e.charCode;
|
5301 | const pageUpDown = swiper.params.keyboard.pageUpDown;
|
5302 | const isPageUp = pageUpDown && kc === 33;
|
5303 | const isPageDown = pageUpDown && kc === 34;
|
5304 | const isArrowLeft = kc === 37;
|
5305 | const isArrowRight = kc === 39;
|
5306 | const isArrowUp = kc === 38;
|
5307 | const isArrowDown = kc === 40;
|
5308 |
|
5309 | if (!swiper.allowSlideNext && (swiper.isHorizontal() && isArrowRight || swiper.isVertical() && isArrowDown || isPageDown)) {
|
5310 | return false;
|
5311 | }
|
5312 |
|
5313 | if (!swiper.allowSlidePrev && (swiper.isHorizontal() && isArrowLeft || swiper.isVertical() && isArrowUp || isPageUp)) {
|
5314 | return false;
|
5315 | }
|
5316 |
|
5317 | if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) {
|
5318 | return undefined;
|
5319 | }
|
5320 |
|
5321 | if (document.activeElement && document.activeElement.nodeName && (document.activeElement.nodeName.toLowerCase() === 'input' || document.activeElement.nodeName.toLowerCase() === 'textarea')) {
|
5322 | return undefined;
|
5323 | }
|
5324 |
|
5325 | if (swiper.params.keyboard.onlyInViewport && (isPageUp || isPageDown || isArrowLeft || isArrowRight || isArrowUp || isArrowDown)) {
|
5326 | let inView = false;
|
5327 |
|
5328 | if (swiper.$el.parents(`.${swiper.params.slideClass}`).length > 0 && swiper.$el.parents(`.${swiper.params.slideActiveClass}`).length === 0) {
|
5329 | return undefined;
|
5330 | }
|
5331 |
|
5332 | const $el = swiper.$el;
|
5333 | const swiperWidth = $el[0].clientWidth;
|
5334 | const swiperHeight = $el[0].clientHeight;
|
5335 | const windowWidth = window.innerWidth;
|
5336 | const windowHeight = window.innerHeight;
|
5337 | const swiperOffset = swiper.$el.offset();
|
5338 | if (rtl) swiperOffset.left -= swiper.$el[0].scrollLeft;
|
5339 | const swiperCoord = [[swiperOffset.left, swiperOffset.top], [swiperOffset.left + swiperWidth, swiperOffset.top], [swiperOffset.left, swiperOffset.top + swiperHeight], [swiperOffset.left + swiperWidth, swiperOffset.top + swiperHeight]];
|
5340 |
|
5341 | for (let i = 0; i < swiperCoord.length; i += 1) {
|
5342 | const point = swiperCoord[i];
|
5343 |
|
5344 | if (point[0] >= 0 && point[0] <= windowWidth && point[1] >= 0 && point[1] <= windowHeight) {
|
5345 | if (point[0] === 0 && point[1] === 0) continue;
|
5346 |
|
5347 | inView = true;
|
5348 | }
|
5349 | }
|
5350 |
|
5351 | if (!inView) return undefined;
|
5352 | }
|
5353 |
|
5354 | if (swiper.isHorizontal()) {
|
5355 | if (isPageUp || isPageDown || isArrowLeft || isArrowRight) {
|
5356 | if (e.preventDefault) e.preventDefault();else e.returnValue = false;
|
5357 | }
|
5358 |
|
5359 | if ((isPageDown || isArrowRight) && !rtl || (isPageUp || isArrowLeft) && rtl) swiper.slideNext();
|
5360 | if ((isPageUp || isArrowLeft) && !rtl || (isPageDown || isArrowRight) && rtl) swiper.slidePrev();
|
5361 | } else {
|
5362 | if (isPageUp || isPageDown || isArrowUp || isArrowDown) {
|
5363 | if (e.preventDefault) e.preventDefault();else e.returnValue = false;
|
5364 | }
|
5365 |
|
5366 | if (isPageDown || isArrowDown) swiper.slideNext();
|
5367 | if (isPageUp || isArrowUp) swiper.slidePrev();
|
5368 | }
|
5369 |
|
5370 | emit('keyPress', kc);
|
5371 | return undefined;
|
5372 | }
|
5373 |
|
5374 | function enable() {
|
5375 | if (swiper.keyboard.enabled) return;
|
5376 | $(document).on('keydown', handle);
|
5377 | swiper.keyboard.enabled = true;
|
5378 | }
|
5379 |
|
5380 | function disable() {
|
5381 | if (!swiper.keyboard.enabled) return;
|
5382 | $(document).off('keydown', handle);
|
5383 | swiper.keyboard.enabled = false;
|
5384 | }
|
5385 |
|
5386 | on('init', () => {
|
5387 | if (swiper.params.keyboard.enabled) {
|
5388 | enable();
|
5389 | }
|
5390 | });
|
5391 | on('destroy', () => {
|
5392 | if (swiper.keyboard.enabled) {
|
5393 | disable();
|
5394 | }
|
5395 | });
|
5396 | Object.assign(swiper.keyboard, {
|
5397 | enable,
|
5398 | disable
|
5399 | });
|
5400 | }
|
5401 |
|
5402 |
|
5403 | function Mousewheel(_ref) {
|
5404 | let {
|
5405 | swiper,
|
5406 | extendParams,
|
5407 | on,
|
5408 | emit
|
5409 | } = _ref;
|
5410 | const window = getWindow();
|
5411 | extendParams({
|
5412 | mousewheel: {
|
5413 | enabled: false,
|
5414 | releaseOnEdges: false,
|
5415 | invert: false,
|
5416 | forceToAxis: false,
|
5417 | sensitivity: 1,
|
5418 | eventsTarget: 'container',
|
5419 | thresholdDelta: null,
|
5420 | thresholdTime: null
|
5421 | }
|
5422 | });
|
5423 | swiper.mousewheel = {
|
5424 | enabled: false
|
5425 | };
|
5426 | let timeout;
|
5427 | let lastScrollTime = now();
|
5428 | let lastEventBeforeSnap;
|
5429 | const recentWheelEvents = [];
|
5430 |
|
5431 | function normalize(e) {
|
5432 |
|
5433 | const PIXEL_STEP = 10;
|
5434 | const LINE_HEIGHT = 40;
|
5435 | const PAGE_HEIGHT = 800;
|
5436 | let sX = 0;
|
5437 | let sY = 0;
|
5438 |
|
5439 | let pX = 0;
|
5440 | let pY = 0;
|
5441 |
|
5442 |
|
5443 | if ('detail' in e) {
|
5444 | sY = e.detail;
|
5445 | }
|
5446 |
|
5447 | if ('wheelDelta' in e) {
|
5448 | sY = -e.wheelDelta / 120;
|
5449 | }
|
5450 |
|
5451 | if ('wheelDeltaY' in e) {
|
5452 | sY = -e.wheelDeltaY / 120;
|
5453 | }
|
5454 |
|
5455 | if ('wheelDeltaX' in e) {
|
5456 | sX = -e.wheelDeltaX / 120;
|
5457 | }
|
5458 |
|
5459 |
|
5460 | if ('axis' in e && e.axis === e.HORIZONTAL_AXIS) {
|
5461 | sX = sY;
|
5462 | sY = 0;
|
5463 | }
|
5464 |
|
5465 | pX = sX * PIXEL_STEP;
|
5466 | pY = sY * PIXEL_STEP;
|
5467 |
|
5468 | if ('deltaY' in e) {
|
5469 | pY = e.deltaY;
|
5470 | }
|
5471 |
|
5472 | if ('deltaX' in e) {
|
5473 | pX = e.deltaX;
|
5474 | }
|
5475 |
|
5476 | if (e.shiftKey && !pX) {
|
5477 |
|
5478 | pX = pY;
|
5479 | pY = 0;
|
5480 | }
|
5481 |
|
5482 | if ((pX || pY) && e.deltaMode) {
|
5483 | if (e.deltaMode === 1) {
|
5484 |
|
5485 | pX *= LINE_HEIGHT;
|
5486 | pY *= LINE_HEIGHT;
|
5487 | } else {
|
5488 |
|
5489 | pX *= PAGE_HEIGHT;
|
5490 | pY *= PAGE_HEIGHT;
|
5491 | }
|
5492 | }
|
5493 |
|
5494 |
|
5495 | if (pX && !sX) {
|
5496 | sX = pX < 1 ? -1 : 1;
|
5497 | }
|
5498 |
|
5499 | if (pY && !sY) {
|
5500 | sY = pY < 1 ? -1 : 1;
|
5501 | }
|
5502 |
|
5503 | return {
|
5504 | spinX: sX,
|
5505 | spinY: sY,
|
5506 | pixelX: pX,
|
5507 | pixelY: pY
|
5508 | };
|
5509 | }
|
5510 |
|
5511 | function handleMouseEnter() {
|
5512 | if (!swiper.enabled) return;
|
5513 | swiper.mouseEntered = true;
|
5514 | }
|
5515 |
|
5516 | function handleMouseLeave() {
|
5517 | if (!swiper.enabled) return;
|
5518 | swiper.mouseEntered = false;
|
5519 | }
|
5520 |
|
5521 | function animateSlider(newEvent) {
|
5522 | if (swiper.params.mousewheel.thresholdDelta && newEvent.delta < swiper.params.mousewheel.thresholdDelta) {
|
5523 |
|
5524 | return false;
|
5525 | }
|
5526 |
|
5527 | if (swiper.params.mousewheel.thresholdTime && now() - lastScrollTime < swiper.params.mousewheel.thresholdTime) {
|
5528 |
|
5529 | return false;
|
5530 | }
|
5531 |
|
5532 |
|
5533 |
|
5534 |
|
5535 | if (newEvent.delta >= 6 && now() - lastScrollTime < 60) {
|
5536 |
|
5537 | return true;
|
5538 | }
|
5539 |
|
5540 |
|
5541 |
|
5542 |
|
5543 |
|
5544 |
|
5545 |
|
5546 |
|
5547 |
|
5548 |
|
5549 |
|
5550 |
|
5551 |
|
5552 | if (newEvent.direction < 0) {
|
5553 | if ((!swiper.isEnd || swiper.params.loop) && !swiper.animating) {
|
5554 | swiper.slideNext();
|
5555 | emit('scroll', newEvent.raw);
|
5556 | }
|
5557 | } else if ((!swiper.isBeginning || swiper.params.loop) && !swiper.animating) {
|
5558 | swiper.slidePrev();
|
5559 | emit('scroll', newEvent.raw);
|
5560 | }
|
5561 |
|
5562 |
|
5563 | lastScrollTime = new window.Date().getTime();
|
5564 |
|
5565 | return false;
|
5566 | }
|
5567 |
|
5568 | function releaseScroll(newEvent) {
|
5569 | const params = swiper.params.mousewheel;
|
5570 |
|
5571 | if (newEvent.direction < 0) {
|
5572 | if (swiper.isEnd && !swiper.params.loop && params.releaseOnEdges) {
|
5573 |
|
5574 | return true;
|
5575 | }
|
5576 | } else if (swiper.isBeginning && !swiper.params.loop && params.releaseOnEdges) {
|
5577 |
|
5578 | return true;
|
5579 | }
|
5580 |
|
5581 | return false;
|
5582 | }
|
5583 |
|
5584 | function handle(event) {
|
5585 | let e = event;
|
5586 | let disableParentSwiper = true;
|
5587 | if (!swiper.enabled) return;
|
5588 | const params = swiper.params.mousewheel;
|
5589 |
|
5590 | if (swiper.params.cssMode) {
|
5591 | e.preventDefault();
|
5592 | }
|
5593 |
|
5594 | let target = swiper.$el;
|
5595 |
|
5596 | if (swiper.params.mousewheel.eventsTarget !== 'container') {
|
5597 | target = $(swiper.params.mousewheel.eventsTarget);
|
5598 | }
|
5599 |
|
5600 | if (!swiper.mouseEntered && !target[0].contains(e.target) && !params.releaseOnEdges) return true;
|
5601 | if (e.originalEvent) e = e.originalEvent;
|
5602 |
|
5603 | let delta = 0;
|
5604 | const rtlFactor = swiper.rtlTranslate ? -1 : 1;
|
5605 | const data = normalize(e);
|
5606 |
|
5607 | if (params.forceToAxis) {
|
5608 | if (swiper.isHorizontal()) {
|
5609 | if (Math.abs(data.pixelX) > Math.abs(data.pixelY)) delta = -data.pixelX * rtlFactor;else return true;
|
5610 | } else if (Math.abs(data.pixelY) > Math.abs(data.pixelX)) delta = -data.pixelY;else return true;
|
5611 | } else {
|
5612 | delta = Math.abs(data.pixelX) > Math.abs(data.pixelY) ? -data.pixelX * rtlFactor : -data.pixelY;
|
5613 | }
|
5614 |
|
5615 | if (delta === 0) return true;
|
5616 | if (params.invert) delta = -delta;
|
5617 |
|
5618 | let positions = swiper.getTranslate() + delta * params.sensitivity;
|
5619 | if (positions >= swiper.minTranslate()) positions = swiper.minTranslate();
|
5620 | if (positions <= swiper.maxTranslate()) positions = swiper.maxTranslate();
|
5621 |
|
5622 |
|
5623 |
|
5624 |
|
5625 |
|
5626 |
|
5627 |
|
5628 | disableParentSwiper = swiper.params.loop ? true : !(positions === swiper.minTranslate() || positions === swiper.maxTranslate());
|
5629 | if (disableParentSwiper && swiper.params.nested) e.stopPropagation();
|
5630 |
|
5631 | if (!swiper.params.freeMode || !swiper.params.freeMode.enabled) {
|
5632 |
|
5633 | const newEvent = {
|
5634 | time: now(),
|
5635 | delta: Math.abs(delta),
|
5636 | direction: Math.sign(delta),
|
5637 | raw: event
|
5638 | };
|
5639 |
|
5640 | if (recentWheelEvents.length >= 2) {
|
5641 | recentWheelEvents.shift();
|
5642 | }
|
5643 |
|
5644 | const prevEvent = recentWheelEvents.length ? recentWheelEvents[recentWheelEvents.length - 1] : undefined;
|
5645 | recentWheelEvents.push(newEvent);
|
5646 |
|
5647 |
|
5648 |
|
5649 |
|
5650 |
|
5651 |
|
5652 | if (prevEvent) {
|
5653 | if (newEvent.direction !== prevEvent.direction || newEvent.delta > prevEvent.delta || newEvent.time > prevEvent.time + 150) {
|
5654 | animateSlider(newEvent);
|
5655 | }
|
5656 | } else {
|
5657 | animateSlider(newEvent);
|
5658 | }
|
5659 |
|
5660 |
|
5661 |
|
5662 | if (releaseScroll(newEvent)) {
|
5663 | return true;
|
5664 | }
|
5665 | } else {
|
5666 |
|
5667 |
|
5668 |
|
5669 |
|
5670 |
|
5671 | const newEvent = {
|
5672 | time: now(),
|
5673 | delta: Math.abs(delta),
|
5674 | direction: Math.sign(delta)
|
5675 | };
|
5676 | const ignoreWheelEvents = lastEventBeforeSnap && newEvent.time < lastEventBeforeSnap.time + 500 && newEvent.delta <= lastEventBeforeSnap.delta && newEvent.direction === lastEventBeforeSnap.direction;
|
5677 |
|
5678 | if (!ignoreWheelEvents) {
|
5679 | lastEventBeforeSnap = undefined;
|
5680 |
|
5681 | if (swiper.params.loop) {
|
5682 | swiper.loopFix();
|
5683 | }
|
5684 |
|
5685 | let position = swiper.getTranslate() + delta * params.sensitivity;
|
5686 | const wasBeginning = swiper.isBeginning;
|
5687 | const wasEnd = swiper.isEnd;
|
5688 | if (position >= swiper.minTranslate()) position = swiper.minTranslate();
|
5689 | if (position <= swiper.maxTranslate()) position = swiper.maxTranslate();
|
5690 | swiper.setTransition(0);
|
5691 | swiper.setTranslate(position);
|
5692 | swiper.updateProgress();
|
5693 | swiper.updateActiveIndex();
|
5694 | swiper.updateSlidesClasses();
|
5695 |
|
5696 | if (!wasBeginning && swiper.isBeginning || !wasEnd && swiper.isEnd) {
|
5697 | swiper.updateSlidesClasses();
|
5698 | }
|
5699 |
|
5700 | if (swiper.params.freeMode.sticky) {
|
5701 |
|
5702 |
|
5703 |
|
5704 |
|
5705 |
|
5706 |
|
5707 |
|
5708 |
|
5709 |
|
5710 |
|
5711 |
|
5712 | clearTimeout(timeout);
|
5713 | timeout = undefined;
|
5714 |
|
5715 | if (recentWheelEvents.length >= 15) {
|
5716 | recentWheelEvents.shift();
|
5717 | }
|
5718 |
|
5719 | const prevEvent = recentWheelEvents.length ? recentWheelEvents[recentWheelEvents.length - 1] : undefined;
|
5720 | const firstEvent = recentWheelEvents[0];
|
5721 | recentWheelEvents.push(newEvent);
|
5722 |
|
5723 | if (prevEvent && (newEvent.delta > prevEvent.delta || newEvent.direction !== prevEvent.direction)) {
|
5724 |
|
5725 | recentWheelEvents.splice(0);
|
5726 | } else if (recentWheelEvents.length >= 15 && newEvent.time - firstEvent.time < 500 && firstEvent.delta - newEvent.delta >= 1 && newEvent.delta <= 6) {
|
5727 |
|
5728 |
|
5729 |
|
5730 |
|
5731 |
|
5732 |
|
5733 | const snapToThreshold = delta > 0 ? 0.8 : 0.2;
|
5734 | lastEventBeforeSnap = newEvent;
|
5735 | recentWheelEvents.splice(0);
|
5736 | timeout = nextTick(() => {
|
5737 | swiper.slideToClosest(swiper.params.speed, true, undefined, snapToThreshold);
|
5738 | }, 0);
|
5739 | }
|
5740 |
|
5741 | if (!timeout) {
|
5742 |
|
5743 |
|
5744 |
|
5745 | timeout = nextTick(() => {
|
5746 | const snapToThreshold = 0.5;
|
5747 | lastEventBeforeSnap = newEvent;
|
5748 | recentWheelEvents.splice(0);
|
5749 | swiper.slideToClosest(swiper.params.speed, true, undefined, snapToThreshold);
|
5750 | }, 500);
|
5751 | }
|
5752 | }
|
5753 |
|
5754 |
|
5755 | if (!ignoreWheelEvents) emit('scroll', e);
|
5756 |
|
5757 | if (swiper.params.autoplay && swiper.params.autoplayDisableOnInteraction) swiper.autoplay.stop();
|
5758 |
|
5759 | if (position === swiper.minTranslate() || position === swiper.maxTranslate()) return true;
|
5760 | }
|
5761 | }
|
5762 |
|
5763 | if (e.preventDefault) e.preventDefault();else e.returnValue = false;
|
5764 | return false;
|
5765 | }
|
5766 |
|
5767 | function events(method) {
|
5768 | let target = swiper.$el;
|
5769 |
|
5770 | if (swiper.params.mousewheel.eventsTarget !== 'container') {
|
5771 | target = $(swiper.params.mousewheel.eventsTarget);
|
5772 | }
|
5773 |
|
5774 | target[method]('mouseenter', handleMouseEnter);
|
5775 | target[method]('mouseleave', handleMouseLeave);
|
5776 | target[method]('wheel', handle);
|
5777 | }
|
5778 |
|
5779 | function enable() {
|
5780 | if (swiper.params.cssMode) {
|
5781 | swiper.wrapperEl.removeEventListener('wheel', handle);
|
5782 | return true;
|
5783 | }
|
5784 |
|
5785 | if (swiper.mousewheel.enabled) return false;
|
5786 | events('on');
|
5787 | swiper.mousewheel.enabled = true;
|
5788 | return true;
|
5789 | }
|
5790 |
|
5791 | function disable() {
|
5792 | if (swiper.params.cssMode) {
|
5793 | swiper.wrapperEl.addEventListener(event, handle);
|
5794 | return true;
|
5795 | }
|
5796 |
|
5797 | if (!swiper.mousewheel.enabled) return false;
|
5798 | events('off');
|
5799 | swiper.mousewheel.enabled = false;
|
5800 | return true;
|
5801 | }
|
5802 |
|
5803 | on('init', () => {
|
5804 | if (!swiper.params.mousewheel.enabled && swiper.params.cssMode) {
|
5805 | disable();
|
5806 | }
|
5807 |
|
5808 | if (swiper.params.mousewheel.enabled) enable();
|
5809 | });
|
5810 | on('destroy', () => {
|
5811 | if (swiper.params.cssMode) {
|
5812 | enable();
|
5813 | }
|
5814 |
|
5815 | if (swiper.mousewheel.enabled) disable();
|
5816 | });
|
5817 | Object.assign(swiper.mousewheel, {
|
5818 | enable,
|
5819 | disable
|
5820 | });
|
5821 | }
|
5822 |
|
5823 | function createElementIfNotDefined(swiper, originalParams, params, checkProps) {
|
5824 | const document = getDocument();
|
5825 |
|
5826 | if (swiper.params.createElements) {
|
5827 | Object.keys(checkProps).forEach(key => {
|
5828 | if (!params[key] && params.auto === true) {
|
5829 | let element = swiper.$el.children(`.${checkProps[key]}`)[0];
|
5830 |
|
5831 | if (!element) {
|
5832 | element = document.createElement('div');
|
5833 | element.className = checkProps[key];
|
5834 | swiper.$el.append(element);
|
5835 | }
|
5836 |
|
5837 | params[key] = element;
|
5838 | originalParams[key] = element;
|
5839 | }
|
5840 | });
|
5841 | }
|
5842 |
|
5843 | return params;
|
5844 | }
|
5845 |
|
5846 | function Navigation(_ref) {
|
5847 | let {
|
5848 | swiper,
|
5849 | extendParams,
|
5850 | on,
|
5851 | emit
|
5852 | } = _ref;
|
5853 | extendParams({
|
5854 | navigation: {
|
5855 | nextEl: null,
|
5856 | prevEl: null,
|
5857 | hideOnClick: false,
|
5858 | disabledClass: 'swiper-button-disabled',
|
5859 | hiddenClass: 'swiper-button-hidden',
|
5860 | lockClass: 'swiper-button-lock'
|
5861 | }
|
5862 | });
|
5863 | swiper.navigation = {
|
5864 | nextEl: null,
|
5865 | $nextEl: null,
|
5866 | prevEl: null,
|
5867 | $prevEl: null
|
5868 | };
|
5869 |
|
5870 | function getEl(el) {
|
5871 | let $el;
|
5872 |
|
5873 | if (el) {
|
5874 | $el = $(el);
|
5875 |
|
5876 | if (swiper.params.uniqueNavElements && typeof el === 'string' && $el.length > 1 && swiper.$el.find(el).length === 1) {
|
5877 | $el = swiper.$el.find(el);
|
5878 | }
|
5879 | }
|
5880 |
|
5881 | return $el;
|
5882 | }
|
5883 |
|
5884 | function toggleEl($el, disabled) {
|
5885 | const params = swiper.params.navigation;
|
5886 |
|
5887 | if ($el && $el.length > 0) {
|
5888 | $el[disabled ? 'addClass' : 'removeClass'](params.disabledClass);
|
5889 | if ($el[0] && $el[0].tagName === 'BUTTON') $el[0].disabled = disabled;
|
5890 |
|
5891 | if (swiper.params.watchOverflow && swiper.enabled) {
|
5892 | $el[swiper.isLocked ? 'addClass' : 'removeClass'](params.lockClass);
|
5893 | }
|
5894 | }
|
5895 | }
|
5896 |
|
5897 | function update() {
|
5898 |
|
5899 | if (swiper.params.loop) return;
|
5900 | const {
|
5901 | $nextEl,
|
5902 | $prevEl
|
5903 | } = swiper.navigation;
|
5904 | toggleEl($prevEl, swiper.isBeginning && !swiper.params.rewind);
|
5905 | toggleEl($nextEl, swiper.isEnd && !swiper.params.rewind);
|
5906 | }
|
5907 |
|
5908 | function onPrevClick(e) {
|
5909 | e.preventDefault();
|
5910 | if (swiper.isBeginning && !swiper.params.loop && !swiper.params.rewind) return;
|
5911 | swiper.slidePrev();
|
5912 | }
|
5913 |
|
5914 | function onNextClick(e) {
|
5915 | e.preventDefault();
|
5916 | if (swiper.isEnd && !swiper.params.loop && !swiper.params.rewind) return;
|
5917 | swiper.slideNext();
|
5918 | }
|
5919 |
|
5920 | function init() {
|
5921 | const params = swiper.params.navigation;
|
5922 | swiper.params.navigation = createElementIfNotDefined(swiper, swiper.originalParams.navigation, swiper.params.navigation, {
|
5923 | nextEl: 'swiper-button-next',
|
5924 | prevEl: 'swiper-button-prev'
|
5925 | });
|
5926 | if (!(params.nextEl || params.prevEl)) return;
|
5927 | const $nextEl = getEl(params.nextEl);
|
5928 | const $prevEl = getEl(params.prevEl);
|
5929 |
|
5930 | if ($nextEl && $nextEl.length > 0) {
|
5931 | $nextEl.on('click', onNextClick);
|
5932 | }
|
5933 |
|
5934 | if ($prevEl && $prevEl.length > 0) {
|
5935 | $prevEl.on('click', onPrevClick);
|
5936 | }
|
5937 |
|
5938 | Object.assign(swiper.navigation, {
|
5939 | $nextEl,
|
5940 | nextEl: $nextEl && $nextEl[0],
|
5941 | $prevEl,
|
5942 | prevEl: $prevEl && $prevEl[0]
|
5943 | });
|
5944 |
|
5945 | if (!swiper.enabled) {
|
5946 | if ($nextEl) $nextEl.addClass(params.lockClass);
|
5947 | if ($prevEl) $prevEl.addClass(params.lockClass);
|
5948 | }
|
5949 | }
|
5950 |
|
5951 | function destroy() {
|
5952 | const {
|
5953 | $nextEl,
|
5954 | $prevEl
|
5955 | } = swiper.navigation;
|
5956 |
|
5957 | if ($nextEl && $nextEl.length) {
|
5958 | $nextEl.off('click', onNextClick);
|
5959 | $nextEl.removeClass(swiper.params.navigation.disabledClass);
|
5960 | }
|
5961 |
|
5962 | if ($prevEl && $prevEl.length) {
|
5963 | $prevEl.off('click', onPrevClick);
|
5964 | $prevEl.removeClass(swiper.params.navigation.disabledClass);
|
5965 | }
|
5966 | }
|
5967 |
|
5968 | on('init', () => {
|
5969 | init();
|
5970 | update();
|
5971 | });
|
5972 | on('toEdge fromEdge lock unlock', () => {
|
5973 | update();
|
5974 | });
|
5975 | on('destroy', () => {
|
5976 | destroy();
|
5977 | });
|
5978 | on('enable disable', () => {
|
5979 | const {
|
5980 | $nextEl,
|
5981 | $prevEl
|
5982 | } = swiper.navigation;
|
5983 |
|
5984 | if ($nextEl) {
|
5985 | $nextEl[swiper.enabled ? 'removeClass' : 'addClass'](swiper.params.navigation.lockClass);
|
5986 | }
|
5987 |
|
5988 | if ($prevEl) {
|
5989 | $prevEl[swiper.enabled ? 'removeClass' : 'addClass'](swiper.params.navigation.lockClass);
|
5990 | }
|
5991 | });
|
5992 | on('click', (_s, e) => {
|
5993 | const {
|
5994 | $nextEl,
|
5995 | $prevEl
|
5996 | } = swiper.navigation;
|
5997 | const targetEl = e.target;
|
5998 |
|
5999 | if (swiper.params.navigation.hideOnClick && !$(targetEl).is($prevEl) && !$(targetEl).is($nextEl)) {
|
6000 | if (swiper.pagination && swiper.params.pagination && swiper.params.pagination.clickable && (swiper.pagination.el === targetEl || swiper.pagination.el.contains(targetEl))) return;
|
6001 | let isHidden;
|
6002 |
|
6003 | if ($nextEl) {
|
6004 | isHidden = $nextEl.hasClass(swiper.params.navigation.hiddenClass);
|
6005 | } else if ($prevEl) {
|
6006 | isHidden = $prevEl.hasClass(swiper.params.navigation.hiddenClass);
|
6007 | }
|
6008 |
|
6009 | if (isHidden === true) {
|
6010 | emit('navigationShow');
|
6011 | } else {
|
6012 | emit('navigationHide');
|
6013 | }
|
6014 |
|
6015 | if ($nextEl) {
|
6016 | $nextEl.toggleClass(swiper.params.navigation.hiddenClass);
|
6017 | }
|
6018 |
|
6019 | if ($prevEl) {
|
6020 | $prevEl.toggleClass(swiper.params.navigation.hiddenClass);
|
6021 | }
|
6022 | }
|
6023 | });
|
6024 | Object.assign(swiper.navigation, {
|
6025 | update,
|
6026 | init,
|
6027 | destroy
|
6028 | });
|
6029 | }
|
6030 |
|
6031 | function classesToSelector(classes) {
|
6032 | if (classes === void 0) {
|
6033 | classes = '';
|
6034 | }
|
6035 |
|
6036 | return `.${classes.trim().replace(/([\.:!\/])/g, '\\$1') // eslint-disable-line
|
6037 | .replace(/ /g, '.')}`;
|
6038 | }
|
6039 |
|
6040 | function Pagination(_ref) {
|
6041 | let {
|
6042 | swiper,
|
6043 | extendParams,
|
6044 | on,
|
6045 | emit
|
6046 | } = _ref;
|
6047 | const pfx = 'swiper-pagination';
|
6048 | extendParams({
|
6049 | pagination: {
|
6050 | el: null,
|
6051 | bulletElement: 'span',
|
6052 | clickable: false,
|
6053 | hideOnClick: false,
|
6054 | renderBullet: null,
|
6055 | renderProgressbar: null,
|
6056 | renderFraction: null,
|
6057 | renderCustom: null,
|
6058 | progressbarOpposite: false,
|
6059 | type: 'bullets',
|
6060 |
|
6061 | dynamicBullets: false,
|
6062 | dynamicMainBullets: 1,
|
6063 | formatFractionCurrent: number => number,
|
6064 | formatFractionTotal: number => number,
|
6065 | bulletClass: `${pfx}-bullet`,
|
6066 | bulletActiveClass: `${pfx}-bullet-active`,
|
6067 | modifierClass: `${pfx}-`,
|
6068 | currentClass: `${pfx}-current`,
|
6069 | totalClass: `${pfx}-total`,
|
6070 | hiddenClass: `${pfx}-hidden`,
|
6071 | progressbarFillClass: `${pfx}-progressbar-fill`,
|
6072 | progressbarOppositeClass: `${pfx}-progressbar-opposite`,
|
6073 | clickableClass: `${pfx}-clickable`,
|
6074 | lockClass: `${pfx}-lock`,
|
6075 | horizontalClass: `${pfx}-horizontal`,
|
6076 | verticalClass: `${pfx}-vertical`
|
6077 | }
|
6078 | });
|
6079 | swiper.pagination = {
|
6080 | el: null,
|
6081 | $el: null,
|
6082 | bullets: []
|
6083 | };
|
6084 | let bulletSize;
|
6085 | let dynamicBulletIndex = 0;
|
6086 |
|
6087 | function isPaginationDisabled() {
|
6088 | return !swiper.params.pagination.el || !swiper.pagination.el || !swiper.pagination.$el || swiper.pagination.$el.length === 0;
|
6089 | }
|
6090 |
|
6091 | function setSideBullets($bulletEl, position) {
|
6092 | const {
|
6093 | bulletActiveClass
|
6094 | } = swiper.params.pagination;
|
6095 | $bulletEl[position]().addClass(`${bulletActiveClass}-${position}`)[position]().addClass(`${bulletActiveClass}-${position}-${position}`);
|
6096 | }
|
6097 |
|
6098 | function update() {
|
6099 |
|
6100 | const rtl = swiper.rtl;
|
6101 | const params = swiper.params.pagination;
|
6102 | if (isPaginationDisabled()) return;
|
6103 | const slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : swiper.slides.length;
|
6104 | const $el = swiper.pagination.$el;
|
6105 |
|
6106 | let current;
|
6107 | const total = swiper.params.loop ? Math.ceil((slidesLength - swiper.loopedSlides * 2) / swiper.params.slidesPerGroup) : swiper.snapGrid.length;
|
6108 |
|
6109 | if (swiper.params.loop) {
|
6110 | current = Math.ceil((swiper.activeIndex - swiper.loopedSlides) / swiper.params.slidesPerGroup);
|
6111 |
|
6112 | if (current > slidesLength - 1 - swiper.loopedSlides * 2) {
|
6113 | current -= slidesLength - swiper.loopedSlides * 2;
|
6114 | }
|
6115 |
|
6116 | if (current > total - 1) current -= total;
|
6117 | if (current < 0 && swiper.params.paginationType !== 'bullets') current = total + current;
|
6118 | } else if (typeof swiper.snapIndex !== 'undefined') {
|
6119 | current = swiper.snapIndex;
|
6120 | } else {
|
6121 | current = swiper.activeIndex || 0;
|
6122 | }
|
6123 |
|
6124 |
|
6125 | if (params.type === 'bullets' && swiper.pagination.bullets && swiper.pagination.bullets.length > 0) {
|
6126 | const bullets = swiper.pagination.bullets;
|
6127 | let firstIndex;
|
6128 | let lastIndex;
|
6129 | let midIndex;
|
6130 |
|
6131 | if (params.dynamicBullets) {
|
6132 | bulletSize = bullets.eq(0)[swiper.isHorizontal() ? 'outerWidth' : 'outerHeight'](true);
|
6133 | $el.css(swiper.isHorizontal() ? 'width' : 'height', `${bulletSize * (params.dynamicMainBullets + 4)}px`);
|
6134 |
|
6135 | if (params.dynamicMainBullets > 1 && swiper.previousIndex !== undefined) {
|
6136 | dynamicBulletIndex += current - (swiper.previousIndex - swiper.loopedSlides || 0);
|
6137 |
|
6138 | if (dynamicBulletIndex > params.dynamicMainBullets - 1) {
|
6139 | dynamicBulletIndex = params.dynamicMainBullets - 1;
|
6140 | } else if (dynamicBulletIndex < 0) {
|
6141 | dynamicBulletIndex = 0;
|
6142 | }
|
6143 | }
|
6144 |
|
6145 | firstIndex = Math.max(current - dynamicBulletIndex, 0);
|
6146 | lastIndex = firstIndex + (Math.min(bullets.length, params.dynamicMainBullets) - 1);
|
6147 | midIndex = (lastIndex + firstIndex) / 2;
|
6148 | }
|
6149 |
|
6150 | bullets.removeClass(['', '-next', '-next-next', '-prev', '-prev-prev', '-main'].map(suffix => `${params.bulletActiveClass}${suffix}`).join(' '));
|
6151 |
|
6152 | if ($el.length > 1) {
|
6153 | bullets.each(bullet => {
|
6154 | const $bullet = $(bullet);
|
6155 | const bulletIndex = $bullet.index();
|
6156 |
|
6157 | if (bulletIndex === current) {
|
6158 | $bullet.addClass(params.bulletActiveClass);
|
6159 | }
|
6160 |
|
6161 | if (params.dynamicBullets) {
|
6162 | if (bulletIndex >= firstIndex && bulletIndex <= lastIndex) {
|
6163 | $bullet.addClass(`${params.bulletActiveClass}-main`);
|
6164 | }
|
6165 |
|
6166 | if (bulletIndex === firstIndex) {
|
6167 | setSideBullets($bullet, 'prev');
|
6168 | }
|
6169 |
|
6170 | if (bulletIndex === lastIndex) {
|
6171 | setSideBullets($bullet, 'next');
|
6172 | }
|
6173 | }
|
6174 | });
|
6175 | } else {
|
6176 | const $bullet = bullets.eq(current);
|
6177 | const bulletIndex = $bullet.index();
|
6178 | $bullet.addClass(params.bulletActiveClass);
|
6179 |
|
6180 | if (params.dynamicBullets) {
|
6181 | const $firstDisplayedBullet = bullets.eq(firstIndex);
|
6182 | const $lastDisplayedBullet = bullets.eq(lastIndex);
|
6183 |
|
6184 | for (let i = firstIndex; i <= lastIndex; i += 1) {
|
6185 | bullets.eq(i).addClass(`${params.bulletActiveClass}-main`);
|
6186 | }
|
6187 |
|
6188 | if (swiper.params.loop) {
|
6189 | if (bulletIndex >= bullets.length) {
|
6190 | for (let i = params.dynamicMainBullets; i >= 0; i -= 1) {
|
6191 | bullets.eq(bullets.length - i).addClass(`${params.bulletActiveClass}-main`);
|
6192 | }
|
6193 |
|
6194 | bullets.eq(bullets.length - params.dynamicMainBullets - 1).addClass(`${params.bulletActiveClass}-prev`);
|
6195 | } else {
|
6196 | setSideBullets($firstDisplayedBullet, 'prev');
|
6197 | setSideBullets($lastDisplayedBullet, 'next');
|
6198 | }
|
6199 | } else {
|
6200 | setSideBullets($firstDisplayedBullet, 'prev');
|
6201 | setSideBullets($lastDisplayedBullet, 'next');
|
6202 | }
|
6203 | }
|
6204 | }
|
6205 |
|
6206 | if (params.dynamicBullets) {
|
6207 | const dynamicBulletsLength = Math.min(bullets.length, params.dynamicMainBullets + 4);
|
6208 | const bulletsOffset = (bulletSize * dynamicBulletsLength - bulletSize) / 2 - midIndex * bulletSize;
|
6209 | const offsetProp = rtl ? 'right' : 'left';
|
6210 | bullets.css(swiper.isHorizontal() ? offsetProp : 'top', `${bulletsOffset}px`);
|
6211 | }
|
6212 | }
|
6213 |
|
6214 | if (params.type === 'fraction') {
|
6215 | $el.find(classesToSelector(params.currentClass)).text(params.formatFractionCurrent(current + 1));
|
6216 | $el.find(classesToSelector(params.totalClass)).text(params.formatFractionTotal(total));
|
6217 | }
|
6218 |
|
6219 | if (params.type === 'progressbar') {
|
6220 | let progressbarDirection;
|
6221 |
|
6222 | if (params.progressbarOpposite) {
|
6223 | progressbarDirection = swiper.isHorizontal() ? 'vertical' : 'horizontal';
|
6224 | } else {
|
6225 | progressbarDirection = swiper.isHorizontal() ? 'horizontal' : 'vertical';
|
6226 | }
|
6227 |
|
6228 | const scale = (current + 1) / total;
|
6229 | let scaleX = 1;
|
6230 | let scaleY = 1;
|
6231 |
|
6232 | if (progressbarDirection === 'horizontal') {
|
6233 | scaleX = scale;
|
6234 | } else {
|
6235 | scaleY = scale;
|
6236 | }
|
6237 |
|
6238 | $el.find(classesToSelector(params.progressbarFillClass)).transform(`translate3d(0,0,0) scaleX(${scaleX}) scaleY(${scaleY})`).transition(swiper.params.speed);
|
6239 | }
|
6240 |
|
6241 | if (params.type === 'custom' && params.renderCustom) {
|
6242 | $el.html(params.renderCustom(swiper, current + 1, total));
|
6243 | emit('paginationRender', $el[0]);
|
6244 | } else {
|
6245 | emit('paginationUpdate', $el[0]);
|
6246 | }
|
6247 |
|
6248 | if (swiper.params.watchOverflow && swiper.enabled) {
|
6249 | $el[swiper.isLocked ? 'addClass' : 'removeClass'](params.lockClass);
|
6250 | }
|
6251 | }
|
6252 |
|
6253 | function render() {
|
6254 |
|
6255 | const params = swiper.params.pagination;
|
6256 | if (isPaginationDisabled()) return;
|
6257 | const slidesLength = swiper.virtual && swiper.params.virtual.enabled ? swiper.virtual.slides.length : swiper.slides.length;
|
6258 | const $el = swiper.pagination.$el;
|
6259 | let paginationHTML = '';
|
6260 |
|
6261 | if (params.type === 'bullets') {
|
6262 | let numberOfBullets = swiper.params.loop ? Math.ceil((slidesLength - swiper.loopedSlides * 2) / swiper.params.slidesPerGroup) : swiper.snapGrid.length;
|
6263 |
|
6264 | if (swiper.params.freeMode && swiper.params.freeMode.enabled && !swiper.params.loop && numberOfBullets > slidesLength) {
|
6265 | numberOfBullets = slidesLength;
|
6266 | }
|
6267 |
|
6268 | for (let i = 0; i < numberOfBullets; i += 1) {
|
6269 | if (params.renderBullet) {
|
6270 | paginationHTML += params.renderBullet.call(swiper, i, params.bulletClass);
|
6271 | } else {
|
6272 | paginationHTML += `<${params.bulletElement} class="${params.bulletClass}"></${params.bulletElement}>`;
|
6273 | }
|
6274 | }
|
6275 |
|
6276 | $el.html(paginationHTML);
|
6277 | swiper.pagination.bullets = $el.find(classesToSelector(params.bulletClass));
|
6278 | }
|
6279 |
|
6280 | if (params.type === 'fraction') {
|
6281 | if (params.renderFraction) {
|
6282 | paginationHTML = params.renderFraction.call(swiper, params.currentClass, params.totalClass);
|
6283 | } else {
|
6284 | paginationHTML = `<span class="${params.currentClass}"></span>` + ' / ' + `<span class="${params.totalClass}"></span>`;
|
6285 | }
|
6286 |
|
6287 | $el.html(paginationHTML);
|
6288 | }
|
6289 |
|
6290 | if (params.type === 'progressbar') {
|
6291 | if (params.renderProgressbar) {
|
6292 | paginationHTML = params.renderProgressbar.call(swiper, params.progressbarFillClass);
|
6293 | } else {
|
6294 | paginationHTML = `<span class="${params.progressbarFillClass}"></span>`;
|
6295 | }
|
6296 |
|
6297 | $el.html(paginationHTML);
|
6298 | }
|
6299 |
|
6300 | if (params.type !== 'custom') {
|
6301 | emit('paginationRender', swiper.pagination.$el[0]);
|
6302 | }
|
6303 | }
|
6304 |
|
6305 | function init() {
|
6306 | swiper.params.pagination = createElementIfNotDefined(swiper, swiper.originalParams.pagination, swiper.params.pagination, {
|
6307 | el: 'swiper-pagination'
|
6308 | });
|
6309 | const params = swiper.params.pagination;
|
6310 | if (!params.el) return;
|
6311 | let $el = $(params.el);
|
6312 | if ($el.length === 0) return;
|
6313 |
|
6314 | if (swiper.params.uniqueNavElements && typeof params.el === 'string' && $el.length > 1) {
|
6315 | $el = swiper.$el.find(params.el);
|
6316 |
|
6317 | if ($el.length > 1) {
|
6318 | $el = $el.filter(el => {
|
6319 | if ($(el).parents('.swiper')[0] !== swiper.el) return false;
|
6320 | return true;
|
6321 | });
|
6322 | }
|
6323 | }
|
6324 |
|
6325 | if (params.type === 'bullets' && params.clickable) {
|
6326 | $el.addClass(params.clickableClass);
|
6327 | }
|
6328 |
|
6329 | $el.addClass(params.modifierClass + params.type);
|
6330 | $el.addClass(params.modifierClass + swiper.params.direction);
|
6331 |
|
6332 | if (params.type === 'bullets' && params.dynamicBullets) {
|
6333 | $el.addClass(`${params.modifierClass}${params.type}-dynamic`);
|
6334 | dynamicBulletIndex = 0;
|
6335 |
|
6336 | if (params.dynamicMainBullets < 1) {
|
6337 | params.dynamicMainBullets = 1;
|
6338 | }
|
6339 | }
|
6340 |
|
6341 | if (params.type === 'progressbar' && params.progressbarOpposite) {
|
6342 | $el.addClass(params.progressbarOppositeClass);
|
6343 | }
|
6344 |
|
6345 | if (params.clickable) {
|
6346 | $el.on('click', classesToSelector(params.bulletClass), function onClick(e) {
|
6347 | e.preventDefault();
|
6348 | let index = $(this).index() * swiper.params.slidesPerGroup;
|
6349 | if (swiper.params.loop) index += swiper.loopedSlides;
|
6350 | swiper.slideTo(index);
|
6351 | });
|
6352 | }
|
6353 |
|
6354 | Object.assign(swiper.pagination, {
|
6355 | $el,
|
6356 | el: $el[0]
|
6357 | });
|
6358 |
|
6359 | if (!swiper.enabled) {
|
6360 | $el.addClass(params.lockClass);
|
6361 | }
|
6362 | }
|
6363 |
|
6364 | function destroy() {
|
6365 | const params = swiper.params.pagination;
|
6366 | if (isPaginationDisabled()) return;
|
6367 | const $el = swiper.pagination.$el;
|
6368 | $el.removeClass(params.hiddenClass);
|
6369 | $el.removeClass(params.modifierClass + params.type);
|
6370 | $el.removeClass(params.modifierClass + swiper.params.direction);
|
6371 | if (swiper.pagination.bullets && swiper.pagination.bullets.removeClass) swiper.pagination.bullets.removeClass(params.bulletActiveClass);
|
6372 |
|
6373 | if (params.clickable) {
|
6374 | $el.off('click', classesToSelector(params.bulletClass));
|
6375 | }
|
6376 | }
|
6377 |
|
6378 | on('init', () => {
|
6379 | init();
|
6380 | render();
|
6381 | update();
|
6382 | });
|
6383 | on('activeIndexChange', () => {
|
6384 | if (swiper.params.loop) {
|
6385 | update();
|
6386 | } else if (typeof swiper.snapIndex === 'undefined') {
|
6387 | update();
|
6388 | }
|
6389 | });
|
6390 | on('snapIndexChange', () => {
|
6391 | if (!swiper.params.loop) {
|
6392 | update();
|
6393 | }
|
6394 | });
|
6395 | on('slidesLengthChange', () => {
|
6396 | if (swiper.params.loop) {
|
6397 | render();
|
6398 | update();
|
6399 | }
|
6400 | });
|
6401 | on('snapGridLengthChange', () => {
|
6402 | if (!swiper.params.loop) {
|
6403 | render();
|
6404 | update();
|
6405 | }
|
6406 | });
|
6407 | on('destroy', () => {
|
6408 | destroy();
|
6409 | });
|
6410 | on('enable disable', () => {
|
6411 | const {
|
6412 | $el
|
6413 | } = swiper.pagination;
|
6414 |
|
6415 | if ($el) {
|
6416 | $el[swiper.enabled ? 'removeClass' : 'addClass'](swiper.params.pagination.lockClass);
|
6417 | }
|
6418 | });
|
6419 | on('lock unlock', () => {
|
6420 | update();
|
6421 | });
|
6422 | on('click', (_s, e) => {
|
6423 | const targetEl = e.target;
|
6424 | const {
|
6425 | $el
|
6426 | } = swiper.pagination;
|
6427 |
|
6428 | if (swiper.params.pagination.el && swiper.params.pagination.hideOnClick && $el.length > 0 && !$(targetEl).hasClass(swiper.params.pagination.bulletClass)) {
|
6429 | if (swiper.navigation && (swiper.navigation.nextEl && targetEl === swiper.navigation.nextEl || swiper.navigation.prevEl && targetEl === swiper.navigation.prevEl)) return;
|
6430 | const isHidden = $el.hasClass(swiper.params.pagination.hiddenClass);
|
6431 |
|
6432 | if (isHidden === true) {
|
6433 | emit('paginationShow');
|
6434 | } else {
|
6435 | emit('paginationHide');
|
6436 | }
|
6437 |
|
6438 | $el.toggleClass(swiper.params.pagination.hiddenClass);
|
6439 | }
|
6440 | });
|
6441 | Object.assign(swiper.pagination, {
|
6442 | render,
|
6443 | update,
|
6444 | init,
|
6445 | destroy
|
6446 | });
|
6447 | }
|
6448 |
|
6449 | function Scrollbar(_ref) {
|
6450 | let {
|
6451 | swiper,
|
6452 | extendParams,
|
6453 | on,
|
6454 | emit
|
6455 | } = _ref;
|
6456 | const document = getDocument();
|
6457 | let isTouched = false;
|
6458 | let timeout = null;
|
6459 | let dragTimeout = null;
|
6460 | let dragStartPos;
|
6461 | let dragSize;
|
6462 | let trackSize;
|
6463 | let divider;
|
6464 | extendParams({
|
6465 | scrollbar: {
|
6466 | el: null,
|
6467 | dragSize: 'auto',
|
6468 | hide: false,
|
6469 | draggable: false,
|
6470 | snapOnRelease: true,
|
6471 | lockClass: 'swiper-scrollbar-lock',
|
6472 | dragClass: 'swiper-scrollbar-drag'
|
6473 | }
|
6474 | });
|
6475 | swiper.scrollbar = {
|
6476 | el: null,
|
6477 | dragEl: null,
|
6478 | $el: null,
|
6479 | $dragEl: null
|
6480 | };
|
6481 |
|
6482 | function setTranslate() {
|
6483 | if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return;
|
6484 | const {
|
6485 | scrollbar,
|
6486 | rtlTranslate: rtl,
|
6487 | progress
|
6488 | } = swiper;
|
6489 | const {
|
6490 | $dragEl,
|
6491 | $el
|
6492 | } = scrollbar;
|
6493 | const params = swiper.params.scrollbar;
|
6494 | let newSize = dragSize;
|
6495 | let newPos = (trackSize - dragSize) * progress;
|
6496 |
|
6497 | if (rtl) {
|
6498 | newPos = -newPos;
|
6499 |
|
6500 | if (newPos > 0) {
|
6501 | newSize = dragSize - newPos;
|
6502 | newPos = 0;
|
6503 | } else if (-newPos + dragSize > trackSize) {
|
6504 | newSize = trackSize + newPos;
|
6505 | }
|
6506 | } else if (newPos < 0) {
|
6507 | newSize = dragSize + newPos;
|
6508 | newPos = 0;
|
6509 | } else if (newPos + dragSize > trackSize) {
|
6510 | newSize = trackSize - newPos;
|
6511 | }
|
6512 |
|
6513 | if (swiper.isHorizontal()) {
|
6514 | $dragEl.transform(`translate3d(${newPos}px, 0, 0)`);
|
6515 | $dragEl[0].style.width = `${newSize}px`;
|
6516 | } else {
|
6517 | $dragEl.transform(`translate3d(0px, ${newPos}px, 0)`);
|
6518 | $dragEl[0].style.height = `${newSize}px`;
|
6519 | }
|
6520 |
|
6521 | if (params.hide) {
|
6522 | clearTimeout(timeout);
|
6523 | $el[0].style.opacity = 1;
|
6524 | timeout = setTimeout(() => {
|
6525 | $el[0].style.opacity = 0;
|
6526 | $el.transition(400);
|
6527 | }, 1000);
|
6528 | }
|
6529 | }
|
6530 |
|
6531 | function setTransition(duration) {
|
6532 | if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return;
|
6533 | swiper.scrollbar.$dragEl.transition(duration);
|
6534 | }
|
6535 |
|
6536 | function updateSize() {
|
6537 | if (!swiper.params.scrollbar.el || !swiper.scrollbar.el) return;
|
6538 | const {
|
6539 | scrollbar
|
6540 | } = swiper;
|
6541 | const {
|
6542 | $dragEl,
|
6543 | $el
|
6544 | } = scrollbar;
|
6545 | $dragEl[0].style.width = '';
|
6546 | $dragEl[0].style.height = '';
|
6547 | trackSize = swiper.isHorizontal() ? $el[0].offsetWidth : $el[0].offsetHeight;
|
6548 | divider = swiper.size / (swiper.virtualSize + swiper.params.slidesOffsetBefore - (swiper.params.centeredSlides ? swiper.snapGrid[0] : 0));
|
6549 |
|
6550 | if (swiper.params.scrollbar.dragSize === 'auto') {
|
6551 | dragSize = trackSize * divider;
|
6552 | } else {
|
6553 | dragSize = parseInt(swiper.params.scrollbar.dragSize, 10);
|
6554 | }
|
6555 |
|
6556 | if (swiper.isHorizontal()) {
|
6557 | $dragEl[0].style.width = `${dragSize}px`;
|
6558 | } else {
|
6559 | $dragEl[0].style.height = `${dragSize}px`;
|
6560 | }
|
6561 |
|
6562 | if (divider >= 1) {
|
6563 | $el[0].style.display = 'none';
|
6564 | } else {
|
6565 | $el[0].style.display = '';
|
6566 | }
|
6567 |
|
6568 | if (swiper.params.scrollbar.hide) {
|
6569 | $el[0].style.opacity = 0;
|
6570 | }
|
6571 |
|
6572 | if (swiper.params.watchOverflow && swiper.enabled) {
|
6573 | scrollbar.$el[swiper.isLocked ? 'addClass' : 'removeClass'](swiper.params.scrollbar.lockClass);
|
6574 | }
|
6575 | }
|
6576 |
|
6577 | function getPointerPosition(e) {
|
6578 | if (swiper.isHorizontal()) {
|
6579 | return e.type === 'touchstart' || e.type === 'touchmove' ? e.targetTouches[0].clientX : e.clientX;
|
6580 | }
|
6581 |
|
6582 | return e.type === 'touchstart' || e.type === 'touchmove' ? e.targetTouches[0].clientY : e.clientY;
|
6583 | }
|
6584 |
|
6585 | function setDragPosition(e) {
|
6586 | const {
|
6587 | scrollbar,
|
6588 | rtlTranslate: rtl
|
6589 | } = swiper;
|
6590 | const {
|
6591 | $el
|
6592 | } = scrollbar;
|
6593 | let positionRatio;
|
6594 | positionRatio = (getPointerPosition(e) - $el.offset()[swiper.isHorizontal() ? 'left' : 'top'] - (dragStartPos !== null ? dragStartPos : dragSize / 2)) / (trackSize - dragSize);
|
6595 | positionRatio = Math.max(Math.min(positionRatio, 1), 0);
|
6596 |
|
6597 | if (rtl) {
|
6598 | positionRatio = 1 - positionRatio;
|
6599 | }
|
6600 |
|
6601 | const position = swiper.minTranslate() + (swiper.maxTranslate() - swiper.minTranslate()) * positionRatio;
|
6602 | swiper.updateProgress(position);
|
6603 | swiper.setTranslate(position);
|
6604 | swiper.updateActiveIndex();
|
6605 | swiper.updateSlidesClasses();
|
6606 | }
|
6607 |
|
6608 | function onDragStart(e) {
|
6609 | const params = swiper.params.scrollbar;
|
6610 | const {
|
6611 | scrollbar,
|
6612 | $wrapperEl
|
6613 | } = swiper;
|
6614 | const {
|
6615 | $el,
|
6616 | $dragEl
|
6617 | } = scrollbar;
|
6618 | isTouched = true;
|
6619 | dragStartPos = e.target === $dragEl[0] || e.target === $dragEl ? getPointerPosition(e) - e.target.getBoundingClientRect()[swiper.isHorizontal() ? 'left' : 'top'] : null;
|
6620 | e.preventDefault();
|
6621 | e.stopPropagation();
|
6622 | $wrapperEl.transition(100);
|
6623 | $dragEl.transition(100);
|
6624 | setDragPosition(e);
|
6625 | clearTimeout(dragTimeout);
|
6626 | $el.transition(0);
|
6627 |
|
6628 | if (params.hide) {
|
6629 | $el.css('opacity', 1);
|
6630 | }
|
6631 |
|
6632 | if (swiper.params.cssMode) {
|
6633 | swiper.$wrapperEl.css('scroll-snap-type', 'none');
|
6634 | }
|
6635 |
|
6636 | emit('scrollbarDragStart', e);
|
6637 | }
|
6638 |
|
6639 | function onDragMove(e) {
|
6640 | const {
|
6641 | scrollbar,
|
6642 | $wrapperEl
|
6643 | } = swiper;
|
6644 | const {
|
6645 | $el,
|
6646 | $dragEl
|
6647 | } = scrollbar;
|
6648 | if (!isTouched) return;
|
6649 | if (e.preventDefault) e.preventDefault();else e.returnValue = false;
|
6650 | setDragPosition(e);
|
6651 | $wrapperEl.transition(0);
|
6652 | $el.transition(0);
|
6653 | $dragEl.transition(0);
|
6654 | emit('scrollbarDragMove', e);
|
6655 | }
|
6656 |
|
6657 | function onDragEnd(e) {
|
6658 | const params = swiper.params.scrollbar;
|
6659 | const {
|
6660 | scrollbar,
|
6661 | $wrapperEl
|
6662 | } = swiper;
|
6663 | const {
|
6664 | $el
|
6665 | } = scrollbar;
|
6666 | if (!isTouched) return;
|
6667 | isTouched = false;
|
6668 |
|
6669 | if (swiper.params.cssMode) {
|
6670 | swiper.$wrapperEl.css('scroll-snap-type', '');
|
6671 | $wrapperEl.transition('');
|
6672 | }
|
6673 |
|
6674 | if (params.hide) {
|
6675 | clearTimeout(dragTimeout);
|
6676 | dragTimeout = nextTick(() => {
|
6677 | $el.css('opacity', 0);
|
6678 | $el.transition(400);
|
6679 | }, 1000);
|
6680 | }
|
6681 |
|
6682 | emit('scrollbarDragEnd', e);
|
6683 |
|
6684 | if (params.snapOnRelease) {
|
6685 | swiper.slideToClosest();
|
6686 | }
|
6687 | }
|
6688 |
|
6689 | function events(method) {
|
6690 | const {
|
6691 | scrollbar,
|
6692 | touchEventsTouch,
|
6693 | touchEventsDesktop,
|
6694 | params,
|
6695 | support
|
6696 | } = swiper;
|
6697 | const $el = scrollbar.$el;
|
6698 | const target = $el[0];
|
6699 | const activeListener = support.passiveListener && params.passiveListeners ? {
|
6700 | passive: false,
|
6701 | capture: false
|
6702 | } : false;
|
6703 | const passiveListener = support.passiveListener && params.passiveListeners ? {
|
6704 | passive: true,
|
6705 | capture: false
|
6706 | } : false;
|
6707 | if (!target) return;
|
6708 | const eventMethod = method === 'on' ? 'addEventListener' : 'removeEventListener';
|
6709 |
|
6710 | if (!support.touch) {
|
6711 | target[eventMethod](touchEventsDesktop.start, onDragStart, activeListener);
|
6712 | document[eventMethod](touchEventsDesktop.move, onDragMove, activeListener);
|
6713 | document[eventMethod](touchEventsDesktop.end, onDragEnd, passiveListener);
|
6714 | } else {
|
6715 | target[eventMethod](touchEventsTouch.start, onDragStart, activeListener);
|
6716 | target[eventMethod](touchEventsTouch.move, onDragMove, activeListener);
|
6717 | target[eventMethod](touchEventsTouch.end, onDragEnd, passiveListener);
|
6718 | }
|
6719 | }
|
6720 |
|
6721 | function enableDraggable() {
|
6722 | if (!swiper.params.scrollbar.el) return;
|
6723 | events('on');
|
6724 | }
|
6725 |
|
6726 | function disableDraggable() {
|
6727 | if (!swiper.params.scrollbar.el) return;
|
6728 | events('off');
|
6729 | }
|
6730 |
|
6731 | function init() {
|
6732 | const {
|
6733 | scrollbar,
|
6734 | $el: $swiperEl
|
6735 | } = swiper;
|
6736 | swiper.params.scrollbar = createElementIfNotDefined(swiper, swiper.originalParams.scrollbar, swiper.params.scrollbar, {
|
6737 | el: 'swiper-scrollbar'
|
6738 | });
|
6739 | const params = swiper.params.scrollbar;
|
6740 | if (!params.el) return;
|
6741 | let $el = $(params.el);
|
6742 |
|
6743 | if (swiper.params.uniqueNavElements && typeof params.el === 'string' && $el.length > 1 && $swiperEl.find(params.el).length === 1) {
|
6744 | $el = $swiperEl.find(params.el);
|
6745 | }
|
6746 |
|
6747 | let $dragEl = $el.find(`.${swiper.params.scrollbar.dragClass}`);
|
6748 |
|
6749 | if ($dragEl.length === 0) {
|
6750 | $dragEl = $(`<div class="${swiper.params.scrollbar.dragClass}"></div>`);
|
6751 | $el.append($dragEl);
|
6752 | }
|
6753 |
|
6754 | Object.assign(scrollbar, {
|
6755 | $el,
|
6756 | el: $el[0],
|
6757 | $dragEl,
|
6758 | dragEl: $dragEl[0]
|
6759 | });
|
6760 |
|
6761 | if (params.draggable) {
|
6762 | enableDraggable();
|
6763 | }
|
6764 |
|
6765 | if ($el) {
|
6766 | $el[swiper.enabled ? 'removeClass' : 'addClass'](swiper.params.scrollbar.lockClass);
|
6767 | }
|
6768 | }
|
6769 |
|
6770 | function destroy() {
|
6771 | disableDraggable();
|
6772 | }
|
6773 |
|
6774 | on('init', () => {
|
6775 | init();
|
6776 | updateSize();
|
6777 | setTranslate();
|
6778 | });
|
6779 | on('update resize observerUpdate lock unlock', () => {
|
6780 | updateSize();
|
6781 | });
|
6782 | on('setTranslate', () => {
|
6783 | setTranslate();
|
6784 | });
|
6785 | on('setTransition', (_s, duration) => {
|
6786 | setTransition(duration);
|
6787 | });
|
6788 | on('enable disable', () => {
|
6789 | const {
|
6790 | $el
|
6791 | } = swiper.scrollbar;
|
6792 |
|
6793 | if ($el) {
|
6794 | $el[swiper.enabled ? 'removeClass' : 'addClass'](swiper.params.scrollbar.lockClass);
|
6795 | }
|
6796 | });
|
6797 | on('destroy', () => {
|
6798 | destroy();
|
6799 | });
|
6800 | Object.assign(swiper.scrollbar, {
|
6801 | updateSize,
|
6802 | setTranslate,
|
6803 | init,
|
6804 | destroy
|
6805 | });
|
6806 | }
|
6807 |
|
6808 | function Parallax(_ref) {
|
6809 | let {
|
6810 | swiper,
|
6811 | extendParams,
|
6812 | on
|
6813 | } = _ref;
|
6814 | extendParams({
|
6815 | parallax: {
|
6816 | enabled: false
|
6817 | }
|
6818 | });
|
6819 |
|
6820 | const setTransform = (el, progress) => {
|
6821 | const {
|
6822 | rtl
|
6823 | } = swiper;
|
6824 | const $el = $(el);
|
6825 | const rtlFactor = rtl ? -1 : 1;
|
6826 | const p = $el.attr('data-swiper-parallax') || '0';
|
6827 | let x = $el.attr('data-swiper-parallax-x');
|
6828 | let y = $el.attr('data-swiper-parallax-y');
|
6829 | const scale = $el.attr('data-swiper-parallax-scale');
|
6830 | const opacity = $el.attr('data-swiper-parallax-opacity');
|
6831 |
|
6832 | if (x || y) {
|
6833 | x = x || '0';
|
6834 | y = y || '0';
|
6835 | } else if (swiper.isHorizontal()) {
|
6836 | x = p;
|
6837 | y = '0';
|
6838 | } else {
|
6839 | y = p;
|
6840 | x = '0';
|
6841 | }
|
6842 |
|
6843 | if (x.indexOf('%') >= 0) {
|
6844 | x = `${parseInt(x, 10) * progress * rtlFactor}%`;
|
6845 | } else {
|
6846 | x = `${x * progress * rtlFactor}px`;
|
6847 | }
|
6848 |
|
6849 | if (y.indexOf('%') >= 0) {
|
6850 | y = `${parseInt(y, 10) * progress}%`;
|
6851 | } else {
|
6852 | y = `${y * progress}px`;
|
6853 | }
|
6854 |
|
6855 | if (typeof opacity !== 'undefined' && opacity !== null) {
|
6856 | const currentOpacity = opacity - (opacity - 1) * (1 - Math.abs(progress));
|
6857 | $el[0].style.opacity = currentOpacity;
|
6858 | }
|
6859 |
|
6860 | if (typeof scale === 'undefined' || scale === null) {
|
6861 | $el.transform(`translate3d(${x}, ${y}, 0px)`);
|
6862 | } else {
|
6863 | const currentScale = scale - (scale - 1) * (1 - Math.abs(progress));
|
6864 | $el.transform(`translate3d(${x}, ${y}, 0px) scale(${currentScale})`);
|
6865 | }
|
6866 | };
|
6867 |
|
6868 | const setTranslate = () => {
|
6869 | const {
|
6870 | $el,
|
6871 | slides,
|
6872 | progress,
|
6873 | snapGrid
|
6874 | } = swiper;
|
6875 | $el.children('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]').each(el => {
|
6876 | setTransform(el, progress);
|
6877 | });
|
6878 | slides.each((slideEl, slideIndex) => {
|
6879 | let slideProgress = slideEl.progress;
|
6880 |
|
6881 | if (swiper.params.slidesPerGroup > 1 && swiper.params.slidesPerView !== 'auto') {
|
6882 | slideProgress += Math.ceil(slideIndex / 2) - progress * (snapGrid.length - 1);
|
6883 | }
|
6884 |
|
6885 | slideProgress = Math.min(Math.max(slideProgress, -1), 1);
|
6886 | $(slideEl).find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]').each(el => {
|
6887 | setTransform(el, slideProgress);
|
6888 | });
|
6889 | });
|
6890 | };
|
6891 |
|
6892 | const setTransition = function (duration) {
|
6893 | if (duration === void 0) {
|
6894 | duration = swiper.params.speed;
|
6895 | }
|
6896 |
|
6897 | const {
|
6898 | $el
|
6899 | } = swiper;
|
6900 | $el.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]').each(parallaxEl => {
|
6901 | const $parallaxEl = $(parallaxEl);
|
6902 | let parallaxDuration = parseInt($parallaxEl.attr('data-swiper-parallax-duration'), 10) || duration;
|
6903 | if (duration === 0) parallaxDuration = 0;
|
6904 | $parallaxEl.transition(parallaxDuration);
|
6905 | });
|
6906 | };
|
6907 |
|
6908 | on('beforeInit', () => {
|
6909 | if (!swiper.params.parallax.enabled) return;
|
6910 | swiper.params.watchSlidesProgress = true;
|
6911 | swiper.originalParams.watchSlidesProgress = true;
|
6912 | });
|
6913 | on('init', () => {
|
6914 | if (!swiper.params.parallax.enabled) return;
|
6915 | setTranslate();
|
6916 | });
|
6917 | on('setTranslate', () => {
|
6918 | if (!swiper.params.parallax.enabled) return;
|
6919 | setTranslate();
|
6920 | });
|
6921 | on('setTransition', (_swiper, duration) => {
|
6922 | if (!swiper.params.parallax.enabled) return;
|
6923 | setTransition(duration);
|
6924 | });
|
6925 | }
|
6926 |
|
6927 | function Zoom(_ref) {
|
6928 | let {
|
6929 | swiper,
|
6930 | extendParams,
|
6931 | on,
|
6932 | emit
|
6933 | } = _ref;
|
6934 | const window = getWindow();
|
6935 | extendParams({
|
6936 | zoom: {
|
6937 | enabled: false,
|
6938 | maxRatio: 3,
|
6939 | minRatio: 1,
|
6940 | toggle: true,
|
6941 | containerClass: 'swiper-zoom-container',
|
6942 | zoomedSlideClass: 'swiper-slide-zoomed'
|
6943 | }
|
6944 | });
|
6945 | swiper.zoom = {
|
6946 | enabled: false
|
6947 | };
|
6948 | let currentScale = 1;
|
6949 | let isScaling = false;
|
6950 | let gesturesEnabled;
|
6951 | let fakeGestureTouched;
|
6952 | let fakeGestureMoved;
|
6953 | const gesture = {
|
6954 | $slideEl: undefined,
|
6955 | slideWidth: undefined,
|
6956 | slideHeight: undefined,
|
6957 | $imageEl: undefined,
|
6958 | $imageWrapEl: undefined,
|
6959 | maxRatio: 3
|
6960 | };
|
6961 | const image = {
|
6962 | isTouched: undefined,
|
6963 | isMoved: undefined,
|
6964 | currentX: undefined,
|
6965 | currentY: undefined,
|
6966 | minX: undefined,
|
6967 | minY: undefined,
|
6968 | maxX: undefined,
|
6969 | maxY: undefined,
|
6970 | width: undefined,
|
6971 | height: undefined,
|
6972 | startX: undefined,
|
6973 | startY: undefined,
|
6974 | touchesStart: {},
|
6975 | touchesCurrent: {}
|
6976 | };
|
6977 | const velocity = {
|
6978 | x: undefined,
|
6979 | y: undefined,
|
6980 | prevPositionX: undefined,
|
6981 | prevPositionY: undefined,
|
6982 | prevTime: undefined
|
6983 | };
|
6984 | let scale = 1;
|
6985 | Object.defineProperty(swiper.zoom, 'scale', {
|
6986 | get() {
|
6987 | return scale;
|
6988 | },
|
6989 |
|
6990 | set(value) {
|
6991 | if (scale !== value) {
|
6992 | const imageEl = gesture.$imageEl ? gesture.$imageEl[0] : undefined;
|
6993 | const slideEl = gesture.$slideEl ? gesture.$slideEl[0] : undefined;
|
6994 | emit('zoomChange', value, imageEl, slideEl);
|
6995 | }
|
6996 |
|
6997 | scale = value;
|
6998 | }
|
6999 |
|
7000 | });
|
7001 |
|
7002 | function getDistanceBetweenTouches(e) {
|
7003 | if (e.targetTouches.length < 2) return 1;
|
7004 | const x1 = e.targetTouches[0].pageX;
|
7005 | const y1 = e.targetTouches[0].pageY;
|
7006 | const x2 = e.targetTouches[1].pageX;
|
7007 | const y2 = e.targetTouches[1].pageY;
|
7008 | const distance = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);
|
7009 | return distance;
|
7010 | }
|
7011 |
|
7012 |
|
7013 | function onGestureStart(e) {
|
7014 | const support = swiper.support;
|
7015 | const params = swiper.params.zoom;
|
7016 | fakeGestureTouched = false;
|
7017 | fakeGestureMoved = false;
|
7018 |
|
7019 | if (!support.gestures) {
|
7020 | if (e.type !== 'touchstart' || e.type === 'touchstart' && e.targetTouches.length < 2) {
|
7021 | return;
|
7022 | }
|
7023 |
|
7024 | fakeGestureTouched = true;
|
7025 | gesture.scaleStart = getDistanceBetweenTouches(e);
|
7026 | }
|
7027 |
|
7028 | if (!gesture.$slideEl || !gesture.$slideEl.length) {
|
7029 | gesture.$slideEl = $(e.target).closest(`.${swiper.params.slideClass}`);
|
7030 | if (gesture.$slideEl.length === 0) gesture.$slideEl = swiper.slides.eq(swiper.activeIndex);
|
7031 | gesture.$imageEl = gesture.$slideEl.find(`.${params.containerClass}`).eq(0).find('picture, img, svg, canvas, .swiper-zoom-target').eq(0);
|
7032 | gesture.$imageWrapEl = gesture.$imageEl.parent(`.${params.containerClass}`);
|
7033 | gesture.maxRatio = gesture.$imageWrapEl.attr('data-swiper-zoom') || params.maxRatio;
|
7034 |
|
7035 | if (gesture.$imageWrapEl.length === 0) {
|
7036 | gesture.$imageEl = undefined;
|
7037 | return;
|
7038 | }
|
7039 | }
|
7040 |
|
7041 | if (gesture.$imageEl) {
|
7042 | gesture.$imageEl.transition(0);
|
7043 | }
|
7044 |
|
7045 | isScaling = true;
|
7046 | }
|
7047 |
|
7048 | function onGestureChange(e) {
|
7049 | const support = swiper.support;
|
7050 | const params = swiper.params.zoom;
|
7051 | const zoom = swiper.zoom;
|
7052 |
|
7053 | if (!support.gestures) {
|
7054 | if (e.type !== 'touchmove' || e.type === 'touchmove' && e.targetTouches.length < 2) {
|
7055 | return;
|
7056 | }
|
7057 |
|
7058 | fakeGestureMoved = true;
|
7059 | gesture.scaleMove = getDistanceBetweenTouches(e);
|
7060 | }
|
7061 |
|
7062 | if (!gesture.$imageEl || gesture.$imageEl.length === 0) {
|
7063 | if (e.type === 'gesturechange') onGestureStart(e);
|
7064 | return;
|
7065 | }
|
7066 |
|
7067 | if (support.gestures) {
|
7068 | zoom.scale = e.scale * currentScale;
|
7069 | } else {
|
7070 | zoom.scale = gesture.scaleMove / gesture.scaleStart * currentScale;
|
7071 | }
|
7072 |
|
7073 | if (zoom.scale > gesture.maxRatio) {
|
7074 | zoom.scale = gesture.maxRatio - 1 + (zoom.scale - gesture.maxRatio + 1) ** 0.5;
|
7075 | }
|
7076 |
|
7077 | if (zoom.scale < params.minRatio) {
|
7078 | zoom.scale = params.minRatio + 1 - (params.minRatio - zoom.scale + 1) ** 0.5;
|
7079 | }
|
7080 |
|
7081 | gesture.$imageEl.transform(`translate3d(0,0,0) scale(${zoom.scale})`);
|
7082 | }
|
7083 |
|
7084 | function onGestureEnd(e) {
|
7085 | const device = swiper.device;
|
7086 | const support = swiper.support;
|
7087 | const params = swiper.params.zoom;
|
7088 | const zoom = swiper.zoom;
|
7089 |
|
7090 | if (!support.gestures) {
|
7091 | if (!fakeGestureTouched || !fakeGestureMoved) {
|
7092 | return;
|
7093 | }
|
7094 |
|
7095 | if (e.type !== 'touchend' || e.type === 'touchend' && e.changedTouches.length < 2 && !device.android) {
|
7096 | return;
|
7097 | }
|
7098 |
|
7099 | fakeGestureTouched = false;
|
7100 | fakeGestureMoved = false;
|
7101 | }
|
7102 |
|
7103 | if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
|
7104 | zoom.scale = Math.max(Math.min(zoom.scale, gesture.maxRatio), params.minRatio);
|
7105 | gesture.$imageEl.transition(swiper.params.speed).transform(`translate3d(0,0,0) scale(${zoom.scale})`);
|
7106 | currentScale = zoom.scale;
|
7107 | isScaling = false;
|
7108 | if (zoom.scale === 1) gesture.$slideEl = undefined;
|
7109 | }
|
7110 |
|
7111 | function onTouchStart(e) {
|
7112 | const device = swiper.device;
|
7113 | if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
|
7114 | if (image.isTouched) return;
|
7115 | if (device.android && e.cancelable) e.preventDefault();
|
7116 | image.isTouched = true;
|
7117 | image.touchesStart.x = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
|
7118 | image.touchesStart.y = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
|
7119 | }
|
7120 |
|
7121 | function onTouchMove(e) {
|
7122 | const zoom = swiper.zoom;
|
7123 | if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
|
7124 | swiper.allowClick = false;
|
7125 | if (!image.isTouched || !gesture.$slideEl) return;
|
7126 |
|
7127 | if (!image.isMoved) {
|
7128 | image.width = gesture.$imageEl[0].offsetWidth;
|
7129 | image.height = gesture.$imageEl[0].offsetHeight;
|
7130 | image.startX = getTranslate(gesture.$imageWrapEl[0], 'x') || 0;
|
7131 | image.startY = getTranslate(gesture.$imageWrapEl[0], 'y') || 0;
|
7132 | gesture.slideWidth = gesture.$slideEl[0].offsetWidth;
|
7133 | gesture.slideHeight = gesture.$slideEl[0].offsetHeight;
|
7134 | gesture.$imageWrapEl.transition(0);
|
7135 | }
|
7136 |
|
7137 |
|
7138 | const scaledWidth = image.width * zoom.scale;
|
7139 | const scaledHeight = image.height * zoom.scale;
|
7140 | if (scaledWidth < gesture.slideWidth && scaledHeight < gesture.slideHeight) return;
|
7141 | image.minX = Math.min(gesture.slideWidth / 2 - scaledWidth / 2, 0);
|
7142 | image.maxX = -image.minX;
|
7143 | image.minY = Math.min(gesture.slideHeight / 2 - scaledHeight / 2, 0);
|
7144 | image.maxY = -image.minY;
|
7145 | image.touchesCurrent.x = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
|
7146 | image.touchesCurrent.y = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
|
7147 |
|
7148 | if (!image.isMoved && !isScaling) {
|
7149 | if (swiper.isHorizontal() && (Math.floor(image.minX) === Math.floor(image.startX) && image.touchesCurrent.x < image.touchesStart.x || Math.floor(image.maxX) === Math.floor(image.startX) && image.touchesCurrent.x > image.touchesStart.x)) {
|
7150 | image.isTouched = false;
|
7151 | return;
|
7152 | }
|
7153 |
|
7154 | if (!swiper.isHorizontal() && (Math.floor(image.minY) === Math.floor(image.startY) && image.touchesCurrent.y < image.touchesStart.y || Math.floor(image.maxY) === Math.floor(image.startY) && image.touchesCurrent.y > image.touchesStart.y)) {
|
7155 | image.isTouched = false;
|
7156 | return;
|
7157 | }
|
7158 | }
|
7159 |
|
7160 | if (e.cancelable) {
|
7161 | e.preventDefault();
|
7162 | }
|
7163 |
|
7164 | e.stopPropagation();
|
7165 | image.isMoved = true;
|
7166 | image.currentX = image.touchesCurrent.x - image.touchesStart.x + image.startX;
|
7167 | image.currentY = image.touchesCurrent.y - image.touchesStart.y + image.startY;
|
7168 |
|
7169 | if (image.currentX < image.minX) {
|
7170 | image.currentX = image.minX + 1 - (image.minX - image.currentX + 1) ** 0.8;
|
7171 | }
|
7172 |
|
7173 | if (image.currentX > image.maxX) {
|
7174 | image.currentX = image.maxX - 1 + (image.currentX - image.maxX + 1) ** 0.8;
|
7175 | }
|
7176 |
|
7177 | if (image.currentY < image.minY) {
|
7178 | image.currentY = image.minY + 1 - (image.minY - image.currentY + 1) ** 0.8;
|
7179 | }
|
7180 |
|
7181 | if (image.currentY > image.maxY) {
|
7182 | image.currentY = image.maxY - 1 + (image.currentY - image.maxY + 1) ** 0.8;
|
7183 | }
|
7184 |
|
7185 |
|
7186 | if (!velocity.prevPositionX) velocity.prevPositionX = image.touchesCurrent.x;
|
7187 | if (!velocity.prevPositionY) velocity.prevPositionY = image.touchesCurrent.y;
|
7188 | if (!velocity.prevTime) velocity.prevTime = Date.now();
|
7189 | velocity.x = (image.touchesCurrent.x - velocity.prevPositionX) / (Date.now() - velocity.prevTime) / 2;
|
7190 | velocity.y = (image.touchesCurrent.y - velocity.prevPositionY) / (Date.now() - velocity.prevTime) / 2;
|
7191 | if (Math.abs(image.touchesCurrent.x - velocity.prevPositionX) < 2) velocity.x = 0;
|
7192 | if (Math.abs(image.touchesCurrent.y - velocity.prevPositionY) < 2) velocity.y = 0;
|
7193 | velocity.prevPositionX = image.touchesCurrent.x;
|
7194 | velocity.prevPositionY = image.touchesCurrent.y;
|
7195 | velocity.prevTime = Date.now();
|
7196 | gesture.$imageWrapEl.transform(`translate3d(${image.currentX}px, ${image.currentY}px,0)`);
|
7197 | }
|
7198 |
|
7199 | function onTouchEnd() {
|
7200 | const zoom = swiper.zoom;
|
7201 | if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
|
7202 |
|
7203 | if (!image.isTouched || !image.isMoved) {
|
7204 | image.isTouched = false;
|
7205 | image.isMoved = false;
|
7206 | return;
|
7207 | }
|
7208 |
|
7209 | image.isTouched = false;
|
7210 | image.isMoved = false;
|
7211 | let momentumDurationX = 300;
|
7212 | let momentumDurationY = 300;
|
7213 | const momentumDistanceX = velocity.x * momentumDurationX;
|
7214 | const newPositionX = image.currentX + momentumDistanceX;
|
7215 | const momentumDistanceY = velocity.y * momentumDurationY;
|
7216 | const newPositionY = image.currentY + momentumDistanceY;
|
7217 |
|
7218 | if (velocity.x !== 0) momentumDurationX = Math.abs((newPositionX - image.currentX) / velocity.x);
|
7219 | if (velocity.y !== 0) momentumDurationY = Math.abs((newPositionY - image.currentY) / velocity.y);
|
7220 | const momentumDuration = Math.max(momentumDurationX, momentumDurationY);
|
7221 | image.currentX = newPositionX;
|
7222 | image.currentY = newPositionY;
|
7223 |
|
7224 | const scaledWidth = image.width * zoom.scale;
|
7225 | const scaledHeight = image.height * zoom.scale;
|
7226 | image.minX = Math.min(gesture.slideWidth / 2 - scaledWidth / 2, 0);
|
7227 | image.maxX = -image.minX;
|
7228 | image.minY = Math.min(gesture.slideHeight / 2 - scaledHeight / 2, 0);
|
7229 | image.maxY = -image.minY;
|
7230 | image.currentX = Math.max(Math.min(image.currentX, image.maxX), image.minX);
|
7231 | image.currentY = Math.max(Math.min(image.currentY, image.maxY), image.minY);
|
7232 | gesture.$imageWrapEl.transition(momentumDuration).transform(`translate3d(${image.currentX}px, ${image.currentY}px,0)`);
|
7233 | }
|
7234 |
|
7235 | function onTransitionEnd() {
|
7236 | const zoom = swiper.zoom;
|
7237 |
|
7238 | if (gesture.$slideEl && swiper.previousIndex !== swiper.activeIndex) {
|
7239 | if (gesture.$imageEl) {
|
7240 | gesture.$imageEl.transform('translate3d(0,0,0) scale(1)');
|
7241 | }
|
7242 |
|
7243 | if (gesture.$imageWrapEl) {
|
7244 | gesture.$imageWrapEl.transform('translate3d(0,0,0)');
|
7245 | }
|
7246 |
|
7247 | zoom.scale = 1;
|
7248 | currentScale = 1;
|
7249 | gesture.$slideEl = undefined;
|
7250 | gesture.$imageEl = undefined;
|
7251 | gesture.$imageWrapEl = undefined;
|
7252 | }
|
7253 | }
|
7254 |
|
7255 | function zoomIn(e) {
|
7256 | const zoom = swiper.zoom;
|
7257 | const params = swiper.params.zoom;
|
7258 |
|
7259 | if (!gesture.$slideEl) {
|
7260 | if (e && e.target) {
|
7261 | gesture.$slideEl = $(e.target).closest(`.${swiper.params.slideClass}`);
|
7262 | }
|
7263 |
|
7264 | if (!gesture.$slideEl) {
|
7265 | if (swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual) {
|
7266 | gesture.$slideEl = swiper.$wrapperEl.children(`.${swiper.params.slideActiveClass}`);
|
7267 | } else {
|
7268 | gesture.$slideEl = swiper.slides.eq(swiper.activeIndex);
|
7269 | }
|
7270 | }
|
7271 |
|
7272 | gesture.$imageEl = gesture.$slideEl.find(`.${params.containerClass}`).eq(0).find('picture, img, svg, canvas, .swiper-zoom-target').eq(0);
|
7273 | gesture.$imageWrapEl = gesture.$imageEl.parent(`.${params.containerClass}`);
|
7274 | }
|
7275 |
|
7276 | if (!gesture.$imageEl || gesture.$imageEl.length === 0 || !gesture.$imageWrapEl || gesture.$imageWrapEl.length === 0) return;
|
7277 |
|
7278 | if (swiper.params.cssMode) {
|
7279 | swiper.wrapperEl.style.overflow = 'hidden';
|
7280 | swiper.wrapperEl.style.touchAction = 'none';
|
7281 | }
|
7282 |
|
7283 | gesture.$slideEl.addClass(`${params.zoomedSlideClass}`);
|
7284 | let touchX;
|
7285 | let touchY;
|
7286 | let offsetX;
|
7287 | let offsetY;
|
7288 | let diffX;
|
7289 | let diffY;
|
7290 | let translateX;
|
7291 | let translateY;
|
7292 | let imageWidth;
|
7293 | let imageHeight;
|
7294 | let scaledWidth;
|
7295 | let scaledHeight;
|
7296 | let translateMinX;
|
7297 | let translateMinY;
|
7298 | let translateMaxX;
|
7299 | let translateMaxY;
|
7300 | let slideWidth;
|
7301 | let slideHeight;
|
7302 |
|
7303 | if (typeof image.touchesStart.x === 'undefined' && e) {
|
7304 | touchX = e.type === 'touchend' ? e.changedTouches[0].pageX : e.pageX;
|
7305 | touchY = e.type === 'touchend' ? e.changedTouches[0].pageY : e.pageY;
|
7306 | } else {
|
7307 | touchX = image.touchesStart.x;
|
7308 | touchY = image.touchesStart.y;
|
7309 | }
|
7310 |
|
7311 | zoom.scale = gesture.$imageWrapEl.attr('data-swiper-zoom') || params.maxRatio;
|
7312 | currentScale = gesture.$imageWrapEl.attr('data-swiper-zoom') || params.maxRatio;
|
7313 |
|
7314 | if (e) {
|
7315 | slideWidth = gesture.$slideEl[0].offsetWidth;
|
7316 | slideHeight = gesture.$slideEl[0].offsetHeight;
|
7317 | offsetX = gesture.$slideEl.offset().left + window.scrollX;
|
7318 | offsetY = gesture.$slideEl.offset().top + window.scrollY;
|
7319 | diffX = offsetX + slideWidth / 2 - touchX;
|
7320 | diffY = offsetY + slideHeight / 2 - touchY;
|
7321 | imageWidth = gesture.$imageEl[0].offsetWidth;
|
7322 | imageHeight = gesture.$imageEl[0].offsetHeight;
|
7323 | scaledWidth = imageWidth * zoom.scale;
|
7324 | scaledHeight = imageHeight * zoom.scale;
|
7325 | translateMinX = Math.min(slideWidth / 2 - scaledWidth / 2, 0);
|
7326 | translateMinY = Math.min(slideHeight / 2 - scaledHeight / 2, 0);
|
7327 | translateMaxX = -translateMinX;
|
7328 | translateMaxY = -translateMinY;
|
7329 | translateX = diffX * zoom.scale;
|
7330 | translateY = diffY * zoom.scale;
|
7331 |
|
7332 | if (translateX < translateMinX) {
|
7333 | translateX = translateMinX;
|
7334 | }
|
7335 |
|
7336 | if (translateX > translateMaxX) {
|
7337 | translateX = translateMaxX;
|
7338 | }
|
7339 |
|
7340 | if (translateY < translateMinY) {
|
7341 | translateY = translateMinY;
|
7342 | }
|
7343 |
|
7344 | if (translateY > translateMaxY) {
|
7345 | translateY = translateMaxY;
|
7346 | }
|
7347 | } else {
|
7348 | translateX = 0;
|
7349 | translateY = 0;
|
7350 | }
|
7351 |
|
7352 | gesture.$imageWrapEl.transition(300).transform(`translate3d(${translateX}px, ${translateY}px,0)`);
|
7353 | gesture.$imageEl.transition(300).transform(`translate3d(0,0,0) scale(${zoom.scale})`);
|
7354 | }
|
7355 |
|
7356 | function zoomOut() {
|
7357 | const zoom = swiper.zoom;
|
7358 | const params = swiper.params.zoom;
|
7359 |
|
7360 | if (!gesture.$slideEl) {
|
7361 | if (swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual) {
|
7362 | gesture.$slideEl = swiper.$wrapperEl.children(`.${swiper.params.slideActiveClass}`);
|
7363 | } else {
|
7364 | gesture.$slideEl = swiper.slides.eq(swiper.activeIndex);
|
7365 | }
|
7366 |
|
7367 | gesture.$imageEl = gesture.$slideEl.find(`.${params.containerClass}`).eq(0).find('picture, img, svg, canvas, .swiper-zoom-target').eq(0);
|
7368 | gesture.$imageWrapEl = gesture.$imageEl.parent(`.${params.containerClass}`);
|
7369 | }
|
7370 |
|
7371 | if (!gesture.$imageEl || gesture.$imageEl.length === 0 || !gesture.$imageWrapEl || gesture.$imageWrapEl.length === 0) return;
|
7372 |
|
7373 | if (swiper.params.cssMode) {
|
7374 | swiper.wrapperEl.style.overflow = '';
|
7375 | swiper.wrapperEl.style.touchAction = '';
|
7376 | }
|
7377 |
|
7378 | zoom.scale = 1;
|
7379 | currentScale = 1;
|
7380 | gesture.$imageWrapEl.transition(300).transform('translate3d(0,0,0)');
|
7381 | gesture.$imageEl.transition(300).transform('translate3d(0,0,0) scale(1)');
|
7382 | gesture.$slideEl.removeClass(`${params.zoomedSlideClass}`);
|
7383 | gesture.$slideEl = undefined;
|
7384 | }
|
7385 |
|
7386 |
|
7387 | function zoomToggle(e) {
|
7388 | const zoom = swiper.zoom;
|
7389 |
|
7390 | if (zoom.scale && zoom.scale !== 1) {
|
7391 |
|
7392 | zoomOut();
|
7393 | } else {
|
7394 |
|
7395 | zoomIn(e);
|
7396 | }
|
7397 | }
|
7398 |
|
7399 | function getListeners() {
|
7400 | const support = swiper.support;
|
7401 | const passiveListener = swiper.touchEvents.start === 'touchstart' && support.passiveListener && swiper.params.passiveListeners ? {
|
7402 | passive: true,
|
7403 | capture: false
|
7404 | } : false;
|
7405 | const activeListenerWithCapture = support.passiveListener ? {
|
7406 | passive: false,
|
7407 | capture: true
|
7408 | } : true;
|
7409 | return {
|
7410 | passiveListener,
|
7411 | activeListenerWithCapture
|
7412 | };
|
7413 | }
|
7414 |
|
7415 | function getSlideSelector() {
|
7416 | return `.${swiper.params.slideClass}`;
|
7417 | }
|
7418 |
|
7419 | function toggleGestures(method) {
|
7420 | const {
|
7421 | passiveListener
|
7422 | } = getListeners();
|
7423 | const slideSelector = getSlideSelector();
|
7424 | swiper.$wrapperEl[method]('gesturestart', slideSelector, onGestureStart, passiveListener);
|
7425 | swiper.$wrapperEl[method]('gesturechange', slideSelector, onGestureChange, passiveListener);
|
7426 | swiper.$wrapperEl[method]('gestureend', slideSelector, onGestureEnd, passiveListener);
|
7427 | }
|
7428 |
|
7429 | function enableGestures() {
|
7430 | if (gesturesEnabled) return;
|
7431 | gesturesEnabled = true;
|
7432 | toggleGestures('on');
|
7433 | }
|
7434 |
|
7435 | function disableGestures() {
|
7436 | if (!gesturesEnabled) return;
|
7437 | gesturesEnabled = false;
|
7438 | toggleGestures('off');
|
7439 | }
|
7440 |
|
7441 |
|
7442 | function enable() {
|
7443 | const zoom = swiper.zoom;
|
7444 | if (zoom.enabled) return;
|
7445 | zoom.enabled = true;
|
7446 | const support = swiper.support;
|
7447 | const {
|
7448 | passiveListener,
|
7449 | activeListenerWithCapture
|
7450 | } = getListeners();
|
7451 | const slideSelector = getSlideSelector();
|
7452 |
|
7453 | if (support.gestures) {
|
7454 | swiper.$wrapperEl.on(swiper.touchEvents.start, enableGestures, passiveListener);
|
7455 | swiper.$wrapperEl.on(swiper.touchEvents.end, disableGestures, passiveListener);
|
7456 | } else if (swiper.touchEvents.start === 'touchstart') {
|
7457 | swiper.$wrapperEl.on(swiper.touchEvents.start, slideSelector, onGestureStart, passiveListener);
|
7458 | swiper.$wrapperEl.on(swiper.touchEvents.move, slideSelector, onGestureChange, activeListenerWithCapture);
|
7459 | swiper.$wrapperEl.on(swiper.touchEvents.end, slideSelector, onGestureEnd, passiveListener);
|
7460 |
|
7461 | if (swiper.touchEvents.cancel) {
|
7462 | swiper.$wrapperEl.on(swiper.touchEvents.cancel, slideSelector, onGestureEnd, passiveListener);
|
7463 | }
|
7464 | }
|
7465 |
|
7466 |
|
7467 | swiper.$wrapperEl.on(swiper.touchEvents.move, `.${swiper.params.zoom.containerClass}`, onTouchMove, activeListenerWithCapture);
|
7468 | }
|
7469 |
|
7470 | function disable() {
|
7471 | const zoom = swiper.zoom;
|
7472 | if (!zoom.enabled) return;
|
7473 | const support = swiper.support;
|
7474 | zoom.enabled = false;
|
7475 | const {
|
7476 | passiveListener,
|
7477 | activeListenerWithCapture
|
7478 | } = getListeners();
|
7479 | const slideSelector = getSlideSelector();
|
7480 |
|
7481 | if (support.gestures) {
|
7482 | swiper.$wrapperEl.off(swiper.touchEvents.start, enableGestures, passiveListener);
|
7483 | swiper.$wrapperEl.off(swiper.touchEvents.end, disableGestures, passiveListener);
|
7484 | } else if (swiper.touchEvents.start === 'touchstart') {
|
7485 | swiper.$wrapperEl.off(swiper.touchEvents.start, slideSelector, onGestureStart, passiveListener);
|
7486 | swiper.$wrapperEl.off(swiper.touchEvents.move, slideSelector, onGestureChange, activeListenerWithCapture);
|
7487 | swiper.$wrapperEl.off(swiper.touchEvents.end, slideSelector, onGestureEnd, passiveListener);
|
7488 |
|
7489 | if (swiper.touchEvents.cancel) {
|
7490 | swiper.$wrapperEl.off(swiper.touchEvents.cancel, slideSelector, onGestureEnd, passiveListener);
|
7491 | }
|
7492 | }
|
7493 |
|
7494 |
|
7495 | swiper.$wrapperEl.off(swiper.touchEvents.move, `.${swiper.params.zoom.containerClass}`, onTouchMove, activeListenerWithCapture);
|
7496 | }
|
7497 |
|
7498 | on('init', () => {
|
7499 | if (swiper.params.zoom.enabled) {
|
7500 | enable();
|
7501 | }
|
7502 | });
|
7503 | on('destroy', () => {
|
7504 | disable();
|
7505 | });
|
7506 | on('touchStart', (_s, e) => {
|
7507 | if (!swiper.zoom.enabled) return;
|
7508 | onTouchStart(e);
|
7509 | });
|
7510 | on('touchEnd', (_s, e) => {
|
7511 | if (!swiper.zoom.enabled) return;
|
7512 | onTouchEnd();
|
7513 | });
|
7514 | on('doubleTap', (_s, e) => {
|
7515 | if (!swiper.animating && swiper.params.zoom.enabled && swiper.zoom.enabled && swiper.params.zoom.toggle) {
|
7516 | zoomToggle(e);
|
7517 | }
|
7518 | });
|
7519 | on('transitionEnd', () => {
|
7520 | if (swiper.zoom.enabled && swiper.params.zoom.enabled) {
|
7521 | onTransitionEnd();
|
7522 | }
|
7523 | });
|
7524 | on('slideChange', () => {
|
7525 | if (swiper.zoom.enabled && swiper.params.zoom.enabled && swiper.params.cssMode) {
|
7526 | onTransitionEnd();
|
7527 | }
|
7528 | });
|
7529 | Object.assign(swiper.zoom, {
|
7530 | enable,
|
7531 | disable,
|
7532 | in: zoomIn,
|
7533 | out: zoomOut,
|
7534 | toggle: zoomToggle
|
7535 | });
|
7536 | }
|
7537 |
|
7538 | function Lazy(_ref) {
|
7539 | let {
|
7540 | swiper,
|
7541 | extendParams,
|
7542 | on,
|
7543 | emit
|
7544 | } = _ref;
|
7545 | extendParams({
|
7546 | lazy: {
|
7547 | checkInView: false,
|
7548 | enabled: false,
|
7549 | loadPrevNext: false,
|
7550 | loadPrevNextAmount: 1,
|
7551 | loadOnTransitionStart: false,
|
7552 | scrollingElement: '',
|
7553 | elementClass: 'swiper-lazy',
|
7554 | loadingClass: 'swiper-lazy-loading',
|
7555 | loadedClass: 'swiper-lazy-loaded',
|
7556 | preloaderClass: 'swiper-lazy-preloader'
|
7557 | }
|
7558 | });
|
7559 | swiper.lazy = {};
|
7560 | let scrollHandlerAttached = false;
|
7561 | let initialImageLoaded = false;
|
7562 |
|
7563 | function loadInSlide(index, loadInDuplicate) {
|
7564 | if (loadInDuplicate === void 0) {
|
7565 | loadInDuplicate = true;
|
7566 | }
|
7567 |
|
7568 | const params = swiper.params.lazy;
|
7569 | if (typeof index === 'undefined') return;
|
7570 | if (swiper.slides.length === 0) return;
|
7571 | const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
|
7572 | const $slideEl = isVirtual ? swiper.$wrapperEl.children(`.${swiper.params.slideClass}[data-swiper-slide-index="${index}"]`) : swiper.slides.eq(index);
|
7573 | const $images = $slideEl.find(`.${params.elementClass}:not(.${params.loadedClass}):not(.${params.loadingClass})`);
|
7574 |
|
7575 | if ($slideEl.hasClass(params.elementClass) && !$slideEl.hasClass(params.loadedClass) && !$slideEl.hasClass(params.loadingClass)) {
|
7576 | $images.push($slideEl[0]);
|
7577 | }
|
7578 |
|
7579 | if ($images.length === 0) return;
|
7580 | $images.each(imageEl => {
|
7581 | const $imageEl = $(imageEl);
|
7582 | $imageEl.addClass(params.loadingClass);
|
7583 | const background = $imageEl.attr('data-background');
|
7584 | const src = $imageEl.attr('data-src');
|
7585 | const srcset = $imageEl.attr('data-srcset');
|
7586 | const sizes = $imageEl.attr('data-sizes');
|
7587 | const $pictureEl = $imageEl.parent('picture');
|
7588 | swiper.loadImage($imageEl[0], src || background, srcset, sizes, false, () => {
|
7589 | if (typeof swiper === 'undefined' || swiper === null || !swiper || swiper && !swiper.params || swiper.destroyed) return;
|
7590 |
|
7591 | if (background) {
|
7592 | $imageEl.css('background-image', `url("${background}")`);
|
7593 | $imageEl.removeAttr('data-background');
|
7594 | } else {
|
7595 | if (srcset) {
|
7596 | $imageEl.attr('srcset', srcset);
|
7597 | $imageEl.removeAttr('data-srcset');
|
7598 | }
|
7599 |
|
7600 | if (sizes) {
|
7601 | $imageEl.attr('sizes', sizes);
|
7602 | $imageEl.removeAttr('data-sizes');
|
7603 | }
|
7604 |
|
7605 | if ($pictureEl.length) {
|
7606 | $pictureEl.children('source').each(sourceEl => {
|
7607 | const $source = $(sourceEl);
|
7608 |
|
7609 | if ($source.attr('data-srcset')) {
|
7610 | $source.attr('srcset', $source.attr('data-srcset'));
|
7611 | $source.removeAttr('data-srcset');
|
7612 | }
|
7613 | });
|
7614 | }
|
7615 |
|
7616 | if (src) {
|
7617 | $imageEl.attr('src', src);
|
7618 | $imageEl.removeAttr('data-src');
|
7619 | }
|
7620 | }
|
7621 |
|
7622 | $imageEl.addClass(params.loadedClass).removeClass(params.loadingClass);
|
7623 | $slideEl.find(`.${params.preloaderClass}`).remove();
|
7624 |
|
7625 | if (swiper.params.loop && loadInDuplicate) {
|
7626 | const slideOriginalIndex = $slideEl.attr('data-swiper-slide-index');
|
7627 |
|
7628 | if ($slideEl.hasClass(swiper.params.slideDuplicateClass)) {
|
7629 | const originalSlide = swiper.$wrapperEl.children(`[data-swiper-slide-index="${slideOriginalIndex}"]:not(.${swiper.params.slideDuplicateClass})`);
|
7630 | loadInSlide(originalSlide.index(), false);
|
7631 | } else {
|
7632 | const duplicatedSlide = swiper.$wrapperEl.children(`.${swiper.params.slideDuplicateClass}[data-swiper-slide-index="${slideOriginalIndex}"]`);
|
7633 | loadInSlide(duplicatedSlide.index(), false);
|
7634 | }
|
7635 | }
|
7636 |
|
7637 | emit('lazyImageReady', $slideEl[0], $imageEl[0]);
|
7638 |
|
7639 | if (swiper.params.autoHeight) {
|
7640 | swiper.updateAutoHeight();
|
7641 | }
|
7642 | });
|
7643 | emit('lazyImageLoad', $slideEl[0], $imageEl[0]);
|
7644 | });
|
7645 | }
|
7646 |
|
7647 | function load() {
|
7648 | const {
|
7649 | $wrapperEl,
|
7650 | params: swiperParams,
|
7651 | slides,
|
7652 | activeIndex
|
7653 | } = swiper;
|
7654 | const isVirtual = swiper.virtual && swiperParams.virtual.enabled;
|
7655 | const params = swiperParams.lazy;
|
7656 | let slidesPerView = swiperParams.slidesPerView;
|
7657 |
|
7658 | if (slidesPerView === 'auto') {
|
7659 | slidesPerView = 0;
|
7660 | }
|
7661 |
|
7662 | function slideExist(index) {
|
7663 | if (isVirtual) {
|
7664 | if ($wrapperEl.children(`.${swiperParams.slideClass}[data-swiper-slide-index="${index}"]`).length) {
|
7665 | return true;
|
7666 | }
|
7667 | } else if (slides[index]) return true;
|
7668 |
|
7669 | return false;
|
7670 | }
|
7671 |
|
7672 | function slideIndex(slideEl) {
|
7673 | if (isVirtual) {
|
7674 | return $(slideEl).attr('data-swiper-slide-index');
|
7675 | }
|
7676 |
|
7677 | return $(slideEl).index();
|
7678 | }
|
7679 |
|
7680 | if (!initialImageLoaded) initialImageLoaded = true;
|
7681 |
|
7682 | if (swiper.params.watchSlidesProgress) {
|
7683 | $wrapperEl.children(`.${swiperParams.slideVisibleClass}`).each(slideEl => {
|
7684 | const index = isVirtual ? $(slideEl).attr('data-swiper-slide-index') : $(slideEl).index();
|
7685 | loadInSlide(index);
|
7686 | });
|
7687 | } else if (slidesPerView > 1) {
|
7688 | for (let i = activeIndex; i < activeIndex + slidesPerView; i += 1) {
|
7689 | if (slideExist(i)) loadInSlide(i);
|
7690 | }
|
7691 | } else {
|
7692 | loadInSlide(activeIndex);
|
7693 | }
|
7694 |
|
7695 | if (params.loadPrevNext) {
|
7696 | if (slidesPerView > 1 || params.loadPrevNextAmount && params.loadPrevNextAmount > 1) {
|
7697 | const amount = params.loadPrevNextAmount;
|
7698 | const spv = slidesPerView;
|
7699 | const maxIndex = Math.min(activeIndex + spv + Math.max(amount, spv), slides.length);
|
7700 | const minIndex = Math.max(activeIndex - Math.max(spv, amount), 0);
|
7701 |
|
7702 | for (let i = activeIndex + slidesPerView; i < maxIndex; i += 1) {
|
7703 | if (slideExist(i)) loadInSlide(i);
|
7704 | }
|
7705 |
|
7706 |
|
7707 | for (let i = minIndex; i < activeIndex; i += 1) {
|
7708 | if (slideExist(i)) loadInSlide(i);
|
7709 | }
|
7710 | } else {
|
7711 | const nextSlide = $wrapperEl.children(`.${swiperParams.slideNextClass}`);
|
7712 | if (nextSlide.length > 0) loadInSlide(slideIndex(nextSlide));
|
7713 | const prevSlide = $wrapperEl.children(`.${swiperParams.slidePrevClass}`);
|
7714 | if (prevSlide.length > 0) loadInSlide(slideIndex(prevSlide));
|
7715 | }
|
7716 | }
|
7717 | }
|
7718 |
|
7719 | function checkInViewOnLoad() {
|
7720 | const window = getWindow();
|
7721 | if (!swiper || swiper.destroyed) return;
|
7722 | const $scrollElement = swiper.params.lazy.scrollingElement ? $(swiper.params.lazy.scrollingElement) : $(window);
|
7723 | const isWindow = $scrollElement[0] === window;
|
7724 | const scrollElementWidth = isWindow ? window.innerWidth : $scrollElement[0].offsetWidth;
|
7725 | const scrollElementHeight = isWindow ? window.innerHeight : $scrollElement[0].offsetHeight;
|
7726 | const swiperOffset = swiper.$el.offset();
|
7727 | const {
|
7728 | rtlTranslate: rtl
|
7729 | } = swiper;
|
7730 | let inView = false;
|
7731 | if (rtl) swiperOffset.left -= swiper.$el[0].scrollLeft;
|
7732 | const swiperCoord = [[swiperOffset.left, swiperOffset.top], [swiperOffset.left + swiper.width, swiperOffset.top], [swiperOffset.left, swiperOffset.top + swiper.height], [swiperOffset.left + swiper.width, swiperOffset.top + swiper.height]];
|
7733 |
|
7734 | for (let i = 0; i < swiperCoord.length; i += 1) {
|
7735 | const point = swiperCoord[i];
|
7736 |
|
7737 | if (point[0] >= 0 && point[0] <= scrollElementWidth && point[1] >= 0 && point[1] <= scrollElementHeight) {
|
7738 | if (point[0] === 0 && point[1] === 0) continue;
|
7739 |
|
7740 | inView = true;
|
7741 | }
|
7742 | }
|
7743 |
|
7744 | const passiveListener = swiper.touchEvents.start === 'touchstart' && swiper.support.passiveListener && swiper.params.passiveListeners ? {
|
7745 | passive: true,
|
7746 | capture: false
|
7747 | } : false;
|
7748 |
|
7749 | if (inView) {
|
7750 | load();
|
7751 | $scrollElement.off('scroll', checkInViewOnLoad, passiveListener);
|
7752 | } else if (!scrollHandlerAttached) {
|
7753 | scrollHandlerAttached = true;
|
7754 | $scrollElement.on('scroll', checkInViewOnLoad, passiveListener);
|
7755 | }
|
7756 | }
|
7757 |
|
7758 | on('beforeInit', () => {
|
7759 | if (swiper.params.lazy.enabled && swiper.params.preloadImages) {
|
7760 | swiper.params.preloadImages = false;
|
7761 | }
|
7762 | });
|
7763 | on('init', () => {
|
7764 | if (swiper.params.lazy.enabled) {
|
7765 | if (swiper.params.lazy.checkInView) {
|
7766 | checkInViewOnLoad();
|
7767 | } else {
|
7768 | load();
|
7769 | }
|
7770 | }
|
7771 | });
|
7772 | on('scroll', () => {
|
7773 | if (swiper.params.freeMode && swiper.params.freeMode.enabled && !swiper.params.freeMode.sticky) {
|
7774 | load();
|
7775 | }
|
7776 | });
|
7777 | on('scrollbarDragMove resize _freeModeNoMomentumRelease', () => {
|
7778 | if (swiper.params.lazy.enabled) {
|
7779 | if (swiper.params.lazy.checkInView) {
|
7780 | checkInViewOnLoad();
|
7781 | } else {
|
7782 | load();
|
7783 | }
|
7784 | }
|
7785 | });
|
7786 | on('transitionStart', () => {
|
7787 | if (swiper.params.lazy.enabled) {
|
7788 | if (swiper.params.lazy.loadOnTransitionStart || !swiper.params.lazy.loadOnTransitionStart && !initialImageLoaded) {
|
7789 | if (swiper.params.lazy.checkInView) {
|
7790 | checkInViewOnLoad();
|
7791 | } else {
|
7792 | load();
|
7793 | }
|
7794 | }
|
7795 | }
|
7796 | });
|
7797 | on('transitionEnd', () => {
|
7798 | if (swiper.params.lazy.enabled && !swiper.params.lazy.loadOnTransitionStart) {
|
7799 | if (swiper.params.lazy.checkInView) {
|
7800 | checkInViewOnLoad();
|
7801 | } else {
|
7802 | load();
|
7803 | }
|
7804 | }
|
7805 | });
|
7806 | on('slideChange', () => {
|
7807 | const {
|
7808 | lazy,
|
7809 | cssMode,
|
7810 | watchSlidesProgress,
|
7811 | touchReleaseOnEdges,
|
7812 | resistanceRatio
|
7813 | } = swiper.params;
|
7814 |
|
7815 | if (lazy.enabled && (cssMode || watchSlidesProgress && (touchReleaseOnEdges || resistanceRatio === 0))) {
|
7816 | load();
|
7817 | }
|
7818 | });
|
7819 | Object.assign(swiper.lazy, {
|
7820 | load,
|
7821 | loadInSlide
|
7822 | });
|
7823 | }
|
7824 |
|
7825 |
|
7826 | function Controller(_ref) {
|
7827 | let {
|
7828 | swiper,
|
7829 | extendParams,
|
7830 | on
|
7831 | } = _ref;
|
7832 | extendParams({
|
7833 | controller: {
|
7834 | control: undefined,
|
7835 | inverse: false,
|
7836 | by: 'slide'
|
7837 |
|
7838 | }
|
7839 | });
|
7840 | swiper.controller = {
|
7841 | control: undefined
|
7842 | };
|
7843 |
|
7844 | function LinearSpline(x, y) {
|
7845 | const binarySearch = function search() {
|
7846 | let maxIndex;
|
7847 | let minIndex;
|
7848 | let guess;
|
7849 | return (array, val) => {
|
7850 | minIndex = -1;
|
7851 | maxIndex = array.length;
|
7852 |
|
7853 | while (maxIndex - minIndex > 1) {
|
7854 | guess = maxIndex + minIndex >> 1;
|
7855 |
|
7856 | if (array[guess] <= val) {
|
7857 | minIndex = guess;
|
7858 | } else {
|
7859 | maxIndex = guess;
|
7860 | }
|
7861 | }
|
7862 |
|
7863 | return maxIndex;
|
7864 | };
|
7865 | }();
|
7866 |
|
7867 | this.x = x;
|
7868 | this.y = y;
|
7869 | this.lastIndex = x.length - 1;
|
7870 |
|
7871 |
|
7872 |
|
7873 | let i1;
|
7874 | let i3;
|
7875 |
|
7876 | this.interpolate = function interpolate(x2) {
|
7877 | if (!x2) return 0;
|
7878 |
|
7879 | i3 = binarySearch(this.x, x2);
|
7880 | i1 = i3 - 1;
|
7881 |
|
7882 |
|
7883 | return (x2 - this.x[i1]) * (this.y[i3] - this.y[i1]) / (this.x[i3] - this.x[i1]) + this.y[i1];
|
7884 | };
|
7885 |
|
7886 | return this;
|
7887 | }
|
7888 |
|
7889 |
|
7890 | function getInterpolateFunction(c) {
|
7891 | if (!swiper.controller.spline) {
|
7892 | swiper.controller.spline = swiper.params.loop ? new LinearSpline(swiper.slidesGrid, c.slidesGrid) : new LinearSpline(swiper.snapGrid, c.snapGrid);
|
7893 | }
|
7894 | }
|
7895 |
|
7896 | function setTranslate(_t, byController) {
|
7897 | const controlled = swiper.controller.control;
|
7898 | let multiplier;
|
7899 | let controlledTranslate;
|
7900 | const Swiper = swiper.constructor;
|
7901 |
|
7902 | function setControlledTranslate(c) {
|
7903 |
|
7904 |
|
7905 |
|
7906 |
|
7907 | const translate = swiper.rtlTranslate ? -swiper.translate : swiper.translate;
|
7908 |
|
7909 | if (swiper.params.controller.by === 'slide') {
|
7910 | getInterpolateFunction(c);
|
7911 |
|
7912 |
|
7913 | controlledTranslate = -swiper.controller.spline.interpolate(-translate);
|
7914 | }
|
7915 |
|
7916 | if (!controlledTranslate || swiper.params.controller.by === 'container') {
|
7917 | multiplier = (c.maxTranslate() - c.minTranslate()) / (swiper.maxTranslate() - swiper.minTranslate());
|
7918 | controlledTranslate = (translate - swiper.minTranslate()) * multiplier + c.minTranslate();
|
7919 | }
|
7920 |
|
7921 | if (swiper.params.controller.inverse) {
|
7922 | controlledTranslate = c.maxTranslate() - controlledTranslate;
|
7923 | }
|
7924 |
|
7925 | c.updateProgress(controlledTranslate);
|
7926 | c.setTranslate(controlledTranslate, swiper);
|
7927 | c.updateActiveIndex();
|
7928 | c.updateSlidesClasses();
|
7929 | }
|
7930 |
|
7931 | if (Array.isArray(controlled)) {
|
7932 | for (let i = 0; i < controlled.length; i += 1) {
|
7933 | if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
|
7934 | setControlledTranslate(controlled[i]);
|
7935 | }
|
7936 | }
|
7937 | } else if (controlled instanceof Swiper && byController !== controlled) {
|
7938 | setControlledTranslate(controlled);
|
7939 | }
|
7940 | }
|
7941 |
|
7942 | function setTransition(duration, byController) {
|
7943 | const Swiper = swiper.constructor;
|
7944 | const controlled = swiper.controller.control;
|
7945 | let i;
|
7946 |
|
7947 | function setControlledTransition(c) {
|
7948 | c.setTransition(duration, swiper);
|
7949 |
|
7950 | if (duration !== 0) {
|
7951 | c.transitionStart();
|
7952 |
|
7953 | if (c.params.autoHeight) {
|
7954 | nextTick(() => {
|
7955 | c.updateAutoHeight();
|
7956 | });
|
7957 | }
|
7958 |
|
7959 | c.$wrapperEl.transitionEnd(() => {
|
7960 | if (!controlled) return;
|
7961 |
|
7962 | if (c.params.loop && swiper.params.controller.by === 'slide') {
|
7963 | c.loopFix();
|
7964 | }
|
7965 |
|
7966 | c.transitionEnd();
|
7967 | });
|
7968 | }
|
7969 | }
|
7970 |
|
7971 | if (Array.isArray(controlled)) {
|
7972 | for (i = 0; i < controlled.length; i += 1) {
|
7973 | if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
|
7974 | setControlledTransition(controlled[i]);
|
7975 | }
|
7976 | }
|
7977 | } else if (controlled instanceof Swiper && byController !== controlled) {
|
7978 | setControlledTransition(controlled);
|
7979 | }
|
7980 | }
|
7981 |
|
7982 | function removeSpline() {
|
7983 | if (!swiper.controller.control) return;
|
7984 |
|
7985 | if (swiper.controller.spline) {
|
7986 | swiper.controller.spline = undefined;
|
7987 | delete swiper.controller.spline;
|
7988 | }
|
7989 | }
|
7990 |
|
7991 | on('beforeInit', () => {
|
7992 | swiper.controller.control = swiper.params.controller.control;
|
7993 | });
|
7994 | on('update', () => {
|
7995 | removeSpline();
|
7996 | });
|
7997 | on('resize', () => {
|
7998 | removeSpline();
|
7999 | });
|
8000 | on('observerUpdate', () => {
|
8001 | removeSpline();
|
8002 | });
|
8003 | on('setTranslate', (_s, translate, byController) => {
|
8004 | if (!swiper.controller.control) return;
|
8005 | swiper.controller.setTranslate(translate, byController);
|
8006 | });
|
8007 | on('setTransition', (_s, duration, byController) => {
|
8008 | if (!swiper.controller.control) return;
|
8009 | swiper.controller.setTransition(duration, byController);
|
8010 | });
|
8011 | Object.assign(swiper.controller, {
|
8012 | setTranslate,
|
8013 | setTransition
|
8014 | });
|
8015 | }
|
8016 |
|
8017 | function A11y(_ref) {
|
8018 | let {
|
8019 | swiper,
|
8020 | extendParams,
|
8021 | on
|
8022 | } = _ref;
|
8023 | extendParams({
|
8024 | a11y: {
|
8025 | enabled: true,
|
8026 | notificationClass: 'swiper-notification',
|
8027 | prevSlideMessage: 'Previous slide',
|
8028 | nextSlideMessage: 'Next slide',
|
8029 | firstSlideMessage: 'This is the first slide',
|
8030 | lastSlideMessage: 'This is the last slide',
|
8031 | paginationBulletMessage: 'Go to slide {{index}}',
|
8032 | slideLabelMessage: '{{index}} / {{slidesLength}}',
|
8033 | containerMessage: null,
|
8034 | containerRoleDescriptionMessage: null,
|
8035 | itemRoleDescriptionMessage: null,
|
8036 | slideRole: 'group'
|
8037 | }
|
8038 | });
|
8039 | let liveRegion = null;
|
8040 |
|
8041 | function notify(message) {
|
8042 | const notification = liveRegion;
|
8043 | if (notification.length === 0) return;
|
8044 | notification.html('');
|
8045 | notification.html(message);
|
8046 | }
|
8047 |
|
8048 | function getRandomNumber(size) {
|
8049 | if (size === void 0) {
|
8050 | size = 16;
|
8051 | }
|
8052 |
|
8053 | const randomChar = () => Math.round(16 * Math.random()).toString(16);
|
8054 |
|
8055 | return 'x'.repeat(size).replace(/x/g, randomChar);
|
8056 | }
|
8057 |
|
8058 | function makeElFocusable($el) {
|
8059 | $el.attr('tabIndex', '0');
|
8060 | }
|
8061 |
|
8062 | function makeElNotFocusable($el) {
|
8063 | $el.attr('tabIndex', '-1');
|
8064 | }
|
8065 |
|
8066 | function addElRole($el, role) {
|
8067 | $el.attr('role', role);
|
8068 | }
|
8069 |
|
8070 | function addElRoleDescription($el, description) {
|
8071 | $el.attr('aria-roledescription', description);
|
8072 | }
|
8073 |
|
8074 | function addElControls($el, controls) {
|
8075 | $el.attr('aria-controls', controls);
|
8076 | }
|
8077 |
|
8078 | function addElLabel($el, label) {
|
8079 | $el.attr('aria-label', label);
|
8080 | }
|
8081 |
|
8082 | function addElId($el, id) {
|
8083 | $el.attr('id', id);
|
8084 | }
|
8085 |
|
8086 | function addElLive($el, live) {
|
8087 | $el.attr('aria-live', live);
|
8088 | }
|
8089 |
|
8090 | function disableEl($el) {
|
8091 | $el.attr('aria-disabled', true);
|
8092 | }
|
8093 |
|
8094 | function enableEl($el) {
|
8095 | $el.attr('aria-disabled', false);
|
8096 | }
|
8097 |
|
8098 | function onEnterOrSpaceKey(e) {
|
8099 | if (e.keyCode !== 13 && e.keyCode !== 32) return;
|
8100 | const params = swiper.params.a11y;
|
8101 | const $targetEl = $(e.target);
|
8102 |
|
8103 | if (swiper.navigation && swiper.navigation.$nextEl && $targetEl.is(swiper.navigation.$nextEl)) {
|
8104 | if (!(swiper.isEnd && !swiper.params.loop)) {
|
8105 | swiper.slideNext();
|
8106 | }
|
8107 |
|
8108 | if (swiper.isEnd) {
|
8109 | notify(params.lastSlideMessage);
|
8110 | } else {
|
8111 | notify(params.nextSlideMessage);
|
8112 | }
|
8113 | }
|
8114 |
|
8115 | if (swiper.navigation && swiper.navigation.$prevEl && $targetEl.is(swiper.navigation.$prevEl)) {
|
8116 | if (!(swiper.isBeginning && !swiper.params.loop)) {
|
8117 | swiper.slidePrev();
|
8118 | }
|
8119 |
|
8120 | if (swiper.isBeginning) {
|
8121 | notify(params.firstSlideMessage);
|
8122 | } else {
|
8123 | notify(params.prevSlideMessage);
|
8124 | }
|
8125 | }
|
8126 |
|
8127 | if (swiper.pagination && $targetEl.is(classesToSelector(swiper.params.pagination.bulletClass))) {
|
8128 | $targetEl[0].click();
|
8129 | }
|
8130 | }
|
8131 |
|
8132 | function updateNavigation() {
|
8133 | if (swiper.params.loop || swiper.params.rewind || !swiper.navigation) return;
|
8134 | const {
|
8135 | $nextEl,
|
8136 | $prevEl
|
8137 | } = swiper.navigation;
|
8138 |
|
8139 | if ($prevEl && $prevEl.length > 0) {
|
8140 | if (swiper.isBeginning) {
|
8141 | disableEl($prevEl);
|
8142 | makeElNotFocusable($prevEl);
|
8143 | } else {
|
8144 | enableEl($prevEl);
|
8145 | makeElFocusable($prevEl);
|
8146 | }
|
8147 | }
|
8148 |
|
8149 | if ($nextEl && $nextEl.length > 0) {
|
8150 | if (swiper.isEnd) {
|
8151 | disableEl($nextEl);
|
8152 | makeElNotFocusable($nextEl);
|
8153 | } else {
|
8154 | enableEl($nextEl);
|
8155 | makeElFocusable($nextEl);
|
8156 | }
|
8157 | }
|
8158 | }
|
8159 |
|
8160 | function hasPagination() {
|
8161 | return swiper.pagination && swiper.pagination.bullets && swiper.pagination.bullets.length;
|
8162 | }
|
8163 |
|
8164 | function hasClickablePagination() {
|
8165 | return hasPagination() && swiper.params.pagination.clickable;
|
8166 | }
|
8167 |
|
8168 | function updatePagination() {
|
8169 | const params = swiper.params.a11y;
|
8170 | if (!hasPagination()) return;
|
8171 | swiper.pagination.bullets.each(bulletEl => {
|
8172 | const $bulletEl = $(bulletEl);
|
8173 |
|
8174 | if (swiper.params.pagination.clickable) {
|
8175 | makeElFocusable($bulletEl);
|
8176 |
|
8177 | if (!swiper.params.pagination.renderBullet) {
|
8178 | addElRole($bulletEl, 'button');
|
8179 | addElLabel($bulletEl, params.paginationBulletMessage.replace(/\{\{index\}\}/, $bulletEl.index() + 1));
|
8180 | }
|
8181 | }
|
8182 |
|
8183 | if ($bulletEl.is(`.${swiper.params.pagination.bulletActiveClass}`)) {
|
8184 | $bulletEl.attr('aria-current', 'true');
|
8185 | } else {
|
8186 | $bulletEl.removeAttr('aria-current');
|
8187 | }
|
8188 | });
|
8189 | }
|
8190 |
|
8191 | const initNavEl = ($el, wrapperId, message) => {
|
8192 | makeElFocusable($el);
|
8193 |
|
8194 | if ($el[0].tagName !== 'BUTTON') {
|
8195 | addElRole($el, 'button');
|
8196 | $el.on('keydown', onEnterOrSpaceKey);
|
8197 | }
|
8198 |
|
8199 | addElLabel($el, message);
|
8200 | addElControls($el, wrapperId);
|
8201 | };
|
8202 |
|
8203 | const handleFocus = e => {
|
8204 | const slideEl = e.target.closest(`.${swiper.params.slideClass}`);
|
8205 | if (!slideEl || !swiper.slides.includes(slideEl)) return;
|
8206 | const isActive = swiper.slides.indexOf(slideEl) === swiper.activeIndex;
|
8207 | const isVisible = swiper.params.watchSlidesProgress && swiper.visibleSlides && swiper.visibleSlides.includes(slideEl);
|
8208 | if (isActive || isVisible) return;
|
8209 | swiper.slideTo(swiper.slides.indexOf(slideEl), 0);
|
8210 | };
|
8211 |
|
8212 | function init() {
|
8213 | const params = swiper.params.a11y;
|
8214 | swiper.$el.append(liveRegion);
|
8215 |
|
8216 | const $containerEl = swiper.$el;
|
8217 |
|
8218 | if (params.containerRoleDescriptionMessage) {
|
8219 | addElRoleDescription($containerEl, params.containerRoleDescriptionMessage);
|
8220 | }
|
8221 |
|
8222 | if (params.containerMessage) {
|
8223 | addElLabel($containerEl, params.containerMessage);
|
8224 | }
|
8225 |
|
8226 |
|
8227 | const $wrapperEl = swiper.$wrapperEl;
|
8228 | const wrapperId = $wrapperEl.attr('id') || `swiper-wrapper-${getRandomNumber(16)}`;
|
8229 | const live = swiper.params.autoplay && swiper.params.autoplay.enabled ? 'off' : 'polite';
|
8230 | addElId($wrapperEl, wrapperId);
|
8231 | addElLive($wrapperEl, live);
|
8232 |
|
8233 | if (params.itemRoleDescriptionMessage) {
|
8234 | addElRoleDescription($(swiper.slides), params.itemRoleDescriptionMessage);
|
8235 | }
|
8236 |
|
8237 | addElRole($(swiper.slides), params.slideRole);
|
8238 | const slidesLength = swiper.params.loop ? swiper.slides.filter(el => !el.classList.contains(swiper.params.slideDuplicateClass)).length : swiper.slides.length;
|
8239 | swiper.slides.each((slideEl, index) => {
|
8240 | const $slideEl = $(slideEl);
|
8241 | const slideIndex = swiper.params.loop ? parseInt($slideEl.attr('data-swiper-slide-index'), 10) : index;
|
8242 | const ariaLabelMessage = params.slideLabelMessage.replace(/\{\{index\}\}/, slideIndex + 1).replace(/\{\{slidesLength\}\}/, slidesLength);
|
8243 | addElLabel($slideEl, ariaLabelMessage);
|
8244 | });
|
8245 |
|
8246 | let $nextEl;
|
8247 | let $prevEl;
|
8248 |
|
8249 | if (swiper.navigation && swiper.navigation.$nextEl) {
|
8250 | $nextEl = swiper.navigation.$nextEl;
|
8251 | }
|
8252 |
|
8253 | if (swiper.navigation && swiper.navigation.$prevEl) {
|
8254 | $prevEl = swiper.navigation.$prevEl;
|
8255 | }
|
8256 |
|
8257 | if ($nextEl && $nextEl.length) {
|
8258 | initNavEl($nextEl, wrapperId, params.nextSlideMessage);
|
8259 | }
|
8260 |
|
8261 | if ($prevEl && $prevEl.length) {
|
8262 | initNavEl($prevEl, wrapperId, params.prevSlideMessage);
|
8263 | }
|
8264 |
|
8265 |
|
8266 | if (hasClickablePagination()) {
|
8267 | swiper.pagination.$el.on('keydown', classesToSelector(swiper.params.pagination.bulletClass), onEnterOrSpaceKey);
|
8268 | }
|
8269 |
|
8270 |
|
8271 | swiper.$el.on('focus', handleFocus, true);
|
8272 | }
|
8273 |
|
8274 | function destroy() {
|
8275 | if (liveRegion && liveRegion.length > 0) liveRegion.remove();
|
8276 | let $nextEl;
|
8277 | let $prevEl;
|
8278 |
|
8279 | if (swiper.navigation && swiper.navigation.$nextEl) {
|
8280 | $nextEl = swiper.navigation.$nextEl;
|
8281 | }
|
8282 |
|
8283 | if (swiper.navigation && swiper.navigation.$prevEl) {
|
8284 | $prevEl = swiper.navigation.$prevEl;
|
8285 | }
|
8286 |
|
8287 | if ($nextEl) {
|
8288 | $nextEl.off('keydown', onEnterOrSpaceKey);
|
8289 | }
|
8290 |
|
8291 | if ($prevEl) {
|
8292 | $prevEl.off('keydown', onEnterOrSpaceKey);
|
8293 | }
|
8294 |
|
8295 |
|
8296 | if (hasClickablePagination()) {
|
8297 | swiper.pagination.$el.off('keydown', classesToSelector(swiper.params.pagination.bulletClass), onEnterOrSpaceKey);
|
8298 | }
|
8299 |
|
8300 |
|
8301 | swiper.$el.off('focus', handleFocus, true);
|
8302 | }
|
8303 |
|
8304 | on('beforeInit', () => {
|
8305 | liveRegion = $(`<span class="${swiper.params.a11y.notificationClass}" aria-live="assertive" aria-atomic="true"></span>`);
|
8306 | });
|
8307 | on('afterInit', () => {
|
8308 | if (!swiper.params.a11y.enabled) return;
|
8309 | init();
|
8310 | });
|
8311 | on('fromEdge toEdge afterInit lock unlock', () => {
|
8312 | if (!swiper.params.a11y.enabled) return;
|
8313 | updateNavigation();
|
8314 | });
|
8315 | on('paginationUpdate', () => {
|
8316 | if (!swiper.params.a11y.enabled) return;
|
8317 | updatePagination();
|
8318 | });
|
8319 | on('destroy', () => {
|
8320 | if (!swiper.params.a11y.enabled) return;
|
8321 | destroy();
|
8322 | });
|
8323 | }
|
8324 |
|
8325 | function History(_ref) {
|
8326 | let {
|
8327 | swiper,
|
8328 | extendParams,
|
8329 | on
|
8330 | } = _ref;
|
8331 | extendParams({
|
8332 | history: {
|
8333 | enabled: false,
|
8334 | root: '',
|
8335 | replaceState: false,
|
8336 | key: 'slides'
|
8337 | }
|
8338 | });
|
8339 | let initialized = false;
|
8340 | let paths = {};
|
8341 |
|
8342 | const slugify = text => {
|
8343 | return text.toString().replace(/\s+/g, '-').replace(/[^\w-]+/g, '').replace(/--+/g, '-').replace(/^-+/, '').replace(/-+$/, '');
|
8344 | };
|
8345 |
|
8346 | const getPathValues = urlOverride => {
|
8347 | const window = getWindow();
|
8348 | let location;
|
8349 |
|
8350 | if (urlOverride) {
|
8351 | location = new URL(urlOverride);
|
8352 | } else {
|
8353 | location = window.location;
|
8354 | }
|
8355 |
|
8356 | const pathArray = location.pathname.slice(1).split('/').filter(part => part !== '');
|
8357 | const total = pathArray.length;
|
8358 | const key = pathArray[total - 2];
|
8359 | const value = pathArray[total - 1];
|
8360 | return {
|
8361 | key,
|
8362 | value
|
8363 | };
|
8364 | };
|
8365 |
|
8366 | const setHistory = (key, index) => {
|
8367 | const window = getWindow();
|
8368 | if (!initialized || !swiper.params.history.enabled) return;
|
8369 | let location;
|
8370 |
|
8371 | if (swiper.params.url) {
|
8372 | location = new URL(swiper.params.url);
|
8373 | } else {
|
8374 | location = window.location;
|
8375 | }
|
8376 |
|
8377 | const slide = swiper.slides.eq(index);
|
8378 | let value = slugify(slide.attr('data-history'));
|
8379 |
|
8380 | if (swiper.params.history.root.length > 0) {
|
8381 | let root = swiper.params.history.root;
|
8382 | if (root[root.length - 1] === '/') root = root.slice(0, root.length - 1);
|
8383 | value = `${root}/${key}/${value}`;
|
8384 | } else if (!location.pathname.includes(key)) {
|
8385 | value = `${key}/${value}`;
|
8386 | }
|
8387 |
|
8388 | const currentState = window.history.state;
|
8389 |
|
8390 | if (currentState && currentState.value === value) {
|
8391 | return;
|
8392 | }
|
8393 |
|
8394 | if (swiper.params.history.replaceState) {
|
8395 | window.history.replaceState({
|
8396 | value
|
8397 | }, null, value);
|
8398 | } else {
|
8399 | window.history.pushState({
|
8400 | value
|
8401 | }, null, value);
|
8402 | }
|
8403 | };
|
8404 |
|
8405 | const scrollToSlide = (speed, value, runCallbacks) => {
|
8406 | if (value) {
|
8407 | for (let i = 0, length = swiper.slides.length; i < length; i += 1) {
|
8408 | const slide = swiper.slides.eq(i);
|
8409 | const slideHistory = slugify(slide.attr('data-history'));
|
8410 |
|
8411 | if (slideHistory === value && !slide.hasClass(swiper.params.slideDuplicateClass)) {
|
8412 | const index = slide.index();
|
8413 | swiper.slideTo(index, speed, runCallbacks);
|
8414 | }
|
8415 | }
|
8416 | } else {
|
8417 | swiper.slideTo(0, speed, runCallbacks);
|
8418 | }
|
8419 | };
|
8420 |
|
8421 | const setHistoryPopState = () => {
|
8422 | paths = getPathValues(swiper.params.url);
|
8423 | scrollToSlide(swiper.params.speed, swiper.paths.value, false);
|
8424 | };
|
8425 |
|
8426 | const init = () => {
|
8427 | const window = getWindow();
|
8428 | if (!swiper.params.history) return;
|
8429 |
|
8430 | if (!window.history || !window.history.pushState) {
|
8431 | swiper.params.history.enabled = false;
|
8432 | swiper.params.hashNavigation.enabled = true;
|
8433 | return;
|
8434 | }
|
8435 |
|
8436 | initialized = true;
|
8437 | paths = getPathValues(swiper.params.url);
|
8438 | if (!paths.key && !paths.value) return;
|
8439 | scrollToSlide(0, paths.value, swiper.params.runCallbacksOnInit);
|
8440 |
|
8441 | if (!swiper.params.history.replaceState) {
|
8442 | window.addEventListener('popstate', setHistoryPopState);
|
8443 | }
|
8444 | };
|
8445 |
|
8446 | const destroy = () => {
|
8447 | const window = getWindow();
|
8448 |
|
8449 | if (!swiper.params.history.replaceState) {
|
8450 | window.removeEventListener('popstate', setHistoryPopState);
|
8451 | }
|
8452 | };
|
8453 |
|
8454 | on('init', () => {
|
8455 | if (swiper.params.history.enabled) {
|
8456 | init();
|
8457 | }
|
8458 | });
|
8459 | on('destroy', () => {
|
8460 | if (swiper.params.history.enabled) {
|
8461 | destroy();
|
8462 | }
|
8463 | });
|
8464 | on('transitionEnd _freeModeNoMomentumRelease', () => {
|
8465 | if (initialized) {
|
8466 | setHistory(swiper.params.history.key, swiper.activeIndex);
|
8467 | }
|
8468 | });
|
8469 | on('slideChange', () => {
|
8470 | if (initialized && swiper.params.cssMode) {
|
8471 | setHistory(swiper.params.history.key, swiper.activeIndex);
|
8472 | }
|
8473 | });
|
8474 | }
|
8475 |
|
8476 | function HashNavigation(_ref) {
|
8477 | let {
|
8478 | swiper,
|
8479 | extendParams,
|
8480 | emit,
|
8481 | on
|
8482 | } = _ref;
|
8483 | let initialized = false;
|
8484 | const document = getDocument();
|
8485 | const window = getWindow();
|
8486 | extendParams({
|
8487 | hashNavigation: {
|
8488 | enabled: false,
|
8489 | replaceState: false,
|
8490 | watchState: false
|
8491 | }
|
8492 | });
|
8493 |
|
8494 | const onHashChange = () => {
|
8495 | emit('hashChange');
|
8496 | const newHash = document.location.hash.replace('#', '');
|
8497 | const activeSlideHash = swiper.slides.eq(swiper.activeIndex).attr('data-hash');
|
8498 |
|
8499 | if (newHash !== activeSlideHash) {
|
8500 | const newIndex = swiper.$wrapperEl.children(`.${swiper.params.slideClass}[data-hash="${newHash}"]`).index();
|
8501 | if (typeof newIndex === 'undefined') return;
|
8502 | swiper.slideTo(newIndex);
|
8503 | }
|
8504 | };
|
8505 |
|
8506 | const setHash = () => {
|
8507 | if (!initialized || !swiper.params.hashNavigation.enabled) return;
|
8508 |
|
8509 | if (swiper.params.hashNavigation.replaceState && window.history && window.history.replaceState) {
|
8510 | window.history.replaceState(null, null, `#${swiper.slides.eq(swiper.activeIndex).attr('data-hash')}` || '');
|
8511 | emit('hashSet');
|
8512 | } else {
|
8513 | const slide = swiper.slides.eq(swiper.activeIndex);
|
8514 | const hash = slide.attr('data-hash') || slide.attr('data-history');
|
8515 | document.location.hash = hash || '';
|
8516 | emit('hashSet');
|
8517 | }
|
8518 | };
|
8519 |
|
8520 | const init = () => {
|
8521 | if (!swiper.params.hashNavigation.enabled || swiper.params.history && swiper.params.history.enabled) return;
|
8522 | initialized = true;
|
8523 | const hash = document.location.hash.replace('#', '');
|
8524 |
|
8525 | if (hash) {
|
8526 | const speed = 0;
|
8527 |
|
8528 | for (let i = 0, length = swiper.slides.length; i < length; i += 1) {
|
8529 | const slide = swiper.slides.eq(i);
|
8530 | const slideHash = slide.attr('data-hash') || slide.attr('data-history');
|
8531 |
|
8532 | if (slideHash === hash && !slide.hasClass(swiper.params.slideDuplicateClass)) {
|
8533 | const index = slide.index();
|
8534 | swiper.slideTo(index, speed, swiper.params.runCallbacksOnInit, true);
|
8535 | }
|
8536 | }
|
8537 | }
|
8538 |
|
8539 | if (swiper.params.hashNavigation.watchState) {
|
8540 | $(window).on('hashchange', onHashChange);
|
8541 | }
|
8542 | };
|
8543 |
|
8544 | const destroy = () => {
|
8545 | if (swiper.params.hashNavigation.watchState) {
|
8546 | $(window).off('hashchange', onHashChange);
|
8547 | }
|
8548 | };
|
8549 |
|
8550 | on('init', () => {
|
8551 | if (swiper.params.hashNavigation.enabled) {
|
8552 | init();
|
8553 | }
|
8554 | });
|
8555 | on('destroy', () => {
|
8556 | if (swiper.params.hashNavigation.enabled) {
|
8557 | destroy();
|
8558 | }
|
8559 | });
|
8560 | on('transitionEnd _freeModeNoMomentumRelease', () => {
|
8561 | if (initialized) {
|
8562 | setHash();
|
8563 | }
|
8564 | });
|
8565 | on('slideChange', () => {
|
8566 | if (initialized && swiper.params.cssMode) {
|
8567 | setHash();
|
8568 | }
|
8569 | });
|
8570 | }
|
8571 |
|
8572 |
|
8573 | function Autoplay(_ref) {
|
8574 | let {
|
8575 | swiper,
|
8576 | extendParams,
|
8577 | on,
|
8578 | emit
|
8579 | } = _ref;
|
8580 | let timeout;
|
8581 | swiper.autoplay = {
|
8582 | running: false,
|
8583 | paused: false
|
8584 | };
|
8585 | extendParams({
|
8586 | autoplay: {
|
8587 | enabled: false,
|
8588 | delay: 3000,
|
8589 | waitForTransition: true,
|
8590 | disableOnInteraction: true,
|
8591 | stopOnLastSlide: false,
|
8592 | reverseDirection: false,
|
8593 | pauseOnMouseEnter: false
|
8594 | }
|
8595 | });
|
8596 |
|
8597 | function run() {
|
8598 | const $activeSlideEl = swiper.slides.eq(swiper.activeIndex);
|
8599 | let delay = swiper.params.autoplay.delay;
|
8600 |
|
8601 | if ($activeSlideEl.attr('data-swiper-autoplay')) {
|
8602 | delay = $activeSlideEl.attr('data-swiper-autoplay') || swiper.params.autoplay.delay;
|
8603 | }
|
8604 |
|
8605 | clearTimeout(timeout);
|
8606 | timeout = nextTick(() => {
|
8607 | let autoplayResult;
|
8608 |
|
8609 | if (swiper.params.autoplay.reverseDirection) {
|
8610 | if (swiper.params.loop) {
|
8611 | swiper.loopFix();
|
8612 | autoplayResult = swiper.slidePrev(swiper.params.speed, true, true);
|
8613 | emit('autoplay');
|
8614 | } else if (!swiper.isBeginning) {
|
8615 | autoplayResult = swiper.slidePrev(swiper.params.speed, true, true);
|
8616 | emit('autoplay');
|
8617 | } else if (!swiper.params.autoplay.stopOnLastSlide) {
|
8618 | autoplayResult = swiper.slideTo(swiper.slides.length - 1, swiper.params.speed, true, true);
|
8619 | emit('autoplay');
|
8620 | } else {
|
8621 | stop();
|
8622 | }
|
8623 | } else if (swiper.params.loop) {
|
8624 | swiper.loopFix();
|
8625 | autoplayResult = swiper.slideNext(swiper.params.speed, true, true);
|
8626 | emit('autoplay');
|
8627 | } else if (!swiper.isEnd) {
|
8628 | autoplayResult = swiper.slideNext(swiper.params.speed, true, true);
|
8629 | emit('autoplay');
|
8630 | } else if (!swiper.params.autoplay.stopOnLastSlide) {
|
8631 | autoplayResult = swiper.slideTo(0, swiper.params.speed, true, true);
|
8632 | emit('autoplay');
|
8633 | } else {
|
8634 | stop();
|
8635 | }
|
8636 |
|
8637 | if (swiper.params.cssMode && swiper.autoplay.running) run();else if (autoplayResult === false) {
|
8638 | run();
|
8639 | }
|
8640 | }, delay);
|
8641 | }
|
8642 |
|
8643 | function start() {
|
8644 | if (typeof timeout !== 'undefined') return false;
|
8645 | if (swiper.autoplay.running) return false;
|
8646 | swiper.autoplay.running = true;
|
8647 | emit('autoplayStart');
|
8648 | run();
|
8649 | return true;
|
8650 | }
|
8651 |
|
8652 | function stop() {
|
8653 | if (!swiper.autoplay.running) return false;
|
8654 | if (typeof timeout === 'undefined') return false;
|
8655 |
|
8656 | if (timeout) {
|
8657 | clearTimeout(timeout);
|
8658 | timeout = undefined;
|
8659 | }
|
8660 |
|
8661 | swiper.autoplay.running = false;
|
8662 | emit('autoplayStop');
|
8663 | return true;
|
8664 | }
|
8665 |
|
8666 | function pause(speed) {
|
8667 | if (!swiper.autoplay.running) return;
|
8668 | if (swiper.autoplay.paused) return;
|
8669 | if (timeout) clearTimeout(timeout);
|
8670 | swiper.autoplay.paused = true;
|
8671 |
|
8672 | if (speed === 0 || !swiper.params.autoplay.waitForTransition) {
|
8673 | swiper.autoplay.paused = false;
|
8674 | run();
|
8675 | } else {
|
8676 | ['transitionend', 'webkitTransitionEnd'].forEach(event => {
|
8677 | swiper.$wrapperEl[0].addEventListener(event, onTransitionEnd);
|
8678 | });
|
8679 | }
|
8680 | }
|
8681 |
|
8682 | function onVisibilityChange() {
|
8683 | const document = getDocument();
|
8684 |
|
8685 | if (document.visibilityState === 'hidden' && swiper.autoplay.running) {
|
8686 | pause();
|
8687 | }
|
8688 |
|
8689 | if (document.visibilityState === 'visible' && swiper.autoplay.paused) {
|
8690 | run();
|
8691 | swiper.autoplay.paused = false;
|
8692 | }
|
8693 | }
|
8694 |
|
8695 | function onTransitionEnd(e) {
|
8696 | if (!swiper || swiper.destroyed || !swiper.$wrapperEl) return;
|
8697 | if (e.target !== swiper.$wrapperEl[0]) return;
|
8698 | ['transitionend', 'webkitTransitionEnd'].forEach(event => {
|
8699 | swiper.$wrapperEl[0].removeEventListener(event, onTransitionEnd);
|
8700 | });
|
8701 | swiper.autoplay.paused = false;
|
8702 |
|
8703 | if (!swiper.autoplay.running) {
|
8704 | stop();
|
8705 | } else {
|
8706 | run();
|
8707 | }
|
8708 | }
|
8709 |
|
8710 | function onMouseEnter() {
|
8711 | if (swiper.params.autoplay.disableOnInteraction) {
|
8712 | stop();
|
8713 | } else {
|
8714 | emit('autoplayPause');
|
8715 | pause();
|
8716 | }
|
8717 |
|
8718 | ['transitionend', 'webkitTransitionEnd'].forEach(event => {
|
8719 | swiper.$wrapperEl[0].removeEventListener(event, onTransitionEnd);
|
8720 | });
|
8721 | }
|
8722 |
|
8723 | function onMouseLeave() {
|
8724 | if (swiper.params.autoplay.disableOnInteraction) {
|
8725 | return;
|
8726 | }
|
8727 |
|
8728 | swiper.autoplay.paused = false;
|
8729 | emit('autoplayResume');
|
8730 | run();
|
8731 | }
|
8732 |
|
8733 | function attachMouseEvents() {
|
8734 | if (swiper.params.autoplay.pauseOnMouseEnter) {
|
8735 | swiper.$el.on('mouseenter', onMouseEnter);
|
8736 | swiper.$el.on('mouseleave', onMouseLeave);
|
8737 | }
|
8738 | }
|
8739 |
|
8740 | function detachMouseEvents() {
|
8741 | swiper.$el.off('mouseenter', onMouseEnter);
|
8742 | swiper.$el.off('mouseleave', onMouseLeave);
|
8743 | }
|
8744 |
|
8745 | on('init', () => {
|
8746 | if (swiper.params.autoplay.enabled) {
|
8747 | start();
|
8748 | const document = getDocument();
|
8749 | document.addEventListener('visibilitychange', onVisibilityChange);
|
8750 | attachMouseEvents();
|
8751 | }
|
8752 | });
|
8753 | on('beforeTransitionStart', (_s, speed, internal) => {
|
8754 | if (swiper.autoplay.running) {
|
8755 | if (internal || !swiper.params.autoplay.disableOnInteraction) {
|
8756 | swiper.autoplay.pause(speed);
|
8757 | } else {
|
8758 | stop();
|
8759 | }
|
8760 | }
|
8761 | });
|
8762 | on('sliderFirstMove', () => {
|
8763 | if (swiper.autoplay.running) {
|
8764 | if (swiper.params.autoplay.disableOnInteraction) {
|
8765 | stop();
|
8766 | } else {
|
8767 | pause();
|
8768 | }
|
8769 | }
|
8770 | });
|
8771 | on('touchEnd', () => {
|
8772 | if (swiper.params.cssMode && swiper.autoplay.paused && !swiper.params.autoplay.disableOnInteraction) {
|
8773 | run();
|
8774 | }
|
8775 | });
|
8776 | on('destroy', () => {
|
8777 | detachMouseEvents();
|
8778 |
|
8779 | if (swiper.autoplay.running) {
|
8780 | stop();
|
8781 | }
|
8782 |
|
8783 | const document = getDocument();
|
8784 | document.removeEventListener('visibilitychange', onVisibilityChange);
|
8785 | });
|
8786 | Object.assign(swiper.autoplay, {
|
8787 | pause,
|
8788 | run,
|
8789 | start,
|
8790 | stop
|
8791 | });
|
8792 | }
|
8793 |
|
8794 | function Thumb(_ref) {
|
8795 | let {
|
8796 | swiper,
|
8797 | extendParams,
|
8798 | on
|
8799 | } = _ref;
|
8800 | extendParams({
|
8801 | thumbs: {
|
8802 | swiper: null,
|
8803 | multipleActiveThumbs: true,
|
8804 | autoScrollOffset: 0,
|
8805 | slideThumbActiveClass: 'swiper-slide-thumb-active',
|
8806 | thumbsContainerClass: 'swiper-thumbs'
|
8807 | }
|
8808 | });
|
8809 | let initialized = false;
|
8810 | let swiperCreated = false;
|
8811 | swiper.thumbs = {
|
8812 | swiper: null
|
8813 | };
|
8814 |
|
8815 | function onThumbClick() {
|
8816 | const thumbsSwiper = swiper.thumbs.swiper;
|
8817 | if (!thumbsSwiper) return;
|
8818 | const clickedIndex = thumbsSwiper.clickedIndex;
|
8819 | const clickedSlide = thumbsSwiper.clickedSlide;
|
8820 | if (clickedSlide && $(clickedSlide).hasClass(swiper.params.thumbs.slideThumbActiveClass)) return;
|
8821 | if (typeof clickedIndex === 'undefined' || clickedIndex === null) return;
|
8822 | let slideToIndex;
|
8823 |
|
8824 | if (thumbsSwiper.params.loop) {
|
8825 | slideToIndex = parseInt($(thumbsSwiper.clickedSlide).attr('data-swiper-slide-index'), 10);
|
8826 | } else {
|
8827 | slideToIndex = clickedIndex;
|
8828 | }
|
8829 |
|
8830 | if (swiper.params.loop) {
|
8831 | let currentIndex = swiper.activeIndex;
|
8832 |
|
8833 | if (swiper.slides.eq(currentIndex).hasClass(swiper.params.slideDuplicateClass)) {
|
8834 | swiper.loopFix();
|
8835 |
|
8836 | swiper._clientLeft = swiper.$wrapperEl[0].clientLeft;
|
8837 | currentIndex = swiper.activeIndex;
|
8838 | }
|
8839 |
|
8840 | const prevIndex = swiper.slides.eq(currentIndex).prevAll(`[data-swiper-slide-index="${slideToIndex}"]`).eq(0).index();
|
8841 | const nextIndex = swiper.slides.eq(currentIndex).nextAll(`[data-swiper-slide-index="${slideToIndex}"]`).eq(0).index();
|
8842 | if (typeof prevIndex === 'undefined') slideToIndex = nextIndex;else if (typeof nextIndex === 'undefined') slideToIndex = prevIndex;else if (nextIndex - currentIndex < currentIndex - prevIndex) slideToIndex = nextIndex;else slideToIndex = prevIndex;
|
8843 | }
|
8844 |
|
8845 | swiper.slideTo(slideToIndex);
|
8846 | }
|
8847 |
|
8848 | function init() {
|
8849 | const {
|
8850 | thumbs: thumbsParams
|
8851 | } = swiper.params;
|
8852 | if (initialized) return false;
|
8853 | initialized = true;
|
8854 | const SwiperClass = swiper.constructor;
|
8855 |
|
8856 | if (thumbsParams.swiper instanceof SwiperClass) {
|
8857 | swiper.thumbs.swiper = thumbsParams.swiper;
|
8858 | Object.assign(swiper.thumbs.swiper.originalParams, {
|
8859 | watchSlidesProgress: true,
|
8860 | slideToClickedSlide: false
|
8861 | });
|
8862 | Object.assign(swiper.thumbs.swiper.params, {
|
8863 | watchSlidesProgress: true,
|
8864 | slideToClickedSlide: false
|
8865 | });
|
8866 | } else if (isObject(thumbsParams.swiper)) {
|
8867 | const thumbsSwiperParams = Object.assign({}, thumbsParams.swiper);
|
8868 | Object.assign(thumbsSwiperParams, {
|
8869 | watchSlidesProgress: true,
|
8870 | slideToClickedSlide: false
|
8871 | });
|
8872 | swiper.thumbs.swiper = new SwiperClass(thumbsSwiperParams);
|
8873 | swiperCreated = true;
|
8874 | }
|
8875 |
|
8876 | swiper.thumbs.swiper.$el.addClass(swiper.params.thumbs.thumbsContainerClass);
|
8877 | swiper.thumbs.swiper.on('tap', onThumbClick);
|
8878 | return true;
|
8879 | }
|
8880 |
|
8881 | function update(initial) {
|
8882 | const thumbsSwiper = swiper.thumbs.swiper;
|
8883 | if (!thumbsSwiper) return;
|
8884 | const slidesPerView = thumbsSwiper.params.slidesPerView === 'auto' ? thumbsSwiper.slidesPerViewDynamic() : thumbsSwiper.params.slidesPerView;
|
8885 | const autoScrollOffset = swiper.params.thumbs.autoScrollOffset;
|
8886 | const useOffset = autoScrollOffset && !thumbsSwiper.params.loop;
|
8887 |
|
8888 | if (swiper.realIndex !== thumbsSwiper.realIndex || useOffset) {
|
8889 | let currentThumbsIndex = thumbsSwiper.activeIndex;
|
8890 | let newThumbsIndex;
|
8891 | let direction;
|
8892 |
|
8893 | if (thumbsSwiper.params.loop) {
|
8894 | if (thumbsSwiper.slides.eq(currentThumbsIndex).hasClass(thumbsSwiper.params.slideDuplicateClass)) {
|
8895 | thumbsSwiper.loopFix();
|
8896 |
|
8897 | thumbsSwiper._clientLeft = thumbsSwiper.$wrapperEl[0].clientLeft;
|
8898 | currentThumbsIndex = thumbsSwiper.activeIndex;
|
8899 | }
|
8900 |
|
8901 |
|
8902 | const prevThumbsIndex = thumbsSwiper.slides.eq(currentThumbsIndex).prevAll(`[data-swiper-slide-index="${swiper.realIndex}"]`).eq(0).index();
|
8903 | const nextThumbsIndex = thumbsSwiper.slides.eq(currentThumbsIndex).nextAll(`[data-swiper-slide-index="${swiper.realIndex}"]`).eq(0).index();
|
8904 |
|
8905 | if (typeof prevThumbsIndex === 'undefined') {
|
8906 | newThumbsIndex = nextThumbsIndex;
|
8907 | } else if (typeof nextThumbsIndex === 'undefined') {
|
8908 | newThumbsIndex = prevThumbsIndex;
|
8909 | } else if (nextThumbsIndex - currentThumbsIndex === currentThumbsIndex - prevThumbsIndex) {
|
8910 | newThumbsIndex = thumbsSwiper.params.slidesPerGroup > 1 ? nextThumbsIndex : currentThumbsIndex;
|
8911 | } else if (nextThumbsIndex - currentThumbsIndex < currentThumbsIndex - prevThumbsIndex) {
|
8912 | newThumbsIndex = nextThumbsIndex;
|
8913 | } else {
|
8914 | newThumbsIndex = prevThumbsIndex;
|
8915 | }
|
8916 |
|
8917 | direction = swiper.activeIndex > swiper.previousIndex ? 'next' : 'prev';
|
8918 | } else {
|
8919 | newThumbsIndex = swiper.realIndex;
|
8920 | direction = newThumbsIndex > swiper.previousIndex ? 'next' : 'prev';
|
8921 | }
|
8922 |
|
8923 | if (useOffset) {
|
8924 | newThumbsIndex += direction === 'next' ? autoScrollOffset : -1 * autoScrollOffset;
|
8925 | }
|
8926 |
|
8927 | if (thumbsSwiper.visibleSlidesIndexes && thumbsSwiper.visibleSlidesIndexes.indexOf(newThumbsIndex) < 0) {
|
8928 | if (thumbsSwiper.params.centeredSlides) {
|
8929 | if (newThumbsIndex > currentThumbsIndex) {
|
8930 | newThumbsIndex = newThumbsIndex - Math.floor(slidesPerView / 2) + 1;
|
8931 | } else {
|
8932 | newThumbsIndex = newThumbsIndex + Math.floor(slidesPerView / 2) - 1;
|
8933 | }
|
8934 | } else if (newThumbsIndex > currentThumbsIndex && thumbsSwiper.params.slidesPerGroup === 1) ;
|
8935 |
|
8936 | thumbsSwiper.slideTo(newThumbsIndex, initial ? 0 : undefined);
|
8937 | }
|
8938 | }
|
8939 |
|
8940 |
|
8941 | let thumbsToActivate = 1;
|
8942 | const thumbActiveClass = swiper.params.thumbs.slideThumbActiveClass;
|
8943 |
|
8944 | if (swiper.params.slidesPerView > 1 && !swiper.params.centeredSlides) {
|
8945 | thumbsToActivate = swiper.params.slidesPerView;
|
8946 | }
|
8947 |
|
8948 | if (!swiper.params.thumbs.multipleActiveThumbs) {
|
8949 | thumbsToActivate = 1;
|
8950 | }
|
8951 |
|
8952 | thumbsToActivate = Math.floor(thumbsToActivate);
|
8953 | thumbsSwiper.slides.removeClass(thumbActiveClass);
|
8954 |
|
8955 | if (thumbsSwiper.params.loop || thumbsSwiper.params.virtual && thumbsSwiper.params.virtual.enabled) {
|
8956 | for (let i = 0; i < thumbsToActivate; i += 1) {
|
8957 | thumbsSwiper.$wrapperEl.children(`[data-swiper-slide-index="${swiper.realIndex + i}"]`).addClass(thumbActiveClass);
|
8958 | }
|
8959 | } else {
|
8960 | for (let i = 0; i < thumbsToActivate; i += 1) {
|
8961 | thumbsSwiper.slides.eq(swiper.realIndex + i).addClass(thumbActiveClass);
|
8962 | }
|
8963 | }
|
8964 | }
|
8965 |
|
8966 | on('beforeInit', () => {
|
8967 | const {
|
8968 | thumbs
|
8969 | } = swiper.params;
|
8970 | if (!thumbs || !thumbs.swiper) return;
|
8971 | init();
|
8972 | update(true);
|
8973 | });
|
8974 | on('slideChange update resize observerUpdate', () => {
|
8975 | if (!swiper.thumbs.swiper) return;
|
8976 | update();
|
8977 | });
|
8978 | on('setTransition', (_s, duration) => {
|
8979 | const thumbsSwiper = swiper.thumbs.swiper;
|
8980 | if (!thumbsSwiper) return;
|
8981 | thumbsSwiper.setTransition(duration);
|
8982 | });
|
8983 | on('beforeDestroy', () => {
|
8984 | const thumbsSwiper = swiper.thumbs.swiper;
|
8985 | if (!thumbsSwiper) return;
|
8986 |
|
8987 | if (swiperCreated && thumbsSwiper) {
|
8988 | thumbsSwiper.destroy();
|
8989 | }
|
8990 | });
|
8991 | Object.assign(swiper.thumbs, {
|
8992 | init,
|
8993 | update
|
8994 | });
|
8995 | }
|
8996 |
|
8997 | function freeMode(_ref) {
|
8998 | let {
|
8999 | swiper,
|
9000 | extendParams,
|
9001 | emit,
|
9002 | once
|
9003 | } = _ref;
|
9004 | extendParams({
|
9005 | freeMode: {
|
9006 | enabled: false,
|
9007 | momentum: true,
|
9008 | momentumRatio: 1,
|
9009 | momentumBounce: true,
|
9010 | momentumBounceRatio: 1,
|
9011 | momentumVelocityRatio: 1,
|
9012 | sticky: false,
|
9013 | minimumVelocity: 0.02
|
9014 | }
|
9015 | });
|
9016 |
|
9017 | function onTouchStart() {
|
9018 | const translate = swiper.getTranslate();
|
9019 | swiper.setTranslate(translate);
|
9020 | swiper.setTransition(0);
|
9021 | swiper.touchEventsData.velocities.length = 0;
|
9022 | swiper.freeMode.onTouchEnd({
|
9023 | currentPos: swiper.rtl ? swiper.translate : -swiper.translate
|
9024 | });
|
9025 | }
|
9026 |
|
9027 | function onTouchMove() {
|
9028 | const {
|
9029 | touchEventsData: data,
|
9030 | touches
|
9031 | } = swiper;
|
9032 |
|
9033 | if (data.velocities.length === 0) {
|
9034 | data.velocities.push({
|
9035 | position: touches[swiper.isHorizontal() ? 'startX' : 'startY'],
|
9036 | time: data.touchStartTime
|
9037 | });
|
9038 | }
|
9039 |
|
9040 | data.velocities.push({
|
9041 | position: touches[swiper.isHorizontal() ? 'currentX' : 'currentY'],
|
9042 | time: now()
|
9043 | });
|
9044 | }
|
9045 |
|
9046 | function onTouchEnd(_ref2) {
|
9047 | let {
|
9048 | currentPos
|
9049 | } = _ref2;
|
9050 | const {
|
9051 | params,
|
9052 | $wrapperEl,
|
9053 | rtlTranslate: rtl,
|
9054 | snapGrid,
|
9055 | touchEventsData: data
|
9056 | } = swiper;
|
9057 |
|
9058 | const touchEndTime = now();
|
9059 | const timeDiff = touchEndTime - data.touchStartTime;
|
9060 |
|
9061 | if (currentPos < -swiper.minTranslate()) {
|
9062 | swiper.slideTo(swiper.activeIndex);
|
9063 | return;
|
9064 | }
|
9065 |
|
9066 | if (currentPos > -swiper.maxTranslate()) {
|
9067 | if (swiper.slides.length < snapGrid.length) {
|
9068 | swiper.slideTo(snapGrid.length - 1);
|
9069 | } else {
|
9070 | swiper.slideTo(swiper.slides.length - 1);
|
9071 | }
|
9072 |
|
9073 | return;
|
9074 | }
|
9075 |
|
9076 | if (params.freeMode.momentum) {
|
9077 | if (data.velocities.length > 1) {
|
9078 | const lastMoveEvent = data.velocities.pop();
|
9079 | const velocityEvent = data.velocities.pop();
|
9080 | const distance = lastMoveEvent.position - velocityEvent.position;
|
9081 | const time = lastMoveEvent.time - velocityEvent.time;
|
9082 | swiper.velocity = distance / time;
|
9083 | swiper.velocity /= 2;
|
9084 |
|
9085 | if (Math.abs(swiper.velocity) < params.freeMode.minimumVelocity) {
|
9086 | swiper.velocity = 0;
|
9087 | }
|
9088 |
|
9089 |
|
9090 |
|
9091 | if (time > 150 || now() - lastMoveEvent.time > 300) {
|
9092 | swiper.velocity = 0;
|
9093 | }
|
9094 | } else {
|
9095 | swiper.velocity = 0;
|
9096 | }
|
9097 |
|
9098 | swiper.velocity *= params.freeMode.momentumVelocityRatio;
|
9099 | data.velocities.length = 0;
|
9100 | let momentumDuration = 1000 * params.freeMode.momentumRatio;
|
9101 | const momentumDistance = swiper.velocity * momentumDuration;
|
9102 | let newPosition = swiper.translate + momentumDistance;
|
9103 | if (rtl) newPosition = -newPosition;
|
9104 | let doBounce = false;
|
9105 | let afterBouncePosition;
|
9106 | const bounceAmount = Math.abs(swiper.velocity) * 20 * params.freeMode.momentumBounceRatio;
|
9107 | let needsLoopFix;
|
9108 |
|
9109 | if (newPosition < swiper.maxTranslate()) {
|
9110 | if (params.freeMode.momentumBounce) {
|
9111 | if (newPosition + swiper.maxTranslate() < -bounceAmount) {
|
9112 | newPosition = swiper.maxTranslate() - bounceAmount;
|
9113 | }
|
9114 |
|
9115 | afterBouncePosition = swiper.maxTranslate();
|
9116 | doBounce = true;
|
9117 | data.allowMomentumBounce = true;
|
9118 | } else {
|
9119 | newPosition = swiper.maxTranslate();
|
9120 | }
|
9121 |
|
9122 | if (params.loop && params.centeredSlides) needsLoopFix = true;
|
9123 | } else if (newPosition > swiper.minTranslate()) {
|
9124 | if (params.freeMode.momentumBounce) {
|
9125 | if (newPosition - swiper.minTranslate() > bounceAmount) {
|
9126 | newPosition = swiper.minTranslate() + bounceAmount;
|
9127 | }
|
9128 |
|
9129 | afterBouncePosition = swiper.minTranslate();
|
9130 | doBounce = true;
|
9131 | data.allowMomentumBounce = true;
|
9132 | } else {
|
9133 | newPosition = swiper.minTranslate();
|
9134 | }
|
9135 |
|
9136 | if (params.loop && params.centeredSlides) needsLoopFix = true;
|
9137 | } else if (params.freeMode.sticky) {
|
9138 | let nextSlide;
|
9139 |
|
9140 | for (let j = 0; j < snapGrid.length; j += 1) {
|
9141 | if (snapGrid[j] > -newPosition) {
|
9142 | nextSlide = j;
|
9143 | break;
|
9144 | }
|
9145 | }
|
9146 |
|
9147 | if (Math.abs(snapGrid[nextSlide] - newPosition) < Math.abs(snapGrid[nextSlide - 1] - newPosition) || swiper.swipeDirection === 'next') {
|
9148 | newPosition = snapGrid[nextSlide];
|
9149 | } else {
|
9150 | newPosition = snapGrid[nextSlide - 1];
|
9151 | }
|
9152 |
|
9153 | newPosition = -newPosition;
|
9154 | }
|
9155 |
|
9156 | if (needsLoopFix) {
|
9157 | once('transitionEnd', () => {
|
9158 | swiper.loopFix();
|
9159 | });
|
9160 | }
|
9161 |
|
9162 |
|
9163 | if (swiper.velocity !== 0) {
|
9164 | if (rtl) {
|
9165 | momentumDuration = Math.abs((-newPosition - swiper.translate) / swiper.velocity);
|
9166 | } else {
|
9167 | momentumDuration = Math.abs((newPosition - swiper.translate) / swiper.velocity);
|
9168 | }
|
9169 |
|
9170 | if (params.freeMode.sticky) {
|
9171 |
|
9172 |
|
9173 |
|
9174 |
|
9175 |
|
9176 |
|
9177 |
|
9178 | const moveDistance = Math.abs((rtl ? -newPosition : newPosition) - swiper.translate);
|
9179 | const currentSlideSize = swiper.slidesSizesGrid[swiper.activeIndex];
|
9180 |
|
9181 | if (moveDistance < currentSlideSize) {
|
9182 | momentumDuration = params.speed;
|
9183 | } else if (moveDistance < 2 * currentSlideSize) {
|
9184 | momentumDuration = params.speed * 1.5;
|
9185 | } else {
|
9186 | momentumDuration = params.speed * 2.5;
|
9187 | }
|
9188 | }
|
9189 | } else if (params.freeMode.sticky) {
|
9190 | swiper.slideToClosest();
|
9191 | return;
|
9192 | }
|
9193 |
|
9194 | if (params.freeMode.momentumBounce && doBounce) {
|
9195 | swiper.updateProgress(afterBouncePosition);
|
9196 | swiper.setTransition(momentumDuration);
|
9197 | swiper.setTranslate(newPosition);
|
9198 | swiper.transitionStart(true, swiper.swipeDirection);
|
9199 | swiper.animating = true;
|
9200 | $wrapperEl.transitionEnd(() => {
|
9201 | if (!swiper || swiper.destroyed || !data.allowMomentumBounce) return;
|
9202 | emit('momentumBounce');
|
9203 | swiper.setTransition(params.speed);
|
9204 | setTimeout(() => {
|
9205 | swiper.setTranslate(afterBouncePosition);
|
9206 | $wrapperEl.transitionEnd(() => {
|
9207 | if (!swiper || swiper.destroyed) return;
|
9208 | swiper.transitionEnd();
|
9209 | });
|
9210 | }, 0);
|
9211 | });
|
9212 | } else if (swiper.velocity) {
|
9213 | emit('_freeModeNoMomentumRelease');
|
9214 | swiper.updateProgress(newPosition);
|
9215 | swiper.setTransition(momentumDuration);
|
9216 | swiper.setTranslate(newPosition);
|
9217 | swiper.transitionStart(true, swiper.swipeDirection);
|
9218 |
|
9219 | if (!swiper.animating) {
|
9220 | swiper.animating = true;
|
9221 | $wrapperEl.transitionEnd(() => {
|
9222 | if (!swiper || swiper.destroyed) return;
|
9223 | swiper.transitionEnd();
|
9224 | });
|
9225 | }
|
9226 | } else {
|
9227 | swiper.updateProgress(newPosition);
|
9228 | }
|
9229 |
|
9230 | swiper.updateActiveIndex();
|
9231 | swiper.updateSlidesClasses();
|
9232 | } else if (params.freeMode.sticky) {
|
9233 | swiper.slideToClosest();
|
9234 | return;
|
9235 | } else if (params.freeMode) {
|
9236 | emit('_freeModeNoMomentumRelease');
|
9237 | }
|
9238 |
|
9239 | if (!params.freeMode.momentum || timeDiff >= params.longSwipesMs) {
|
9240 | swiper.updateProgress();
|
9241 | swiper.updateActiveIndex();
|
9242 | swiper.updateSlidesClasses();
|
9243 | }
|
9244 | }
|
9245 |
|
9246 | Object.assign(swiper, {
|
9247 | freeMode: {
|
9248 | onTouchStart,
|
9249 | onTouchMove,
|
9250 | onTouchEnd
|
9251 | }
|
9252 | });
|
9253 | }
|
9254 |
|
9255 | function Grid(_ref) {
|
9256 | let {
|
9257 | swiper,
|
9258 | extendParams
|
9259 | } = _ref;
|
9260 | extendParams({
|
9261 | grid: {
|
9262 | rows: 1,
|
9263 | fill: 'column'
|
9264 | }
|
9265 | });
|
9266 | let slidesNumberEvenToRows;
|
9267 | let slidesPerRow;
|
9268 | let numFullColumns;
|
9269 |
|
9270 | const initSlides = slidesLength => {
|
9271 | const {
|
9272 | slidesPerView
|
9273 | } = swiper.params;
|
9274 | const {
|
9275 | rows,
|
9276 | fill
|
9277 | } = swiper.params.grid;
|
9278 | slidesPerRow = slidesNumberEvenToRows / rows;
|
9279 | numFullColumns = Math.floor(slidesLength / rows);
|
9280 |
|
9281 | if (Math.floor(slidesLength / rows) === slidesLength / rows) {
|
9282 | slidesNumberEvenToRows = slidesLength;
|
9283 | } else {
|
9284 | slidesNumberEvenToRows = Math.ceil(slidesLength / rows) * rows;
|
9285 | }
|
9286 |
|
9287 | if (slidesPerView !== 'auto' && fill === 'row') {
|
9288 | slidesNumberEvenToRows = Math.max(slidesNumberEvenToRows, slidesPerView * rows);
|
9289 | }
|
9290 | };
|
9291 |
|
9292 | const updateSlide = (i, slide, slidesLength, getDirectionLabel) => {
|
9293 | const {
|
9294 | slidesPerGroup,
|
9295 | spaceBetween
|
9296 | } = swiper.params;
|
9297 | const {
|
9298 | rows,
|
9299 | fill
|
9300 | } = swiper.params.grid;
|
9301 |
|
9302 | let newSlideOrderIndex;
|
9303 | let column;
|
9304 | let row;
|
9305 |
|
9306 | if (fill === 'row' && slidesPerGroup > 1) {
|
9307 | const groupIndex = Math.floor(i / (slidesPerGroup * rows));
|
9308 | const slideIndexInGroup = i - rows * slidesPerGroup * groupIndex;
|
9309 | const columnsInGroup = groupIndex === 0 ? slidesPerGroup : Math.min(Math.ceil((slidesLength - groupIndex * rows * slidesPerGroup) / rows), slidesPerGroup);
|
9310 | row = Math.floor(slideIndexInGroup / columnsInGroup);
|
9311 | column = slideIndexInGroup - row * columnsInGroup + groupIndex * slidesPerGroup;
|
9312 | newSlideOrderIndex = column + row * slidesNumberEvenToRows / rows;
|
9313 | slide.css({
|
9314 | '-webkit-order': newSlideOrderIndex,
|
9315 | order: newSlideOrderIndex
|
9316 | });
|
9317 | } else if (fill === 'column') {
|
9318 | column = Math.floor(i / rows);
|
9319 | row = i - column * rows;
|
9320 |
|
9321 | if (column > numFullColumns || column === numFullColumns && row === rows - 1) {
|
9322 | row += 1;
|
9323 |
|
9324 | if (row >= rows) {
|
9325 | row = 0;
|
9326 | column += 1;
|
9327 | }
|
9328 | }
|
9329 | } else {
|
9330 | row = Math.floor(i / slidesPerRow);
|
9331 | column = i - row * slidesPerRow;
|
9332 | }
|
9333 |
|
9334 | slide.css(getDirectionLabel('margin-top'), row !== 0 ? spaceBetween && `${spaceBetween}px` : '');
|
9335 | };
|
9336 |
|
9337 | const updateWrapperSize = (slideSize, snapGrid, getDirectionLabel) => {
|
9338 | const {
|
9339 | spaceBetween,
|
9340 | centeredSlides,
|
9341 | roundLengths
|
9342 | } = swiper.params;
|
9343 | const {
|
9344 | rows
|
9345 | } = swiper.params.grid;
|
9346 | swiper.virtualSize = (slideSize + spaceBetween) * slidesNumberEvenToRows;
|
9347 | swiper.virtualSize = Math.ceil(swiper.virtualSize / rows) - spaceBetween;
|
9348 | swiper.$wrapperEl.css({
|
9349 | [getDirectionLabel('width')]: `${swiper.virtualSize + spaceBetween}px`
|
9350 | });
|
9351 |
|
9352 | if (centeredSlides) {
|
9353 | snapGrid.splice(0, snapGrid.length);
|
9354 | const newSlidesGrid = [];
|
9355 |
|
9356 | for (let i = 0; i < snapGrid.length; i += 1) {
|
9357 | let slidesGridItem = snapGrid[i];
|
9358 | if (roundLengths) slidesGridItem = Math.floor(slidesGridItem);
|
9359 | if (snapGrid[i] < swiper.virtualSize + snapGrid[0]) newSlidesGrid.push(slidesGridItem);
|
9360 | }
|
9361 |
|
9362 | snapGrid.push(...newSlidesGrid);
|
9363 | }
|
9364 | };
|
9365 |
|
9366 | swiper.grid = {
|
9367 | initSlides,
|
9368 | updateSlide,
|
9369 | updateWrapperSize
|
9370 | };
|
9371 | }
|
9372 |
|
9373 | function appendSlide(slides) {
|
9374 | const swiper = this;
|
9375 | const {
|
9376 | $wrapperEl,
|
9377 | params
|
9378 | } = swiper;
|
9379 |
|
9380 | if (params.loop) {
|
9381 | swiper.loopDestroy();
|
9382 | }
|
9383 |
|
9384 | if (typeof slides === 'object' && 'length' in slides) {
|
9385 | for (let i = 0; i < slides.length; i += 1) {
|
9386 | if (slides[i]) $wrapperEl.append(slides[i]);
|
9387 | }
|
9388 | } else {
|
9389 | $wrapperEl.append(slides);
|
9390 | }
|
9391 |
|
9392 | if (params.loop) {
|
9393 | swiper.loopCreate();
|
9394 | }
|
9395 |
|
9396 | if (!params.observer) {
|
9397 | swiper.update();
|
9398 | }
|
9399 | }
|
9400 |
|
9401 | function prependSlide(slides) {
|
9402 | const swiper = this;
|
9403 | const {
|
9404 | params,
|
9405 | $wrapperEl,
|
9406 | activeIndex
|
9407 | } = swiper;
|
9408 |
|
9409 | if (params.loop) {
|
9410 | swiper.loopDestroy();
|
9411 | }
|
9412 |
|
9413 | let newActiveIndex = activeIndex + 1;
|
9414 |
|
9415 | if (typeof slides === 'object' && 'length' in slides) {
|
9416 | for (let i = 0; i < slides.length; i += 1) {
|
9417 | if (slides[i]) $wrapperEl.prepend(slides[i]);
|
9418 | }
|
9419 |
|
9420 | newActiveIndex = activeIndex + slides.length;
|
9421 | } else {
|
9422 | $wrapperEl.prepend(slides);
|
9423 | }
|
9424 |
|
9425 | if (params.loop) {
|
9426 | swiper.loopCreate();
|
9427 | }
|
9428 |
|
9429 | if (!params.observer) {
|
9430 | swiper.update();
|
9431 | }
|
9432 |
|
9433 | swiper.slideTo(newActiveIndex, 0, false);
|
9434 | }
|
9435 |
|
9436 | function addSlide(index, slides) {
|
9437 | const swiper = this;
|
9438 | const {
|
9439 | $wrapperEl,
|
9440 | params,
|
9441 | activeIndex
|
9442 | } = swiper;
|
9443 | let activeIndexBuffer = activeIndex;
|
9444 |
|
9445 | if (params.loop) {
|
9446 | activeIndexBuffer -= swiper.loopedSlides;
|
9447 | swiper.loopDestroy();
|
9448 | swiper.slides = $wrapperEl.children(`.${params.slideClass}`);
|
9449 | }
|
9450 |
|
9451 | const baseLength = swiper.slides.length;
|
9452 |
|
9453 | if (index <= 0) {
|
9454 | swiper.prependSlide(slides);
|
9455 | return;
|
9456 | }
|
9457 |
|
9458 | if (index >= baseLength) {
|
9459 | swiper.appendSlide(slides);
|
9460 | return;
|
9461 | }
|
9462 |
|
9463 | let newActiveIndex = activeIndexBuffer > index ? activeIndexBuffer + 1 : activeIndexBuffer;
|
9464 | const slidesBuffer = [];
|
9465 |
|
9466 | for (let i = baseLength - 1; i >= index; i -= 1) {
|
9467 | const currentSlide = swiper.slides.eq(i);
|
9468 | currentSlide.remove();
|
9469 | slidesBuffer.unshift(currentSlide);
|
9470 | }
|
9471 |
|
9472 | if (typeof slides === 'object' && 'length' in slides) {
|
9473 | for (let i = 0; i < slides.length; i += 1) {
|
9474 | if (slides[i]) $wrapperEl.append(slides[i]);
|
9475 | }
|
9476 |
|
9477 | newActiveIndex = activeIndexBuffer > index ? activeIndexBuffer + slides.length : activeIndexBuffer;
|
9478 | } else {
|
9479 | $wrapperEl.append(slides);
|
9480 | }
|
9481 |
|
9482 | for (let i = 0; i < slidesBuffer.length; i += 1) {
|
9483 | $wrapperEl.append(slidesBuffer[i]);
|
9484 | }
|
9485 |
|
9486 | if (params.loop) {
|
9487 | swiper.loopCreate();
|
9488 | }
|
9489 |
|
9490 | if (!params.observer) {
|
9491 | swiper.update();
|
9492 | }
|
9493 |
|
9494 | if (params.loop) {
|
9495 | swiper.slideTo(newActiveIndex + swiper.loopedSlides, 0, false);
|
9496 | } else {
|
9497 | swiper.slideTo(newActiveIndex, 0, false);
|
9498 | }
|
9499 | }
|
9500 |
|
9501 | function removeSlide(slidesIndexes) {
|
9502 | const swiper = this;
|
9503 | const {
|
9504 | params,
|
9505 | $wrapperEl,
|
9506 | activeIndex
|
9507 | } = swiper;
|
9508 | let activeIndexBuffer = activeIndex;
|
9509 |
|
9510 | if (params.loop) {
|
9511 | activeIndexBuffer -= swiper.loopedSlides;
|
9512 | swiper.loopDestroy();
|
9513 | swiper.slides = $wrapperEl.children(`.${params.slideClass}`);
|
9514 | }
|
9515 |
|
9516 | let newActiveIndex = activeIndexBuffer;
|
9517 | let indexToRemove;
|
9518 |
|
9519 | if (typeof slidesIndexes === 'object' && 'length' in slidesIndexes) {
|
9520 | for (let i = 0; i < slidesIndexes.length; i += 1) {
|
9521 | indexToRemove = slidesIndexes[i];
|
9522 | if (swiper.slides[indexToRemove]) swiper.slides.eq(indexToRemove).remove();
|
9523 | if (indexToRemove < newActiveIndex) newActiveIndex -= 1;
|
9524 | }
|
9525 |
|
9526 | newActiveIndex = Math.max(newActiveIndex, 0);
|
9527 | } else {
|
9528 | indexToRemove = slidesIndexes;
|
9529 | if (swiper.slides[indexToRemove]) swiper.slides.eq(indexToRemove).remove();
|
9530 | if (indexToRemove < newActiveIndex) newActiveIndex -= 1;
|
9531 | newActiveIndex = Math.max(newActiveIndex, 0);
|
9532 | }
|
9533 |
|
9534 | if (params.loop) {
|
9535 | swiper.loopCreate();
|
9536 | }
|
9537 |
|
9538 | if (!params.observer) {
|
9539 | swiper.update();
|
9540 | }
|
9541 |
|
9542 | if (params.loop) {
|
9543 | swiper.slideTo(newActiveIndex + swiper.loopedSlides, 0, false);
|
9544 | } else {
|
9545 | swiper.slideTo(newActiveIndex, 0, false);
|
9546 | }
|
9547 | }
|
9548 |
|
9549 | function removeAllSlides() {
|
9550 | const swiper = this;
|
9551 | const slidesIndexes = [];
|
9552 |
|
9553 | for (let i = 0; i < swiper.slides.length; i += 1) {
|
9554 | slidesIndexes.push(i);
|
9555 | }
|
9556 |
|
9557 | swiper.removeSlide(slidesIndexes);
|
9558 | }
|
9559 |
|
9560 | function Manipulation(_ref) {
|
9561 | let {
|
9562 | swiper
|
9563 | } = _ref;
|
9564 | Object.assign(swiper, {
|
9565 | appendSlide: appendSlide.bind(swiper),
|
9566 | prependSlide: prependSlide.bind(swiper),
|
9567 | addSlide: addSlide.bind(swiper),
|
9568 | removeSlide: removeSlide.bind(swiper),
|
9569 | removeAllSlides: removeAllSlides.bind(swiper)
|
9570 | });
|
9571 | }
|
9572 |
|
9573 | function effectInit(params) {
|
9574 | const {
|
9575 | effect,
|
9576 | swiper,
|
9577 | on,
|
9578 | setTranslate,
|
9579 | setTransition,
|
9580 | overwriteParams,
|
9581 | perspective
|
9582 | } = params;
|
9583 | on('beforeInit', () => {
|
9584 | if (swiper.params.effect !== effect) return;
|
9585 | swiper.classNames.push(`${swiper.params.containerModifierClass}${effect}`);
|
9586 |
|
9587 | if (perspective && perspective()) {
|
9588 | swiper.classNames.push(`${swiper.params.containerModifierClass}3d`);
|
9589 | }
|
9590 |
|
9591 | const overwriteParamsResult = overwriteParams ? overwriteParams() : {};
|
9592 | Object.assign(swiper.params, overwriteParamsResult);
|
9593 | Object.assign(swiper.originalParams, overwriteParamsResult);
|
9594 | });
|
9595 | on('setTranslate', () => {
|
9596 | if (swiper.params.effect !== effect) return;
|
9597 | setTranslate();
|
9598 | });
|
9599 | on('setTransition', (_s, duration) => {
|
9600 | if (swiper.params.effect !== effect) return;
|
9601 | setTransition(duration);
|
9602 | });
|
9603 | }
|
9604 |
|
9605 | function effectTarget(effectParams, $slideEl) {
|
9606 | if (effectParams.transformEl) {
|
9607 | return $slideEl.find(effectParams.transformEl).css({
|
9608 | 'backface-visibility': 'hidden',
|
9609 | '-webkit-backface-visibility': 'hidden'
|
9610 | });
|
9611 | }
|
9612 |
|
9613 | return $slideEl;
|
9614 | }
|
9615 |
|
9616 | function effectVirtualTransitionEnd(_ref) {
|
9617 | let {
|
9618 | swiper,
|
9619 | duration,
|
9620 | transformEl,
|
9621 | allSlides
|
9622 | } = _ref;
|
9623 | const {
|
9624 | slides,
|
9625 | activeIndex,
|
9626 | $wrapperEl
|
9627 | } = swiper;
|
9628 |
|
9629 | if (swiper.params.virtualTranslate && duration !== 0) {
|
9630 | let eventTriggered = false;
|
9631 | let $transitionEndTarget;
|
9632 |
|
9633 | if (allSlides) {
|
9634 | $transitionEndTarget = transformEl ? slides.find(transformEl) : slides;
|
9635 | } else {
|
9636 | $transitionEndTarget = transformEl ? slides.eq(activeIndex).find(transformEl) : slides.eq(activeIndex);
|
9637 | }
|
9638 |
|
9639 | $transitionEndTarget.transitionEnd(() => {
|
9640 | if (eventTriggered) return;
|
9641 | if (!swiper || swiper.destroyed) return;
|
9642 | eventTriggered = true;
|
9643 | swiper.animating = false;
|
9644 | const triggerEvents = ['webkitTransitionEnd', 'transitionend'];
|
9645 |
|
9646 | for (let i = 0; i < triggerEvents.length; i += 1) {
|
9647 | $wrapperEl.trigger(triggerEvents[i]);
|
9648 | }
|
9649 | });
|
9650 | }
|
9651 | }
|
9652 |
|
9653 | function EffectFade(_ref) {
|
9654 | let {
|
9655 | swiper,
|
9656 | extendParams,
|
9657 | on
|
9658 | } = _ref;
|
9659 | extendParams({
|
9660 | fadeEffect: {
|
9661 | crossFade: false,
|
9662 | transformEl: null
|
9663 | }
|
9664 | });
|
9665 |
|
9666 | const setTranslate = () => {
|
9667 | const {
|
9668 | slides
|
9669 | } = swiper;
|
9670 | const params = swiper.params.fadeEffect;
|
9671 |
|
9672 | for (let i = 0; i < slides.length; i += 1) {
|
9673 | const $slideEl = swiper.slides.eq(i);
|
9674 | const offset = $slideEl[0].swiperSlideOffset;
|
9675 | let tx = -offset;
|
9676 | if (!swiper.params.virtualTranslate) tx -= swiper.translate;
|
9677 | let ty = 0;
|
9678 |
|
9679 | if (!swiper.isHorizontal()) {
|
9680 | ty = tx;
|
9681 | tx = 0;
|
9682 | }
|
9683 |
|
9684 | const slideOpacity = swiper.params.fadeEffect.crossFade ? Math.max(1 - Math.abs($slideEl[0].progress), 0) : 1 + Math.min(Math.max($slideEl[0].progress, -1), 0);
|
9685 | const $targetEl = effectTarget(params, $slideEl);
|
9686 | $targetEl.css({
|
9687 | opacity: slideOpacity
|
9688 | }).transform(`translate3d(${tx}px, ${ty}px, 0px)`);
|
9689 | }
|
9690 | };
|
9691 |
|
9692 | const setTransition = duration => {
|
9693 | const {
|
9694 | transformEl
|
9695 | } = swiper.params.fadeEffect;
|
9696 | const $transitionElements = transformEl ? swiper.slides.find(transformEl) : swiper.slides;
|
9697 | $transitionElements.transition(duration);
|
9698 | effectVirtualTransitionEnd({
|
9699 | swiper,
|
9700 | duration,
|
9701 | transformEl,
|
9702 | allSlides: true
|
9703 | });
|
9704 | };
|
9705 |
|
9706 | effectInit({
|
9707 | effect: 'fade',
|
9708 | swiper,
|
9709 | on,
|
9710 | setTranslate,
|
9711 | setTransition,
|
9712 | overwriteParams: () => ({
|
9713 | slidesPerView: 1,
|
9714 | slidesPerGroup: 1,
|
9715 | watchSlidesProgress: true,
|
9716 | spaceBetween: 0,
|
9717 | virtualTranslate: !swiper.params.cssMode
|
9718 | })
|
9719 | });
|
9720 | }
|
9721 |
|
9722 | function EffectCube(_ref) {
|
9723 | let {
|
9724 | swiper,
|
9725 | extendParams,
|
9726 | on
|
9727 | } = _ref;
|
9728 | extendParams({
|
9729 | cubeEffect: {
|
9730 | slideShadows: true,
|
9731 | shadow: true,
|
9732 | shadowOffset: 20,
|
9733 | shadowScale: 0.94
|
9734 | }
|
9735 | });
|
9736 |
|
9737 | const setTranslate = () => {
|
9738 | const {
|
9739 | $el,
|
9740 | $wrapperEl,
|
9741 | slides,
|
9742 | width: swiperWidth,
|
9743 | height: swiperHeight,
|
9744 | rtlTranslate: rtl,
|
9745 | size: swiperSize,
|
9746 | browser
|
9747 | } = swiper;
|
9748 | const params = swiper.params.cubeEffect;
|
9749 | const isHorizontal = swiper.isHorizontal();
|
9750 | const isVirtual = swiper.virtual && swiper.params.virtual.enabled;
|
9751 | let wrapperRotate = 0;
|
9752 | let $cubeShadowEl;
|
9753 |
|
9754 | if (params.shadow) {
|
9755 | if (isHorizontal) {
|
9756 | $cubeShadowEl = $wrapperEl.find('.swiper-cube-shadow');
|
9757 |
|
9758 | if ($cubeShadowEl.length === 0) {
|
9759 | $cubeShadowEl = $('<div class="swiper-cube-shadow"></div>');
|
9760 | $wrapperEl.append($cubeShadowEl);
|
9761 | }
|
9762 |
|
9763 | $cubeShadowEl.css({
|
9764 | height: `${swiperWidth}px`
|
9765 | });
|
9766 | } else {
|
9767 | $cubeShadowEl = $el.find('.swiper-cube-shadow');
|
9768 |
|
9769 | if ($cubeShadowEl.length === 0) {
|
9770 | $cubeShadowEl = $('<div class="swiper-cube-shadow"></div>');
|
9771 | $el.append($cubeShadowEl);
|
9772 | }
|
9773 | }
|
9774 | }
|
9775 |
|
9776 | for (let i = 0; i < slides.length; i += 1) {
|
9777 | const $slideEl = slides.eq(i);
|
9778 | let slideIndex = i;
|
9779 |
|
9780 | if (isVirtual) {
|
9781 | slideIndex = parseInt($slideEl.attr('data-swiper-slide-index'), 10);
|
9782 | }
|
9783 |
|
9784 | let slideAngle = slideIndex * 90;
|
9785 | let round = Math.floor(slideAngle / 360);
|
9786 |
|
9787 | if (rtl) {
|
9788 | slideAngle = -slideAngle;
|
9789 | round = Math.floor(-slideAngle / 360);
|
9790 | }
|
9791 |
|
9792 | const progress = Math.max(Math.min($slideEl[0].progress, 1), -1);
|
9793 | let tx = 0;
|
9794 | let ty = 0;
|
9795 | let tz = 0;
|
9796 |
|
9797 | if (slideIndex % 4 === 0) {
|
9798 | tx = -round * 4 * swiperSize;
|
9799 | tz = 0;
|
9800 | } else if ((slideIndex - 1) % 4 === 0) {
|
9801 | tx = 0;
|
9802 | tz = -round * 4 * swiperSize;
|
9803 | } else if ((slideIndex - 2) % 4 === 0) {
|
9804 | tx = swiperSize + round * 4 * swiperSize;
|
9805 | tz = swiperSize;
|
9806 | } else if ((slideIndex - 3) % 4 === 0) {
|
9807 | tx = -swiperSize;
|
9808 | tz = 3 * swiperSize + swiperSize * 4 * round;
|
9809 | }
|
9810 |
|
9811 | if (rtl) {
|
9812 | tx = -tx;
|
9813 | }
|
9814 |
|
9815 | if (!isHorizontal) {
|
9816 | ty = tx;
|
9817 | tx = 0;
|
9818 | }
|
9819 |
|
9820 | const transform = `rotateX(${isHorizontal ? 0 : -slideAngle}deg) rotateY(${isHorizontal ? slideAngle : 0}deg) translate3d(${tx}px, ${ty}px, ${tz}px)`;
|
9821 |
|
9822 | if (progress <= 1 && progress > -1) {
|
9823 | wrapperRotate = slideIndex * 90 + progress * 90;
|
9824 | if (rtl) wrapperRotate = -slideIndex * 90 - progress * 90;
|
9825 | }
|
9826 |
|
9827 | $slideEl.transform(transform);
|
9828 |
|
9829 | if (params.slideShadows) {
|
9830 |
|
9831 | let shadowBefore = isHorizontal ? $slideEl.find('.swiper-slide-shadow-left') : $slideEl.find('.swiper-slide-shadow-top');
|
9832 | let shadowAfter = isHorizontal ? $slideEl.find('.swiper-slide-shadow-right') : $slideEl.find('.swiper-slide-shadow-bottom');
|
9833 |
|
9834 | if (shadowBefore.length === 0) {
|
9835 | shadowBefore = $(`<div class="swiper-slide-shadow-${isHorizontal ? 'left' : 'top'}"></div>`);
|
9836 | $slideEl.append(shadowBefore);
|
9837 | }
|
9838 |
|
9839 | if (shadowAfter.length === 0) {
|
9840 | shadowAfter = $(`<div class="swiper-slide-shadow-${isHorizontal ? 'right' : 'bottom'}"></div>`);
|
9841 | $slideEl.append(shadowAfter);
|
9842 | }
|
9843 |
|
9844 | if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0);
|
9845 | if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0);
|
9846 | }
|
9847 | }
|
9848 |
|
9849 | $wrapperEl.css({
|
9850 | '-webkit-transform-origin': `50% 50% -${swiperSize / 2}px`,
|
9851 | 'transform-origin': `50% 50% -${swiperSize / 2}px`
|
9852 | });
|
9853 |
|
9854 | if (params.shadow) {
|
9855 | if (isHorizontal) {
|
9856 | $cubeShadowEl.transform(`translate3d(0px, ${swiperWidth / 2 + params.shadowOffset}px, ${-swiperWidth / 2}px) rotateX(90deg) rotateZ(0deg) scale(${params.shadowScale})`);
|
9857 | } else {
|
9858 | const shadowAngle = Math.abs(wrapperRotate) - Math.floor(Math.abs(wrapperRotate) / 90) * 90;
|
9859 | const multiplier = 1.5 - (Math.sin(shadowAngle * 2 * Math.PI / 360) / 2 + Math.cos(shadowAngle * 2 * Math.PI / 360) / 2);
|
9860 | const scale1 = params.shadowScale;
|
9861 | const scale2 = params.shadowScale / multiplier;
|
9862 | const offset = params.shadowOffset;
|
9863 | $cubeShadowEl.transform(`scale3d(${scale1}, 1, ${scale2}) translate3d(0px, ${swiperHeight / 2 + offset}px, ${-swiperHeight / 2 / scale2}px) rotateX(-90deg)`);
|
9864 | }
|
9865 | }
|
9866 |
|
9867 | const zFactor = browser.isSafari || browser.isWebView ? -swiperSize / 2 : 0;
|
9868 | $wrapperEl.transform(`translate3d(0px,0,${zFactor}px) rotateX(${swiper.isHorizontal() ? 0 : wrapperRotate}deg) rotateY(${swiper.isHorizontal() ? -wrapperRotate : 0}deg)`);
|
9869 | };
|
9870 |
|
9871 | const setTransition = duration => {
|
9872 | const {
|
9873 | $el,
|
9874 | slides
|
9875 | } = swiper;
|
9876 | slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
|
9877 |
|
9878 | if (swiper.params.cubeEffect.shadow && !swiper.isHorizontal()) {
|
9879 | $el.find('.swiper-cube-shadow').transition(duration);
|
9880 | }
|
9881 | };
|
9882 |
|
9883 | effectInit({
|
9884 | effect: 'cube',
|
9885 | swiper,
|
9886 | on,
|
9887 | setTranslate,
|
9888 | setTransition,
|
9889 | perspective: () => true,
|
9890 | overwriteParams: () => ({
|
9891 | slidesPerView: 1,
|
9892 | slidesPerGroup: 1,
|
9893 | watchSlidesProgress: true,
|
9894 | resistanceRatio: 0,
|
9895 | spaceBetween: 0,
|
9896 | centeredSlides: false,
|
9897 | virtualTranslate: true
|
9898 | })
|
9899 | });
|
9900 | }
|
9901 |
|
9902 | function createShadow(params, $slideEl, side) {
|
9903 | const shadowClass = `swiper-slide-shadow${side ? `-${side}` : ''}`;
|
9904 | const $shadowContainer = params.transformEl ? $slideEl.find(params.transformEl) : $slideEl;
|
9905 | let $shadowEl = $shadowContainer.children(`.${shadowClass}`);
|
9906 |
|
9907 | if (!$shadowEl.length) {
|
9908 | $shadowEl = $(`<div class="swiper-slide-shadow${side ? `-${side}` : ''}"></div>`);
|
9909 | $shadowContainer.append($shadowEl);
|
9910 | }
|
9911 |
|
9912 | return $shadowEl;
|
9913 | }
|
9914 |
|
9915 | function EffectFlip(_ref) {
|
9916 | let {
|
9917 | swiper,
|
9918 | extendParams,
|
9919 | on
|
9920 | } = _ref;
|
9921 | extendParams({
|
9922 | flipEffect: {
|
9923 | slideShadows: true,
|
9924 | limitRotation: true,
|
9925 | transformEl: null
|
9926 | }
|
9927 | });
|
9928 |
|
9929 | const setTranslate = () => {
|
9930 | const {
|
9931 | slides,
|
9932 | rtlTranslate: rtl
|
9933 | } = swiper;
|
9934 | const params = swiper.params.flipEffect;
|
9935 |
|
9936 | for (let i = 0; i < slides.length; i += 1) {
|
9937 | const $slideEl = slides.eq(i);
|
9938 | let progress = $slideEl[0].progress;
|
9939 |
|
9940 | if (swiper.params.flipEffect.limitRotation) {
|
9941 | progress = Math.max(Math.min($slideEl[0].progress, 1), -1);
|
9942 | }
|
9943 |
|
9944 | const offset = $slideEl[0].swiperSlideOffset;
|
9945 | const rotate = -180 * progress;
|
9946 | let rotateY = rotate;
|
9947 | let rotateX = 0;
|
9948 | let tx = swiper.params.cssMode ? -offset - swiper.translate : -offset;
|
9949 | let ty = 0;
|
9950 |
|
9951 | if (!swiper.isHorizontal()) {
|
9952 | ty = tx;
|
9953 | tx = 0;
|
9954 | rotateX = -rotateY;
|
9955 | rotateY = 0;
|
9956 | } else if (rtl) {
|
9957 | rotateY = -rotateY;
|
9958 | }
|
9959 |
|
9960 | $slideEl[0].style.zIndex = -Math.abs(Math.round(progress)) + slides.length;
|
9961 |
|
9962 | if (params.slideShadows) {
|
9963 |
|
9964 | let shadowBefore = swiper.isHorizontal() ? $slideEl.find('.swiper-slide-shadow-left') : $slideEl.find('.swiper-slide-shadow-top');
|
9965 | let shadowAfter = swiper.isHorizontal() ? $slideEl.find('.swiper-slide-shadow-right') : $slideEl.find('.swiper-slide-shadow-bottom');
|
9966 |
|
9967 | if (shadowBefore.length === 0) {
|
9968 | shadowBefore = createShadow(params, $slideEl, swiper.isHorizontal() ? 'left' : 'top');
|
9969 | }
|
9970 |
|
9971 | if (shadowAfter.length === 0) {
|
9972 | shadowAfter = createShadow(params, $slideEl, swiper.isHorizontal() ? 'right' : 'bottom');
|
9973 | }
|
9974 |
|
9975 | if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0);
|
9976 | if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0);
|
9977 | }
|
9978 |
|
9979 | const transform = `translate3d(${tx}px, ${ty}px, 0px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`;
|
9980 | const $targetEl = effectTarget(params, $slideEl);
|
9981 | $targetEl.transform(transform);
|
9982 | }
|
9983 | };
|
9984 |
|
9985 | const setTransition = duration => {
|
9986 | const {
|
9987 | transformEl
|
9988 | } = swiper.params.flipEffect;
|
9989 | const $transitionElements = transformEl ? swiper.slides.find(transformEl) : swiper.slides;
|
9990 | $transitionElements.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
|
9991 | effectVirtualTransitionEnd({
|
9992 | swiper,
|
9993 | duration,
|
9994 | transformEl
|
9995 | });
|
9996 | };
|
9997 |
|
9998 | effectInit({
|
9999 | effect: 'flip',
|
10000 | swiper,
|
10001 | on,
|
10002 | setTranslate,
|
10003 | setTransition,
|
10004 | perspective: () => true,
|
10005 | overwriteParams: () => ({
|
10006 | slidesPerView: 1,
|
10007 | slidesPerGroup: 1,
|
10008 | watchSlidesProgress: true,
|
10009 | spaceBetween: 0,
|
10010 | virtualTranslate: !swiper.params.cssMode
|
10011 | })
|
10012 | });
|
10013 | }
|
10014 |
|
10015 | function EffectCoverflow(_ref) {
|
10016 | let {
|
10017 | swiper,
|
10018 | extendParams,
|
10019 | on
|
10020 | } = _ref;
|
10021 | extendParams({
|
10022 | coverflowEffect: {
|
10023 | rotate: 50,
|
10024 | stretch: 0,
|
10025 | depth: 100,
|
10026 | scale: 1,
|
10027 | modifier: 1,
|
10028 | slideShadows: true,
|
10029 | transformEl: null
|
10030 | }
|
10031 | });
|
10032 |
|
10033 | const setTranslate = () => {
|
10034 | const {
|
10035 | width: swiperWidth,
|
10036 | height: swiperHeight,
|
10037 | slides,
|
10038 | slidesSizesGrid
|
10039 | } = swiper;
|
10040 | const params = swiper.params.coverflowEffect;
|
10041 | const isHorizontal = swiper.isHorizontal();
|
10042 | const transform = swiper.translate;
|
10043 | const center = isHorizontal ? -transform + swiperWidth / 2 : -transform + swiperHeight / 2;
|
10044 | const rotate = isHorizontal ? params.rotate : -params.rotate;
|
10045 | const translate = params.depth;
|
10046 |
|
10047 | for (let i = 0, length = slides.length; i < length; i += 1) {
|
10048 | const $slideEl = slides.eq(i);
|
10049 | const slideSize = slidesSizesGrid[i];
|
10050 | const slideOffset = $slideEl[0].swiperSlideOffset;
|
10051 | const offsetMultiplier = (center - slideOffset - slideSize / 2) / slideSize * params.modifier;
|
10052 | let rotateY = isHorizontal ? rotate * offsetMultiplier : 0;
|
10053 | let rotateX = isHorizontal ? 0 : rotate * offsetMultiplier;
|
10054 |
|
10055 | let translateZ = -translate * Math.abs(offsetMultiplier);
|
10056 | let stretch = params.stretch;
|
10057 |
|
10058 | if (typeof stretch === 'string' && stretch.indexOf('%') !== -1) {
|
10059 | stretch = parseFloat(params.stretch) / 100 * slideSize;
|
10060 | }
|
10061 |
|
10062 | let translateY = isHorizontal ? 0 : stretch * offsetMultiplier;
|
10063 | let translateX = isHorizontal ? stretch * offsetMultiplier : 0;
|
10064 | let scale = 1 - (1 - params.scale) * Math.abs(offsetMultiplier);
|
10065 |
|
10066 | if (Math.abs(translateX) < 0.001) translateX = 0;
|
10067 | if (Math.abs(translateY) < 0.001) translateY = 0;
|
10068 | if (Math.abs(translateZ) < 0.001) translateZ = 0;
|
10069 | if (Math.abs(rotateY) < 0.001) rotateY = 0;
|
10070 | if (Math.abs(rotateX) < 0.001) rotateX = 0;
|
10071 | if (Math.abs(scale) < 0.001) scale = 0;
|
10072 | const slideTransform = `translate3d(${translateX}px,${translateY}px,${translateZ}px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale(${scale})`;
|
10073 | const $targetEl = effectTarget(params, $slideEl);
|
10074 | $targetEl.transform(slideTransform);
|
10075 | $slideEl[0].style.zIndex = -Math.abs(Math.round(offsetMultiplier)) + 1;
|
10076 |
|
10077 | if (params.slideShadows) {
|
10078 |
|
10079 | let $shadowBeforeEl = isHorizontal ? $slideEl.find('.swiper-slide-shadow-left') : $slideEl.find('.swiper-slide-shadow-top');
|
10080 | let $shadowAfterEl = isHorizontal ? $slideEl.find('.swiper-slide-shadow-right') : $slideEl.find('.swiper-slide-shadow-bottom');
|
10081 |
|
10082 | if ($shadowBeforeEl.length === 0) {
|
10083 | $shadowBeforeEl = createShadow(params, $slideEl, isHorizontal ? 'left' : 'top');
|
10084 | }
|
10085 |
|
10086 | if ($shadowAfterEl.length === 0) {
|
10087 | $shadowAfterEl = createShadow(params, $slideEl, isHorizontal ? 'right' : 'bottom');
|
10088 | }
|
10089 |
|
10090 | if ($shadowBeforeEl.length) $shadowBeforeEl[0].style.opacity = offsetMultiplier > 0 ? offsetMultiplier : 0;
|
10091 | if ($shadowAfterEl.length) $shadowAfterEl[0].style.opacity = -offsetMultiplier > 0 ? -offsetMultiplier : 0;
|
10092 | }
|
10093 | }
|
10094 | };
|
10095 |
|
10096 | const setTransition = duration => {
|
10097 | const {
|
10098 | transformEl
|
10099 | } = swiper.params.coverflowEffect;
|
10100 | const $transitionElements = transformEl ? swiper.slides.find(transformEl) : swiper.slides;
|
10101 | $transitionElements.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
|
10102 | };
|
10103 |
|
10104 | effectInit({
|
10105 | effect: 'coverflow',
|
10106 | swiper,
|
10107 | on,
|
10108 | setTranslate,
|
10109 | setTransition,
|
10110 | perspective: () => true,
|
10111 | overwriteParams: () => ({
|
10112 | watchSlidesProgress: true
|
10113 | })
|
10114 | });
|
10115 | }
|
10116 |
|
10117 | function EffectCreative(_ref) {
|
10118 | let {
|
10119 | swiper,
|
10120 | extendParams,
|
10121 | on
|
10122 | } = _ref;
|
10123 | extendParams({
|
10124 | creativeEffect: {
|
10125 | transformEl: null,
|
10126 | limitProgress: 1,
|
10127 | shadowPerProgress: false,
|
10128 | progressMultiplier: 1,
|
10129 | perspective: true,
|
10130 | prev: {
|
10131 | translate: [0, 0, 0],
|
10132 | rotate: [0, 0, 0],
|
10133 | opacity: 1,
|
10134 | scale: 1
|
10135 | },
|
10136 | next: {
|
10137 | translate: [0, 0, 0],
|
10138 | rotate: [0, 0, 0],
|
10139 | opacity: 1,
|
10140 | scale: 1
|
10141 | }
|
10142 | }
|
10143 | });
|
10144 |
|
10145 | const getTranslateValue = value => {
|
10146 | if (typeof value === 'string') return value;
|
10147 | return `${value}px`;
|
10148 | };
|
10149 |
|
10150 | const setTranslate = () => {
|
10151 | const {
|
10152 | slides,
|
10153 | $wrapperEl,
|
10154 | slidesSizesGrid
|
10155 | } = swiper;
|
10156 | const params = swiper.params.creativeEffect;
|
10157 | const {
|
10158 | progressMultiplier: multiplier
|
10159 | } = params;
|
10160 | const isCenteredSlides = swiper.params.centeredSlides;
|
10161 |
|
10162 | if (isCenteredSlides) {
|
10163 | const margin = slidesSizesGrid[0] / 2 - swiper.params.slidesOffsetBefore || 0;
|
10164 | $wrapperEl.transform(`translateX(calc(50% - ${margin}px))`);
|
10165 | }
|
10166 |
|
10167 | for (let i = 0; i < slides.length; i += 1) {
|
10168 | const $slideEl = slides.eq(i);
|
10169 | const slideProgress = $slideEl[0].progress;
|
10170 | const progress = Math.min(Math.max($slideEl[0].progress, -params.limitProgress), params.limitProgress);
|
10171 | let originalProgress = progress;
|
10172 |
|
10173 | if (!isCenteredSlides) {
|
10174 | originalProgress = Math.min(Math.max($slideEl[0].originalProgress, -params.limitProgress), params.limitProgress);
|
10175 | }
|
10176 |
|
10177 | const offset = $slideEl[0].swiperSlideOffset;
|
10178 | const t = [swiper.params.cssMode ? -offset - swiper.translate : -offset, 0, 0];
|
10179 | const r = [0, 0, 0];
|
10180 | let custom = false;
|
10181 |
|
10182 | if (!swiper.isHorizontal()) {
|
10183 | t[1] = t[0];
|
10184 | t[0] = 0;
|
10185 | }
|
10186 |
|
10187 | let data = {
|
10188 | translate: [0, 0, 0],
|
10189 | rotate: [0, 0, 0],
|
10190 | scale: 1,
|
10191 | opacity: 1
|
10192 | };
|
10193 |
|
10194 | if (progress < 0) {
|
10195 | data = params.next;
|
10196 | custom = true;
|
10197 | } else if (progress > 0) {
|
10198 | data = params.prev;
|
10199 | custom = true;
|
10200 | }
|
10201 |
|
10202 |
|
10203 | t.forEach((value, index) => {
|
10204 | t[index] = `calc(${value}px + (${getTranslateValue(data.translate[index])} * ${Math.abs(progress * multiplier)}))`;
|
10205 | });
|
10206 |
|
10207 | r.forEach((value, index) => {
|
10208 | r[index] = data.rotate[index] * Math.abs(progress * multiplier);
|
10209 | });
|
10210 | $slideEl[0].style.zIndex = -Math.abs(Math.round(slideProgress)) + slides.length;
|
10211 | const translateString = t.join(', ');
|
10212 | const rotateString = `rotateX(${r[0]}deg) rotateY(${r[1]}deg) rotateZ(${r[2]}deg)`;
|
10213 | const scaleString = originalProgress < 0 ? `scale(${1 + (1 - data.scale) * originalProgress * multiplier})` : `scale(${1 - (1 - data.scale) * originalProgress * multiplier})`;
|
10214 | const opacityString = originalProgress < 0 ? 1 + (1 - data.opacity) * originalProgress * multiplier : 1 - (1 - data.opacity) * originalProgress * multiplier;
|
10215 | const transform = `translate3d(${translateString}) ${rotateString} ${scaleString}`;
|
10216 |
|
10217 | if (custom && data.shadow || !custom) {
|
10218 | let $shadowEl = $slideEl.children('.swiper-slide-shadow');
|
10219 |
|
10220 | if ($shadowEl.length === 0 && data.shadow) {
|
10221 | $shadowEl = createShadow(params, $slideEl);
|
10222 | }
|
10223 |
|
10224 | if ($shadowEl.length) {
|
10225 | const shadowOpacity = params.shadowPerProgress ? progress * (1 / params.limitProgress) : progress;
|
10226 | $shadowEl[0].style.opacity = Math.min(Math.max(Math.abs(shadowOpacity), 0), 1);
|
10227 | }
|
10228 | }
|
10229 |
|
10230 | const $targetEl = effectTarget(params, $slideEl);
|
10231 | $targetEl.transform(transform).css({
|
10232 | opacity: opacityString
|
10233 | });
|
10234 |
|
10235 | if (data.origin) {
|
10236 | $targetEl.css('transform-origin', data.origin);
|
10237 | }
|
10238 | }
|
10239 | };
|
10240 |
|
10241 | const setTransition = duration => {
|
10242 | const {
|
10243 | transformEl
|
10244 | } = swiper.params.creativeEffect;
|
10245 | const $transitionElements = transformEl ? swiper.slides.find(transformEl) : swiper.slides;
|
10246 | $transitionElements.transition(duration).find('.swiper-slide-shadow').transition(duration);
|
10247 | effectVirtualTransitionEnd({
|
10248 | swiper,
|
10249 | duration,
|
10250 | transformEl,
|
10251 | allSlides: true
|
10252 | });
|
10253 | };
|
10254 |
|
10255 | effectInit({
|
10256 | effect: 'creative',
|
10257 | swiper,
|
10258 | on,
|
10259 | setTranslate,
|
10260 | setTransition,
|
10261 | perspective: () => swiper.params.creativeEffect.perspective,
|
10262 | overwriteParams: () => ({
|
10263 | watchSlidesProgress: true,
|
10264 | virtualTranslate: !swiper.params.cssMode
|
10265 | })
|
10266 | });
|
10267 | }
|
10268 |
|
10269 | function EffectCards(_ref) {
|
10270 | let {
|
10271 | swiper,
|
10272 | extendParams,
|
10273 | on
|
10274 | } = _ref;
|
10275 | extendParams({
|
10276 | cardsEffect: {
|
10277 | slideShadows: true,
|
10278 | transformEl: null
|
10279 | }
|
10280 | });
|
10281 |
|
10282 | const setTranslate = () => {
|
10283 | const {
|
10284 | slides,
|
10285 | activeIndex
|
10286 | } = swiper;
|
10287 | const params = swiper.params.cardsEffect;
|
10288 | const {
|
10289 | startTranslate,
|
10290 | isTouched
|
10291 | } = swiper.touchEventsData;
|
10292 | const currentTranslate = swiper.translate;
|
10293 |
|
10294 | for (let i = 0; i < slides.length; i += 1) {
|
10295 | const $slideEl = slides.eq(i);
|
10296 | const slideProgress = $slideEl[0].progress;
|
10297 | const progress = Math.min(Math.max(slideProgress, -4), 4);
|
10298 | let offset = $slideEl[0].swiperSlideOffset;
|
10299 |
|
10300 | if (swiper.params.centeredSlides && !swiper.params.cssMode) {
|
10301 | swiper.$wrapperEl.transform(`translateX(${swiper.minTranslate()}px)`);
|
10302 | }
|
10303 |
|
10304 | if (swiper.params.centeredSlides && swiper.params.cssMode) {
|
10305 | offset -= slides[0].swiperSlideOffset;
|
10306 | }
|
10307 |
|
10308 | let tX = swiper.params.cssMode ? -offset - swiper.translate : -offset;
|
10309 | let tY = 0;
|
10310 | const tZ = -100 * Math.abs(progress);
|
10311 | let scale = 1;
|
10312 | let rotate = -2 * progress;
|
10313 | let tXAdd = 8 - Math.abs(progress) * 0.75;
|
10314 | const isSwipeToNext = (i === activeIndex || i === activeIndex - 1) && progress > 0 && progress < 1 && (isTouched || swiper.params.cssMode) && currentTranslate < startTranslate;
|
10315 | const isSwipeToPrev = (i === activeIndex || i === activeIndex + 1) && progress < 0 && progress > -1 && (isTouched || swiper.params.cssMode) && currentTranslate > startTranslate;
|
10316 |
|
10317 | if (isSwipeToNext || isSwipeToPrev) {
|
10318 | const subProgress = (1 - Math.abs((Math.abs(progress) - 0.5) / 0.5)) ** 0.5;
|
10319 | rotate += -28 * progress * subProgress;
|
10320 | scale += -0.5 * subProgress;
|
10321 | tXAdd += 96 * subProgress;
|
10322 | tY = `${-25 * subProgress * Math.abs(progress)}%`;
|
10323 | }
|
10324 |
|
10325 | if (progress < 0) {
|
10326 |
|
10327 | tX = `calc(${tX}px + (${tXAdd * Math.abs(progress)}%))`;
|
10328 | } else if (progress > 0) {
|
10329 |
|
10330 | tX = `calc(${tX}px + (-${tXAdd * Math.abs(progress)}%))`;
|
10331 | } else {
|
10332 | tX = `${tX}px`;
|
10333 | }
|
10334 |
|
10335 | if (!swiper.isHorizontal()) {
|
10336 | const prevY = tY;
|
10337 | tY = tX;
|
10338 | tX = prevY;
|
10339 | }
|
10340 |
|
10341 | const scaleString = progress < 0 ? `${1 + (1 - scale) * progress}` : `${1 - (1 - scale) * progress}`;
|
10342 | const transform = `
|
10343 | translate3d(${tX}, ${tY}, ${tZ}px)
|
10344 | rotateZ(${rotate}deg)
|
10345 | scale(${scaleString})
|
10346 | `;
|
10347 |
|
10348 | if (params.slideShadows) {
|
10349 |
|
10350 | let $shadowEl = $slideEl.find('.swiper-slide-shadow');
|
10351 |
|
10352 | if ($shadowEl.length === 0) {
|
10353 | $shadowEl = createShadow(params, $slideEl);
|
10354 | }
|
10355 |
|
10356 | if ($shadowEl.length) $shadowEl[0].style.opacity = Math.min(Math.max((Math.abs(progress) - 0.5) / 0.5, 0), 1);
|
10357 | }
|
10358 |
|
10359 | $slideEl[0].style.zIndex = -Math.abs(Math.round(slideProgress)) + slides.length;
|
10360 | const $targetEl = effectTarget(params, $slideEl);
|
10361 | $targetEl.transform(transform);
|
10362 | }
|
10363 | };
|
10364 |
|
10365 | const setTransition = duration => {
|
10366 | const {
|
10367 | transformEl
|
10368 | } = swiper.params.cardsEffect;
|
10369 | const $transitionElements = transformEl ? swiper.slides.find(transformEl) : swiper.slides;
|
10370 | $transitionElements.transition(duration).find('.swiper-slide-shadow').transition(duration);
|
10371 | effectVirtualTransitionEnd({
|
10372 | swiper,
|
10373 | duration,
|
10374 | transformEl
|
10375 | });
|
10376 | };
|
10377 |
|
10378 | effectInit({
|
10379 | effect: 'cards',
|
10380 | swiper,
|
10381 | on,
|
10382 | setTranslate,
|
10383 | setTransition,
|
10384 | perspective: () => true,
|
10385 | overwriteParams: () => ({
|
10386 | watchSlidesProgress: true,
|
10387 | virtualTranslate: !swiper.params.cssMode
|
10388 | })
|
10389 | });
|
10390 | }
|
10391 |
|
10392 |
|
10393 | const modules = [Virtual, Keyboard, Mousewheel, Navigation, Pagination, Scrollbar, Parallax, Zoom, Lazy, Controller, A11y, History, HashNavigation, Autoplay, Thumb, freeMode, Grid, Manipulation, EffectFade, EffectCube, EffectFlip, EffectCoverflow, EffectCreative, EffectCards];
|
10394 | Swiper.use(modules);
|
10395 |
|
10396 | return Swiper;
|
10397 |
|
10398 | }));
|
10399 |
|