-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fullscreen.js
77 lines (67 loc) · 1.81 KB
/
Fullscreen.js
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
71
72
73
74
75
76
77
var apiMap = (function () {
const apis = {
ms: {
element: 'msFullscreenElement',
enabled: 'msFullscreenEnabled',
change: 'MSFullscreenChange',
error: 'MSFullscreenError',
exit: 'msExitFullscreen',
request: 'msRequestFullscreen'
},
webkit: {
element: 'webkitFullscreenElement',
enabled: 'webkitFullscreenEnabled',
change: 'webkitfullscreenchange',
error: 'webkitfullscreenerror',
exit: 'webkitExitFullscreen',
request: 'webkitRequestFullScreen'
},
moz: {
element: 'mozFullScreenElement',
enabled: 'mozFullScreenEnabled',
change: 'mozfullscreenchange',
error: 'mozfullscreenerror',
exit: 'mozCancelFullScreen',
request: 'mozRequestFullScreen',
},
'standard': {
element: 'fullscreenElement',
enabled: 'fullscreenEnabled',
change: 'fullscreenchange',
error: 'fullscreenerror',
exit: 'exitFullscreen',
request: 'requestFullscreen'
}
};
var types = ['standard', 'ms', 'webkit', 'moz'];
var len = types.length;
var result = null;
for (let i = 0; i < len; i++) {
if (document[apis[types[i]].enabled]) {
result = apis[types[i]];
break;
}
}
return result || {};
})();
export default class Fullscreen {
static get isEnabled () {
delete Fullscreen.isEnabled;
Fullscreen.isEnabled = document[apiMap.enabled];
}
static get isFullscreen () {
return document[apiMap.element];
}
static on (eventType, callback) {
document.addEventListener(apiMap[eventType], callback);
}
static off (eventType, callback) {
document.removeEventListener(apiMap[eventType], callback);
}
static exit () {
document[apiMap.exit].call(document);
}
static request (element) {
element[apiMap.request].call(element);
}
}