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