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