bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/fullscreen-button/service.js

57 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-07-27 00:48:51 +08:00
function getFullscreenElement() {
if (document.fullscreenElement) return document.fullscreenElement;
if (document.webkitFullscreenElement) return document.webkitFullscreenElement;
if (document.mozFullScreenElement) return document.mozFullScreenElement;
if (document.msFullscreenElement) return document.msFullscreenElement;
return null;
}
const isFullScreen = (element) => {
if (getFullscreenElement() && getFullscreenElement() === element) {
return true;
}
return false;
};
function cancelFullScreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
function fullscreenRequest(element) {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
2021-02-13 09:20:45 +08:00
} else {
return;
2019-07-27 00:48:51 +08:00
}
2021-02-13 09:20:45 +08:00
document.activeElement.blur();
element.focus();
2019-07-27 00:48:51 +08:00
}
const toggleFullScreen = (ref = null) => {
const element = ref || document.documentElement;
if (isFullScreen(element)) {
cancelFullScreen();
} else {
fullscreenRequest(element);
}
};
export default {
toggleFullScreen,
isFullScreen,
2019-07-27 03:24:53 +08:00
getFullscreenElement,
2019-07-27 00:48:51 +08:00
};