Skip to content

fix(overlay): make overlay work in fullscreen mode #1653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/demo-app/demo-app/demo-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
</button>
<div class="demo-toolbar">
<h1>Angular Material 2 Demos</h1>
<button md-button (click)="toggleFullscreen()" title="Toggle fullscreen">
Fullscreen
</button>
<button md-button (click)="root.dir = (root.dir == 'rtl' ? 'ltr' : 'rtl')" title="Toggle between RTL and LTR">
{{root.dir.toUpperCase()}}
</button>
Expand Down
7 changes: 7 additions & 0 deletions src/demo-app/demo-app/demo-app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ body {
padding: 32px;
}

// stretch to screen size in fullscreen mode
.demo-content:fullscreen {
width: 100%;
height: 100%;
background-color: white;
}

md-toolbar {
md-icon {
cursor: pointer;
Expand Down
19 changes: 18 additions & 1 deletion src/demo-app/demo-app/demo-app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, ViewEncapsulation} from '@angular/core';
import {Component, ViewEncapsulation, ElementRef} from '@angular/core';


@Component({
Expand Down Expand Up @@ -47,4 +47,21 @@ export class DemoApp {
{name: 'Toolbar', route: 'toolbar'},
{name: 'Tooltip', route: 'tooltip'}
];

constructor(private _element: ElementRef) {

}

public toggleFullscreen() {
let elem = this._element.nativeElement.querySelector('.demo-content');
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.webkitRequestFullScreen) {
elem.webkitRequestFullScreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
}
}
}
30 changes: 29 additions & 1 deletion src/lib/core/overlay/overlay-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,35 @@ export class OverlayContainer {
private _createContainer(): void {
let container = document.createElement('div');
container.classList.add('md-overlay-container');
document.body.appendChild(container);
this._containerElement = container;
this._adjustContainerParent();
if (document.fullscreenEnabled) {
document.addEventListener('fullscreenchange', () => this._adjustContainerParent());
}
if (document.webkitFullscreenEnabled) {
document.addEventListener('webkitfullscreenchange', () => this._adjustContainerParent());
}
if ((<any>document).mozFullScreenEnabled) {
document.addEventListener('mozfullscreenchange', () => this._adjustContainerParent());
}
if ((<any>document).msFullscreenEnabled) {
document.addEventListener('MSFullscreenChange', () => this._adjustContainerParent());
}
}

private _adjustContainerParent() {
// use any type because document type doesn't declare full screen variables
let currentDocument: any = document;
if (currentDocument.fullscreenElement) {
currentDocument.fullScreenElement.appendChild(this._containerElement);
} else if (currentDocument.mozFullScreenElement) {
currentDocument.mozFullScreenElement.appendChild(this._containerElement);
} else if (currentDocument.webkitFullscreenElement) {
currentDocument.webkitCurrentFullScreenElement.appendChild(this._containerElement);
} else if (currentDocument.msFullscreenElement) {
currentDocument.msFullscreenElement.appendChild(this._containerElement);
} else {
document.body.appendChild(this._containerElement);
}
}
}