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