1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/gallery/fullscreen.service.ts

47 lines
1.3 KiB
TypeScript
Raw Normal View History

2016-07-06 18:53:49 +08:00
import {Injectable} from "@angular/core";
import {Event} from "../../../common/event/Event";
2016-07-06 18:53:49 +08:00
@Injectable()
export class FullScreenService {
OnFullScreenChange = new Event<boolean>();
2016-12-27 06:36:38 +08:00
public isFullScreenEnabled(): boolean {
2016-07-06 18:53:49 +08:00
return !!(document.fullscreenElement || document['mozFullScreenElement'] || document.webkitFullscreenElement);
}
2016-12-27 06:36:38 +08:00
public showFullScreen(element: any) {
2016-07-06 18:53:49 +08:00
if (this.isFullScreenEnabled()) {
return;
}
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
}
this.OnFullScreenChange.trigger(true);
2016-07-06 18:53:49 +08:00
}
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);
2016-07-06 18:53:49 +08:00
}
}