lg-fullscreen.umd.js 6.0 KB

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