Skip to content

Commit

Permalink
v2
Browse files Browse the repository at this point in the history
  • Loading branch information
aliraza556 committed Aug 11, 2024
1 parent b8f80e7 commit dd48ca3
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions src/ui/fullscreen.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,55 @@
export class Fullscreen {
private button: HTMLElement;
private isFullscreen: boolean;

constructor(button: HTMLElement, isFullscreen = false) {
this.button = button;
this.isFullscreen = isFullscreen;
if (isFullscreen) {
button.classList.add('fullscreenMode');
}

document.addEventListener('fullscreenchange', this.onFullscreenChange.bind(this));
document.addEventListener('keydown', this.onKeyDown.bind(this));
}

toggle() {
if (isAppInNativeFullscreenMode()) {
this.button.classList.remove('fullscreenMode');
this.button
.querySelectorAll('.fullscreen__title')
.forEach((el) => (el.textContent = 'FullScreen'));
document.exitFullscreen();
this.exitFullscreen();
} else if (!isAppInNativeFullscreenMode() && window.innerHeight === screen.height) {
alert('Use F11 to exit fullscreen');
} else {
this.button.classList.add('fullscreenMode');
this.button
.querySelectorAll('.fullscreen__title')
.forEach((el) => (el.textContent = 'Contract'));
document.getElementById('AncientBeast').requestFullscreen();
this.enterFullscreen();
}
}

enterFullscreen() {
this.button.classList.add('fullscreenMode');
this.button
.querySelectorAll('.fullscreen__title')
.forEach((el) => (el.textContent = 'Contract'));
document.getElementById('AncientBeast').requestFullscreen();
this.isFullscreen = true;
}

exitFullscreen() {
this.button.classList.remove('fullscreenMode');
this.button
.querySelectorAll('.fullscreen__title')
.forEach((el) => (el.textContent = 'FullScreen'));
document.exitFullscreen();
this.isFullscreen = false;
}

onFullscreenChange() {
if (!document.fullscreenElement) {
this.isFullscreen = false;
}
}

private onFullscreenChange() {
if (!isAppInNativeFullscreenMode() && window.innerHeight !== screen.height) {
this.button.classList.add('fullscreenMode');
document.getElementById('AncientBeast').requestFullscreen();
onKeyDown(event: KeyboardEvent) {
if (this.isFullscreen && event.key === 'Escape') {
event.preventDefault();
}
}
}
Expand Down

0 comments on commit dd48ca3

Please sign in to comment.