This commit is contained in:
parent
6bc125be1c
commit
ed5a4379db
76 changed files with 1418 additions and 988 deletions
|
|
@ -1,22 +1,24 @@
|
|||
export class FullScreenHandler {
|
||||
public constructor(
|
||||
private readonly minimizeButton: HTMLElement,
|
||||
private readonly maximizeButton: HTMLElement,
|
||||
private readonly toggleButton: HTMLElement,
|
||||
target: HTMLElement
|
||||
) {
|
||||
if (!document.fullscreenEnabled || typeof target.requestFullscreen !== 'function') {
|
||||
minimizeButton.hidden = true;
|
||||
maximizeButton.hidden = true;
|
||||
toggleButton.hidden = true;
|
||||
return;
|
||||
}
|
||||
|
||||
this.updateButtons();
|
||||
|
||||
addEventListener('fullscreenchange', this.updateButtons.bind(this));
|
||||
maximizeButton.addEventListener('click', () => {
|
||||
toggleButton.addEventListener('click', () => {
|
||||
if (FullScreenHandler.isInFullScreenMode()) {
|
||||
void document.exitFullscreen();
|
||||
return;
|
||||
}
|
||||
|
||||
void target.requestFullscreen().catch(() => undefined);
|
||||
});
|
||||
minimizeButton.addEventListener('click', () => document.exitFullscreen());
|
||||
}
|
||||
|
||||
public static isInFullScreenMode(): boolean {
|
||||
|
|
@ -25,7 +27,9 @@ export class FullScreenHandler {
|
|||
|
||||
private updateButtons(): void {
|
||||
const isInFullScreenMode = FullScreenHandler.isInFullScreenMode();
|
||||
this.minimizeButton.hidden = !isInFullScreenMode;
|
||||
this.maximizeButton.hidden = isInFullScreenMode;
|
||||
const label = isInFullScreenMode ? 'Exit fullscreen' : 'Enter fullscreen';
|
||||
this.toggleButton.classList.toggle('active', isInFullScreenMode);
|
||||
this.toggleButton.setAttribute('aria-label', label);
|
||||
this.toggleButton.title = label;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue