Skip to content

Commit

Permalink
v4
Browse files Browse the repository at this point in the history
  • Loading branch information
aliraza556 committed Aug 11, 2024
1 parent dd48ca3 commit 30139a1
Showing 1 changed file with 13 additions and 33 deletions.
46 changes: 13 additions & 33 deletions src/ui/fullscreen.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,35 @@
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.exitFullscreen();
this.button.classList.remove('fullscreenMode');
this.button
.querySelectorAll('.fullscreen__title')
.forEach((el) => (el.textContent = 'FullScreen'));
document.exitFullscreen();
} else if (!isAppInNativeFullscreenMode() && window.innerHeight === screen.height) {
alert('Use F11 to exit fullscreen');
} else {
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;
this.button.classList.add('fullscreenMode');
this.button
.querySelectorAll('.fullscreen__title')
.forEach((el) => (el.textContent = 'Contract'));
document.getElementById('AncientBeast').requestFullscreen();
}
}

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

0 comments on commit 30139a1

Please sign in to comment.