snappymail/dev/Common/Fullscreen.js

23 lines
809 B
JavaScript
Raw Normal View History

2023-02-20 22:47:46 +08:00
import { doc, appEl, $htmlCL } from 'Common/Globals';
2022-03-22 23:24:58 +08:00
// Fullscreen must be on app, else other popups fail
export const
2023-02-20 22:47:46 +08:00
appFullscreen = () => (doc.fullscreenElement || doc.webkitFullscreenElement) === appEl,
2022-03-22 23:24:58 +08:00
exitFullscreen = () => appFullscreen() && (doc.exitFullscreen || doc.webkitExitFullscreen).call(doc),
isFullscreen = ko.observable(false),
2023-02-20 22:47:46 +08:00
toggleFullscreen = () => isFullscreen() ? exitFullscreen() : appEl.requestFullscreen();
2022-03-22 23:24:58 +08:00
2023-02-20 22:47:46 +08:00
if (appEl) {
2022-03-22 23:24:58 +08:00
let event = 'fullscreenchange';
2023-02-20 22:47:46 +08:00
if (!appEl.requestFullscreen && appEl.webkitRequestFullscreen) {
appEl.requestFullscreen = appEl.webkitRequestFullscreen;
2022-03-22 23:24:58 +08:00
event = 'webkit'+event;
}
2023-02-20 22:47:46 +08:00
if (appEl.requestFullscreen) {
2022-03-22 23:24:58 +08:00
doc.addEventListener(event, () => {
isFullscreen(appFullscreen());
$htmlCL.toggle('rl-fullscreen', appFullscreen());
});
}
}