lightgallery 2.5.0 → 2.6.0

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 (82) hide show
  1. package/README.md +1 -1
  2. package/css/lg-rotate.css +7 -0
  3. package/css/lg-zoom.css +37 -5
  4. package/css/lightgallery-bundle.css +45 -6
  5. package/css/lightgallery-bundle.min.css +1 -1
  6. package/css/lightgallery.css +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/thumbnail/lg-thumbnail-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-settings.d.ts +2 -1
  53. package/plugins/thumbnail/lg-thumbnail.es5.js +1 -1
  54. package/plugins/thumbnail/lg-thumbnail.es5.js.map +1 -1
  55. package/plugins/thumbnail/lg-thumbnail.min.js +1 -1
  56. package/plugins/thumbnail/lg-thumbnail.umd.js +1 -1
  57. package/plugins/thumbnail/lg-thumbnail.umd.js.map +1 -1
  58. package/plugins/video/lg-video.es5.js +1 -1
  59. package/plugins/video/lg-video.min.js +1 -1
  60. package/plugins/video/lg-video.umd.js +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-variables.scss +1 -1
  75. package/scss/lg-rotate.scss +8 -0
  76. package/scss/lg-zoom.scss +29 -2
  77. package/vue/LightGalleryVue.common.js +24 -19
  78. package/vue/LightGalleryVue.common.js.map +1 -1
  79. package/vue/LightGalleryVue.umd.js +24 -19
  80. package/vue/LightGalleryVue.umd.js.map +1 -1
  81. package/vue/LightGalleryVue.umd.min.js +1 -1
  82. package/vue/LightGalleryVue.umd.min.js.map +1 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * lightgallery | 2.5.0 | June 13th 2022
2
+ * lightgallery | 2.6.0 | August 29th 2022
3
3
  * http://www.lightgalleryjs.com/
4
4
  * Copyright (c) 2020 Sachin Neravath;
5
5
  * @license GPLv3
@@ -141,158 +141,50 @@
141
141
  // Add zoomable class
142
142
  this.core.LGel.on(lGEvents.slideItemLoad + ".zoom", this.enableZoom.bind(this));
143
143
  };
144
- Zoom.prototype.getModifier = function (rotateValue, axis, el) {
145
- var originalRotate = rotateValue;
146
- rotateValue = Math.abs(rotateValue);
147
- var transformValues = this.getCurrentTransform(el);
148
- if (!transformValues) {
149
- return 1;
150
- }
151
- var modifier = 1;
152
- if (axis === 'X') {
153
- var flipHorizontalValue = Math.sign(parseFloat(transformValues[0]));
154
- if (rotateValue === 0 || rotateValue === 180) {
155
- modifier = 1;
156
- }
157
- else if (rotateValue === 90) {
158
- if ((originalRotate === -90 && flipHorizontalValue === 1) ||
159
- (originalRotate === 90 && flipHorizontalValue === -1)) {
160
- modifier = -1;
161
- }
162
- else {
163
- modifier = 1;
164
- }
165
- }
166
- modifier = modifier * flipHorizontalValue;
167
- }
168
- else {
169
- var flipVerticalValue = Math.sign(parseFloat(transformValues[3]));
170
- if (rotateValue === 0 || rotateValue === 180) {
171
- modifier = 1;
172
- }
173
- else if (rotateValue === 90) {
174
- var sinX = parseFloat(transformValues[1]);
175
- var sinMinusX = parseFloat(transformValues[2]);
176
- modifier = Math.sign(sinX * sinMinusX * originalRotate * flipVerticalValue);
177
- }
178
- modifier = modifier * flipVerticalValue;
179
- }
180
- return modifier;
181
- };
182
- Zoom.prototype.getImageSize = function ($image, rotateValue, axis) {
183
- var imageSizes = {
184
- y: 'offsetHeight',
185
- x: 'offsetWidth',
144
+ Zoom.prototype.getDragCords = function (e) {
145
+ return {
146
+ x: e.pageX,
147
+ y: e.pageY,
186
148
  };
187
- if (Math.abs(rotateValue) === 90) {
188
- // Swap axis
189
- if (axis === 'x') {
190
- axis = 'y';
191
- }
192
- else {
193
- axis = 'x';
194
- }
195
- }
196
- return $image[imageSizes[axis]];
197
- };
198
- Zoom.prototype.getDragCords = function (e, rotateValue) {
199
- if (rotateValue === 90) {
200
- return {
201
- x: e.pageY,
202
- y: e.pageX,
203
- };
204
- }
205
- else {
206
- return {
207
- x: e.pageX,
208
- y: e.pageY,
209
- };
210
- }
211
- };
212
- Zoom.prototype.getSwipeCords = function (e, rotateValue) {
213
- var x = e.targetTouches[0].pageX;
214
- var y = e.targetTouches[0].pageY;
215
- if (rotateValue === 90) {
216
- return {
217
- x: y,
218
- y: x,
219
- };
220
- }
221
- else {
222
- return {
223
- x: x,
224
- y: y,
225
- };
226
- }
227
- };
228
- Zoom.prototype.getDragAllowedAxises = function (rotateValue, scale) {
229
- scale = scale || this.scale || 1;
230
- var allowY = this.imageYSize * scale > this.containerRect.height;
231
- var allowX = this.imageXSize * scale > this.containerRect.width;
232
- if (rotateValue === 90) {
233
- return {
234
- allowX: allowY,
235
- allowY: allowX,
236
- };
237
- }
238
- else {
239
- return {
240
- allowX: allowX,
241
- allowY: allowY,
242
- };
243
- }
244
149
  };
245
- /**
246
- *
247
- * @param {Element} el
248
- * @return matrix(cos(X), sin(X), -sin(X), cos(X), 0, 0);
249
- * Get the current transform value
250
- */
251
- Zoom.prototype.getCurrentTransform = function (el) {
252
- if (!el) {
253
- return;
254
- }
255
- var st = window.getComputedStyle(el, null);
256
- var tm = st.getPropertyValue('-webkit-transform') ||
257
- st.getPropertyValue('-moz-transform') ||
258
- st.getPropertyValue('-ms-transform') ||
259
- st.getPropertyValue('-o-transform') ||
260
- st.getPropertyValue('transform') ||
261
- 'none';
262
- if (tm !== 'none') {
263
- return tm.split('(')[1].split(')')[0].split(',');
264
- }
265
- return;
266
- };
267
- Zoom.prototype.getCurrentRotation = function (el) {
268
- if (!el) {
269
- return 0;
270
- }
271
- var values = this.getCurrentTransform(el);
272
- if (values) {
273
- return Math.round(Math.atan2(parseFloat(values[1]), parseFloat(values[0])) *
274
- (180 / Math.PI));
275
- // If you want rotate in 360
276
- //return (angle < 0 ? angle + 360 : angle);
277
- }
278
- return 0;
150
+ Zoom.prototype.getSwipeCords = function (e) {
151
+ var x = e.touches[0].pageX;
152
+ var y = e.touches[0].pageY;
153
+ return {
154
+ x: x,
155
+ y: y,
156
+ };
279
157
  };
280
- Zoom.prototype.setZoomEssentials = function () {
158
+ Zoom.prototype.getDragAllowedAxises = function (scale, scaleDiff) {
281
159
  var $image = this.core
282
160
  .getSlideItem(this.core.index)
283
161
  .find('.lg-image')
284
- .first();
285
- var rotateEl = this.core
286
- .getSlideItem(this.core.index)
287
- .find('.lg-img-rotate')
288
162
  .first()
289
163
  .get();
290
- this.rotateValue = this.getCurrentRotation(rotateEl);
291
- this.imageYSize = this.getImageSize($image.get(), this.rotateValue, 'y');
292
- this.imageXSize = this.getImageSize($image.get(), this.rotateValue, 'x');
293
- this.containerRect = this.core.outer.get().getBoundingClientRect();
294
- this.modifierX = this.getModifier(this.rotateValue, 'X', rotateEl);
295
- this.modifierY = this.getModifier(this.rotateValue, 'Y', rotateEl);
164
+ var height = 0;
165
+ var width = 0;
166
+ var rect = $image.getBoundingClientRect();
167
+ if (scale) {
168
+ height = $image.offsetHeight * scale;
169
+ width = $image.offsetWidth * scale;
170
+ }
171
+ else if (scaleDiff) {
172
+ height = rect.height + scaleDiff * rect.height;
173
+ width = rect.width + scaleDiff * rect.width;
174
+ }
175
+ else {
176
+ height = rect.height;
177
+ width = rect.width;
178
+ }
179
+ var allowY = height > this.containerRect.height;
180
+ var allowX = width > this.containerRect.width;
181
+ return {
182
+ allowX: allowX,
183
+ allowY: allowY,
184
+ };
185
+ };
186
+ Zoom.prototype.setZoomEssentials = function () {
187
+ this.containerRect = this.core.$content.get().getBoundingClientRect();
296
188
  };
297
189
  /**
298
190
  * @desc Image zoom
@@ -300,86 +192,152 @@
300
192
  *
301
193
  * @param {String} scale - Zoom decrement/increment value
302
194
  */
303
- Zoom.prototype.zoomImage = function (scale) {
304
- // Find offset manually to avoid issue after zoom
305
- var offsetX = (this.containerRect.width - this.imageXSize) / 2 +
306
- this.containerRect.left;
307
- var _a = this.core.mediaContainerPosition, top = _a.top, bottom = _a.bottom;
308
- var topBottomSpacing = Math.abs(top - bottom) / 2;
309
- var offsetY = (this.containerRect.height -
310
- this.imageYSize -
311
- topBottomSpacing * this.modifierX) /
312
- 2 +
313
- this.scrollTop +
314
- this.containerRect.top;
195
+ Zoom.prototype.zoomImage = function (scale, scaleDiff, reposition, resetToMax) {
196
+ if (Math.abs(scaleDiff) <= 0)
197
+ return;
198
+ var offsetX = this.containerRect.width / 2 + this.containerRect.left;
199
+ var offsetY = this.containerRect.height / 2 +
200
+ this.containerRect.top +
201
+ this.scrollTop;
315
202
  var originalX;
316
203
  var originalY;
317
204
  if (scale === 1) {
318
205
  this.positionChanged = false;
319
206
  }
320
- var dragAllowedAxises = this.getDragAllowedAxises(Math.abs(this.rotateValue), scale);
207
+ var dragAllowedAxises = this.getDragAllowedAxises(0, scaleDiff);
321
208
  var allowY = dragAllowedAxises.allowY, allowX = dragAllowedAxises.allowX;
322
209
  if (this.positionChanged) {
323
- originalX = this.left / (this.scale - 1);
324
- originalY = this.top / (this.scale - 1);
325
- this.pageX = Math.abs(originalX) + offsetX;
326
- this.pageY = Math.abs(originalY) + offsetY;
210
+ originalX = this.left / (this.scale - scaleDiff);
211
+ originalY = this.top / (this.scale - scaleDiff);
212
+ this.pageX = offsetX - originalX;
213
+ this.pageY = offsetY - originalY;
327
214
  this.positionChanged = false;
328
215
  }
329
- var possibleSwipeCords = this.getPossibleSwipeDragCords(this.rotateValue, scale);
216
+ var possibleSwipeCords = this.getPossibleSwipeDragCords(scaleDiff);
217
+ var x;
218
+ var y;
330
219
  var _x = offsetX - this.pageX;
331
220
  var _y = offsetY - this.pageY;
332
- var x = (scale - 1) * _x;
333
- var y = (scale - 1) * _y;
334
- if (allowX) {
335
- if (this.isBeyondPossibleLeft(x, possibleSwipeCords.minX)) {
336
- x = possibleSwipeCords.minX;
337
- }
338
- else if (this.isBeyondPossibleRight(x, possibleSwipeCords.maxX)) {
339
- x = possibleSwipeCords.maxX;
340
- }
221
+ if (scale - scaleDiff > 1) {
222
+ var scaleVal = (scale - scaleDiff) / Math.abs(scaleDiff);
223
+ _x =
224
+ (scaleDiff < 0 ? -_x : _x) +
225
+ this.left * (scaleVal + (scaleDiff < 0 ? -1 : 1));
226
+ _y =
227
+ (scaleDiff < 0 ? -_y : _y) +
228
+ this.top * (scaleVal + (scaleDiff < 0 ? -1 : 1));
229
+ x = _x / scaleVal;
230
+ y = _y / scaleVal;
341
231
  }
342
232
  else {
343
- if (scale > 1) {
344
- if (x < possibleSwipeCords.minX) {
233
+ var scaleVal = (scale - scaleDiff) * scaleDiff;
234
+ x = _x * scaleVal;
235
+ y = _y * scaleVal;
236
+ }
237
+ if (reposition) {
238
+ if (allowX) {
239
+ if (this.isBeyondPossibleLeft(x, possibleSwipeCords.minX)) {
345
240
  x = possibleSwipeCords.minX;
346
241
  }
347
- else if (x > possibleSwipeCords.maxX) {
242
+ else if (this.isBeyondPossibleRight(x, possibleSwipeCords.maxX)) {
348
243
  x = possibleSwipeCords.maxX;
349
244
  }
350
245
  }
351
- }
352
- if (allowY) {
353
- if (this.isBeyondPossibleTop(y, possibleSwipeCords.minY)) {
354
- y = possibleSwipeCords.minY;
355
- }
356
- else if (this.isBeyondPossibleBottom(y, possibleSwipeCords.maxY)) {
357
- y = possibleSwipeCords.maxY;
246
+ else {
247
+ if (scale > 1) {
248
+ if (x < possibleSwipeCords.minX) {
249
+ x = possibleSwipeCords.minX;
250
+ }
251
+ else if (x > possibleSwipeCords.maxX) {
252
+ x = possibleSwipeCords.maxX;
253
+ }
254
+ }
358
255
  }
359
- }
360
- else {
361
- // If the translate value based on index of beyond the viewport, utilize the available space to prevent image being cut out
362
- if (scale > 1) {
363
- //If image goes beyond viewport top, use the minim possible translate value
364
- if (y < possibleSwipeCords.minY) {
256
+ // @todo fix this
257
+ if (allowY) {
258
+ if (this.isBeyondPossibleTop(y, possibleSwipeCords.minY)) {
365
259
  y = possibleSwipeCords.minY;
366
260
  }
367
- else if (y > possibleSwipeCords.maxY) {
261
+ else if (this.isBeyondPossibleBottom(y, possibleSwipeCords.maxY)) {
368
262
  y = possibleSwipeCords.maxY;
369
263
  }
370
264
  }
265
+ else {
266
+ // If the translate value based on index of beyond the viewport, utilize the available space to prevent image being cut out
267
+ if (scale > 1) {
268
+ //If image goes beyond viewport top, use the minim possible translate value
269
+ if (y < possibleSwipeCords.minY) {
270
+ y = possibleSwipeCords.minY;
271
+ }
272
+ else if (y > possibleSwipeCords.maxY) {
273
+ y = possibleSwipeCords.maxY;
274
+ }
275
+ }
276
+ }
371
277
  }
372
278
  this.setZoomStyles({
373
279
  x: x,
374
280
  y: y,
375
281
  scale: scale,
376
282
  });
283
+ this.left = x;
284
+ this.top = y;
285
+ if (resetToMax) {
286
+ var actualSizeScale = this.getCurrentImageActualSizeScale();
287
+ if (scale >= actualSizeScale) {
288
+ this.setZoomImageSize();
289
+ }
290
+ }
291
+ };
292
+ Zoom.prototype.resetImageTranslate = function () {
293
+ var $image = this.core
294
+ .getSlideItem(this.core.index)
295
+ .find('.lg-image')
296
+ .first();
297
+ this.imageReset = false;
298
+ $image.removeClass('reset-transition reset-transition-y reset-transition-x');
299
+ this.core.outer.removeClass('lg-actual-size');
300
+ $image.css('width', 'auto').css('height', 'auto');
301
+ setTimeout(function () {
302
+ $image.removeClass('no-transition');
303
+ }, 10);
304
+ };
305
+ Zoom.prototype.setZoomImageSize = function () {
306
+ var _this = this;
307
+ var $image = this.core
308
+ .getSlideItem(this.core.index)
309
+ .find('.lg-image')
310
+ .first();
311
+ setTimeout(function () {
312
+ $image.addClass('no-transition');
313
+ _this.imageReset = true;
314
+ }, 500);
315
+ setTimeout(function () {
316
+ var dragAllowedAxises = _this.getDragAllowedAxises(_this.scale);
317
+ $image
318
+ .css('width', $image.get().naturalWidth + 'px')
319
+ .css('height', $image.get().naturalHeight + 'px');
320
+ _this.core.outer.addClass('lg-actual-size');
321
+ if (dragAllowedAxises.allowX && dragAllowedAxises.allowY) {
322
+ $image.addClass('reset-transition');
323
+ }
324
+ else if (dragAllowedAxises.allowX && !dragAllowedAxises.allowY) {
325
+ $image.addClass('reset-transition-x');
326
+ }
327
+ else if (!dragAllowedAxises.allowX && dragAllowedAxises.allowY) {
328
+ $image.addClass('reset-transition-y');
329
+ }
330
+ }, 550);
377
331
  };
378
332
  /**
379
333
  * @desc apply scale3d to image and translate to image wrap
380
334
  * @param {style} X,Y and scale
381
335
  */
382
336
  Zoom.prototype.setZoomStyles = function (style) {
337
+ var $imageWrap = this.core
338
+ .getSlideItem(this.core.index)
339
+ .find('.lg-img-wrap')
340
+ .first();
383
341
  var $image = this.core
384
342
  .getSlideItem(this.core.index)
385
343
  .find('.lg-image')
@@ -387,14 +345,11 @@
387
345
  var $dummyImage = this.core.outer
388
346
  .find('.lg-current .lg-dummy-img')
389
347
  .first();
390
- var $imageWrap = $image.parent();
391
348
  this.scale = style.scale;
392
349
  $image.css('transform', 'scale3d(' + style.scale + ', ' + style.scale + ', 1)');
393
350
  $dummyImage.css('transform', 'scale3d(' + style.scale + ', ' + style.scale + ', 1)');
394
351
  var transform = 'translate3d(' + style.x + 'px, ' + style.y + 'px, 0)';
395
352
  $imageWrap.css('transform', transform);
396
- this.left = style.x;
397
- this.top = style.y;
398
353
  };
399
354
  /**
400
355
  * @param index - Index of the current slide
@@ -402,24 +357,29 @@
402
357
  */
403
358
  Zoom.prototype.setActualSize = function (index, event) {
404
359
  var _this = this;
405
- // Allow zoom only on image
406
- if (!this.isImageSlide() ||
407
- this.core.outer.hasClass('lg-first-slide-loading')) {
408
- return;
409
- }
410
- var scale = this.getCurrentImageActualSizeScale();
411
- if (this.core.outer.hasClass('lg-zoomed')) {
412
- this.scale = 1;
413
- }
414
- else {
415
- this.scale = this.getScale(scale);
416
- }
417
- this.setPageCords(event);
418
- this.beginZoom(this.scale);
419
- this.zoomImage(this.scale);
360
+ var currentItem = this.core.galleryItems[this.core.index];
361
+ this.resetImageTranslate();
420
362
  setTimeout(function () {
421
- _this.core.outer.removeClass('lg-grabbing').addClass('lg-grab');
422
- }, 10);
363
+ // Allow zoom only on image
364
+ if (!currentItem.src ||
365
+ _this.core.outer.hasClass('lg-first-slide-loading')) {
366
+ return;
367
+ }
368
+ var scale = _this.getCurrentImageActualSizeScale();
369
+ var prevScale = _this.scale;
370
+ if (_this.core.outer.hasClass('lg-zoomed')) {
371
+ _this.scale = 1;
372
+ }
373
+ else {
374
+ _this.scale = _this.getScale(scale);
375
+ }
376
+ _this.setPageCords(event);
377
+ _this.beginZoom(_this.scale);
378
+ _this.zoomImage(_this.scale, _this.scale - prevScale, true, true);
379
+ setTimeout(function () {
380
+ _this.core.outer.removeClass('lg-grabbing').addClass('lg-grab');
381
+ }, 10);
382
+ }, 50);
423
383
  };
424
384
  Zoom.prototype.getNaturalWidth = function (index) {
425
385
  var $image = this.core.getSlideItem(index).find('.lg-image').first();
@@ -431,7 +391,7 @@
431
391
  Zoom.prototype.getActualSizeScale = function (naturalWidth, width) {
432
392
  var _scale;
433
393
  var scale;
434
- if (naturalWidth > width) {
394
+ if (naturalWidth >= width) {
435
395
  _scale = naturalWidth / width;
436
396
  scale = _scale || 2;
437
397
  }
@@ -452,11 +412,13 @@
452
412
  Zoom.prototype.getPageCords = function (event) {
453
413
  var cords = {};
454
414
  if (event) {
455
- cords.x = event.pageX || event.targetTouches[0].pageX;
456
- cords.y = event.pageY || event.targetTouches[0].pageY;
415
+ cords.x = event.pageX || event.touches[0].pageX;
416
+ cords.y = event.pageY || event.touches[0].pageY;
457
417
  }
458
418
  else {
459
- var containerRect = this.core.outer.get().getBoundingClientRect();
419
+ var containerRect = this.core.$content
420
+ .get()
421
+ .getBoundingClientRect();
460
422
  cords.x = containerRect.width / 2 + containerRect.left;
461
423
  cords.y =
462
424
  containerRect.height / 2 + this.scrollTop + containerRect.top;
@@ -468,15 +430,18 @@
468
430
  this.pageX = pageCords.x;
469
431
  this.pageY = pageCords.y;
470
432
  };
433
+ Zoom.prototype.manageActualPixelClassNames = function () {
434
+ var $actualSize = this.core.getElementById('lg-actual-size');
435
+ $actualSize
436
+ .removeClass(this.settings.actualSizeIcons.zoomIn)
437
+ .addClass(this.settings.actualSizeIcons.zoomOut);
438
+ };
471
439
  // If true, zoomed - in else zoomed out
472
440
  Zoom.prototype.beginZoom = function (scale) {
473
441
  this.core.outer.removeClass('lg-zoom-drag-transition lg-zoom-dragging');
474
442
  if (scale > 1) {
475
443
  this.core.outer.addClass('lg-zoomed');
476
- var $actualSize = this.core.getElementById('lg-actual-size');
477
- $actualSize
478
- .removeClass(this.settings.actualSizeIcons.zoomIn)
479
- .addClass(this.settings.actualSizeIcons.zoomOut);
444
+ this.manageActualPixelClassNames();
480
445
  }
481
446
  else {
482
447
  this.resetZoom();
@@ -509,8 +474,7 @@
509
474
  });
510
475
  this.core.outer.on('touchstart.lg', function (event) {
511
476
  var $target = _this.$LG(event.target);
512
- if (event.targetTouches.length === 1 &&
513
- $target.hasClass('lg-image')) {
477
+ if (event.touches.length === 1 && $target.hasClass('lg-image')) {
514
478
  if (!tapped) {
515
479
  tapped = setTimeout(function () {
516
480
  tapped = null;
@@ -524,13 +488,21 @@
524
488
  }
525
489
  }
526
490
  });
527
- // Update zoom on resize and orientationchange
528
491
  this.core.LGel.on(lGEvents.containerResize + ".zoom " + lGEvents.rotateRight + ".zoom " + lGEvents.rotateLeft + ".zoom " + lGEvents.flipHorizontal + ".zoom " + lGEvents.flipVertical + ".zoom", function () {
529
- if (!_this.core.lgOpened || !_this.isImageSlide())
492
+ if (!_this.core.lgOpened ||
493
+ !_this.isImageSlide() ||
494
+ _this.core.touchAction) {
530
495
  return;
531
- _this.setPageCords();
496
+ }
497
+ var _LGel = _this.core
498
+ .getSlideItem(_this.core.index)
499
+ .find('.lg-img-wrap')
500
+ .first();
501
+ _this.top = 0;
502
+ _this.left = 0;
532
503
  _this.setZoomEssentials();
533
- _this.zoomImage(_this.scale);
504
+ _this.setZoomSwipeStyles(_LGel, { x: 0, y: 0 });
505
+ _this.positionChanged = true;
534
506
  });
535
507
  // Update zoom on resize and orientationchange
536
508
  this.$LG(window).on("scroll.lg.zoom.global" + this.core.lgId, function () {
@@ -539,12 +511,23 @@
539
511
  _this.scrollTop = _this.$LG(window).scrollTop();
540
512
  });
541
513
  this.core.getElementById('lg-zoom-out').on('click.lg', function () {
542
- if (_this.core.outer.find('.lg-current .lg-image').get()) {
543
- _this.scale -= _this.settings.scale;
544
- _this.scale = _this.getScale(_this.scale);
545
- _this.beginZoom(_this.scale);
546
- _this.zoomImage(_this.scale);
514
+ // Allow zoom only on image
515
+ if (!_this.isImageSlide()) {
516
+ return;
547
517
  }
518
+ var timeout = 0;
519
+ if (_this.imageReset) {
520
+ _this.resetImageTranslate();
521
+ timeout = 50;
522
+ }
523
+ setTimeout(function () {
524
+ var scale = _this.scale - _this.settings.scale;
525
+ if (scale < 1) {
526
+ scale = 1;
527
+ }
528
+ _this.beginZoom(scale);
529
+ _this.zoomImage(scale, -_this.settings.scale, true, true);
530
+ }, timeout);
548
531
  });
549
532
  this.core.getElementById('lg-zoom-in').on('click.lg', function () {
550
533
  _this.zoomIn();
@@ -580,20 +563,15 @@
580
563
  this.zoomableTimeout = false;
581
564
  this.positionChanged = false;
582
565
  };
583
- Zoom.prototype.zoomIn = function (scale) {
566
+ Zoom.prototype.zoomIn = function () {
584
567
  // Allow zoom only on image
585
568
  if (!this.isImageSlide()) {
586
569
  return;
587
570
  }
588
- if (scale) {
589
- this.scale = scale;
590
- }
591
- else {
592
- this.scale += this.settings.scale;
593
- }
594
- this.scale = this.getScale(this.scale);
595
- this.beginZoom(this.scale);
596
- this.zoomImage(this.scale);
571
+ var scale = this.scale + this.settings.scale;
572
+ scale = this.getScale(scale);
573
+ this.beginZoom(scale);
574
+ this.zoomImage(scale, this.settings.scale, true, true);
597
575
  };
598
576
  // Reset zoom effect
599
577
  Zoom.prototype.resetZoom = function (index) {
@@ -612,34 +590,38 @@
612
590
  this.setPageCords();
613
591
  };
614
592
  Zoom.prototype.getTouchDistance = function (e) {
615
- return Math.sqrt((e.targetTouches[0].pageX - e.targetTouches[1].pageX) *
616
- (e.targetTouches[0].pageX - e.targetTouches[1].pageX) +
617
- (e.targetTouches[0].pageY - e.targetTouches[1].pageY) *
618
- (e.targetTouches[0].pageY - e.targetTouches[1].pageY));
593
+ return Math.sqrt((e.touches[0].pageX - e.touches[1].pageX) *
594
+ (e.touches[0].pageX - e.touches[1].pageX) +
595
+ (e.touches[0].pageY - e.touches[1].pageY) *
596
+ (e.touches[0].pageY - e.touches[1].pageY));
619
597
  };
620
598
  Zoom.prototype.pinchZoom = function () {
621
599
  var _this = this;
622
600
  var startDist = 0;
623
601
  var pinchStarted = false;
624
602
  var initScale = 1;
603
+ var prevScale = 0;
625
604
  var $item = this.core.getSlideItem(this.core.index);
626
- this.core.$inner.on('touchstart.lg', function (e) {
605
+ this.core.outer.on('touchstart.lg', function (e) {
627
606
  $item = _this.core.getSlideItem(_this.core.index);
628
607
  if (!_this.isImageSlide()) {
629
608
  return;
630
609
  }
631
- if (e.targetTouches.length === 2 &&
632
- !_this.core.outer.hasClass('lg-first-slide-loading') &&
633
- (_this.$LG(e.target).hasClass('lg-item') ||
634
- $item.get().contains(e.target))) {
610
+ if (e.touches.length === 2) {
611
+ e.preventDefault();
612
+ if (_this.core.outer.hasClass('lg-first-slide-loading')) {
613
+ return;
614
+ }
635
615
  initScale = _this.scale || 1;
636
616
  _this.core.outer.removeClass('lg-zoom-drag-transition lg-zoom-dragging');
617
+ _this.setPageCords(e);
618
+ _this.resetImageTranslate();
637
619
  _this.core.touchAction = 'pinch';
638
620
  startDist = _this.getTouchDistance(e);
639
621
  }
640
622
  });
641
623
  this.core.$inner.on('touchmove.lg', function (e) {
642
- if (e.targetTouches.length === 2 &&
624
+ if (e.touches.length === 2 &&
643
625
  _this.core.touchAction === 'pinch' &&
644
626
  (_this.$LG(e.target).hasClass('lg-item') ||
645
627
  $item.get().contains(e.target))) {
@@ -650,8 +632,12 @@
650
632
  pinchStarted = true;
651
633
  }
652
634
  if (pinchStarted) {
653
- _this.scale = Math.max(1, initScale + -distance * 0.008);
654
- _this.zoomImage(_this.scale);
635
+ prevScale = _this.scale;
636
+ var _scale = Math.max(1, initScale + -distance * 0.02);
637
+ _this.scale =
638
+ Math.round((_scale + Number.EPSILON) * 100) / 100;
639
+ var diff = _this.scale - prevScale;
640
+ _this.zoomImage(_this.scale, Math.round((diff + Number.EPSILON) * 100) / 100, false, false);
655
641
  }
656
642
  }
657
643
  });
@@ -665,15 +651,22 @@
665
651
  _this.resetZoom();
666
652
  }
667
653
  else {
668
- _this.scale = _this.getScale(_this.scale);
669
- _this.zoomImage(_this.scale);
654
+ var actualSizeScale = _this.getCurrentImageActualSizeScale();
655
+ if (_this.scale >= actualSizeScale) {
656
+ var scaleDiff = actualSizeScale - _this.scale;
657
+ if (scaleDiff === 0) {
658
+ scaleDiff = 0.01;
659
+ }
660
+ _this.zoomImage(actualSizeScale, scaleDiff, false, true);
661
+ }
662
+ _this.manageActualPixelClassNames();
670
663
  _this.core.outer.addClass('lg-zoomed');
671
664
  }
672
665
  _this.core.touchAction = undefined;
673
666
  }
674
667
  });
675
668
  };
676
- Zoom.prototype.touchendZoom = function (startCoords, endCoords, allowX, allowY, touchDuration, rotateValue) {
669
+ Zoom.prototype.touchendZoom = function (startCoords, endCoords, allowX, allowY, touchDuration) {
677
670
  var distanceXnew = endCoords.x - startCoords.x;
678
671
  var distanceYnew = endCoords.y - startCoords.y;
679
672
  var speedX = Math.abs(distanceXnew) / touchDuration + 1;
@@ -691,9 +684,9 @@
691
684
  .find('.lg-img-wrap')
692
685
  .first();
693
686
  var distance = {};
694
- distance.x = this.left + distanceXnew * this.modifierX;
695
- distance.y = this.top + distanceYnew * this.modifierY;
696
- var possibleSwipeCords = this.getPossibleSwipeDragCords(rotateValue);
687
+ distance.x = this.left + distanceXnew;
688
+ distance.y = this.top + distanceYnew;
689
+ var possibleSwipeCords = this.getPossibleSwipeDragCords();
697
690
  if (Math.abs(distanceXnew) > 15 || Math.abs(distanceYnew) > 15) {
698
691
  if (allowY) {
699
692
  if (this.isBeyondPossibleTop(distance.y, possibleSwipeCords.minY)) {
@@ -730,8 +723,7 @@
730
723
  Zoom.prototype.getZoomSwipeCords = function (startCoords, endCoords, allowX, allowY, possibleSwipeCords) {
731
724
  var distance = {};
732
725
  if (allowY) {
733
- distance.y =
734
- this.top + (endCoords.y - startCoords.y) * this.modifierY;
726
+ distance.y = this.top + (endCoords.y - startCoords.y);
735
727
  if (this.isBeyondPossibleTop(distance.y, possibleSwipeCords.minY)) {
736
728
  var diffMinY = possibleSwipeCords.minY - distance.y;
737
729
  distance.y = possibleSwipeCords.minY - diffMinY / 6;
@@ -745,8 +737,7 @@
745
737
  distance.y = this.top;
746
738
  }
747
739
  if (allowX) {
748
- distance.x =
749
- this.left + (endCoords.x - startCoords.x) * this.modifierX;
740
+ distance.x = this.left + (endCoords.x - startCoords.x);
750
741
  if (this.isBeyondPossibleLeft(distance.x, possibleSwipeCords.minX)) {
751
742
  var diffMinX = possibleSwipeCords.minX - distance.x;
752
743
  distance.x = possibleSwipeCords.minX - diffMinX / 6;
@@ -777,30 +768,29 @@
777
768
  var currentItem = this.core.galleryItems[this.core.index];
778
769
  return this.core.getSlideType(currentItem) === 'image';
779
770
  };
780
- Zoom.prototype.getPossibleSwipeDragCords = function (rotateValue, scale) {
781
- var dataScale = scale || this.scale || 1;
782
- var elDataScale = Math.abs(dataScale);
783
- var _a = this.core.mediaContainerPosition, top = _a.top, bottom = _a.bottom;
784
- var topBottomSpacing = Math.abs(top - bottom) / 2;
785
- var minY = (this.imageYSize - this.containerRect.height) / 2 +
786
- topBottomSpacing * this.modifierX;
787
- var maxY = this.containerRect.height - this.imageYSize * elDataScale + minY;
788
- var minX = (this.imageXSize - this.containerRect.width) / 2;
789
- var maxX = this.containerRect.width - this.imageXSize * elDataScale + minX;
771
+ Zoom.prototype.getPossibleSwipeDragCords = function (scale) {
772
+ var $image = this.core
773
+ .getSlideItem(this.core.index)
774
+ .find('.lg-image')
775
+ .first();
776
+ var bottom = this.core.mediaContainerPosition.bottom;
777
+ var imgRect = $image.get().getBoundingClientRect();
778
+ var imageHeight = imgRect.height;
779
+ var imageWidth = imgRect.width;
780
+ if (scale) {
781
+ imageHeight = imageHeight + scale * imageHeight;
782
+ imageWidth = imageWidth + scale * imageWidth;
783
+ }
784
+ var minY = (imageHeight - this.containerRect.height) / 2;
785
+ var maxY = (this.containerRect.height - imageHeight) / 2 + bottom;
786
+ var minX = (imageWidth - this.containerRect.width) / 2;
787
+ var maxX = (this.containerRect.width - imageWidth) / 2;
790
788
  var possibleSwipeCords = {
791
789
  minY: minY,
792
790
  maxY: maxY,
793
791
  minX: minX,
794
792
  maxX: maxX,
795
793
  };
796
- if (Math.abs(rotateValue) === 90) {
797
- possibleSwipeCords = {
798
- minY: minX,
799
- maxY: maxX,
800
- minX: minY,
801
- maxX: maxY,
802
- };
803
- }
804
794
  return possibleSwipeCords;
805
795
  };
806
796
  Zoom.prototype.setZoomSwipeStyles = function (LGel, distance) {
@@ -828,7 +818,7 @@
828
818
  $item = _this.core.getSlideItem(_this.core.index);
829
819
  if ((_this.$LG(e.target).hasClass('lg-item') ||
830
820
  $item.get().contains(e.target)) &&
831
- e.targetTouches.length === 1 &&
821
+ e.touches.length === 1 &&
832
822
  _this.core.outer.hasClass('lg-zoomed')) {
833
823
  e.preventDefault();
834
824
  startTime = new Date();
@@ -837,25 +827,25 @@
837
827
  .getSlideItem(_this.core.index)
838
828
  .find('.lg-img-wrap')
839
829
  .first();
840
- var dragAllowedAxises = _this.getDragAllowedAxises(Math.abs(_this.rotateValue));
830
+ var dragAllowedAxises = _this.getDragAllowedAxises(0);
841
831
  allowY = dragAllowedAxises.allowY;
842
832
  allowX = dragAllowedAxises.allowX;
843
833
  if (allowX || allowY) {
844
- startCoords = _this.getSwipeCords(e, Math.abs(_this.rotateValue));
834
+ startCoords = _this.getSwipeCords(e);
845
835
  }
846
- possibleSwipeCords = _this.getPossibleSwipeDragCords(_this.rotateValue);
836
+ possibleSwipeCords = _this.getPossibleSwipeDragCords();
847
837
  // reset opacity and transition duration
848
838
  _this.core.outer.addClass('lg-zoom-dragging lg-zoom-drag-transition');
849
839
  }
850
840
  });
851
841
  this.core.$inner.on('touchmove.lg', function (e) {
852
- if (e.targetTouches.length === 1 &&
842
+ if (e.touches.length === 1 &&
853
843
  _this.core.touchAction === 'zoomSwipe' &&
854
844
  (_this.$LG(e.target).hasClass('lg-item') ||
855
845
  $item.get().contains(e.target))) {
856
846
  e.preventDefault();
857
847
  _this.core.touchAction = 'zoomSwipe';
858
- endCoords = _this.getSwipeCords(e, Math.abs(_this.rotateValue));
848
+ endCoords = _this.getSwipeCords(e);
859
849
  var distance = _this.getZoomSwipeCords(startCoords, endCoords, allowX, allowY, possibleSwipeCords);
860
850
  if (Math.abs(endCoords.x - startCoords.x) > 15 ||
861
851
  Math.abs(endCoords.y - startCoords.y) > 15) {
@@ -868,6 +858,7 @@
868
858
  if (_this.core.touchAction === 'zoomSwipe' &&
869
859
  (_this.$LG(e.target).hasClass('lg-item') ||
870
860
  $item.get().contains(e.target))) {
861
+ e.preventDefault();
871
862
  _this.core.touchAction = undefined;
872
863
  _this.core.outer.removeClass('lg-zoom-dragging');
873
864
  if (!isMoved) {
@@ -876,7 +867,7 @@
876
867
  isMoved = false;
877
868
  endTime = new Date();
878
869
  var touchDuration = endTime.valueOf() - startTime.valueOf();
879
- _this.touchendZoom(startCoords, endCoords, allowX, allowY, touchDuration, _this.rotateValue);
870
+ _this.touchendZoom(startCoords, endCoords, allowX, allowY, touchDuration);
880
871
  }
881
872
  });
882
873
  };
@@ -907,19 +898,16 @@
907
898
  .getSlideItem(_this.core.index)
908
899
  .find('.lg-img-wrap')
909
900
  .first();
910
- var dragAllowedAxises = _this.getDragAllowedAxises(Math.abs(_this.rotateValue));
901
+ var dragAllowedAxises = _this.getDragAllowedAxises(0);
911
902
  allowY = dragAllowedAxises.allowY;
912
903
  allowX = dragAllowedAxises.allowX;
913
904
  if (_this.core.outer.hasClass('lg-zoomed')) {
914
905
  if (_this.$LG(e.target).hasClass('lg-object') &&
915
906
  (allowX || allowY)) {
916
907
  e.preventDefault();
917
- startCoords = _this.getDragCords(e, Math.abs(_this.rotateValue));
918
- possibleSwipeCords = _this.getPossibleSwipeDragCords(_this.rotateValue);
908
+ startCoords = _this.getDragCords(e);
909
+ possibleSwipeCords = _this.getPossibleSwipeDragCords();
919
910
  isDragging = true;
920
- // ** Fix for webkit cursor issue https://code.google.com/p/chromium/issues/detail?id=26723
921
- _this.core.outer.get().scrollLeft += 1;
922
- _this.core.outer.get().scrollLeft -= 1;
923
911
  _this.core.outer
924
912
  .removeClass('lg-grab')
925
913
  .addClass('lg-grabbing lg-zoom-drag-transition lg-zoom-dragging');
@@ -931,7 +919,7 @@
931
919
  this.$LG(window).on("mousemove.lg.zoom.global" + this.core.lgId, function (e) {
932
920
  if (isDragging) {
933
921
  isMoved = true;
934
- endCoords = _this.getDragCords(e, Math.abs(_this.rotateValue));
922
+ endCoords = _this.getDragCords(e);
935
923
  var distance = _this.getZoomSwipeCords(startCoords, endCoords, allowX, allowY, possibleSwipeCords);
936
924
  _this.setZoomSwipeStyles(_LGel, distance);
937
925
  }
@@ -945,9 +933,9 @@
945
933
  if (isMoved &&
946
934
  (startCoords.x !== endCoords.x ||
947
935
  startCoords.y !== endCoords.y)) {
948
- endCoords = _this.getDragCords(e, Math.abs(_this.rotateValue));
936
+ endCoords = _this.getDragCords(e);
949
937
  var touchDuration = endTime.valueOf() - startTime.valueOf();
950
- _this.touchendZoom(startCoords, endCoords, allowX, allowY, touchDuration, _this.rotateValue);
938
+ _this.touchendZoom(startCoords, endCoords, allowX, allowY, touchDuration);
951
939
  }
952
940
  isMoved = false;
953
941
  }