Skip to content

Commit

Permalink
Merge pull request FreezingMoon#2475 from andretchen0/fullscreen
Browse files Browse the repository at this point in the history
refactor: fullscreen.js -> fullscreen.ts FreezingMoon#1969
  • Loading branch information
DreadKnight authored Aug 8, 2023
2 parents 1db90c1 + 2870497 commit d7801cb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ $j(() => {
disableScrollAndArrowKeys(document.getElementById('loader')); // Disable scroll and arrow keys for loader element

// Add listener for Fullscreen API
const fullscreen = new Fullscreen($j('#fullscreen'));
const fullscreen = new Fullscreen(document.getElementById('fullscreen'));
$j('#fullscreen').on('click', () => fullscreen.toggle());

const startScreenHotkeys = {
Expand Down
35 changes: 0 additions & 35 deletions src/ui/fullscreen.js

This file was deleted.

40 changes: 40 additions & 0 deletions src/ui/fullscreen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export class Fullscreen {
private button: HTMLElement;

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

toggle() {
if (isAppInNativeFullscreenMode()) {
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.button.classList.add('fullscreenMode');
this.button
.querySelectorAll('.fullscreen__title')
.forEach((el) => (el.textContent = 'Contract'));
document.getElementById('AncientBeast').requestFullscreen();
}
}
}

/**
* @returns {boolean} true if app is currently in [fullscreen mode using the native API](https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API), else false.
*/
function isAppInNativeFullscreenMode(): boolean {
// NOTE: These properties were vendor-prefixed until very recently.
// Keeping vendor prefixes, though they make TS report an error.
return (
// @ts-expect-error 2551
document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement
);
}
5 changes: 4 additions & 1 deletion src/ui/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export class UI {
*/
constructor(game) {
this.game = game;
this.fullscreen = new Fullscreen($j('#fullscreen.button'), game.fullscreenMode);
this.fullscreen = new Fullscreen(
document.querySelector('#fullscreen.button'),
game.fullscreenMode,
);
this.$display = $j('#ui');
this.$dash = $j('#dash');
this.$grid = $j(this.#makeCreatureGrid(document.getElementById('creaturerasterwrapper')));
Expand Down

0 comments on commit d7801cb

Please sign in to comment.