source: imaps-frontend/node_modules/screenfull/dist/screenfull.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[d565449]1/*!
2* screenfull
3* v5.2.0 - 2021-11-03
4* (c) Sindre Sorhus; MIT License
5*/
6(function () {
7 'use strict';
8
9 var document = typeof window !== 'undefined' && typeof window.document !== 'undefined' ? window.document : {};
10 var isCommonjs = typeof module !== 'undefined' && module.exports;
11
12 var fn = (function () {
13 var val;
14
15 var fnMap = [
16 [
17 'requestFullscreen',
18 'exitFullscreen',
19 'fullscreenElement',
20 'fullscreenEnabled',
21 'fullscreenchange',
22 'fullscreenerror'
23 ],
24 // New WebKit
25 [
26 'webkitRequestFullscreen',
27 'webkitExitFullscreen',
28 'webkitFullscreenElement',
29 'webkitFullscreenEnabled',
30 'webkitfullscreenchange',
31 'webkitfullscreenerror'
32
33 ],
34 // Old WebKit
35 [
36 'webkitRequestFullScreen',
37 'webkitCancelFullScreen',
38 'webkitCurrentFullScreenElement',
39 'webkitCancelFullScreen',
40 'webkitfullscreenchange',
41 'webkitfullscreenerror'
42
43 ],
44 [
45 'mozRequestFullScreen',
46 'mozCancelFullScreen',
47 'mozFullScreenElement',
48 'mozFullScreenEnabled',
49 'mozfullscreenchange',
50 'mozfullscreenerror'
51 ],
52 [
53 'msRequestFullscreen',
54 'msExitFullscreen',
55 'msFullscreenElement',
56 'msFullscreenEnabled',
57 'MSFullscreenChange',
58 'MSFullscreenError'
59 ]
60 ];
61
62 var i = 0;
63 var l = fnMap.length;
64 var ret = {};
65
66 for (; i < l; i++) {
67 val = fnMap[i];
68 if (val && val[1] in document) {
69 for (i = 0; i < val.length; i++) {
70 ret[fnMap[0][i]] = val[i];
71 }
72 return ret;
73 }
74 }
75
76 return false;
77 })();
78
79 var eventNameMap = {
80 change: fn.fullscreenchange,
81 error: fn.fullscreenerror
82 };
83
84 var screenfull = {
85 request: function (element, options) {
86 return new Promise(function (resolve, reject) {
87 var onFullScreenEntered = function () {
88 this.off('change', onFullScreenEntered);
89 resolve();
90 }.bind(this);
91
92 this.on('change', onFullScreenEntered);
93
94 element = element || document.documentElement;
95
96 var returnPromise = element[fn.requestFullscreen](options);
97
98 if (returnPromise instanceof Promise) {
99 returnPromise.then(onFullScreenEntered).catch(reject);
100 }
101 }.bind(this));
102 },
103 exit: function () {
104 return new Promise(function (resolve, reject) {
105 if (!this.isFullscreen) {
106 resolve();
107 return;
108 }
109
110 var onFullScreenExit = function () {
111 this.off('change', onFullScreenExit);
112 resolve();
113 }.bind(this);
114
115 this.on('change', onFullScreenExit);
116
117 var returnPromise = document[fn.exitFullscreen]();
118
119 if (returnPromise instanceof Promise) {
120 returnPromise.then(onFullScreenExit).catch(reject);
121 }
122 }.bind(this));
123 },
124 toggle: function (element, options) {
125 return this.isFullscreen ? this.exit() : this.request(element, options);
126 },
127 onchange: function (callback) {
128 this.on('change', callback);
129 },
130 onerror: function (callback) {
131 this.on('error', callback);
132 },
133 on: function (event, callback) {
134 var eventName = eventNameMap[event];
135 if (eventName) {
136 document.addEventListener(eventName, callback, false);
137 }
138 },
139 off: function (event, callback) {
140 var eventName = eventNameMap[event];
141 if (eventName) {
142 document.removeEventListener(eventName, callback, false);
143 }
144 },
145 raw: fn
146 };
147
148 if (!fn) {
149 if (isCommonjs) {
150 module.exports = {isEnabled: false};
151 } else {
152 window.screenfull = {isEnabled: false};
153 }
154
155 return;
156 }
157
158 Object.defineProperties(screenfull, {
159 isFullscreen: {
160 get: function () {
161 return Boolean(document[fn.fullscreenElement]);
162 }
163 },
164 element: {
165 enumerable: true,
166 get: function () {
167 return document[fn.fullscreenElement];
168 }
169 },
170 isEnabled: {
171 enumerable: true,
172 get: function () {
173 // Coerce to boolean in case of old WebKit
174 return Boolean(document[fn.fullscreenEnabled]);
175 }
176 }
177 });
178
179 if (isCommonjs) {
180 module.exports = screenfull;
181 } else {
182 window.screenfull = screenfull;
183 }
184})();
Note: See TracBrowser for help on using the repository browser.