1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/ui/gallery/fullscreen.service.ts
Patrik J. Braun 0d3b8823e4 ui directory refactoring
adding thumbnail loader for faces
2019-03-03 10:30:12 +01:00

58 lines
1.5 KiB
TypeScript

import {Injectable} from '@angular/core';
import {Event} from '../../../../common/event/Event';
declare const document: {
fullscreenElement: any;
mozFullScreenElement: any;
webkitFullscreenElement: any;
exitFullscreen: () => void;
mozCancelFullScreen: () => void;
webkitExitFullscreen: () => void;
};
@Injectable()
export class FullScreenService {
OnFullScreenChange = new Event<boolean>();
public isFullScreenEnabled(): boolean {
return !!(document['fullscreenElement'] ||
document['mozFullScreenElement'] ||
document['webkitFullscreenElement']);
}
public showFullScreen(element: Element) {
if (this.isFullScreenEnabled()) {
return;
}
if (element.requestFullscreen) {
element.requestFullscreen().catch(console.error);
} else if ((<any>element).mozRequestFullScreen) {
(<any>element).mozRequestFullScreen();
} else if ((<any>element).webkitRequestFullscreen) {
(<any>element).webkitRequestFullscreen();
} else if ((<any>element).msRequestFullscreen) {
(<any>element).msRequestFullscreen();
}
this.OnFullScreenChange.trigger(true);
}
public exitFullScreen() {
if (!this.isFullScreenEnabled()) {
return;
}
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document['mozCancelFullScreen']) {
document['mozCancelFullScreen']();
} else if (document['webkitExitFullscreen']) {
document['webkitExitFullscreen']();
}
this.OnFullScreenChange.trigger(false);
}
}