forked from FreezingMoon/AncientBeast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request FreezingMoon#2475 from andretchen0/fullscreen
refactor: fullscreen.js -> fullscreen.ts FreezingMoon#1969
- Loading branch information
Showing
4 changed files
with
45 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters