Browse code

Refactor and rewrite as contao bundle

Benjamin Roth authored on04/11/2022 22:32:32
Showing1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,606 +0,0 @@
1
-"use strict";
2
-
3
-exports.__esModule = true;
4
-exports.default = void 0;
5
-
6
-var _dom = _interopRequireDefault(require("../../utils/dom"));
7
-
8
-var _utils = require("../../utils/utils");
9
-
10
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
-function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
13
-
14
-var Zoom = {
15
-  // Calc Scale From Multi-touches
16
-  getDistanceBetweenTouches: function getDistanceBetweenTouches(e) {
17
-    if (e.targetTouches.length < 2) return 1;
18
-    var x1 = e.targetTouches[0].pageX;
19
-    var y1 = e.targetTouches[0].pageY;
20
-    var x2 = e.targetTouches[1].pageX;
21
-    var y2 = e.targetTouches[1].pageY;
22
-    var distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
23
-    return distance;
24
-  },
25
-  // Events
26
-  onGestureStart: function onGestureStart(e) {
27
-    var swiper = this;
28
-    var support = swiper.support;
29
-    var params = swiper.params.zoom;
30
-    var zoom = swiper.zoom;
31
-    var gesture = zoom.gesture;
32
-    zoom.fakeGestureTouched = false;
33
-    zoom.fakeGestureMoved = false;
34
-
35
-    if (!support.gestures) {
36
-      if (e.type !== 'touchstart' || e.type === 'touchstart' && e.targetTouches.length < 2) {
37
-        return;
38
-      }
39
-
40
-      zoom.fakeGestureTouched = true;
41
-      gesture.scaleStart = Zoom.getDistanceBetweenTouches(e);
42
-    }
43
-
44
-    if (!gesture.$slideEl || !gesture.$slideEl.length) {
45
-      gesture.$slideEl = (0, _dom.default)(e.target).closest("." + swiper.params.slideClass);
46
-      if (gesture.$slideEl.length === 0) gesture.$slideEl = swiper.slides.eq(swiper.activeIndex);
47
-      gesture.$imageEl = gesture.$slideEl.find('img, svg, canvas, picture, .swiper-zoom-target');
48
-      gesture.$imageWrapEl = gesture.$imageEl.parent("." + params.containerClass);
49
-      gesture.maxRatio = gesture.$imageWrapEl.attr('data-swiper-zoom') || params.maxRatio;
50
-
51
-      if (gesture.$imageWrapEl.length === 0) {
52
-        gesture.$imageEl = undefined;
53
-        return;
54
-      }
55
-    }
56
-
57
-    if (gesture.$imageEl) {
58
-      gesture.$imageEl.transition(0);
59
-    }
60
-
61
-    swiper.zoom.isScaling = true;
62
-  },
63
-  onGestureChange: function onGestureChange(e) {
64
-    var swiper = this;
65
-    var support = swiper.support;
66
-    var params = swiper.params.zoom;
67
-    var zoom = swiper.zoom;
68
-    var gesture = zoom.gesture;
69
-
70
-    if (!support.gestures) {
71
-      if (e.type !== 'touchmove' || e.type === 'touchmove' && e.targetTouches.length < 2) {
72
-        return;
73
-      }
74
-
75
-      zoom.fakeGestureMoved = true;
76
-      gesture.scaleMove = Zoom.getDistanceBetweenTouches(e);
77
-    }
78
-
79
-    if (!gesture.$imageEl || gesture.$imageEl.length === 0) {
80
-      if (e.type === 'gesturechange') zoom.onGestureStart(e);
81
-      return;
82
-    }
83
-
84
-    if (support.gestures) {
85
-      zoom.scale = e.scale * zoom.currentScale;
86
-    } else {
87
-      zoom.scale = gesture.scaleMove / gesture.scaleStart * zoom.currentScale;
88
-    }
89
-
90
-    if (zoom.scale > gesture.maxRatio) {
91
-      zoom.scale = gesture.maxRatio - 1 + Math.pow(zoom.scale - gesture.maxRatio + 1, 0.5);
92
-    }
93
-
94
-    if (zoom.scale < params.minRatio) {
95
-      zoom.scale = params.minRatio + 1 - Math.pow(params.minRatio - zoom.scale + 1, 0.5);
96
-    }
97
-
98
-    gesture.$imageEl.transform("translate3d(0,0,0) scale(" + zoom.scale + ")");
99
-  },
100
-  onGestureEnd: function onGestureEnd(e) {
101
-    var swiper = this;
102
-    var device = swiper.device;
103
-    var support = swiper.support;
104
-    var params = swiper.params.zoom;
105
-    var zoom = swiper.zoom;
106
-    var gesture = zoom.gesture;
107
-
108
-    if (!support.gestures) {
109
-      if (!zoom.fakeGestureTouched || !zoom.fakeGestureMoved) {
110
-        return;
111
-      }
112
-
113
-      if (e.type !== 'touchend' || e.type === 'touchend' && e.changedTouches.length < 2 && !device.android) {
114
-        return;
115
-      }
116
-
117
-      zoom.fakeGestureTouched = false;
118
-      zoom.fakeGestureMoved = false;
119
-    }
120
-
121
-    if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
122
-    zoom.scale = Math.max(Math.min(zoom.scale, gesture.maxRatio), params.minRatio);
123
-    gesture.$imageEl.transition(swiper.params.speed).transform("translate3d(0,0,0) scale(" + zoom.scale + ")");
124
-    zoom.currentScale = zoom.scale;
125
-    zoom.isScaling = false;
126
-    if (zoom.scale === 1) gesture.$slideEl = undefined;
127
-  },
128
-  onTouchStart: function onTouchStart(e) {
129
-    var swiper = this;
130
-    var device = swiper.device;
131
-    var zoom = swiper.zoom;
132
-    var gesture = zoom.gesture,
133
-        image = zoom.image;
134
-    if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
135
-    if (image.isTouched) return;
136
-    if (device.android && e.cancelable) e.preventDefault();
137
-    image.isTouched = true;
138
-    image.touchesStart.x = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
139
-    image.touchesStart.y = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
140
-  },
141
-  onTouchMove: function onTouchMove(e) {
142
-    var swiper = this;
143
-    var zoom = swiper.zoom;
144
-    var gesture = zoom.gesture,
145
-        image = zoom.image,
146
-        velocity = zoom.velocity;
147
-    if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
148
-    swiper.allowClick = false;
149
-    if (!image.isTouched || !gesture.$slideEl) return;
150
-
151
-    if (!image.isMoved) {
152
-      image.width = gesture.$imageEl[0].offsetWidth;
153
-      image.height = gesture.$imageEl[0].offsetHeight;
154
-      image.startX = (0, _utils.getTranslate)(gesture.$imageWrapEl[0], 'x') || 0;
155
-      image.startY = (0, _utils.getTranslate)(gesture.$imageWrapEl[0], 'y') || 0;
156
-      gesture.slideWidth = gesture.$slideEl[0].offsetWidth;
157
-      gesture.slideHeight = gesture.$slideEl[0].offsetHeight;
158
-      gesture.$imageWrapEl.transition(0);
159
-
160
-      if (swiper.rtl) {
161
-        image.startX = -image.startX;
162
-        image.startY = -image.startY;
163
-      }
164
-    } // Define if we need image drag
165
-
166
-
167
-    var scaledWidth = image.width * zoom.scale;
168
-    var scaledHeight = image.height * zoom.scale;
169
-    if (scaledWidth < gesture.slideWidth && scaledHeight < gesture.slideHeight) return;
170
-    image.minX = Math.min(gesture.slideWidth / 2 - scaledWidth / 2, 0);
171
-    image.maxX = -image.minX;
172
-    image.minY = Math.min(gesture.slideHeight / 2 - scaledHeight / 2, 0);
173
-    image.maxY = -image.minY;
174
-    image.touchesCurrent.x = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
175
-    image.touchesCurrent.y = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
176
-
177
-    if (!image.isMoved && !zoom.isScaling) {
178
-      if (swiper.isHorizontal() && (Math.floor(image.minX) === Math.floor(image.startX) && image.touchesCurrent.x < image.touchesStart.x || Math.floor(image.maxX) === Math.floor(image.startX) && image.touchesCurrent.x > image.touchesStart.x)) {
179
-        image.isTouched = false;
180
-        return;
181
-      }
182
-
183
-      if (!swiper.isHorizontal() && (Math.floor(image.minY) === Math.floor(image.startY) && image.touchesCurrent.y < image.touchesStart.y || Math.floor(image.maxY) === Math.floor(image.startY) && image.touchesCurrent.y > image.touchesStart.y)) {
184
-        image.isTouched = false;
185
-        return;
186
-      }
187
-    }
188
-
189
-    if (e.cancelable) {
190
-      e.preventDefault();
191
-    }
192
-
193
-    e.stopPropagation();
194
-    image.isMoved = true;
195
-    image.currentX = image.touchesCurrent.x - image.touchesStart.x + image.startX;
196
-    image.currentY = image.touchesCurrent.y - image.touchesStart.y + image.startY;
197
-
198
-    if (image.currentX < image.minX) {
199
-      image.currentX = image.minX + 1 - Math.pow(image.minX - image.currentX + 1, 0.8);
200
-    }
201
-
202
-    if (image.currentX > image.maxX) {
203
-      image.currentX = image.maxX - 1 + Math.pow(image.currentX - image.maxX + 1, 0.8);
204
-    }
205
-
206
-    if (image.currentY < image.minY) {
207
-      image.currentY = image.minY + 1 - Math.pow(image.minY - image.currentY + 1, 0.8);
208
-    }
209
-
210
-    if (image.currentY > image.maxY) {
211
-      image.currentY = image.maxY - 1 + Math.pow(image.currentY - image.maxY + 1, 0.8);
212
-    } // Velocity
213
-
214
-
215
-    if (!velocity.prevPositionX) velocity.prevPositionX = image.touchesCurrent.x;
216
-    if (!velocity.prevPositionY) velocity.prevPositionY = image.touchesCurrent.y;
217
-    if (!velocity.prevTime) velocity.prevTime = Date.now();
218
-    velocity.x = (image.touchesCurrent.x - velocity.prevPositionX) / (Date.now() - velocity.prevTime) / 2;
219
-    velocity.y = (image.touchesCurrent.y - velocity.prevPositionY) / (Date.now() - velocity.prevTime) / 2;
220
-    if (Math.abs(image.touchesCurrent.x - velocity.prevPositionX) < 2) velocity.x = 0;
221
-    if (Math.abs(image.touchesCurrent.y - velocity.prevPositionY) < 2) velocity.y = 0;
222
-    velocity.prevPositionX = image.touchesCurrent.x;
223
-    velocity.prevPositionY = image.touchesCurrent.y;
224
-    velocity.prevTime = Date.now();
225
-    gesture.$imageWrapEl.transform("translate3d(" + image.currentX + "px, " + image.currentY + "px,0)");
226
-  },
227
-  onTouchEnd: function onTouchEnd() {
228
-    var swiper = this;
229
-    var zoom = swiper.zoom;
230
-    var gesture = zoom.gesture,
231
-        image = zoom.image,
232
-        velocity = zoom.velocity;
233
-    if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
234
-
235
-    if (!image.isTouched || !image.isMoved) {
236
-      image.isTouched = false;
237
-      image.isMoved = false;
238
-      return;
239
-    }
240
-
241
-    image.isTouched = false;
242
-    image.isMoved = false;
243
-    var momentumDurationX = 300;
244
-    var momentumDurationY = 300;
245
-    var momentumDistanceX = velocity.x * momentumDurationX;
246
-    var newPositionX = image.currentX + momentumDistanceX;
247
-    var momentumDistanceY = velocity.y * momentumDurationY;
248
-    var newPositionY = image.currentY + momentumDistanceY; // Fix duration
249
-
250
-    if (velocity.x !== 0) momentumDurationX = Math.abs((newPositionX - image.currentX) / velocity.x);
251
-    if (velocity.y !== 0) momentumDurationY = Math.abs((newPositionY - image.currentY) / velocity.y);
252
-    var momentumDuration = Math.max(momentumDurationX, momentumDurationY);
253
-    image.currentX = newPositionX;
254
-    image.currentY = newPositionY; // Define if we need image drag
255
-
256
-    var scaledWidth = image.width * zoom.scale;
257
-    var scaledHeight = image.height * zoom.scale;
258
-    image.minX = Math.min(gesture.slideWidth / 2 - scaledWidth / 2, 0);
259
-    image.maxX = -image.minX;
260
-    image.minY = Math.min(gesture.slideHeight / 2 - scaledHeight / 2, 0);
261
-    image.maxY = -image.minY;
262
-    image.currentX = Math.max(Math.min(image.currentX, image.maxX), image.minX);
263
-    image.currentY = Math.max(Math.min(image.currentY, image.maxY), image.minY);
264
-    gesture.$imageWrapEl.transition(momentumDuration).transform("translate3d(" + image.currentX + "px, " + image.currentY + "px,0)");
265
-  },
266
-  onTransitionEnd: function onTransitionEnd() {
267
-    var swiper = this;
268
-    var zoom = swiper.zoom;
269
-    var gesture = zoom.gesture;
270
-
271
-    if (gesture.$slideEl && swiper.previousIndex !== swiper.activeIndex) {
272
-      if (gesture.$imageEl) {
273
-        gesture.$imageEl.transform('translate3d(0,0,0) scale(1)');
274
-      }
275
-
276
-      if (gesture.$imageWrapEl) {
277
-        gesture.$imageWrapEl.transform('translate3d(0,0,0)');
278
-      }
279
-
280
-      zoom.scale = 1;
281
-      zoom.currentScale = 1;
282
-      gesture.$slideEl = undefined;
283
-      gesture.$imageEl = undefined;
284
-      gesture.$imageWrapEl = undefined;
285
-    }
286
-  },
287
-  // Toggle Zoom
288
-  toggle: function toggle(e) {
289
-    var swiper = this;
290
-    var zoom = swiper.zoom;
291
-
292
-    if (zoom.scale && zoom.scale !== 1) {
293
-      // Zoom Out
294
-      zoom.out();
295
-    } else {
296
-      // Zoom In
297
-      zoom.in(e);
298
-    }
299
-  },
300
-  in: function _in(e) {
301
-    var swiper = this;
302
-    var zoom = swiper.zoom;
303
-    var params = swiper.params.zoom;
304
-    var gesture = zoom.gesture,
305
-        image = zoom.image;
306
-
307
-    if (!gesture.$slideEl) {
308
-      if (swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual) {
309
-        gesture.$slideEl = swiper.$wrapperEl.children("." + swiper.params.slideActiveClass);
310
-      } else {
311
-        gesture.$slideEl = swiper.slides.eq(swiper.activeIndex);
312
-      }
313
-
314
-      gesture.$imageEl = gesture.$slideEl.find('img, svg, canvas, picture, .swiper-zoom-target');
315
-      gesture.$imageWrapEl = gesture.$imageEl.parent("." + params.containerClass);
316
-    }
317
-
318
-    if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
319
-    gesture.$slideEl.addClass("" + params.zoomedSlideClass);
320
-    var touchX;
321
-    var touchY;
322
-    var offsetX;
323
-    var offsetY;
324
-    var diffX;
325
-    var diffY;
326
-    var translateX;
327
-    var translateY;
328
-    var imageWidth;
329
-    var imageHeight;
330
-    var scaledWidth;
331
-    var scaledHeight;
332
-    var translateMinX;
333
-    var translateMinY;
334
-    var translateMaxX;
335
-    var translateMaxY;
336
-    var slideWidth;
337
-    var slideHeight;
338
-
339
-    if (typeof image.touchesStart.x === 'undefined' && e) {
340
-      touchX = e.type === 'touchend' ? e.changedTouches[0].pageX : e.pageX;
341
-      touchY = e.type === 'touchend' ? e.changedTouches[0].pageY : e.pageY;
342
-    } else {
343
-      touchX = image.touchesStart.x;
344
-      touchY = image.touchesStart.y;
345
-    }
346
-
347
-    zoom.scale = gesture.$imageWrapEl.attr('data-swiper-zoom') || params.maxRatio;
348
-    zoom.currentScale = gesture.$imageWrapEl.attr('data-swiper-zoom') || params.maxRatio;
349
-
350
-    if (e) {
351
-      slideWidth = gesture.$slideEl[0].offsetWidth;
352
-      slideHeight = gesture.$slideEl[0].offsetHeight;
353
-      offsetX = gesture.$slideEl.offset().left;
354
-      offsetY = gesture.$slideEl.offset().top;
355
-      diffX = offsetX + slideWidth / 2 - touchX;
356
-      diffY = offsetY + slideHeight / 2 - touchY;
357
-      imageWidth = gesture.$imageEl[0].offsetWidth;
358
-      imageHeight = gesture.$imageEl[0].offsetHeight;
359
-      scaledWidth = imageWidth * zoom.scale;
360
-      scaledHeight = imageHeight * zoom.scale;
361
-      translateMinX = Math.min(slideWidth / 2 - scaledWidth / 2, 0);
362
-      translateMinY = Math.min(slideHeight / 2 - scaledHeight / 2, 0);
363
-      translateMaxX = -translateMinX;
364
-      translateMaxY = -translateMinY;
365
-      translateX = diffX * zoom.scale;
366
-      translateY = diffY * zoom.scale;
367
-
368
-      if (translateX < translateMinX) {
369
-        translateX = translateMinX;
370
-      }
371
-
372
-      if (translateX > translateMaxX) {
373
-        translateX = translateMaxX;
374
-      }
375
-
376
-      if (translateY < translateMinY) {
377
-        translateY = translateMinY;
378
-      }
379
-
380
-      if (translateY > translateMaxY) {
381
-        translateY = translateMaxY;
382
-      }
383
-    } else {
384
-      translateX = 0;
385
-      translateY = 0;
386
-    }
387
-
388
-    gesture.$imageWrapEl.transition(300).transform("translate3d(" + translateX + "px, " + translateY + "px,0)");
389
-    gesture.$imageEl.transition(300).transform("translate3d(0,0,0) scale(" + zoom.scale + ")");
390
-  },
391
-  out: function out() {
392
-    var swiper = this;
393
-    var zoom = swiper.zoom;
394
-    var params = swiper.params.zoom;
395
-    var gesture = zoom.gesture;
396
-
397
-    if (!gesture.$slideEl) {
398
-      if (swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual) {
399
-        gesture.$slideEl = swiper.$wrapperEl.children("." + swiper.params.slideActiveClass);
400
-      } else {
401
-        gesture.$slideEl = swiper.slides.eq(swiper.activeIndex);
402
-      }
403
-
404
-      gesture.$imageEl = gesture.$slideEl.find('img, svg, canvas, picture, .swiper-zoom-target');
405
-      gesture.$imageWrapEl = gesture.$imageEl.parent("." + params.containerClass);
406
-    }
407
-
408
-    if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
409
-    zoom.scale = 1;
410
-    zoom.currentScale = 1;
411
-    gesture.$imageWrapEl.transition(300).transform('translate3d(0,0,0)');
412
-    gesture.$imageEl.transition(300).transform('translate3d(0,0,0) scale(1)');
413
-    gesture.$slideEl.removeClass("" + params.zoomedSlideClass);
414
-    gesture.$slideEl = undefined;
415
-  },
416
-  toggleGestures: function toggleGestures(method) {
417
-    var swiper = this;
418
-    var zoom = swiper.zoom;
419
-    var selector = zoom.slideSelector,
420
-        passive = zoom.passiveListener;
421
-    swiper.$wrapperEl[method]('gesturestart', selector, zoom.onGestureStart, passive);
422
-    swiper.$wrapperEl[method]('gesturechange', selector, zoom.onGestureChange, passive);
423
-    swiper.$wrapperEl[method]('gestureend', selector, zoom.onGestureEnd, passive);
424
-  },
425
-  enableGestures: function enableGestures() {
426
-    if (this.zoom.gesturesEnabled) return;
427
-    this.zoom.gesturesEnabled = true;
428
-    this.zoom.toggleGestures('on');
429
-  },
430
-  disableGestures: function disableGestures() {
431
-    if (!this.zoom.gesturesEnabled) return;
432
-    this.zoom.gesturesEnabled = false;
433
-    this.zoom.toggleGestures('off');
434
-  },
435
-  // Attach/Detach Events
436
-  enable: function enable() {
437
-    var swiper = this;
438
-    var support = swiper.support;
439
-    var zoom = swiper.zoom;
440
-    if (zoom.enabled) return;
441
-    zoom.enabled = true;
442
-    var passiveListener = swiper.touchEvents.start === 'touchstart' && support.passiveListener && swiper.params.passiveListeners ? {
443
-      passive: true,
444
-      capture: false
445
-    } : false;
446
-    var activeListenerWithCapture = support.passiveListener ? {
447
-      passive: false,
448
-      capture: true
449
-    } : true;
450
-    var slideSelector = "." + swiper.params.slideClass;
451
-    swiper.zoom.passiveListener = passiveListener;
452
-    swiper.zoom.slideSelector = slideSelector; // Scale image
453
-
454
-    if (support.gestures) {
455
-      swiper.$wrapperEl.on(swiper.touchEvents.start, swiper.zoom.enableGestures, passiveListener);
456
-      swiper.$wrapperEl.on(swiper.touchEvents.end, swiper.zoom.disableGestures, passiveListener);
457
-    } else if (swiper.touchEvents.start === 'touchstart') {
458
-      swiper.$wrapperEl.on(swiper.touchEvents.start, slideSelector, zoom.onGestureStart, passiveListener);
459
-      swiper.$wrapperEl.on(swiper.touchEvents.move, slideSelector, zoom.onGestureChange, activeListenerWithCapture);
460
-      swiper.$wrapperEl.on(swiper.touchEvents.end, slideSelector, zoom.onGestureEnd, passiveListener);
461
-
462
-      if (swiper.touchEvents.cancel) {
463
-        swiper.$wrapperEl.on(swiper.touchEvents.cancel, slideSelector, zoom.onGestureEnd, passiveListener);
464
-      }
465
-    } // Move image
466
-
467
-
468
-    swiper.$wrapperEl.on(swiper.touchEvents.move, "." + swiper.params.zoom.containerClass, zoom.onTouchMove, activeListenerWithCapture);
469
-  },
470
-  disable: function disable() {
471
-    var swiper = this;
472
-    var zoom = swiper.zoom;
473
-    if (!zoom.enabled) return;
474
-    var support = swiper.support;
475
-    swiper.zoom.enabled = false;
476
-    var passiveListener = swiper.touchEvents.start === 'touchstart' && support.passiveListener && swiper.params.passiveListeners ? {
477
-      passive: true,
478
-      capture: false
479
-    } : false;
480
-    var activeListenerWithCapture = support.passiveListener ? {
481
-      passive: false,
482
-      capture: true
483
-    } : true;
484
-    var slideSelector = "." + swiper.params.slideClass; // Scale image
485
-
486
-    if (support.gestures) {
487
-      swiper.$wrapperEl.off(swiper.touchEvents.start, swiper.zoom.enableGestures, passiveListener);
488
-      swiper.$wrapperEl.off(swiper.touchEvents.end, swiper.zoom.disableGestures, passiveListener);
489
-    } else if (swiper.touchEvents.start === 'touchstart') {
490
-      swiper.$wrapperEl.off(swiper.touchEvents.start, slideSelector, zoom.onGestureStart, passiveListener);
491
-      swiper.$wrapperEl.off(swiper.touchEvents.move, slideSelector, zoom.onGestureChange, activeListenerWithCapture);
492
-      swiper.$wrapperEl.off(swiper.touchEvents.end, slideSelector, zoom.onGestureEnd, passiveListener);
493
-
494
-      if (swiper.touchEvents.cancel) {
495
-        swiper.$wrapperEl.off(swiper.touchEvents.cancel, slideSelector, zoom.onGestureEnd, passiveListener);
496
-      }
497
-    } // Move image
498
-
499
-
500
-    swiper.$wrapperEl.off(swiper.touchEvents.move, "." + swiper.params.zoom.containerClass, zoom.onTouchMove, activeListenerWithCapture);
501
-  }
502
-};
503
-var _default = {
504
-  name: 'zoom',
505
-  params: {
506
-    zoom: {
507
-      enabled: false,
508
-      maxRatio: 3,
509
-      minRatio: 1,
510
-      toggle: true,
511
-      containerClass: 'swiper-zoom-container',
512
-      zoomedSlideClass: 'swiper-slide-zoomed'
513
-    }
514
-  },
515
-  create: function create() {
516
-    var swiper = this;
517
-    (0, _utils.bindModuleMethods)(swiper, {
518
-      zoom: _extends({
519
-        enabled: false,
520
-        scale: 1,
521
-        currentScale: 1,
522
-        isScaling: false,
523
-        gesture: {
524
-          $slideEl: undefined,
525
-          slideWidth: undefined,
526
-          slideHeight: undefined,
527
-          $imageEl: undefined,
528
-          $imageWrapEl: undefined,
529
-          maxRatio: 3
530
-        },
531
-        image: {
532
-          isTouched: undefined,
533
-          isMoved: undefined,
534
-          currentX: undefined,
535
-          currentY: undefined,
536
-          minX: undefined,
537
-          minY: undefined,
538
-          maxX: undefined,
539
-          maxY: undefined,
540
-          width: undefined,
541
-          height: undefined,
542
-          startX: undefined,
543
-          startY: undefined,
544
-          touchesStart: {},
545
-          touchesCurrent: {}
546
-        },
547
-        velocity: {
548
-          x: undefined,
549
-          y: undefined,
550
-          prevPositionX: undefined,
551
-          prevPositionY: undefined,
552
-          prevTime: undefined
553
-        }
554
-      }, Zoom)
555
-    });
556
-    var scale = 1;
557
-    Object.defineProperty(swiper.zoom, 'scale', {
558
-      get: function get() {
559
-        return scale;
560
-      },
561
-      set: function set(value) {
562
-        if (scale !== value) {
563
-          var imageEl = swiper.zoom.gesture.$imageEl ? swiper.zoom.gesture.$imageEl[0] : undefined;
564
-          var slideEl = swiper.zoom.gesture.$slideEl ? swiper.zoom.gesture.$slideEl[0] : undefined;
565
-          swiper.emit('zoomChange', value, imageEl, slideEl);
566
-        }
567
-
568
-        scale = value;
569
-      }
570
-    });
571
-  },
572
-  on: {
573
-    init: function init(swiper) {
574
-      if (swiper.params.zoom.enabled) {
575
-        swiper.zoom.enable();
576
-      }
577
-    },
578
-    destroy: function destroy(swiper) {
579
-      swiper.zoom.disable();
580
-    },
581
-    touchStart: function touchStart(swiper, e) {
582
-      if (!swiper.zoom.enabled) return;
583
-      swiper.zoom.onTouchStart(e);
584
-    },
585
-    touchEnd: function touchEnd(swiper, e) {
586
-      if (!swiper.zoom.enabled) return;
587
-      swiper.zoom.onTouchEnd(e);
588
-    },
589
-    doubleTap: function doubleTap(swiper, e) {
590
-      if (swiper.params.zoom.enabled && swiper.zoom.enabled && swiper.params.zoom.toggle) {
591
-        swiper.zoom.toggle(e);
592
-      }
593
-    },
594
-    transitionEnd: function transitionEnd(swiper) {
595
-      if (swiper.zoom.enabled && swiper.params.zoom.enabled) {
596
-        swiper.zoom.onTransitionEnd();
597
-      }
598
-    },
599
-    slideChange: function slideChange(swiper) {
600
-      if (swiper.zoom.enabled && swiper.params.zoom.enabled && swiper.params.cssMode) {
601
-        swiper.zoom.onTransitionEnd();
602
-      }
603
-    }
604
-  }
605
-};
606
-exports.default = _default;
607 0
\ No newline at end of file
Browse code

swiper.js version 6.3.3

Benjamin Roth authored on13/10/2020 19:31:56
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,606 @@
1
+"use strict";
2
+
3
+exports.__esModule = true;
4
+exports.default = void 0;
5
+
6
+var _dom = _interopRequireDefault(require("../../utils/dom"));
7
+
8
+var _utils = require("../../utils/utils");
9
+
10
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
13
+
14
+var Zoom = {
15
+  // Calc Scale From Multi-touches
16
+  getDistanceBetweenTouches: function getDistanceBetweenTouches(e) {
17
+    if (e.targetTouches.length < 2) return 1;
18
+    var x1 = e.targetTouches[0].pageX;
19
+    var y1 = e.targetTouches[0].pageY;
20
+    var x2 = e.targetTouches[1].pageX;
21
+    var y2 = e.targetTouches[1].pageY;
22
+    var distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
23
+    return distance;
24
+  },
25
+  // Events
26
+  onGestureStart: function onGestureStart(e) {
27
+    var swiper = this;
28
+    var support = swiper.support;
29
+    var params = swiper.params.zoom;
30
+    var zoom = swiper.zoom;
31
+    var gesture = zoom.gesture;
32
+    zoom.fakeGestureTouched = false;
33
+    zoom.fakeGestureMoved = false;
34
+
35
+    if (!support.gestures) {
36
+      if (e.type !== 'touchstart' || e.type === 'touchstart' && e.targetTouches.length < 2) {
37
+        return;
38
+      }
39
+
40
+      zoom.fakeGestureTouched = true;
41
+      gesture.scaleStart = Zoom.getDistanceBetweenTouches(e);
42
+    }
43
+
44
+    if (!gesture.$slideEl || !gesture.$slideEl.length) {
45
+      gesture.$slideEl = (0, _dom.default)(e.target).closest("." + swiper.params.slideClass);
46
+      if (gesture.$slideEl.length === 0) gesture.$slideEl = swiper.slides.eq(swiper.activeIndex);
47
+      gesture.$imageEl = gesture.$slideEl.find('img, svg, canvas, picture, .swiper-zoom-target');
48
+      gesture.$imageWrapEl = gesture.$imageEl.parent("." + params.containerClass);
49
+      gesture.maxRatio = gesture.$imageWrapEl.attr('data-swiper-zoom') || params.maxRatio;
50
+
51
+      if (gesture.$imageWrapEl.length === 0) {
52
+        gesture.$imageEl = undefined;
53
+        return;
54
+      }
55
+    }
56
+
57
+    if (gesture.$imageEl) {
58
+      gesture.$imageEl.transition(0);
59
+    }
60
+
61
+    swiper.zoom.isScaling = true;
62
+  },
63
+  onGestureChange: function onGestureChange(e) {
64
+    var swiper = this;
65
+    var support = swiper.support;
66
+    var params = swiper.params.zoom;
67
+    var zoom = swiper.zoom;
68
+    var gesture = zoom.gesture;
69
+
70
+    if (!support.gestures) {
71
+      if (e.type !== 'touchmove' || e.type === 'touchmove' && e.targetTouches.length < 2) {
72
+        return;
73
+      }
74
+
75
+      zoom.fakeGestureMoved = true;
76
+      gesture.scaleMove = Zoom.getDistanceBetweenTouches(e);
77
+    }
78
+
79
+    if (!gesture.$imageEl || gesture.$imageEl.length === 0) {
80
+      if (e.type === 'gesturechange') zoom.onGestureStart(e);
81
+      return;
82
+    }
83
+
84
+    if (support.gestures) {
85
+      zoom.scale = e.scale * zoom.currentScale;
86
+    } else {
87
+      zoom.scale = gesture.scaleMove / gesture.scaleStart * zoom.currentScale;
88
+    }
89
+
90
+    if (zoom.scale > gesture.maxRatio) {
91
+      zoom.scale = gesture.maxRatio - 1 + Math.pow(zoom.scale - gesture.maxRatio + 1, 0.5);
92
+    }
93
+
94
+    if (zoom.scale < params.minRatio) {
95
+      zoom.scale = params.minRatio + 1 - Math.pow(params.minRatio - zoom.scale + 1, 0.5);
96
+    }
97
+
98
+    gesture.$imageEl.transform("translate3d(0,0,0) scale(" + zoom.scale + ")");
99
+  },
100
+  onGestureEnd: function onGestureEnd(e) {
101
+    var swiper = this;
102
+    var device = swiper.device;
103
+    var support = swiper.support;
104
+    var params = swiper.params.zoom;
105
+    var zoom = swiper.zoom;
106
+    var gesture = zoom.gesture;
107
+
108
+    if (!support.gestures) {
109
+      if (!zoom.fakeGestureTouched || !zoom.fakeGestureMoved) {
110
+        return;
111
+      }
112
+
113
+      if (e.type !== 'touchend' || e.type === 'touchend' && e.changedTouches.length < 2 && !device.android) {
114
+        return;
115
+      }
116
+
117
+      zoom.fakeGestureTouched = false;
118
+      zoom.fakeGestureMoved = false;
119
+    }
120
+
121
+    if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
122
+    zoom.scale = Math.max(Math.min(zoom.scale, gesture.maxRatio), params.minRatio);
123
+    gesture.$imageEl.transition(swiper.params.speed).transform("translate3d(0,0,0) scale(" + zoom.scale + ")");
124
+    zoom.currentScale = zoom.scale;
125
+    zoom.isScaling = false;
126
+    if (zoom.scale === 1) gesture.$slideEl = undefined;
127
+  },
128
+  onTouchStart: function onTouchStart(e) {
129
+    var swiper = this;
130
+    var device = swiper.device;
131
+    var zoom = swiper.zoom;
132
+    var gesture = zoom.gesture,
133
+        image = zoom.image;
134
+    if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
135
+    if (image.isTouched) return;
136
+    if (device.android && e.cancelable) e.preventDefault();
137
+    image.isTouched = true;
138
+    image.touchesStart.x = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
139
+    image.touchesStart.y = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
140
+  },
141
+  onTouchMove: function onTouchMove(e) {
142
+    var swiper = this;
143
+    var zoom = swiper.zoom;
144
+    var gesture = zoom.gesture,
145
+        image = zoom.image,
146
+        velocity = zoom.velocity;
147
+    if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
148
+    swiper.allowClick = false;
149
+    if (!image.isTouched || !gesture.$slideEl) return;
150
+
151
+    if (!image.isMoved) {
152
+      image.width = gesture.$imageEl[0].offsetWidth;
153
+      image.height = gesture.$imageEl[0].offsetHeight;
154
+      image.startX = (0, _utils.getTranslate)(gesture.$imageWrapEl[0], 'x') || 0;
155
+      image.startY = (0, _utils.getTranslate)(gesture.$imageWrapEl[0], 'y') || 0;
156
+      gesture.slideWidth = gesture.$slideEl[0].offsetWidth;
157
+      gesture.slideHeight = gesture.$slideEl[0].offsetHeight;
158
+      gesture.$imageWrapEl.transition(0);
159
+
160
+      if (swiper.rtl) {
161
+        image.startX = -image.startX;
162
+        image.startY = -image.startY;
163
+      }
164
+    } // Define if we need image drag
165
+
166
+
167
+    var scaledWidth = image.width * zoom.scale;
168
+    var scaledHeight = image.height * zoom.scale;
169
+    if (scaledWidth < gesture.slideWidth && scaledHeight < gesture.slideHeight) return;
170
+    image.minX = Math.min(gesture.slideWidth / 2 - scaledWidth / 2, 0);
171
+    image.maxX = -image.minX;
172
+    image.minY = Math.min(gesture.slideHeight / 2 - scaledHeight / 2, 0);
173
+    image.maxY = -image.minY;
174
+    image.touchesCurrent.x = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
175
+    image.touchesCurrent.y = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
176
+
177
+    if (!image.isMoved && !zoom.isScaling) {
178
+      if (swiper.isHorizontal() && (Math.floor(image.minX) === Math.floor(image.startX) && image.touchesCurrent.x < image.touchesStart.x || Math.floor(image.maxX) === Math.floor(image.startX) && image.touchesCurrent.x > image.touchesStart.x)) {
179
+        image.isTouched = false;
180
+        return;
181
+      }
182
+
183
+      if (!swiper.isHorizontal() && (Math.floor(image.minY) === Math.floor(image.startY) && image.touchesCurrent.y < image.touchesStart.y || Math.floor(image.maxY) === Math.floor(image.startY) && image.touchesCurrent.y > image.touchesStart.y)) {
184
+        image.isTouched = false;
185
+        return;
186
+      }
187
+    }
188
+
189
+    if (e.cancelable) {
190
+      e.preventDefault();
191
+    }
192
+
193
+    e.stopPropagation();
194
+    image.isMoved = true;
195
+    image.currentX = image.touchesCurrent.x - image.touchesStart.x + image.startX;
196
+    image.currentY = image.touchesCurrent.y - image.touchesStart.y + image.startY;
197
+
198
+    if (image.currentX < image.minX) {
199
+      image.currentX = image.minX + 1 - Math.pow(image.minX - image.currentX + 1, 0.8);
200
+    }
201
+
202
+    if (image.currentX > image.maxX) {
203
+      image.currentX = image.maxX - 1 + Math.pow(image.currentX - image.maxX + 1, 0.8);
204
+    }
205
+
206
+    if (image.currentY < image.minY) {
207
+      image.currentY = image.minY + 1 - Math.pow(image.minY - image.currentY + 1, 0.8);
208
+    }
209
+
210
+    if (image.currentY > image.maxY) {
211
+      image.currentY = image.maxY - 1 + Math.pow(image.currentY - image.maxY + 1, 0.8);
212
+    } // Velocity
213
+
214
+
215
+    if (!velocity.prevPositionX) velocity.prevPositionX = image.touchesCurrent.x;
216
+    if (!velocity.prevPositionY) velocity.prevPositionY = image.touchesCurrent.y;
217
+    if (!velocity.prevTime) velocity.prevTime = Date.now();
218
+    velocity.x = (image.touchesCurrent.x - velocity.prevPositionX) / (Date.now() - velocity.prevTime) / 2;
219
+    velocity.y = (image.touchesCurrent.y - velocity.prevPositionY) / (Date.now() - velocity.prevTime) / 2;
220
+    if (Math.abs(image.touchesCurrent.x - velocity.prevPositionX) < 2) velocity.x = 0;
221
+    if (Math.abs(image.touchesCurrent.y - velocity.prevPositionY) < 2) velocity.y = 0;
222
+    velocity.prevPositionX = image.touchesCurrent.x;
223
+    velocity.prevPositionY = image.touchesCurrent.y;
224
+    velocity.prevTime = Date.now();
225
+    gesture.$imageWrapEl.transform("translate3d(" + image.currentX + "px, " + image.currentY + "px,0)");
226
+  },
227
+  onTouchEnd: function onTouchEnd() {
228
+    var swiper = this;
229
+    var zoom = swiper.zoom;
230
+    var gesture = zoom.gesture,
231
+        image = zoom.image,
232
+        velocity = zoom.velocity;
233
+    if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
234
+
235
+    if (!image.isTouched || !image.isMoved) {
236
+      image.isTouched = false;
237
+      image.isMoved = false;
238
+      return;
239
+    }
240
+
241
+    image.isTouched = false;
242
+    image.isMoved = false;
243
+    var momentumDurationX = 300;
244
+    var momentumDurationY = 300;
245
+    var momentumDistanceX = velocity.x * momentumDurationX;
246
+    var newPositionX = image.currentX + momentumDistanceX;
247
+    var momentumDistanceY = velocity.y * momentumDurationY;
248
+    var newPositionY = image.currentY + momentumDistanceY; // Fix duration
249
+
250
+    if (velocity.x !== 0) momentumDurationX = Math.abs((newPositionX - image.currentX) / velocity.x);
251
+    if (velocity.y !== 0) momentumDurationY = Math.abs((newPositionY - image.currentY) / velocity.y);
252
+    var momentumDuration = Math.max(momentumDurationX, momentumDurationY);
253
+    image.currentX = newPositionX;
254
+    image.currentY = newPositionY; // Define if we need image drag
255
+
256
+    var scaledWidth = image.width * zoom.scale;
257
+    var scaledHeight = image.height * zoom.scale;
258
+    image.minX = Math.min(gesture.slideWidth / 2 - scaledWidth / 2, 0);
259
+    image.maxX = -image.minX;
260
+    image.minY = Math.min(gesture.slideHeight / 2 - scaledHeight / 2, 0);
261
+    image.maxY = -image.minY;
262
+    image.currentX = Math.max(Math.min(image.currentX, image.maxX), image.minX);
263
+    image.currentY = Math.max(Math.min(image.currentY, image.maxY), image.minY);
264
+    gesture.$imageWrapEl.transition(momentumDuration).transform("translate3d(" + image.currentX + "px, " + image.currentY + "px,0)");
265
+  },
266
+  onTransitionEnd: function onTransitionEnd() {
267
+    var swiper = this;
268
+    var zoom = swiper.zoom;
269
+    var gesture = zoom.gesture;
270
+
271
+    if (gesture.$slideEl && swiper.previousIndex !== swiper.activeIndex) {
272
+      if (gesture.$imageEl) {
273
+        gesture.$imageEl.transform('translate3d(0,0,0) scale(1)');
274
+      }
275
+
276
+      if (gesture.$imageWrapEl) {
277
+        gesture.$imageWrapEl.transform('translate3d(0,0,0)');
278
+      }
279
+
280
+      zoom.scale = 1;
281
+      zoom.currentScale = 1;
282
+      gesture.$slideEl = undefined;
283
+      gesture.$imageEl = undefined;
284
+      gesture.$imageWrapEl = undefined;
285
+    }
286
+  },
287
+  // Toggle Zoom
288
+  toggle: function toggle(e) {
289
+    var swiper = this;
290
+    var zoom = swiper.zoom;
291
+
292
+    if (zoom.scale && zoom.scale !== 1) {
293
+      // Zoom Out
294
+      zoom.out();
295
+    } else {
296
+      // Zoom In
297
+      zoom.in(e);
298
+    }
299
+  },
300
+  in: function _in(e) {
301
+    var swiper = this;
302
+    var zoom = swiper.zoom;
303
+    var params = swiper.params.zoom;
304
+    var gesture = zoom.gesture,
305
+        image = zoom.image;
306
+
307
+    if (!gesture.$slideEl) {
308
+      if (swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual) {
309
+        gesture.$slideEl = swiper.$wrapperEl.children("." + swiper.params.slideActiveClass);
310
+      } else {
311
+        gesture.$slideEl = swiper.slides.eq(swiper.activeIndex);
312
+      }
313
+
314
+      gesture.$imageEl = gesture.$slideEl.find('img, svg, canvas, picture, .swiper-zoom-target');
315
+      gesture.$imageWrapEl = gesture.$imageEl.parent("." + params.containerClass);
316
+    }
317
+
318
+    if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
319
+    gesture.$slideEl.addClass("" + params.zoomedSlideClass);
320
+    var touchX;
321
+    var touchY;
322
+    var offsetX;
323
+    var offsetY;
324
+    var diffX;
325
+    var diffY;
326
+    var translateX;
327
+    var translateY;
328
+    var imageWidth;
329
+    var imageHeight;
330
+    var scaledWidth;
331
+    var scaledHeight;
332
+    var translateMinX;
333
+    var translateMinY;
334
+    var translateMaxX;
335
+    var translateMaxY;
336
+    var slideWidth;
337
+    var slideHeight;
338
+
339
+    if (typeof image.touchesStart.x === 'undefined' && e) {
340
+      touchX = e.type === 'touchend' ? e.changedTouches[0].pageX : e.pageX;
341
+      touchY = e.type === 'touchend' ? e.changedTouches[0].pageY : e.pageY;
342
+    } else {
343
+      touchX = image.touchesStart.x;
344
+      touchY = image.touchesStart.y;
345
+    }
346
+
347
+    zoom.scale = gesture.$imageWrapEl.attr('data-swiper-zoom') || params.maxRatio;
348
+    zoom.currentScale = gesture.$imageWrapEl.attr('data-swiper-zoom') || params.maxRatio;
349
+
350
+    if (e) {
351
+      slideWidth = gesture.$slideEl[0].offsetWidth;
352
+      slideHeight = gesture.$slideEl[0].offsetHeight;
353
+      offsetX = gesture.$slideEl.offset().left;
354
+      offsetY = gesture.$slideEl.offset().top;
355
+      diffX = offsetX + slideWidth / 2 - touchX;
356
+      diffY = offsetY + slideHeight / 2 - touchY;
357
+      imageWidth = gesture.$imageEl[0].offsetWidth;
358
+      imageHeight = gesture.$imageEl[0].offsetHeight;
359
+      scaledWidth = imageWidth * zoom.scale;
360
+      scaledHeight = imageHeight * zoom.scale;
361
+      translateMinX = Math.min(slideWidth / 2 - scaledWidth / 2, 0);
362
+      translateMinY = Math.min(slideHeight / 2 - scaledHeight / 2, 0);
363
+      translateMaxX = -translateMinX;
364
+      translateMaxY = -translateMinY;
365
+      translateX = diffX * zoom.scale;
366
+      translateY = diffY * zoom.scale;
367
+
368
+      if (translateX < translateMinX) {
369
+        translateX = translateMinX;
370
+      }
371
+
372
+      if (translateX > translateMaxX) {
373
+        translateX = translateMaxX;
374
+      }
375
+
376
+      if (translateY < translateMinY) {
377
+        translateY = translateMinY;
378
+      }
379
+
380
+      if (translateY > translateMaxY) {
381
+        translateY = translateMaxY;
382
+      }
383
+    } else {
384
+      translateX = 0;
385
+      translateY = 0;
386
+    }
387
+
388
+    gesture.$imageWrapEl.transition(300).transform("translate3d(" + translateX + "px, " + translateY + "px,0)");
389
+    gesture.$imageEl.transition(300).transform("translate3d(0,0,0) scale(" + zoom.scale + ")");
390
+  },
391
+  out: function out() {
392
+    var swiper = this;
393
+    var zoom = swiper.zoom;
394
+    var params = swiper.params.zoom;
395
+    var gesture = zoom.gesture;
396
+
397
+    if (!gesture.$slideEl) {
398
+      if (swiper.params.virtual && swiper.params.virtual.enabled && swiper.virtual) {
399
+        gesture.$slideEl = swiper.$wrapperEl.children("." + swiper.params.slideActiveClass);
400
+      } else {
401
+        gesture.$slideEl = swiper.slides.eq(swiper.activeIndex);
402
+      }
403
+
404
+      gesture.$imageEl = gesture.$slideEl.find('img, svg, canvas, picture, .swiper-zoom-target');
405
+      gesture.$imageWrapEl = gesture.$imageEl.parent("." + params.containerClass);
406
+    }
407
+
408
+    if (!gesture.$imageEl || gesture.$imageEl.length === 0) return;
409
+    zoom.scale = 1;
410
+    zoom.currentScale = 1;
411
+    gesture.$imageWrapEl.transition(300).transform('translate3d(0,0,0)');
412
+    gesture.$imageEl.transition(300).transform('translate3d(0,0,0) scale(1)');
413
+    gesture.$slideEl.removeClass("" + params.zoomedSlideClass);
414
+    gesture.$slideEl = undefined;
415
+  },
416
+  toggleGestures: function toggleGestures(method) {
417
+    var swiper = this;
418
+    var zoom = swiper.zoom;
419
+    var selector = zoom.slideSelector,
420
+        passive = zoom.passiveListener;
421
+    swiper.$wrapperEl[method]('gesturestart', selector, zoom.onGestureStart, passive);
422
+    swiper.$wrapperEl[method]('gesturechange', selector, zoom.onGestureChange, passive);
423
+    swiper.$wrapperEl[method]('gestureend', selector, zoom.onGestureEnd, passive);
424
+  },
425
+  enableGestures: function enableGestures() {
426
+    if (this.zoom.gesturesEnabled) return;
427
+    this.zoom.gesturesEnabled = true;
428
+    this.zoom.toggleGestures('on');
429
+  },
430
+  disableGestures: function disableGestures() {
431
+    if (!this.zoom.gesturesEnabled) return;
432
+    this.zoom.gesturesEnabled = false;
433
+    this.zoom.toggleGestures('off');
434
+  },
435
+  // Attach/Detach Events
436
+  enable: function enable() {
437
+    var swiper = this;
438
+    var support = swiper.support;
439
+    var zoom = swiper.zoom;
440
+    if (zoom.enabled) return;
441
+    zoom.enabled = true;
442
+    var passiveListener = swiper.touchEvents.start === 'touchstart' && support.passiveListener && swiper.params.passiveListeners ? {
443
+      passive: true,
444
+      capture: false
445
+    } : false;
446
+    var activeListenerWithCapture = support.passiveListener ? {
447
+      passive: false,
448
+      capture: true
449
+    } : true;
450
+    var slideSelector = "." + swiper.params.slideClass;
451
+    swiper.zoom.passiveListener = passiveListener;
452
+    swiper.zoom.slideSelector = slideSelector; // Scale image
453
+
454
+    if (support.gestures) {
455
+      swiper.$wrapperEl.on(swiper.touchEvents.start, swiper.zoom.enableGestures, passiveListener);
456
+      swiper.$wrapperEl.on(swiper.touchEvents.end, swiper.zoom.disableGestures, passiveListener);
457
+    } else if (swiper.touchEvents.start === 'touchstart') {
458
+      swiper.$wrapperEl.on(swiper.touchEvents.start, slideSelector, zoom.onGestureStart, passiveListener);
459
+      swiper.$wrapperEl.on(swiper.touchEvents.move, slideSelector, zoom.onGestureChange, activeListenerWithCapture);
460
+      swiper.$wrapperEl.on(swiper.touchEvents.end, slideSelector, zoom.onGestureEnd, passiveListener);
461
+
462
+      if (swiper.touchEvents.cancel) {
463
+        swiper.$wrapperEl.on(swiper.touchEvents.cancel, slideSelector, zoom.onGestureEnd, passiveListener);
464
+      }
465
+    } // Move image
466
+
467
+
468
+    swiper.$wrapperEl.on(swiper.touchEvents.move, "." + swiper.params.zoom.containerClass, zoom.onTouchMove, activeListenerWithCapture);
469
+  },
470
+  disable: function disable() {
471
+    var swiper = this;
472
+    var zoom = swiper.zoom;
473
+    if (!zoom.enabled) return;
474
+    var support = swiper.support;
475
+    swiper.zoom.enabled = false;
476
+    var passiveListener = swiper.touchEvents.start === 'touchstart' && support.passiveListener && swiper.params.passiveListeners ? {
477
+      passive: true,
478
+      capture: false
479
+    } : false;
480
+    var activeListenerWithCapture = support.passiveListener ? {
481
+      passive: false,
482
+      capture: true
483
+    } : true;
484
+    var slideSelector = "." + swiper.params.slideClass; // Scale image
485
+
486
+    if (support.gestures) {
487
+      swiper.$wrapperEl.off(swiper.touchEvents.start, swiper.zoom.enableGestures, passiveListener);
488
+      swiper.$wrapperEl.off(swiper.touchEvents.end, swiper.zoom.disableGestures, passiveListener);
489
+    } else if (swiper.touchEvents.start === 'touchstart') {
490
+      swiper.$wrapperEl.off(swiper.touchEvents.start, slideSelector, zoom.onGestureStart, passiveListener);
491
+      swiper.$wrapperEl.off(swiper.touchEvents.move, slideSelector, zoom.onGestureChange, activeListenerWithCapture);
492
+      swiper.$wrapperEl.off(swiper.touchEvents.end, slideSelector, zoom.onGestureEnd, passiveListener);
493
+
494
+      if (swiper.touchEvents.cancel) {
495
+        swiper.$wrapperEl.off(swiper.touchEvents.cancel, slideSelector, zoom.onGestureEnd, passiveListener);
496
+      }
497
+    } // Move image
498
+
499
+
500
+    swiper.$wrapperEl.off(swiper.touchEvents.move, "." + swiper.params.zoom.containerClass, zoom.onTouchMove, activeListenerWithCapture);
501
+  }
502
+};
503
+var _default = {
504
+  name: 'zoom',
505
+  params: {
506
+    zoom: {
507
+      enabled: false,
508
+      maxRatio: 3,
509
+      minRatio: 1,
510
+      toggle: true,
511
+      containerClass: 'swiper-zoom-container',
512
+      zoomedSlideClass: 'swiper-slide-zoomed'
513
+    }
514
+  },
515
+  create: function create() {
516
+    var swiper = this;
517
+    (0, _utils.bindModuleMethods)(swiper, {
518
+      zoom: _extends({
519
+        enabled: false,
520
+        scale: 1,
521
+        currentScale: 1,
522
+        isScaling: false,
523
+        gesture: {
524
+          $slideEl: undefined,
525
+          slideWidth: undefined,
526
+          slideHeight: undefined,
527
+          $imageEl: undefined,
528
+          $imageWrapEl: undefined,
529
+          maxRatio: 3
530
+        },
531
+        image: {
532
+          isTouched: undefined,
533
+          isMoved: undefined,
534
+          currentX: undefined,
535
+          currentY: undefined,
536
+          minX: undefined,
537
+          minY: undefined,
538
+          maxX: undefined,
539
+          maxY: undefined,
540
+          width: undefined,
541
+          height: undefined,
542
+          startX: undefined,
543
+          startY: undefined,
544
+          touchesStart: {},
545
+          touchesCurrent: {}
546
+        },
547
+        velocity: {
548
+          x: undefined,
549
+          y: undefined,
550
+          prevPositionX: undefined,
551
+          prevPositionY: undefined,
552
+          prevTime: undefined
553
+        }
554
+      }, Zoom)
555
+    });
556
+    var scale = 1;
557
+    Object.defineProperty(swiper.zoom, 'scale', {
558
+      get: function get() {
559
+        return scale;
560
+      },
561
+      set: function set(value) {
562
+        if (scale !== value) {
563
+          var imageEl = swiper.zoom.gesture.$imageEl ? swiper.zoom.gesture.$imageEl[0] : undefined;
564
+          var slideEl = swiper.zoom.gesture.$slideEl ? swiper.zoom.gesture.$slideEl[0] : undefined;
565
+          swiper.emit('zoomChange', value, imageEl, slideEl);
566
+        }
567
+
568
+        scale = value;
569
+      }
570
+    });
571
+  },
572
+  on: {
573
+    init: function init(swiper) {
574
+      if (swiper.params.zoom.enabled) {
575
+        swiper.zoom.enable();
576
+      }
577
+    },
578
+    destroy: function destroy(swiper) {
579
+      swiper.zoom.disable();
580
+    },
581
+    touchStart: function touchStart(swiper, e) {
582
+      if (!swiper.zoom.enabled) return;
583
+      swiper.zoom.onTouchStart(e);
584
+    },
585
+    touchEnd: function touchEnd(swiper, e) {
586
+      if (!swiper.zoom.enabled) return;
587
+      swiper.zoom.onTouchEnd(e);
588
+    },
589
+    doubleTap: function doubleTap(swiper, e) {
590
+      if (swiper.params.zoom.enabled && swiper.zoom.enabled && swiper.params.zoom.toggle) {
591
+        swiper.zoom.toggle(e);
592
+      }
593
+    },
594
+    transitionEnd: function transitionEnd(swiper) {
595
+      if (swiper.zoom.enabled && swiper.params.zoom.enabled) {
596
+        swiper.zoom.onTransitionEnd();
597
+      }
598
+    },
599
+    slideChange: function slideChange(swiper) {
600
+      if (swiper.zoom.enabled && swiper.params.zoom.enabled && swiper.params.cssMode) {
601
+        swiper.zoom.onTransitionEnd();
602
+      }
603
+    }
604
+  }
605
+};
606
+exports.default = _default;
0 607
\ No newline at end of file