web: Use fullscreen helper methods

In order to be compatible with browsers that don't support the
standard Fullscreen API.

Co-authored-by: Sean-Thomas <sean-thomas@pocketonion.net>
This commit is contained in:
relrelb 2020-11-17 21:43:57 +02:00 committed by Mike Welsh
parent d71c886e48
commit 1674132b36
1 changed files with 44 additions and 8 deletions

View File

@ -241,6 +241,46 @@ exports.RufflePlayer = class RufflePlayer extends HTMLElement {
}
}
fullscreenEnabled() {
return (
document.fullscreenEnabled ||
document.mozFullScreenEnabled ||
document.webkitFullscreenEnabled
);
}
isFullscreen() {
return (
(document.fullscreenElement ||
document.mozFullScreenElement ||
document.webkitFullscreenElement) === this
);
}
enterFullscreen() {
if (this.requestFullscreen) {
this.requestFullscreen();
} else if (this.mozRequestFullScreen) {
this.mozRequestFullScreen();
} else if (this.webkitRequestFullScreen) {
this.webkitRequestFullScreen();
} else if (this.msRequestFullscreen) {
this.msRequestFullscreen();
}
}
exitFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
open_right_click_menu(e) {
e.preventDefault();
@ -249,20 +289,16 @@ exports.RufflePlayer = class RufflePlayer extends HTMLElement {
}
const items = [];
if (document.fullscreenEnabled) {
if (document.fullscreenElement) {
if (this.fullscreenEnabled()) {
if (this.isFullscreen()) {
items.push({
text: "Exit fullscreen",
onClick: () => {
document.exitFullscreen();
},
onClick: this.exitFullscreen.bind(this),
});
} else {
items.push({
text: "Enter fullscreen",
onClick: () => {
this.requestFullscreen();
},
onClick: this.enterFullscreen.bind(this),
});
}
}