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