-
Notifications
You must be signed in to change notification settings - Fork 9
/
fullscreen.js
80 lines (63 loc) · 2.54 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
78
79
80
(function fullscreenBtn() {
'use strict';
// requires menuButton.js
//
// fullscreen API is a pain at the moment
// https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API
/* globals l10nStrings, scUtils */
// each vendor has it's spelling, so we can't just iterate prefixes
const isFullScreenEnabled = document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled;
if (!isFullScreenEnabled) {
// no fullscreen, don't create the button
return;
}
function isFullScreen(doc) {
return !!(doc.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement);
}
function getRequestFullScreenFn(el) {
return (el.requestFullscreen || el.webkitRequestFullscreen || el.mozRequestFullScreen || el.msRequestFullscreen);
}
function getExitFullScreenFn(doc) {
return doc.exitFullscreen ||doc.webkitExitFullscreen || doc.mozCancelFullScreen || doc.msExitFullscreen;
}
const requestFullScreenFn = getRequestFullScreenFn(document.documentElement);
// without bound context, there's `Illegal invocation` exception
const requestFullScreen = requestFullScreenFn.bind(document.documentElement);
const exitFullScreen = getExitFullScreenFn(document).bind(document);
// stored vendor-prefixes, mapped to requestFullScreen function name
const vendorSelectorsMap = {
requestFullscreen: 'fullscreen',
webkitRequestFullscreen: '-webkit-full-screen',
mozRequestFullScreen: '-moz-full-screen',
msRequestFullscreen: '-ms-full-screen',
};
const selector = vendorSelectorsMap[requestFullScreenFn.name];
function handler() {
if (isFullScreen(document)) {
exitFullScreen();
} else {
requestFullScreen();
}
}
const {style} = scUtils.createHandlerButton(l10nStrings.uiFullScreen || 'Full screen', '', 'fullscreen', handler);
const styleId = style.attr('id').replace(/-style$/, '');
const styles = `
#menu-core #${styleId} a::before {
content: '\\e830\\00a0';
}
html:${selector} {
height: 100%;
}
:${selector} body {
height: calc(100% - 2.5em);
padding-top: 2.5em;
}
:${selector} #story {
margin-top: 0;
}
:${selector} #menu-core #${styleId} a::before {
content: '\\e831\\00a0';
}
`;
style.text(styles);
}());