|
| 1 | +import {Component, ElementRef, Output, EventEmitter} from '@angular/core'; |
| 2 | +import {MdDialog, MdDialogRef} from '@angular/material'; |
| 3 | + |
| 4 | +@Component({ |
| 5 | + selector: 'fullscreen-e2e', |
| 6 | + moduleId: module.id, |
| 7 | + templateUrl: 'fullscreen-e2e.html' |
| 8 | +}) |
| 9 | +export class FullscreenE2E { |
| 10 | + dialogRef: MdDialogRef<TestDialog>; |
| 11 | + |
| 12 | + constructor (private _element: ElementRef, private _dialog: MdDialog) { } |
| 13 | + |
| 14 | + openDialog() { |
| 15 | + this.dialogRef = this._dialog.open(TestDialog); |
| 16 | + this.dialogRef.componentInstance.fullscreen.subscribe(() => this.toggleFullScreen()); |
| 17 | + this.dialogRef.componentInstance.exitfullscreen.subscribe(() => this.exitFullscreen()); |
| 18 | + this.dialogRef.afterClosed().subscribe(() => { |
| 19 | + this.dialogRef = null; |
| 20 | + }); |
| 21 | + } |
| 22 | + |
| 23 | + toggleFullScreen() { |
| 24 | + let element = this._element.nativeElement.querySelector('#fullscreenpane'); |
| 25 | + if (element.requestFullscreen) { |
| 26 | + element.requestFullscreen(); |
| 27 | + } else if (element.webkitRequestFullScreen) { |
| 28 | + element.webkitRequestFullScreen(); |
| 29 | + } else if ((element as any).mozRequestFullScreen) { |
| 30 | + (element as any).mozRequestFullScreen(); |
| 31 | + } else if ((element as any).msRequestFullScreen) { |
| 32 | + (element as any).msRequestFullScreen(); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + exitFullscreen() { |
| 37 | + if (document.exitFullscreen) { |
| 38 | + document.exitFullscreen(); |
| 39 | + } else if (document.webkitExitFullscreen) { |
| 40 | + document.webkitExitFullscreen(); |
| 41 | + } else if ((document as any).mozExitFullScreen) { |
| 42 | + (document as any).mozExitFullScreen(); |
| 43 | + } else if ((document as any).msExitFullScreen) { |
| 44 | + (document as any).msExitFullScreen(); |
| 45 | + } |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +@Component({ |
| 50 | + selector: 'fullscreen-dialog-e2e-test', |
| 51 | + template: ` |
| 52 | + <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p> |
| 53 | + <button id="fullscreenindialog" (click)="fullscreen.emit()">FULLSCREEN</button> |
| 54 | + <button id="exitfullscreenindialog" (click)="exitfullscreen.emit()">EXIT FULLSCREEN</button> |
| 55 | + <button type="button" (click)="dialogRef.close()" id="close">CLOSE</button>` |
| 56 | +}) |
| 57 | +export class TestDialog { |
| 58 | + constructor(public dialogRef: MdDialogRef<TestDialog>) { } |
| 59 | + @Output() fullscreen = new EventEmitter<void>(); |
| 60 | + @Output() exitfullscreen = new EventEmitter<void>(); |
| 61 | +} |
0 commit comments