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

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 (73) hide show
  1. package/README.md +3 -3
  2. package/css/lightgallery-bundle.css +15 -0
  3. package/css/lightgallery-bundle.min.css +1 -1
  4. package/css/lightgallery-core.css +4 -0
  5. package/css/lightgallery.css +15 -0
  6. package/lg-settings.d.ts +14 -0
  7. package/lg-utils.d.ts +1 -0
  8. package/lib/lg-settings.js +3 -0
  9. package/lib/lg-settings.js.map +1 -1
  10. package/lib/lg-utils.js +8 -0
  11. package/lib/lg-utils.js.map +1 -1
  12. package/lib/lightgallery.js +69 -5
  13. package/lib/lightgallery.js.map +1 -1
  14. package/lightgallery.d.ts +5 -0
  15. package/lightgallery.es5.js +81 -6
  16. package/lightgallery.es5.js.map +1 -1
  17. package/lightgallery.min.js +2 -2
  18. package/lightgallery.umd.js +81 -6
  19. package/lightgallery.umd.js.map +1 -1
  20. package/lit/lightgallery.esm.js +7 -7
  21. package/lit/lightgallery.umd.js +3 -3
  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 +1 -1
  45. package/plugins/rotate/lg-rotate.min.js +1 -1
  46. package/plugins/rotate/lg-rotate.umd.js +1 -1
  47. package/plugins/share/lg-share.es5.js +1 -1
  48. package/plugins/share/lg-share.min.js +1 -1
  49. package/plugins/share/lg-share.umd.js +1 -1
  50. package/plugins/thumbnail/lg-thumbnail.es5.js +1 -1
  51. package/plugins/thumbnail/lg-thumbnail.min.js +1 -1
  52. package/plugins/thumbnail/lg-thumbnail.umd.js +1 -1
  53. package/plugins/video/lg-video.es5.js +1 -1
  54. package/plugins/video/lg-video.min.js +1 -1
  55. package/plugins/video/lg-video.umd.js +1 -1
  56. package/plugins/vimeoThumbnail/lg-vimeo-thumbnail.es5.js +1 -1
  57. package/plugins/vimeoThumbnail/lg-vimeo-thumbnail.min.js +1 -1
  58. package/plugins/vimeoThumbnail/lg-vimeo-thumbnail.umd.js +1 -1
  59. package/plugins/zoom/lg-zoom.es5.js +1 -1
  60. package/plugins/zoom/lg-zoom.min.js +1 -1
  61. package/plugins/zoom/lg-zoom.umd.js +1 -1
  62. package/react/Lightgallery.es5.js +81 -6
  63. package/react/Lightgallery.es5.js.map +1 -1
  64. package/react/Lightgallery.umd.js +81 -6
  65. package/react/Lightgallery.umd.js.map +1 -1
  66. package/scss/_lg-theme-default.scss +16 -0
  67. package/scss/lightgallery-core.scss +3 -0
  68. package/vue/LightGalleryVue.common.js +123 -32
  69. package/vue/LightGalleryVue.common.js.map +1 -1
  70. package/vue/LightGalleryVue.umd.js +123 -32
  71. package/vue/LightGalleryVue.umd.js.map +1 -1
  72. package/vue/LightGalleryVue.umd.min.js +2 -2
  73. package/vue/LightGalleryVue.umd.min.js.map +1 -1
@@ -32,7 +32,7 @@
32
32
  }
33
33
 
34
34
  /*!
35
- * lightgallery | 2.5.0-beta.2 | March 6th 2022
35
+ * lightgallery | 2.5.0-beta.5 | May 11th 2022
36
36
  * http://www.lightgalleryjs.com/
37
37
  * Copyright (c) 2020 Sachin Neravath;
38
38
  * @license GPLv3
@@ -129,6 +129,8 @@
129
129
  defaultCaptionHeight: 0,
130
130
  ariaLabelledby: '',
131
131
  ariaDescribedby: '',
132
+ resetScrollPosition: true,
133
+ hideScrollbar: false,
132
134
  closable: true,
133
135
  swipeToClose: true,
134
136
  closeOnTap: true,
@@ -137,6 +139,7 @@
137
139
  loop: true,
138
140
  escKey: true,
139
141
  keyPress: true,
142
+ trapFocus: true,
140
143
  controls: true,
141
144
  slideEndAnimation: true,
142
145
  hideControlOnEnd: false,
@@ -753,6 +756,14 @@
753
756
  }
754
757
  return "<div class=\"lg-video-cont " + videoClass + "\" style=\"" + videoContStyle + "\">\n <div class=\"lg-video-play-button\">\n <svg\n viewBox=\"0 0 20 20\"\n preserveAspectRatio=\"xMidYMid\"\n focusable=\"false\"\n aria-labelledby=\"" + playVideoString + "\"\n role=\"img\"\n class=\"lg-video-play-icon\"\n >\n <title>" + playVideoString + "</title>\n <polygon class=\"lg-video-play-icon-inner\" points=\"1,0 20,10 1,20\"></polygon>\n </svg>\n <svg class=\"lg-video-play-icon-bg\" viewBox=\"0 0 50 50\" focusable=\"false\">\n <circle cx=\"50%\" cy=\"50%\" r=\"20\"></circle></svg>\n <svg class=\"lg-video-play-icon-circle\" viewBox=\"0 0 50 50\" focusable=\"false\">\n <circle cx=\"50%\" cy=\"50%\" r=\"20\"></circle>\n </svg>\n </div>\n " + (dummyImg || '') + "\n <img class=\"lg-object lg-video-poster\" src=\"" + _poster + "\" />\n </div>";
755
758
  },
759
+ getFocusableElements: function (container) {
760
+ var elements = container.querySelectorAll('a[href]:not([disabled]), button:not([disabled]), textarea:not([disabled]), input[type="text"]:not([disabled]), input[type="radio"]:not([disabled]), input[type="checkbox"]:not([disabled]), select:not([disabled])');
761
+ var visibleElements = [].filter.call(elements, function (element) {
762
+ var style = window.getComputedStyle(element);
763
+ return style.display !== 'none' && style.visibility !== 'hidden';
764
+ });
765
+ return visibleElements;
766
+ },
756
767
  /**
757
768
  * @desc Create dynamic elements array from gallery items when dynamic option is false
758
769
  * It helps to avoid frequent DOM interaction
@@ -856,6 +867,7 @@
856
867
  this.currentItemsInDom = [];
857
868
  // Scroll top value before lightGallery is opened
858
869
  this.prevScrollTop = 0;
870
+ this.bodyPaddingRight = 0;
859
871
  this.isDummyImageRemoved = false;
860
872
  this.dragOrSwipeEnabled = false;
861
873
  this.mediaContainerPosition = {
@@ -1203,6 +1215,27 @@
1203
1215
  return this.settings.dynamicEl || [];
1204
1216
  }
1205
1217
  };
1218
+ LightGallery.prototype.shouldHideScrollbar = function () {
1219
+ return (this.settings.hideScrollbar &&
1220
+ document.body === this.settings.container);
1221
+ };
1222
+ LightGallery.prototype.hideScrollbar = function () {
1223
+ if (!this.shouldHideScrollbar()) {
1224
+ return;
1225
+ }
1226
+ this.bodyPaddingRight = parseFloat($LG('body').style().paddingRight);
1227
+ var bodyRect = document.documentElement.getBoundingClientRect();
1228
+ var scrollbarWidth = window.innerWidth - bodyRect.width;
1229
+ $LG(document.body).css('padding-right', scrollbarWidth + this.bodyPaddingRight + 'px');
1230
+ $LG(document.body).addClass('lg-overlay-open');
1231
+ };
1232
+ LightGallery.prototype.resetScrollBar = function () {
1233
+ if (!this.shouldHideScrollbar()) {
1234
+ return;
1235
+ }
1236
+ $LG(document.body).css('padding-right', this.bodyPaddingRight + 'px');
1237
+ $LG(document.body).removeClass('lg-overlay-open');
1238
+ };
1206
1239
  /**
1207
1240
  * Open lightGallery.
1208
1241
  * Open gallery with specific slide by passing index of the slide as parameter.
@@ -1238,8 +1271,8 @@
1238
1271
  if (this.lgOpened)
1239
1272
  return;
1240
1273
  this.lgOpened = true;
1241
- this.outer.get().focus();
1242
1274
  this.outer.removeClass('lg-hide-items');
1275
+ this.hideScrollbar();
1243
1276
  // Add display block, but still has opacity 0
1244
1277
  this.$container.addClass('lg-show');
1245
1278
  var itemsToBeInsertedToDom = this.getItemsToBeInsertedToDom(index, index);
@@ -1298,6 +1331,12 @@
1298
1331
  _this.$backdrop.addClass('in');
1299
1332
  _this.$container.addClass('lg-show-in');
1300
1333
  }, 10);
1334
+ setTimeout(function () {
1335
+ if (_this.settings.trapFocus &&
1336
+ document.body === _this.settings.container) {
1337
+ _this.trapFocus();
1338
+ }
1339
+ }, _this.settings.backdropDuration + 50);
1301
1340
  // lg-visible class resets gallery opacity to 1
1302
1341
  if (!_this.zoomFromOrigin || !transform) {
1303
1342
  setTimeout(function () {
@@ -1685,9 +1724,11 @@
1685
1724
  if (!$currentSlide.hasClass('lg-loaded')) {
1686
1725
  setTimeout(function () {
1687
1726
  if (_this.getSlideType(currentGalleryItem) === 'image') {
1727
+ var alt = currentGalleryItem.alt;
1728
+ var altAttr = alt ? 'alt="' + alt + '"' : '';
1688
1729
  $currentSlide
1689
1730
  .find('.lg-img-wrap')
1690
- .append(utils.getImgMarkup(index, src, '', srcset, sizes, currentGalleryItem.sources));
1731
+ .append(utils.getImgMarkup(index, src, altAttr, srcset, sizes, currentGalleryItem.sources));
1691
1732
  if (srcset || sources) {
1692
1733
  var $img = $currentSlide.find('.lg-object');
1693
1734
  _this.initPictureFill($img);
@@ -2473,6 +2514,36 @@
2473
2514
  $element.off("click.lgcustom-item-" + $element.attr('data-lg-id'));
2474
2515
  }
2475
2516
  };
2517
+ LightGallery.prototype.trapFocus = function () {
2518
+ var _this = this;
2519
+ this.$container.get().focus({
2520
+ preventScroll: true,
2521
+ });
2522
+ $LG(window).on("keydown.lg.global" + this.lgId, function (e) {
2523
+ if (!_this.lgOpened) {
2524
+ return;
2525
+ }
2526
+ var isTabPressed = e.key === 'Tab' || e.keyCode === 9;
2527
+ if (!isTabPressed) {
2528
+ return;
2529
+ }
2530
+ var focusableEls = utils.getFocusableElements(_this.$container.get());
2531
+ var firstFocusableEl = focusableEls[0];
2532
+ var lastFocusableEl = focusableEls[focusableEls.length - 1];
2533
+ if (e.shiftKey) {
2534
+ if (document.activeElement === firstFocusableEl) {
2535
+ lastFocusableEl.focus();
2536
+ e.preventDefault();
2537
+ }
2538
+ }
2539
+ else {
2540
+ if (document.activeElement === lastFocusableEl) {
2541
+ firstFocusableEl.focus();
2542
+ e.preventDefault();
2543
+ }
2544
+ }
2545
+ });
2546
+ };
2476
2547
  LightGallery.prototype.manageCloseGallery = function () {
2477
2548
  var _this = this;
2478
2549
  if (!this.settings.closable)
@@ -2523,7 +2594,9 @@
2523
2594
  return 0;
2524
2595
  }
2525
2596
  this.LGel.trigger(lGEvents.beforeClose);
2526
- $LG(window).scrollTop(this.prevScrollTop);
2597
+ if (this.settings.resetScrollPosition && !this.settings.hideScrollbar) {
2598
+ $LG(window).scrollTop(this.prevScrollTop);
2599
+ }
2527
2600
  var currentItem = this.items[this.index];
2528
2601
  var transform;
2529
2602
  if (this.zoomFromOrigin && currentItem) {
@@ -2568,6 +2641,8 @@
2568
2641
  _this.outer.removeClass('lg-zoom-from-image');
2569
2642
  }
2570
2643
  _this.$container.removeClass('lg-show');
2644
+ // Reset scrollbar
2645
+ _this.resetScrollBar();
2571
2646
  // Need to remove inline opacity as it is used in the stylesheet as well
2572
2647
  _this.$backdrop
2573
2648
  .removeAttr('style')
@@ -2580,8 +2655,8 @@
2580
2655
  instance: _this,
2581
2656
  });
2582
2657
  }
2583
- if (_this.outer.get()) {
2584
- _this.outer.get().blur();
2658
+ if (_this.$container.get()) {
2659
+ _this.$container.get().blur();
2585
2660
  }
2586
2661
  _this.lgOpened = false;
2587
2662
  }, removeTimeout + 100);