2018-03-30 21:30:30 +02:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {Event} from '../../../common/event/Event';
|
2016-07-06 12:53:49 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class FullScreenService {
|
|
|
|
|
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
OnFullScreenChange = new Event<boolean>();
|
2017-03-25 22:59:30 +02:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
public isFullScreenEnabled(): boolean {
|
|
|
|
return !!(document.fullscreenElement || document['mozFullScreenElement'] || document.webkitFullscreenElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
public showFullScreen(element: any) {
|
|
|
|
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();
|
2016-07-06 12:53:49 +02:00
|
|
|
}
|
2017-06-10 22:32:56 +02:00
|
|
|
this.OnFullScreenChange.trigger(true);
|
|
|
|
}
|
2016-07-06 12:53:49 +02:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
public exitFullScreen() {
|
|
|
|
if (!this.isFullScreenEnabled()) {
|
|
|
|
return;
|
2016-07-06 12:53:49 +02:00
|
|
|
}
|
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
if (document.exitFullscreen) {
|
|
|
|
document.exitFullscreen();
|
|
|
|
} else if (document['mozCancelFullScreen']) {
|
|
|
|
document['mozCancelFullScreen']();
|
|
|
|
} else if (document.webkitExitFullscreen) {
|
|
|
|
document.webkitExitFullscreen();
|
2016-07-06 12:53:49 +02:00
|
|
|
}
|
2017-06-10 22:32:56 +02:00
|
|
|
this.OnFullScreenChange.trigger(false);
|
|
|
|
}
|
2016-07-06 12:53:49 +02:00
|
|
|
|
|
|
|
}
|