-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Expand file tree
/
Copy pathfullscreen-api.js
More file actions
70 lines (63 loc) · 1.61 KB
/
fullscreen-api.js
File metadata and controls
70 lines (63 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* @file fullscreen-api.js
* @module fullscreen-api
*/
import document from 'global/document';
/**
* Store the browser-specific methods for the fullscreen API.
*
* @type {Object}
* @property {string} requestFullscreen
* @property {string} exitFullscreen
* @property {string} fullscreenElement
* @property {string} fullscreenEnabled
* @property {string} fullscreenchange
* @property {string} fullscreenerror
* @property {string} fullscreen
* @property {boolean} prefixed
* @see [Specification]{@link https://fullscreen.spec.whatwg.org}
* @see [Map Approach From Screenfull.js]{@link https://github.com/sindresorhus/screenfull.js}
*/
const FullscreenApi = {
prefixed: true
};
// browser API methods
const apiMap = [
[
'requestFullscreen',
'exitFullscreen',
'fullscreenElement',
'fullscreenEnabled',
'fullscreenchange',
'fullscreenerror',
'fullscreen'
],
// WebKit
[
'webkitRequestFullscreen',
'webkitExitFullscreen',
'webkitFullscreenElement',
'webkitFullscreenEnabled',
'webkitfullscreenchange',
'webkitfullscreenerror',
'-webkit-full-screen'
]
];
const specApi = apiMap[0];
let browserApi;
// determine the supported set of functions
for (let i = 0; i < apiMap.length; i++) {
// check for exitFullscreen function
if (apiMap[i][1] in document) {
browserApi = apiMap[i];
break;
}
}
// map the browser API names to the spec API names
if (browserApi) {
for (let i = 0; i < browserApi.length; i++) {
FullscreenApi[specApi[i]] = browserApi[i];
}
FullscreenApi.prefixed = browserApi[0] !== specApi[0];
}
export default FullscreenApi;