lg-fullscreen.es5.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*!
  2. * lightgallery | 2.4.0-beta.0 | December 12th 2021
  3. * http://www.lightgalleryjs.com/
  4. * Copyright (c) 2020 Sachin Neravath;
  5. * @license GPLv3
  6. */
  7. /*! *****************************************************************************
  8. Copyright (c) Microsoft Corporation.
  9. Permission to use, copy, modify, and/or distribute this software for any
  10. purpose with or without fee is hereby granted.
  11. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  12. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  13. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  14. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  15. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  16. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. PERFORMANCE OF THIS SOFTWARE.
  18. ***************************************************************************** */
  19. var __assign = function() {
  20. __assign = Object.assign || function __assign(t) {
  21. for (var s, i = 1, n = arguments.length; i < n; i++) {
  22. s = arguments[i];
  23. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  24. }
  25. return t;
  26. };
  27. return __assign.apply(this, arguments);
  28. };
  29. var fullscreenSettings = {
  30. fullScreen: true,
  31. fullscreenPluginStrings: { toggleFullscreen: 'Toggle Fullscreen' },
  32. };
  33. var FullScreen = /** @class */ (function () {
  34. function FullScreen(instance, $LG) {
  35. // get lightGallery core plugin instance
  36. this.core = instance;
  37. this.$LG = $LG;
  38. // extend module default settings with lightGallery core settings
  39. this.settings = __assign(__assign({}, fullscreenSettings), this.core.settings);
  40. return this;
  41. }
  42. FullScreen.prototype.init = function () {
  43. var fullScreen = '';
  44. if (this.settings.fullScreen) {
  45. // check for fullscreen browser support
  46. if (!document.fullscreenEnabled &&
  47. !document.webkitFullscreenEnabled &&
  48. !document.mozFullScreenEnabled &&
  49. !document.msFullscreenEnabled) {
  50. return;
  51. }
  52. else {
  53. fullScreen = "<button type=\"button\" aria-label=\"" + this.settings.fullscreenPluginStrings['toggleFullscreen'] + "\" class=\"lg-fullscreen lg-icon\"></button>";
  54. this.core.$toolbar.append(fullScreen);
  55. this.fullScreen();
  56. }
  57. }
  58. };
  59. FullScreen.prototype.isFullScreen = function () {
  60. return (document.fullscreenElement ||
  61. document.mozFullScreenElement ||
  62. document.webkitFullscreenElement ||
  63. document.msFullscreenElement);
  64. };
  65. FullScreen.prototype.requestFullscreen = function () {
  66. var el = document.documentElement;
  67. if (el.requestFullscreen) {
  68. el.requestFullscreen();
  69. }
  70. else if (el.msRequestFullscreen) {
  71. el.msRequestFullscreen();
  72. }
  73. else if (el.mozRequestFullScreen) {
  74. el.mozRequestFullScreen();
  75. }
  76. else if (el.webkitRequestFullscreen) {
  77. el.webkitRequestFullscreen();
  78. }
  79. };
  80. FullScreen.prototype.exitFullscreen = function () {
  81. if (document.exitFullscreen) {
  82. document.exitFullscreen();
  83. }
  84. else if (document.msExitFullscreen) {
  85. document.msExitFullscreen();
  86. }
  87. else if (document.mozCancelFullScreen) {
  88. document.mozCancelFullScreen();
  89. }
  90. else if (document.webkitExitFullscreen) {
  91. document.webkitExitFullscreen();
  92. }
  93. };
  94. // https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode
  95. FullScreen.prototype.fullScreen = function () {
  96. var _this = this;
  97. this.$LG(document).on("fullscreenchange.lg.global" + this.core.lgId + " \n webkitfullscreenchange.lg.global" + this.core.lgId + " \n mozfullscreenchange.lg.global" + this.core.lgId + " \n MSFullscreenChange.lg.global" + this.core.lgId, function () {
  98. if (!_this.core.lgOpened)
  99. return;
  100. _this.core.outer.toggleClass('lg-fullscreen-on');
  101. });
  102. this.core.outer
  103. .find('.lg-fullscreen')
  104. .first()
  105. .on('click.lg', function () {
  106. if (_this.isFullScreen()) {
  107. _this.exitFullscreen();
  108. }
  109. else {
  110. _this.requestFullscreen();
  111. }
  112. });
  113. };
  114. FullScreen.prototype.closeGallery = function () {
  115. // exit from fullscreen if activated
  116. if (this.isFullScreen()) {
  117. this.exitFullscreen();
  118. }
  119. };
  120. FullScreen.prototype.destroy = function () {
  121. this.$LG(document).off("fullscreenchange.lg.global" + this.core.lgId + " \n webkitfullscreenchange.lg.global" + this.core.lgId + " \n mozfullscreenchange.lg.global" + this.core.lgId + " \n MSFullscreenChange.lg.global" + this.core.lgId);
  122. };
  123. return FullScreen;
  124. }());
  125. export default FullScreen;
  126. //# sourceMappingURL=lg-fullscreen.es5.js.map