pleroma/app/soapbox/features/ui/util/fullscreen.ts

36 lines
982 B
TypeScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
// APIs for normalizing fullscreen operations. Note that Edge uses
// the WebKit-prefixed APIs currently (as of Edge 16).
2022-09-30 17:52:41 -07:00
export const isFullscreen = (): boolean => {
return Boolean(
document.fullscreenElement ||
// @ts-ignore
document.webkitFullscreenElement ||
// @ts-ignore
document.mozFullScreenElement,
);
};
2020-03-27 13:59:38 -07:00
2022-09-30 17:52:41 -07:00
export const exitFullscreen = (): void => {
2020-03-27 13:59:38 -07:00
if (document.exitFullscreen) {
document.exitFullscreen();
2022-09-30 17:52:41 -07:00
} else if ('webkitExitFullscreen' in document) {
// @ts-ignore
2020-03-27 13:59:38 -07:00
document.webkitExitFullscreen();
2022-09-30 17:52:41 -07:00
} else if ('mozCancelFullScreen' in document) {
// @ts-ignore
2020-03-27 13:59:38 -07:00
document.mozCancelFullScreen();
}
};
2022-09-30 17:52:41 -07:00
export const requestFullscreen = (el: Element): void => {
2020-03-27 13:59:38 -07:00
if (el.requestFullscreen) {
el.requestFullscreen();
2022-09-30 17:52:41 -07:00
} else if ('webkitRequestFullscreen' in el) {
// @ts-ignore
2020-03-27 13:59:38 -07:00
el.webkitRequestFullscreen();
2022-09-30 17:52:41 -07:00
} else if ('mozRequestFullScreen' in el) {
// @ts-ignore
2020-03-27 13:59:38 -07:00
el.mozRequestFullScreen();
}
2023-06-13 14:25:39 -07:00
};