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