-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(overlay): add fullscreen-enabled overlay class (#1949)
* feat(overlay): add fullscreen overlay class * fix lint error * move fs container to a new file and rename it * add e2e tests * fix tests * rebased and fix comments * fix typings * fix e2e tests * address comments * fix tests
- Loading branch information
1 parent
f9dd34f
commit 0640302
Showing
13 changed files
with
207 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {browser, by, element, Key, ProtractorBy} from 'protractor'; | ||
|
||
describe('fullscreen', () => { | ||
beforeEach(() => browser.get('/fullscreen')); | ||
|
||
let overlayInBody = () => | ||
browser.isElementPresent(by.css('body > .cdk-overlay-container') as ProtractorBy); | ||
let overlayInFullscreen = () => | ||
browser.isElementPresent(by.css('#fullscreenpane > .cdk-overlay-container') as ProtractorBy); | ||
|
||
it('should open a dialog inside a fullscreen element and move it to the document body', () => { | ||
element(by.id('fullscreen')).click(); | ||
element(by.id('dialog')).click(); | ||
|
||
overlayInFullscreen().then((isPresent: boolean) => { | ||
expect(isPresent).toBe(true); | ||
element(by.id('exitfullscreenindialog')).click(); | ||
overlayInBody().then((isPresent: boolean) => { | ||
expect(isPresent).toBe(true); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should open a dialog inside the document body and move it to a fullscreen element', () => { | ||
element(by.id('dialog')).click(); | ||
overlayInBody().then((isPresent: boolean) => { | ||
expect(isPresent).toBe(true); | ||
element(by.id('fullscreenindialog')).click(); | ||
overlayInFullscreen().then((isPresent: boolean) => { | ||
expect(isPresent).toBe(true); | ||
element(by.id('exitfullscreenindialog')).click(); | ||
overlayInBody().then((isPresent: boolean) => { | ||
expect(isPresent).toBe(true); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<button id="fullscreen" (click)="toggleFullScreen()">FULLSCREEN</button> | ||
<div id="fullscreenpane" style="width: 100%; height: 100%"> | ||
<button id="dialog" (click)="openDialog()">DIALOG</button> | ||
<button id="exitfullscreen" (click)="exitFullscreen()">EXIT FULLSCREEN</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import {Component, ElementRef, Output, EventEmitter} from '@angular/core'; | ||
import {MdDialog, MdDialogRef} from '@angular/material'; | ||
|
||
@Component({ | ||
selector: 'fullscreen-e2e', | ||
moduleId: module.id, | ||
templateUrl: 'fullscreen-e2e.html' | ||
}) | ||
export class FullscreenE2E { | ||
dialogRef: MdDialogRef<TestDialog>; | ||
|
||
constructor (private _element: ElementRef, private _dialog: MdDialog) { } | ||
|
||
openDialog() { | ||
this.dialogRef = this._dialog.open(TestDialog); | ||
this.dialogRef.componentInstance.fullscreen.subscribe(() => this.toggleFullScreen()); | ||
this.dialogRef.componentInstance.exitfullscreen.subscribe(() => this.exitFullscreen()); | ||
this.dialogRef.afterClosed().subscribe(() => { | ||
this.dialogRef = null; | ||
}); | ||
} | ||
|
||
toggleFullScreen() { | ||
let element = this._element.nativeElement.querySelector('#fullscreenpane'); | ||
if (element.requestFullscreen) { | ||
element.requestFullscreen(); | ||
} else if (element.webkitRequestFullScreen) { | ||
element.webkitRequestFullScreen(); | ||
} else if ((element as any).mozRequestFullScreen) { | ||
(element as any).mozRequestFullScreen(); | ||
} else if ((element as any).msRequestFullScreen) { | ||
(element as any).msRequestFullScreen(); | ||
} | ||
} | ||
|
||
exitFullscreen() { | ||
if (document.exitFullscreen) { | ||
document.exitFullscreen(); | ||
} else if (document.webkitExitFullscreen) { | ||
document.webkitExitFullscreen(); | ||
} else if ((document as any).mozExitFullScreen) { | ||
(document as any).mozExitFullScreen(); | ||
} else if ((document as any).msExitFullScreen) { | ||
(document as any).msExitFullScreen(); | ||
} | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: 'fullscreen-dialog-e2e-test', | ||
template: ` | ||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p> | ||
<button id="fullscreenindialog" (click)="fullscreen.emit()">FULLSCREEN</button> | ||
<button id="exitfullscreenindialog" (click)="exitfullscreen.emit()">EXIT FULLSCREEN</button> | ||
<button type="button" (click)="dialogRef.close()" id="close">CLOSE</button>` | ||
}) | ||
export class TestDialog { | ||
constructor(public dialogRef: MdDialogRef<TestDialog>) { } | ||
@Output() fullscreen = new EventEmitter<void>(); | ||
@Output() exitfullscreen = new EventEmitter<void>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {Injectable} from '@angular/core'; | ||
import {OverlayContainer} from './overlay-container'; | ||
|
||
/** | ||
* The FullscreenOverlayContainer is the alternative to OverlayContainer | ||
* that supports correct displaying of overlay elements in Fullscreen mode | ||
* https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen | ||
* It should be provided in the root component that way: | ||
* providers: [ | ||
* {provide: OverlayContainer, useClass: FullscreenOverlayContainer} | ||
* ], | ||
*/ | ||
@Injectable() | ||
export class FullscreenOverlayContainer extends OverlayContainer { | ||
protected _createContainer(): void { | ||
super._createContainer(); | ||
this._adjustParentForFullscreenChange(); | ||
this._addFullscreenChangeListener(() => this._adjustParentForFullscreenChange()); | ||
} | ||
|
||
private _adjustParentForFullscreenChange(): void { | ||
if (!this._containerElement) { | ||
return; | ||
} | ||
let fullscreenElement = this.getFullscreenElement(); | ||
let parent = fullscreenElement || document.body; | ||
parent.appendChild(this._containerElement); | ||
} | ||
|
||
private _addFullscreenChangeListener(fn: () => void) { | ||
if (document.fullscreenEnabled) { | ||
document.addEventListener('fullscreenchange', fn); | ||
} else if (document.webkitFullscreenEnabled) { | ||
document.addEventListener('webkitfullscreenchange', fn); | ||
} else if ((document as any).mozFullScreenEnabled) { | ||
document.addEventListener('mozfullscreenchange', fn); | ||
} else if ((document as any).msFullscreenEnabled) { | ||
document.addEventListener('MSFullscreenChange', fn); | ||
} | ||
} | ||
|
||
/** | ||
* When the page is put into fullscreen mode, a specific element is specified. | ||
* Only that element and its children are visible when in fullscreen mode. | ||
*/ | ||
getFullscreenElement(): Element { | ||
return document.fullscreenElement || | ||
document.webkitFullscreenElement || | ||
(document as any).mozFullScreenElement || | ||
(document as any).msFullscreenElement || | ||
null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters