UNPKG

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