lightgallery 2.5.0-beta.5 → 2.6.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/css/lg-rotate.css +7 -0
  2. package/css/lg-zoom.css +37 -5
  3. package/css/lightgallery-bundle.css +44 -5
  4. package/css/lightgallery-bundle.min.css +1 -1
  5. package/lg-settings.d.ts +4 -1
  6. package/lib/lg-settings.js.map +1 -1
  7. package/lib/lightgallery.js +21 -16
  8. package/lib/lightgallery.js.map +1 -1
  9. package/lib/plugins/rotate/lg-rotate.js +15 -8
  10. package/lib/plugins/rotate/lg-rotate.js.map +1 -1
  11. package/lib/plugins/video/lg-video-settings.js.map +1 -1
  12. package/lib/plugins/zoom/lg-zoom.js +281 -293
  13. package/lib/plugins/zoom/lg-zoom.js.map +1 -1
  14. package/lightgallery.d.ts +1 -0
  15. package/lightgallery.es5.js +22 -17
  16. package/lightgallery.es5.js.map +1 -1
  17. package/lightgallery.min.js +2 -2
  18. package/lightgallery.umd.js +22 -17
  19. package/lightgallery.umd.js.map +1 -1
  20. package/lit/lightgallery.esm.js +2 -2
  21. package/lit/lightgallery.umd.js +2 -2
  22. package/package.json +1 -1
  23. package/plugins/autoplay/lg-autoplay.es5.js +1 -1
  24. package/plugins/autoplay/lg-autoplay.min.js +1 -1
  25. package/plugins/autoplay/lg-autoplay.umd.js +1 -1
  26. package/plugins/comment/lg-comment.es5.js +1 -1
  27. package/plugins/comment/lg-comment.min.js +1 -1
  28. package/plugins/comment/lg-comment.umd.js +1 -1
  29. package/plugins/fullscreen/lg-fullscreen.es5.js +1 -1
  30. package/plugins/fullscreen/lg-fullscreen.min.js +1 -1
  31. package/plugins/fullscreen/lg-fullscreen.umd.js +1 -1
  32. package/plugins/hash/lg-hash.es5.js +1 -1
  33. package/plugins/hash/lg-hash.min.js +1 -1
  34. package/plugins/hash/lg-hash.umd.js +1 -1
  35. package/plugins/mediumZoom/lg-medium-zoom.es5.js +1 -1
  36. package/plugins/mediumZoom/lg-medium-zoom.min.js +1 -1
  37. package/plugins/mediumZoom/lg-medium-zoom.umd.js +1 -1
  38. package/plugins/pager/lg-pager.es5.js +1 -1
  39. package/plugins/pager/lg-pager.min.js +1 -1
  40. package/plugins/pager/lg-pager.umd.js +1 -1
  41. package/plugins/relativeCaption/lg-relative-caption.es5.js +1 -1
  42. package/plugins/relativeCaption/lg-relative-caption.min.js +1 -1
  43. package/plugins/relativeCaption/lg-relative-caption.umd.js +1 -1
  44. package/plugins/rotate/lg-rotate.es5.js +16 -9
  45. package/plugins/rotate/lg-rotate.es5.js.map +1 -1
  46. package/plugins/rotate/lg-rotate.min.js +2 -2
  47. package/plugins/rotate/lg-rotate.umd.js +16 -9
  48. package/plugins/rotate/lg-rotate.umd.js.map +1 -1
  49. package/plugins/share/lg-share.es5.js +1 -1
  50. package/plugins/share/lg-share.min.js +1 -1
  51. package/plugins/share/lg-share.umd.js +1 -1
  52. package/plugins/thumbnail/lg-thumbnail.es5.js +1 -1
  53. package/plugins/thumbnail/lg-thumbnail.min.js +1 -1
  54. package/plugins/thumbnail/lg-thumbnail.umd.js +1 -1
  55. package/plugins/video/lg-video-settings.d.ts +1 -0
  56. package/plugins/video/lg-video.es5.js +1 -1
  57. package/plugins/video/lg-video.es5.js.map +1 -1
  58. package/plugins/video/lg-video.min.js +1 -1
  59. package/plugins/video/lg-video.umd.js +1 -1
  60. package/plugins/video/lg-video.umd.js.map +1 -1
  61. package/plugins/vimeoThumbnail/lg-vimeo-thumbnail.es5.js +1 -1
  62. package/plugins/vimeoThumbnail/lg-vimeo-thumbnail.min.js +1 -1
  63. package/plugins/vimeoThumbnail/lg-vimeo-thumbnail.umd.js +1 -1
  64. package/plugins/zoom/lg-zoom.d.ts +12 -23
  65. package/plugins/zoom/lg-zoom.es5.js +282 -294
  66. package/plugins/zoom/lg-zoom.es5.js.map +1 -1
  67. package/plugins/zoom/lg-zoom.min.js +2 -2
  68. package/plugins/zoom/lg-zoom.umd.js +282 -294
  69. package/plugins/zoom/lg-zoom.umd.js.map +1 -1
  70. package/react/Lightgallery.es5.js +23 -18
  71. package/react/Lightgallery.es5.js.map +1 -1
  72. package/react/Lightgallery.umd.js +23 -18
  73. package/react/Lightgallery.umd.js.map +1 -1
  74. package/scss/lg-rotate.scss +8 -0
  75. package/scss/lg-zoom.scss +29 -2
  76. package/vue/LightGalleryVue.common.js +24 -19
  77. package/vue/LightGalleryVue.common.js.map +1 -1
  78. package/vue/LightGalleryVue.umd.js +24 -19
  79. package/vue/LightGalleryVue.umd.js.map +1 -1
  80. package/vue/LightGalleryVue.umd.min.js +1 -1
  81. package/vue/LightGalleryVue.umd.min.js.map +1 -1
@@ -66,158 +66,50 @@ var Zoom = /** @class */ (function () {
66
66
  // Add zoomable class
67
67
  this.core.LGel.on(lg_events_1.lGEvents.slideItemLoad + ".zoom", this.enableZoom.bind(this));
68
68
  };
69
- Zoom.prototype.getModifier = function (rotateValue, axis, el) {
70
- var originalRotate = rotateValue;
71
- rotateValue = Math.abs(rotateValue);
72
- var transformValues = this.getCurrentTransform(el);
73
- if (!transformValues) {
74
- return 1;
75
- }
76
- var modifier = 1;
77
- if (axis === 'X') {
78
- var flipHorizontalValue = Math.sign(parseFloat(transformValues[0]));
79
- if (rotateValue === 0 || rotateValue === 180) {
80
- modifier = 1;
81
- }
82
- else if (rotateValue === 90) {
83
- if ((originalRotate === -90 && flipHorizontalValue === 1) ||
84
- (originalRotate === 90 && flipHorizontalValue === -1)) {
85
- modifier = -1;
86
- }
87
- else {
88
- modifier = 1;
89
- }
90
- }
91
- modifier = modifier * flipHorizontalValue;
92
- }
93
- else {
94
- var flipVerticalValue = Math.sign(parseFloat(transformValues[3]));
95
- if (rotateValue === 0 || rotateValue === 180) {
96
- modifier = 1;
97
- }
98
- else if (rotateValue === 90) {
99
- var sinX = parseFloat(transformValues[1]);
100
- var sinMinusX = parseFloat(transformValues[2]);
101
- modifier = Math.sign(sinX * sinMinusX * originalRotate * flipVerticalValue);
102
- }
103
- modifier = modifier * flipVerticalValue;
104
- }
105
- return modifier;
106
- };
107
- Zoom.prototype.getImageSize = function ($image, rotateValue, axis) {
108
- var imageSizes = {
109
- y: 'offsetHeight',
110
- x: 'offsetWidth',
69
+ Zoom.prototype.getDragCords = function (e) {
70
+ return {
71
+ x: e.pageX,
72
+ y: e.pageY,
111
73
  };
112
- if (Math.abs(rotateValue) === 90) {
113
- // Swap axis
114
- if (axis === 'x') {
115
- axis = 'y';
116
- }
117
- else {
118
- axis = 'x';
119
- }
120
- }
121
- return $image[imageSizes[axis]];
122
- };
123
- Zoom.prototype.getDragCords = function (e, rotateValue) {
124
- if (rotateValue === 90) {
125
- return {
126
- x: e.pageY,
127
- y: e.pageX,
128
- };
129
- }
130
- else {
131
- return {
132
- x: e.pageX,
133
- y: e.pageY,
134
- };
135
- }
136
- };
137
- Zoom.prototype.getSwipeCords = function (e, rotateValue) {
138
- var x = e.targetTouches[0].pageX;
139
- var y = e.targetTouches[0].pageY;
140
- if (rotateValue === 90) {
141
- return {
142
- x: y,
143
- y: x,
144
- };
145
- }
146
- else {
147
- return {
148
- x: x,
149
- y: y,
150
- };
151
- }
152
- };
153
- Zoom.prototype.getDragAllowedAxises = function (rotateValue, scale) {
154
- scale = scale || this.scale || 1;
155
- var allowY = this.imageYSize * scale > this.containerRect.height;
156
- var allowX = this.imageXSize * scale > this.containerRect.width;
157
- if (rotateValue === 90) {
158
- return {
159
- allowX: allowY,
160
- allowY: allowX,
161
- };
162
- }
163
- else {
164
- return {
165
- allowX: allowX,
166
- allowY: allowY,
167
- };
168
- }
169
74
  };
170
- /**
171
- *
172
- * @param {Element} el
173
- * @return matrix(cos(X), sin(X), -sin(X), cos(X), 0, 0);
174
- * Get the current transform value
175
- */
176
- Zoom.prototype.getCurrentTransform = function (el) {
177
- if (!el) {
178
- return;
179
- }
180
- var st = window.getComputedStyle(el, null);
181
- var tm = st.getPropertyValue('-webkit-transform') ||
182
- st.getPropertyValue('-moz-transform') ||
183
- st.getPropertyValue('-ms-transform') ||
184
- st.getPropertyValue('-o-transform') ||
185
- st.getPropertyValue('transform') ||
186
- 'none';
187
- if (tm !== 'none') {
188
- return tm.split('(')[1].split(')')[0].split(',');
189
- }
190
- return;
191
- };
192
- Zoom.prototype.getCurrentRotation = function (el) {
193
- if (!el) {
194
- return 0;
195
- }
196
- var values = this.getCurrentTransform(el);
197
- if (values) {
198
- return Math.round(Math.atan2(parseFloat(values[1]), parseFloat(values[0])) *
199
- (180 / Math.PI));
200
- // If you want rotate in 360
201
- //return (angle < 0 ? angle + 360 : angle);
202
- }
203
- return 0;
75
+ Zoom.prototype.getSwipeCords = function (e) {
76
+ var x = e.touches[0].pageX;
77
+ var y = e.touches[0].pageY;
78
+ return {
79
+ x: x,
80
+ y: y,
81
+ };
204
82
  };
205
- Zoom.prototype.setZoomEssentials = function () {
83
+ Zoom.prototype.getDragAllowedAxises = function (scale, scaleDiff) {
206
84
  var $image = this.core
207
85
  .getSlideItem(this.core.index)
208
86
  .find('.lg-image')
209
- .first();
210
- var rotateEl = this.core
211
- .getSlideItem(this.core.index)
212
- .find('.lg-img-rotate')
213
87
  .first()
214
88
  .get();
215
- this.rotateValue = this.getCurrentRotation(rotateEl);
216
- this.imageYSize = this.getImageSize($image.get(), this.rotateValue, 'y');
217
- this.imageXSize = this.getImageSize($image.get(), this.rotateValue, 'x');
218
- this.containerRect = this.core.outer.get().getBoundingClientRect();
219
- this.modifierX = this.getModifier(this.rotateValue, 'X', rotateEl);
220
- this.modifierY = this.getModifier(this.rotateValue, 'Y', rotateEl);
89
+ var height = 0;
90
+ var width = 0;
91
+ var rect = $image.getBoundingClientRect();
92
+ if (scale) {
93
+ height = $image.offsetHeight * scale;
94
+ width = $image.offsetWidth * scale;
95
+ }
96
+ else if (scaleDiff) {
97
+ height = rect.height + scaleDiff * rect.height;
98
+ width = rect.width + scaleDiff * rect.width;
99
+ }
100
+ else {
101
+ height = rect.height;
102
+ width = rect.width;
103
+ }
104
+ var allowY = height > this.containerRect.height;
105
+ var allowX = width > this.containerRect.width;
106
+ return {
107
+ allowX: allowX,
108
+ allowY: allowY,
109
+ };
110
+ };
111
+ Zoom.prototype.setZoomEssentials = function () {
112
+ this.containerRect = this.core.$content.get().getBoundingClientRect();
221
113
  };
222
114
  /**
223
115
  * @desc Image zoom
@@ -225,86 +117,152 @@ var Zoom = /** @class */ (function () {
225
117
  *
226
118
  * @param {String} scale - Zoom decrement/increment value
227
119
  */
228
- Zoom.prototype.zoomImage = function (scale) {
229
- // Find offset manually to avoid issue after zoom
230
- var offsetX = (this.containerRect.width - this.imageXSize) / 2 +
231
- this.containerRect.left;
232
- var _a = this.core.mediaContainerPosition, top = _a.top, bottom = _a.bottom;
233
- var topBottomSpacing = Math.abs(top - bottom) / 2;
234
- var offsetY = (this.containerRect.height -
235
- this.imageYSize -
236
- topBottomSpacing * this.modifierX) /
237
- 2 +
238
- this.scrollTop +
239
- this.containerRect.top;
120
+ Zoom.prototype.zoomImage = function (scale, scaleDiff, reposition, resetToMax) {
121
+ if (Math.abs(scaleDiff) <= 0)
122
+ return;
123
+ var offsetX = this.containerRect.width / 2 + this.containerRect.left;
124
+ var offsetY = this.containerRect.height / 2 +
125
+ this.containerRect.top +
126
+ this.scrollTop;
240
127
  var originalX;
241
128
  var originalY;
242
129
  if (scale === 1) {
243
130
  this.positionChanged = false;
244
131
  }
245
- var dragAllowedAxises = this.getDragAllowedAxises(Math.abs(this.rotateValue), scale);
132
+ var dragAllowedAxises = this.getDragAllowedAxises(0, scaleDiff);
246
133
  var allowY = dragAllowedAxises.allowY, allowX = dragAllowedAxises.allowX;
247
134
  if (this.positionChanged) {
248
- originalX = this.left / (this.scale - 1);
249
- originalY = this.top / (this.scale - 1);
250
- this.pageX = Math.abs(originalX) + offsetX;
251
- this.pageY = Math.abs(originalY) + offsetY;
135
+ originalX = this.left / (this.scale - scaleDiff);
136
+ originalY = this.top / (this.scale - scaleDiff);
137
+ this.pageX = offsetX - originalX;
138
+ this.pageY = offsetY - originalY;
252
139
  this.positionChanged = false;
253
140
  }
254
- var possibleSwipeCords = this.getPossibleSwipeDragCords(this.rotateValue, scale);
141
+ var possibleSwipeCords = this.getPossibleSwipeDragCords(scaleDiff);
142
+ var x;
143
+ var y;
255
144
  var _x = offsetX - this.pageX;
256
145
  var _y = offsetY - this.pageY;
257
- var x = (scale - 1) * _x;
258
- var y = (scale - 1) * _y;
259
- if (allowX) {
260
- if (this.isBeyondPossibleLeft(x, possibleSwipeCords.minX)) {
261
- x = possibleSwipeCords.minX;
262
- }
263
- else if (this.isBeyondPossibleRight(x, possibleSwipeCords.maxX)) {
264
- x = possibleSwipeCords.maxX;
265
- }
146
+ if (scale - scaleDiff > 1) {
147
+ var scaleVal = (scale - scaleDiff) / Math.abs(scaleDiff);
148
+ _x =
149
+ (scaleDiff < 0 ? -_x : _x) +
150
+ this.left * (scaleVal + (scaleDiff < 0 ? -1 : 1));
151
+ _y =
152
+ (scaleDiff < 0 ? -_y : _y) +
153
+ this.top * (scaleVal + (scaleDiff < 0 ? -1 : 1));
154
+ x = _x / scaleVal;
155
+ y = _y / scaleVal;
266
156
  }
267
157
  else {
268
- if (scale > 1) {
269
- if (x < possibleSwipeCords.minX) {
158
+ var scaleVal = (scale - scaleDiff) * scaleDiff;
159
+ x = _x * scaleVal;
160
+ y = _y * scaleVal;
161
+ }
162
+ if (reposition) {
163
+ if (allowX) {
164
+ if (this.isBeyondPossibleLeft(x, possibleSwipeCords.minX)) {
270
165
  x = possibleSwipeCords.minX;
271
166
  }
272
- else if (x > possibleSwipeCords.maxX) {
167
+ else if (this.isBeyondPossibleRight(x, possibleSwipeCords.maxX)) {
273
168
  x = possibleSwipeCords.maxX;
274
169
  }
275
170
  }
276
- }
277
- if (allowY) {
278
- if (this.isBeyondPossibleTop(y, possibleSwipeCords.minY)) {
279
- y = possibleSwipeCords.minY;
280
- }
281
- else if (this.isBeyondPossibleBottom(y, possibleSwipeCords.maxY)) {
282
- y = possibleSwipeCords.maxY;
171
+ else {
172
+ if (scale > 1) {
173
+ if (x < possibleSwipeCords.minX) {
174
+ x = possibleSwipeCords.minX;
175
+ }
176
+ else if (x > possibleSwipeCords.maxX) {
177
+ x = possibleSwipeCords.maxX;
178
+ }
179
+ }
283
180
  }
284
- }
285
- else {
286
- // If the translate value based on index of beyond the viewport, utilize the available space to prevent image being cut out
287
- if (scale > 1) {
288
- //If image goes beyond viewport top, use the minim possible translate value
289
- if (y < possibleSwipeCords.minY) {
181
+ // @todo fix this
182
+ if (allowY) {
183
+ if (this.isBeyondPossibleTop(y, possibleSwipeCords.minY)) {
290
184
  y = possibleSwipeCords.minY;
291
185
  }
292
- else if (y > possibleSwipeCords.maxY) {
186
+ else if (this.isBeyondPossibleBottom(y, possibleSwipeCords.maxY)) {
293
187
  y = possibleSwipeCords.maxY;
294
188
  }
295
189
  }
190
+ else {
191
+ // If the translate value based on index of beyond the viewport, utilize the available space to prevent image being cut out
192
+ if (scale > 1) {
193
+ //If image goes beyond viewport top, use the minim possible translate value
194
+ if (y < possibleSwipeCords.minY) {
195
+ y = possibleSwipeCords.minY;
196
+ }
197
+ else if (y > possibleSwipeCords.maxY) {
198
+ y = possibleSwipeCords.maxY;
199
+ }
200
+ }
201
+ }
296
202
  }
297
203
  this.setZoomStyles({
298
204
  x: x,
299
205
  y: y,
300
206
  scale: scale,
301
207
  });
208
+ this.left = x;
209
+ this.top = y;
210
+ if (resetToMax) {
211
+ var actualSizeScale = this.getCurrentImageActualSizeScale();
212
+ if (scale >= actualSizeScale) {
213
+ this.setZoomImageSize();
214
+ }
215
+ }
216
+ };
217
+ Zoom.prototype.resetImageTranslate = function () {
218
+ var $image = this.core
219
+ .getSlideItem(this.core.index)
220
+ .find('.lg-image')
221
+ .first();
222
+ this.imageReset = false;
223
+ $image.removeClass('reset-transition reset-transition-y reset-transition-x');
224
+ this.core.outer.removeClass('lg-actual-size');
225
+ $image.css('width', 'auto').css('height', 'auto');
226
+ setTimeout(function () {
227
+ $image.removeClass('no-transition');
228
+ }, 10);
229
+ };
230
+ Zoom.prototype.setZoomImageSize = function () {
231
+ var _this = this;
232
+ var $image = this.core
233
+ .getSlideItem(this.core.index)
234
+ .find('.lg-image')
235
+ .first();
236
+ setTimeout(function () {
237
+ $image.addClass('no-transition');
238
+ _this.imageReset = true;
239
+ }, 500);
240
+ setTimeout(function () {
241
+ var dragAllowedAxises = _this.getDragAllowedAxises(_this.scale);
242
+ $image
243
+ .css('width', $image.get().naturalWidth + 'px')
244
+ .css('height', $image.get().naturalHeight + 'px');
245
+ _this.core.outer.addClass('lg-actual-size');
246
+ if (dragAllowedAxises.allowX && dragAllowedAxises.allowY) {
247
+ $image.addClass('reset-transition');
248
+ }
249
+ else if (dragAllowedAxises.allowX && !dragAllowedAxises.allowY) {
250
+ $image.addClass('reset-transition-x');
251
+ }
252
+ else if (!dragAllowedAxises.allowX && dragAllowedAxises.allowY) {
253
+ $image.addClass('reset-transition-y');
254
+ }
255
+ }, 550);
302
256
  };
303
257
  /**
304
258
  * @desc apply scale3d to image and translate to image wrap
305
259
  * @param {style} X,Y and scale
306
260
  */
307
261
  Zoom.prototype.setZoomStyles = function (style) {
262
+ var $imageWrap = this.core
263
+ .getSlideItem(this.core.index)
264
+ .find('.lg-img-wrap')
265
+ .first();
308
266
  var $image = this.core
309
267
  .getSlideItem(this.core.index)
310
268
  .find('.lg-image')
@@ -312,14 +270,11 @@ var Zoom = /** @class */ (function () {
312
270
  var $dummyImage = this.core.outer
313
271
  .find('.lg-current .lg-dummy-img')
314
272
  .first();
315
- var $imageWrap = $image.parent();
316
273
  this.scale = style.scale;
317
274
  $image.css('transform', 'scale3d(' + style.scale + ', ' + style.scale + ', 1)');
318
275
  $dummyImage.css('transform', 'scale3d(' + style.scale + ', ' + style.scale + ', 1)');
319
276
  var transform = 'translate3d(' + style.x + 'px, ' + style.y + 'px, 0)';
320
277
  $imageWrap.css('transform', transform);
321
- this.left = style.x;
322
- this.top = style.y;
323
278
  };
324
279
  /**
325
280
  * @param index - Index of the current slide
@@ -327,24 +282,29 @@ var Zoom = /** @class */ (function () {
327
282
  */
328
283
  Zoom.prototype.setActualSize = function (index, event) {
329
284
  var _this = this;
330
- // Allow zoom only on image
331
- if (!this.isImageSlide() ||
332
- this.core.outer.hasClass('lg-first-slide-loading')) {
333
- return;
334
- }
335
- var scale = this.getCurrentImageActualSizeScale();
336
- if (this.core.outer.hasClass('lg-zoomed')) {
337
- this.scale = 1;
338
- }
339
- else {
340
- this.scale = this.getScale(scale);
341
- }
342
- this.setPageCords(event);
343
- this.beginZoom(this.scale);
344
- this.zoomImage(this.scale);
285
+ var currentItem = this.core.galleryItems[this.core.index];
286
+ this.resetImageTranslate();
345
287
  setTimeout(function () {
346
- _this.core.outer.removeClass('lg-grabbing').addClass('lg-grab');
347
- }, 10);
288
+ // Allow zoom only on image
289
+ if (!currentItem.src ||
290
+ _this.core.outer.hasClass('lg-first-slide-loading')) {
291
+ return;
292
+ }
293
+ var scale = _this.getCurrentImageActualSizeScale();
294
+ var prevScale = _this.scale;
295
+ if (_this.core.outer.hasClass('lg-zoomed')) {
296
+ _this.scale = 1;
297
+ }
298
+ else {
299
+ _this.scale = _this.getScale(scale);
300
+ }
301
+ _this.setPageCords(event);
302
+ _this.beginZoom(_this.scale);
303
+ _this.zoomImage(_this.scale, _this.scale - prevScale, true, true);
304
+ setTimeout(function () {
305
+ _this.core.outer.removeClass('lg-grabbing').addClass('lg-grab');
306
+ }, 10);
307
+ }, 50);
348
308
  };
349
309
  Zoom.prototype.getNaturalWidth = function (index) {
350
310
  var $image = this.core.getSlideItem(index).find('.lg-image').first();
@@ -356,7 +316,7 @@ var Zoom = /** @class */ (function () {
356
316
  Zoom.prototype.getActualSizeScale = function (naturalWidth, width) {
357
317
  var _scale;
358
318
  var scale;
359
- if (naturalWidth > width) {
319
+ if (naturalWidth >= width) {
360
320
  _scale = naturalWidth / width;
361
321
  scale = _scale || 2;
362
322
  }
@@ -377,11 +337,13 @@ var Zoom = /** @class */ (function () {
377
337
  Zoom.prototype.getPageCords = function (event) {
378
338
  var cords = {};
379
339
  if (event) {
380
- cords.x = event.pageX || event.targetTouches[0].pageX;
381
- cords.y = event.pageY || event.targetTouches[0].pageY;
340
+ cords.x = event.pageX || event.touches[0].pageX;
341
+ cords.y = event.pageY || event.touches[0].pageY;
382
342
  }
383
343
  else {
384
- var containerRect = this.core.outer.get().getBoundingClientRect();
344
+ var containerRect = this.core.$content
345
+ .get()
346
+ .getBoundingClientRect();
385
347
  cords.x = containerRect.width / 2 + containerRect.left;
386
348
  cords.y =
387
349
  containerRect.height / 2 + this.scrollTop + containerRect.top;
@@ -393,15 +355,18 @@ var Zoom = /** @class */ (function () {
393
355
  this.pageX = pageCords.x;
394
356
  this.pageY = pageCords.y;
395
357
  };
358
+ Zoom.prototype.manageActualPixelClassNames = function () {
359
+ var $actualSize = this.core.getElementById('lg-actual-size');
360
+ $actualSize
361
+ .removeClass(this.settings.actualSizeIcons.zoomIn)
362
+ .addClass(this.settings.actualSizeIcons.zoomOut);
363
+ };
396
364
  // If true, zoomed - in else zoomed out
397
365
  Zoom.prototype.beginZoom = function (scale) {
398
366
  this.core.outer.removeClass('lg-zoom-drag-transition lg-zoom-dragging');
399
367
  if (scale > 1) {
400
368
  this.core.outer.addClass('lg-zoomed');
401
- var $actualSize = this.core.getElementById('lg-actual-size');
402
- $actualSize
403
- .removeClass(this.settings.actualSizeIcons.zoomIn)
404
- .addClass(this.settings.actualSizeIcons.zoomOut);
369
+ this.manageActualPixelClassNames();
405
370
  }
406
371
  else {
407
372
  this.resetZoom();
@@ -434,8 +399,7 @@ var Zoom = /** @class */ (function () {
434
399
  });
435
400
  this.core.outer.on('touchstart.lg', function (event) {
436
401
  var $target = _this.$LG(event.target);
437
- if (event.targetTouches.length === 1 &&
438
- $target.hasClass('lg-image')) {
402
+ if (event.touches.length === 1 && $target.hasClass('lg-image')) {
439
403
  if (!tapped) {
440
404
  tapped = setTimeout(function () {
441
405
  tapped = null;
@@ -449,13 +413,21 @@ var Zoom = /** @class */ (function () {
449
413
  }
450
414
  }
451
415
  });
452
- // Update zoom on resize and orientationchange
453
416
  this.core.LGel.on(lg_events_1.lGEvents.containerResize + ".zoom " + lg_events_1.lGEvents.rotateRight + ".zoom " + lg_events_1.lGEvents.rotateLeft + ".zoom " + lg_events_1.lGEvents.flipHorizontal + ".zoom " + lg_events_1.lGEvents.flipVertical + ".zoom", function () {
454
- if (!_this.core.lgOpened || !_this.isImageSlide())
417
+ if (!_this.core.lgOpened ||
418
+ !_this.isImageSlide() ||
419
+ _this.core.touchAction) {
455
420
  return;
456
- _this.setPageCords();
421
+ }
422
+ var _LGel = _this.core
423
+ .getSlideItem(_this.core.index)
424
+ .find('.lg-img-wrap')
425
+ .first();
426
+ _this.top = 0;
427
+ _this.left = 0;
457
428
  _this.setZoomEssentials();
458
- _this.zoomImage(_this.scale);
429
+ _this.setZoomSwipeStyles(_LGel, { x: 0, y: 0 });
430
+ _this.positionChanged = true;
459
431
  });
460
432
  // Update zoom on resize and orientationchange
461
433
  this.$LG(window).on("scroll.lg.zoom.global" + this.core.lgId, function () {
@@ -464,12 +436,23 @@ var Zoom = /** @class */ (function () {
464
436
  _this.scrollTop = _this.$LG(window).scrollTop();
465
437
  });
466
438
  this.core.getElementById('lg-zoom-out').on('click.lg', function () {
467
- if (_this.core.outer.find('.lg-current .lg-image').get()) {
468
- _this.scale -= _this.settings.scale;
469
- _this.scale = _this.getScale(_this.scale);
470
- _this.beginZoom(_this.scale);
471
- _this.zoomImage(_this.scale);
439
+ // Allow zoom only on image
440
+ if (!_this.isImageSlide()) {
441
+ return;
472
442
  }
443
+ var timeout = 0;
444
+ if (_this.imageReset) {
445
+ _this.resetImageTranslate();
446
+ timeout = 50;
447
+ }
448
+ setTimeout(function () {
449
+ var scale = _this.scale - _this.settings.scale;
450
+ if (scale < 1) {
451
+ scale = 1;
452
+ }
453
+ _this.beginZoom(scale);
454
+ _this.zoomImage(scale, -_this.settings.scale, true, true);
455
+ }, timeout);
473
456
  });
474
457
  this.core.getElementById('lg-zoom-in').on('click.lg', function () {
475
458
  _this.zoomIn();
@@ -505,20 +488,15 @@ var Zoom = /** @class */ (function () {
505
488
  this.zoomableTimeout = false;
506
489
  this.positionChanged = false;
507
490
  };
508
- Zoom.prototype.zoomIn = function (scale) {
491
+ Zoom.prototype.zoomIn = function () {
509
492
  // Allow zoom only on image
510
493
  if (!this.isImageSlide()) {
511
494
  return;
512
495
  }
513
- if (scale) {
514
- this.scale = scale;
515
- }
516
- else {
517
- this.scale += this.settings.scale;
518
- }
519
- this.scale = this.getScale(this.scale);
520
- this.beginZoom(this.scale);
521
- this.zoomImage(this.scale);
496
+ var scale = this.scale + this.settings.scale;
497
+ scale = this.getScale(scale);
498
+ this.beginZoom(scale);
499
+ this.zoomImage(scale, this.settings.scale, true, true);
522
500
  };
523
501
  // Reset zoom effect
524
502
  Zoom.prototype.resetZoom = function (index) {
@@ -537,34 +515,38 @@ var Zoom = /** @class */ (function () {
537
515
  this.setPageCords();
538
516
  };
539
517
  Zoom.prototype.getTouchDistance = function (e) {
540
- return Math.sqrt((e.targetTouches[0].pageX - e.targetTouches[1].pageX) *
541
- (e.targetTouches[0].pageX - e.targetTouches[1].pageX) +
542
- (e.targetTouches[0].pageY - e.targetTouches[1].pageY) *
543
- (e.targetTouches[0].pageY - e.targetTouches[1].pageY));
518
+ return Math.sqrt((e.touches[0].pageX - e.touches[1].pageX) *
519
+ (e.touches[0].pageX - e.touches[1].pageX) +
520
+ (e.touches[0].pageY - e.touches[1].pageY) *
521
+ (e.touches[0].pageY - e.touches[1].pageY));
544
522
  };
545
523
  Zoom.prototype.pinchZoom = function () {
546
524
  var _this = this;
547
525
  var startDist = 0;
548
526
  var pinchStarted = false;
549
527
  var initScale = 1;
528
+ var prevScale = 0;
550
529
  var $item = this.core.getSlideItem(this.core.index);
551
- this.core.$inner.on('touchstart.lg', function (e) {
530
+ this.core.outer.on('touchstart.lg', function (e) {
552
531
  $item = _this.core.getSlideItem(_this.core.index);
553
532
  if (!_this.isImageSlide()) {
554
533
  return;
555
534
  }
556
- if (e.targetTouches.length === 2 &&
557
- !_this.core.outer.hasClass('lg-first-slide-loading') &&
558
- (_this.$LG(e.target).hasClass('lg-item') ||
559
- $item.get().contains(e.target))) {
535
+ if (e.touches.length === 2) {
536
+ e.preventDefault();
537
+ if (_this.core.outer.hasClass('lg-first-slide-loading')) {
538
+ return;
539
+ }
560
540
  initScale = _this.scale || 1;
561
541
  _this.core.outer.removeClass('lg-zoom-drag-transition lg-zoom-dragging');
542
+ _this.setPageCords(e);
543
+ _this.resetImageTranslate();
562
544
  _this.core.touchAction = 'pinch';
563
545
  startDist = _this.getTouchDistance(e);
564
546
  }
565
547
  });
566
548
  this.core.$inner.on('touchmove.lg', function (e) {
567
- if (e.targetTouches.length === 2 &&
549
+ if (e.touches.length === 2 &&
568
550
  _this.core.touchAction === 'pinch' &&
569
551
  (_this.$LG(e.target).hasClass('lg-item') ||
570
552
  $item.get().contains(e.target))) {
@@ -575,8 +557,12 @@ var Zoom = /** @class */ (function () {
575
557
  pinchStarted = true;
576
558
  }
577
559
  if (pinchStarted) {
578
- _this.scale = Math.max(1, initScale + -distance * 0.008);
579
- _this.zoomImage(_this.scale);
560
+ prevScale = _this.scale;
561
+ var _scale = Math.max(1, initScale + -distance * 0.02);
562
+ _this.scale =
563
+ Math.round((_scale + Number.EPSILON) * 100) / 100;
564
+ var diff = _this.scale - prevScale;
565
+ _this.zoomImage(_this.scale, Math.round((diff + Number.EPSILON) * 100) / 100, false, false);
580
566
  }
581
567
  }
582
568
  });
@@ -590,15 +576,22 @@ var Zoom = /** @class */ (function () {
590
576
  _this.resetZoom();
591
577
  }
592
578
  else {
593
- _this.scale = _this.getScale(_this.scale);
594
- _this.zoomImage(_this.scale);
579
+ var actualSizeScale = _this.getCurrentImageActualSizeScale();
580
+ if (_this.scale >= actualSizeScale) {
581
+ var scaleDiff = actualSizeScale - _this.scale;
582
+ if (scaleDiff === 0) {
583
+ scaleDiff = 0.01;
584
+ }
585
+ _this.zoomImage(actualSizeScale, scaleDiff, false, true);
586
+ }
587
+ _this.manageActualPixelClassNames();
595
588
  _this.core.outer.addClass('lg-zoomed');
596
589
  }
597
590
  _this.core.touchAction = undefined;
598
591
  }
599
592
  });
600
593
  };
601
- Zoom.prototype.touchendZoom = function (startCoords, endCoords, allowX, allowY, touchDuration, rotateValue) {
594
+ Zoom.prototype.touchendZoom = function (startCoords, endCoords, allowX, allowY, touchDuration) {
602
595
  var distanceXnew = endCoords.x - startCoords.x;
603
596
  var distanceYnew = endCoords.y - startCoords.y;
604
597
  var speedX = Math.abs(distanceXnew) / touchDuration + 1;
@@ -616,9 +609,9 @@ var Zoom = /** @class */ (function () {
616
609
  .find('.lg-img-wrap')
617
610
  .first();
618
611
  var distance = {};
619
- distance.x = this.left + distanceXnew * this.modifierX;
620
- distance.y = this.top + distanceYnew * this.modifierY;
621
- var possibleSwipeCords = this.getPossibleSwipeDragCords(rotateValue);
612
+ distance.x = this.left + distanceXnew;
613
+ distance.y = this.top + distanceYnew;
614
+ var possibleSwipeCords = this.getPossibleSwipeDragCords();
622
615
  if (Math.abs(distanceXnew) > 15 || Math.abs(distanceYnew) > 15) {
623
616
  if (allowY) {
624
617
  if (this.isBeyondPossibleTop(distance.y, possibleSwipeCords.minY)) {
@@ -655,8 +648,7 @@ var Zoom = /** @class */ (function () {
655
648
  Zoom.prototype.getZoomSwipeCords = function (startCoords, endCoords, allowX, allowY, possibleSwipeCords) {
656
649
  var distance = {};
657
650
  if (allowY) {
658
- distance.y =
659
- this.top + (endCoords.y - startCoords.y) * this.modifierY;
651
+ distance.y = this.top + (endCoords.y - startCoords.y);
660
652
  if (this.isBeyondPossibleTop(distance.y, possibleSwipeCords.minY)) {
661
653
  var diffMinY = possibleSwipeCords.minY - distance.y;
662
654
  distance.y = possibleSwipeCords.minY - diffMinY / 6;
@@ -670,8 +662,7 @@ var Zoom = /** @class */ (function () {
670
662
  distance.y = this.top;
671
663
  }
672
664
  if (allowX) {
673
- distance.x =
674
- this.left + (endCoords.x - startCoords.x) * this.modifierX;
665
+ distance.x = this.left + (endCoords.x - startCoords.x);
675
666
  if (this.isBeyondPossibleLeft(distance.x, possibleSwipeCords.minX)) {
676
667
  var diffMinX = possibleSwipeCords.minX - distance.x;
677
668
  distance.x = possibleSwipeCords.minX - diffMinX / 6;
@@ -702,30 +693,29 @@ var Zoom = /** @class */ (function () {
702
693
  var currentItem = this.core.galleryItems[this.core.index];
703
694
  return this.core.getSlideType(currentItem) === 'image';
704
695
  };
705
- Zoom.prototype.getPossibleSwipeDragCords = function (rotateValue, scale) {
706
- var dataScale = scale || this.scale || 1;
707
- var elDataScale = Math.abs(dataScale);
708
- var _a = this.core.mediaContainerPosition, top = _a.top, bottom = _a.bottom;
709
- var topBottomSpacing = Math.abs(top - bottom) / 2;
710
- var minY = (this.imageYSize - this.containerRect.height) / 2 +
711
- topBottomSpacing * this.modifierX;
712
- var maxY = this.containerRect.height - this.imageYSize * elDataScale + minY;
713
- var minX = (this.imageXSize - this.containerRect.width) / 2;
714
- var maxX = this.containerRect.width - this.imageXSize * elDataScale + minX;
696
+ Zoom.prototype.getPossibleSwipeDragCords = function (scale) {
697
+ var $image = this.core
698
+ .getSlideItem(this.core.index)
699
+ .find('.lg-image')
700
+ .first();
701
+ var bottom = this.core.mediaContainerPosition.bottom;
702
+ var imgRect = $image.get().getBoundingClientRect();
703
+ var imageHeight = imgRect.height;
704
+ var imageWidth = imgRect.width;
705
+ if (scale) {
706
+ imageHeight = imageHeight + scale * imageHeight;
707
+ imageWidth = imageWidth + scale * imageWidth;
708
+ }
709
+ var minY = (imageHeight - this.containerRect.height) / 2;
710
+ var maxY = (this.containerRect.height - imageHeight) / 2 + bottom;
711
+ var minX = (imageWidth - this.containerRect.width) / 2;
712
+ var maxX = (this.containerRect.width - imageWidth) / 2;
715
713
  var possibleSwipeCords = {
716
714
  minY: minY,
717
715
  maxY: maxY,
718
716
  minX: minX,
719
717
  maxX: maxX,
720
718
  };
721
- if (Math.abs(rotateValue) === 90) {
722
- possibleSwipeCords = {
723
- minY: minX,
724
- maxY: maxX,
725
- minX: minY,
726
- maxX: maxY,
727
- };
728
- }
729
719
  return possibleSwipeCords;
730
720
  };
731
721
  Zoom.prototype.setZoomSwipeStyles = function (LGel, distance) {
@@ -753,7 +743,7 @@ var Zoom = /** @class */ (function () {
753
743
  $item = _this.core.getSlideItem(_this.core.index);
754
744
  if ((_this.$LG(e.target).hasClass('lg-item') ||
755
745
  $item.get().contains(e.target)) &&
756
- e.targetTouches.length === 1 &&
746
+ e.touches.length === 1 &&
757
747
  _this.core.outer.hasClass('lg-zoomed')) {
758
748
  e.preventDefault();
759
749
  startTime = new Date();
@@ -762,25 +752,25 @@ var Zoom = /** @class */ (function () {
762
752
  .getSlideItem(_this.core.index)
763
753
  .find('.lg-img-wrap')
764
754
  .first();
765
- var dragAllowedAxises = _this.getDragAllowedAxises(Math.abs(_this.rotateValue));
755
+ var dragAllowedAxises = _this.getDragAllowedAxises(0);
766
756
  allowY = dragAllowedAxises.allowY;
767
757
  allowX = dragAllowedAxises.allowX;
768
758
  if (allowX || allowY) {
769
- startCoords = _this.getSwipeCords(e, Math.abs(_this.rotateValue));
759
+ startCoords = _this.getSwipeCords(e);
770
760
  }
771
- possibleSwipeCords = _this.getPossibleSwipeDragCords(_this.rotateValue);
761
+ possibleSwipeCords = _this.getPossibleSwipeDragCords();
772
762
  // reset opacity and transition duration
773
763
  _this.core.outer.addClass('lg-zoom-dragging lg-zoom-drag-transition');
774
764
  }
775
765
  });
776
766
  this.core.$inner.on('touchmove.lg', function (e) {
777
- if (e.targetTouches.length === 1 &&
767
+ if (e.touches.length === 1 &&
778
768
  _this.core.touchAction === 'zoomSwipe' &&
779
769
  (_this.$LG(e.target).hasClass('lg-item') ||
780
770
  $item.get().contains(e.target))) {
781
771
  e.preventDefault();
782
772
  _this.core.touchAction = 'zoomSwipe';
783
- endCoords = _this.getSwipeCords(e, Math.abs(_this.rotateValue));
773
+ endCoords = _this.getSwipeCords(e);
784
774
  var distance = _this.getZoomSwipeCords(startCoords, endCoords, allowX, allowY, possibleSwipeCords);
785
775
  if (Math.abs(endCoords.x - startCoords.x) > 15 ||
786
776
  Math.abs(endCoords.y - startCoords.y) > 15) {
@@ -793,6 +783,7 @@ var Zoom = /** @class */ (function () {
793
783
  if (_this.core.touchAction === 'zoomSwipe' &&
794
784
  (_this.$LG(e.target).hasClass('lg-item') ||
795
785
  $item.get().contains(e.target))) {
786
+ e.preventDefault();
796
787
  _this.core.touchAction = undefined;
797
788
  _this.core.outer.removeClass('lg-zoom-dragging');
798
789
  if (!isMoved) {
@@ -801,7 +792,7 @@ var Zoom = /** @class */ (function () {
801
792
  isMoved = false;
802
793
  endTime = new Date();
803
794
  var touchDuration = endTime.valueOf() - startTime.valueOf();
804
- _this.touchendZoom(startCoords, endCoords, allowX, allowY, touchDuration, _this.rotateValue);
795
+ _this.touchendZoom(startCoords, endCoords, allowX, allowY, touchDuration);
805
796
  }
806
797
  });
807
798
  };
@@ -832,19 +823,16 @@ var Zoom = /** @class */ (function () {
832
823
  .getSlideItem(_this.core.index)
833
824
  .find('.lg-img-wrap')
834
825
  .first();
835
- var dragAllowedAxises = _this.getDragAllowedAxises(Math.abs(_this.rotateValue));
826
+ var dragAllowedAxises = _this.getDragAllowedAxises(0);
836
827
  allowY = dragAllowedAxises.allowY;
837
828
  allowX = dragAllowedAxises.allowX;
838
829
  if (_this.core.outer.hasClass('lg-zoomed')) {
839
830
  if (_this.$LG(e.target).hasClass('lg-object') &&
840
831
  (allowX || allowY)) {
841
832
  e.preventDefault();
842
- startCoords = _this.getDragCords(e, Math.abs(_this.rotateValue));
843
- possibleSwipeCords = _this.getPossibleSwipeDragCords(_this.rotateValue);
833
+ startCoords = _this.getDragCords(e);
834
+ possibleSwipeCords = _this.getPossibleSwipeDragCords();
844
835
  isDragging = true;
845
- // ** Fix for webkit cursor issue https://code.google.com/p/chromium/issues/detail?id=26723
846
- _this.core.outer.get().scrollLeft += 1;
847
- _this.core.outer.get().scrollLeft -= 1;
848
836
  _this.core.outer
849
837
  .removeClass('lg-grab')
850
838
  .addClass('lg-grabbing lg-zoom-drag-transition lg-zoom-dragging');
@@ -856,7 +844,7 @@ var Zoom = /** @class */ (function () {
856
844
  this.$LG(window).on("mousemove.lg.zoom.global" + this.core.lgId, function (e) {
857
845
  if (isDragging) {
858
846
  isMoved = true;
859
- endCoords = _this.getDragCords(e, Math.abs(_this.rotateValue));
847
+ endCoords = _this.getDragCords(e);
860
848
  var distance = _this.getZoomSwipeCords(startCoords, endCoords, allowX, allowY, possibleSwipeCords);
861
849
  _this.setZoomSwipeStyles(_LGel, distance);
862
850
  }
@@ -870,9 +858,9 @@ var Zoom = /** @class */ (function () {
870
858
  if (isMoved &&
871
859
  (startCoords.x !== endCoords.x ||
872
860
  startCoords.y !== endCoords.y)) {
873
- endCoords = _this.getDragCords(e, Math.abs(_this.rotateValue));
861
+ endCoords = _this.getDragCords(e);
874
862
  var touchDuration = endTime.valueOf() - startTime.valueOf();
875
- _this.touchendZoom(startCoords, endCoords, allowX, allowY, touchDuration, _this.rotateValue);
863
+ _this.touchendZoom(startCoords, endCoords, allowX, allowY, touchDuration);
876
864
  }
877
865
  isMoved = false;
878
866
  }