123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- namespace polyfill {
- interface API {
- request: string;
- changeEvent: string;
- }
- const VARIANTS = [
- {
- request: 'requestFullscreen',
- changeEvent: 'fullscreenchange'
- },
- {
- request: 'mozRequestFullScreen',
- changeEvent: 'mozfullscreenchange',
- },
- {
- request: 'webkitRequestFullscreen',
- changeEvent: 'webkitfullscreenchange',
- },
- {
- request: 'msRequestFullscreen',
- changeEvent: 'MSFullscreenChange',
- },
- ];
- class FullscreenPolyfill {
- private api: API | undefined;
- constructor() {
- this.api = VARIANTS.find((variant) =>
- // @ts-ignore
- document.firstChild[variant.request] !== undefined
- );
- }
- request(element: HTMLElement) {
- if (this.api !== undefined) {
- // @ts-ignore
- element[this.api.request]();
- }
- }
- addEventListener(listener: () => void) {
- if (this.api !== undefined) {
- document.addEventListener(this.api.changeEvent, listener);
- }
- }
- }
- export const fullscreen = new FullscreenPolyfill();
- }
|