Portable implementation of fullscreen JS methods
This commit is contained in:
parent
e44dfbc169
commit
7e0a91d839
1 changed files with 28 additions and 3 deletions
|
@ -1,9 +1,34 @@
|
||||||
function enterFullScreen() {
|
function enterFullScreen() {
|
||||||
return document.getElementsByTagName('body')[0].requestFullscreen();
|
const body = document.getElementsByTagName('body')[0];
|
||||||
|
if (body.requestFullscreen()) {
|
||||||
|
return body.requestFullscreen();
|
||||||
|
} else if (body.msRequestFullscreen()) {
|
||||||
|
return body.msRequestFullscreen();
|
||||||
|
} else if (body.mozRequestFullScreen()) {
|
||||||
|
return body.mozRequestFullScreen();
|
||||||
|
} else if (body.webkitRequestFullscreen()) {
|
||||||
|
return body.webkitRequestFullscreen();
|
||||||
|
} else {
|
||||||
|
console.warn('This browser does not support fullscreen mode');
|
||||||
|
}
|
||||||
|
|
||||||
|
// The day will come when browser developers will have to pay web developers
|
||||||
|
// back for all the time wasted to write such crappy portable code. A two-lines
|
||||||
|
// function becomes a 10-lines function just because they can't talk to
|
||||||
|
// one another before implementing sh*t.
|
||||||
}
|
}
|
||||||
|
|
||||||
function exitFullScreen() {
|
function exitFullScreen() {
|
||||||
const self = this;
|
if (document.exitFullscreen()) {
|
||||||
return document.exitFullscreen();
|
return document.exitFullscreen();
|
||||||
|
} else if (document.msExitFullscreen()) {
|
||||||
|
return document.msExitFullscreen();
|
||||||
|
} else if (document.mozCancelFullScreen()) {
|
||||||
|
return document.mozCancelFullScreen();
|
||||||
|
} else if (document.webkitExitFullscreen()) {
|
||||||
|
return document.webkitExitFullscreen();
|
||||||
|
} else {
|
||||||
|
console.warn('This browser does not support fullscreen mode');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue