This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fullscreen.js
103 lines (91 loc) · 2.88 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var fullscreenEnabled = !document.location.hash.match(/^#nofullscreen/);
if (fullscreenEnabled) {
setTimeout(function() {
const button = document.createElement("button");
document.body.appendChild(button);
button.setAttribute("id", "fullscreen");
button.setAttribute("style", "cursor:pointer;");
button.innerHTML = "Fullscreen";
button.addEventListener("click", goFullscreen);
}, 200);
}
function goFullscreen() {
this._exitFired = false;
if (fullScreenApi.supportsFullScreen) {
if (fullScreenApi.isFullScreen(document.body)) {
fullScreenApi.cancelFullScreen(document.body);
} else {
fullScreenApi.requestFullScreen(document.body);
}
setTimeout(redraw, 200);
}
}
/*
Native FullScreen JavaScript API
-------------
Assumes Mozilla naming conventions instead of W3C for now
source : http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/
*/
(function() {
var fullScreenApi = {
supportsFullScreen: false,
isFullScreen: function() {
return false;
},
requestFullScreen: function() {},
cancelFullScreen: function() {},
fullScreenEventName: "",
prefix: ""
},
browserPrefixes = "webkit moz o ms khtml".split(" ");
// check for native support
if (typeof document.cancelFullScreen != "undefined") {
fullScreenApi.supportsFullScreen = true;
} else {
// check for fullscreen support by vendor prefix
for (var i = 0, il = browserPrefixes.length; i < il; i++) {
fullScreenApi.prefix = browserPrefixes[i];
if (
typeof document[fullScreenApi.prefix + "CancelFullScreen"] !=
"undefined"
) {
fullScreenApi.supportsFullScreen = true;
break;
}
}
}
// update methods to do something useful
if (fullScreenApi.supportsFullScreen) {
fullScreenApi.fullScreenEventName =
fullScreenApi.prefix + "fullscreenchange";
fullScreenApi.isFullScreen = function() {
switch (this.prefix) {
case "":
return document.fullScreen;
case "webkit":
return document.webkitIsFullScreen;
default:
return document[this.prefix + "FullScreen"];
}
};
fullScreenApi.requestFullScreen = function(el) {
return this.prefix === ""
? el.requestFullScreen()
: el[this.prefix + "RequestFullScreen"]();
};
fullScreenApi.cancelFullScreen = function(el) {
return this.prefix === ""
? document.cancelFullScreen()
: document[this.prefix + "CancelFullScreen"]();
};
document.addEventListener(fullScreenApi.fullScreenEventName, function() {
if (fullScreenApi.isFullScreen(document.body)) {
document.getElementById("fullscreen").innerHTML = "×";
} else {
document.getElementById("fullscreen").innerHTML = "Fullscreen";
}
});
}
// export api
window.fullScreenApi = fullScreenApi;
})();