2018-03-31 03:30:30 +08:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {Event} from '../../../common/event/Event';
|
2016-07-06 18:53:49 +08:00
|
|
|
|
2018-11-29 06:49:33 +08:00
|
|
|
declare const document: {
|
|
|
|
fullscreenElement: any;
|
|
|
|
mozFullScreenElement: any;
|
|
|
|
webkitFullscreenElement: any;
|
|
|
|
exitFullscreen: () => void;
|
|
|
|
mozCancelFullScreen: () => void;
|
|
|
|
webkitExitFullscreen: () => void;
|
|
|
|
};
|
|
|
|
|
2016-07-06 18:53:49 +08:00
|
|
|
@Injectable()
|
|
|
|
export class FullScreenService {
|
|
|
|
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
OnFullScreenChange = new Event<boolean>();
|
2017-03-26 04:59:30 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
public isFullScreenEnabled(): boolean {
|
2018-10-22 06:24:17 +08:00
|
|
|
return !!(document['fullscreenElement'] ||
|
|
|
|
document['mozFullScreenElement'] ||
|
|
|
|
document['webkitFullscreenElement']);
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
|
|
|
|
2018-12-13 04:03:06 +08:00
|
|
|
public showFullScreen(element: Element) {
|
2017-06-11 04:32:56 +08:00
|
|
|
if (this.isFullScreenEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (element.requestFullscreen) {
|
2018-12-13 04:03:06 +08:00
|
|
|
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();
|
2016-07-06 18:53:49 +08:00
|
|
|
}
|
2017-06-11 04:32:56 +08:00
|
|
|
this.OnFullScreenChange.trigger(true);
|
|
|
|
}
|
2016-07-06 18:53:49 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
public exitFullScreen() {
|
|
|
|
if (!this.isFullScreenEnabled()) {
|
|
|
|
return;
|
2016-07-06 18:53:49 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
if (document.exitFullscreen) {
|
|
|
|
document.exitFullscreen();
|
|
|
|
} else if (document['mozCancelFullScreen']) {
|
|
|
|
document['mozCancelFullScreen']();
|
2018-10-22 06:24:17 +08:00
|
|
|
} else if (document['webkitExitFullscreen']) {
|
|
|
|
document['webkitExitFullscreen']();
|
2016-07-06 18:53:49 +08:00
|
|
|
}
|
2017-06-11 04:32:56 +08:00
|
|
|
this.OnFullScreenChange.trigger(false);
|
|
|
|
}
|
2016-07-06 18:53:49 +08:00
|
|
|
|
|
|
|
}
|