UNPKG

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