Merge pull request #165 from toasted-nutbread/fullscreen-support

Allow popup window to be visible in fullscreen mode
This commit is contained in:
Alex Yatskov 2019-06-26 14:17:01 -07:00 committed by GitHub
commit 654b059b74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,7 +33,8 @@ class Popup {
if (!this.injected) {
this.injected = new Promise((resolve, reject) => {
this.container.addEventListener('load', resolve);
document.body.appendChild(this.container);
this.observeFullscreen();
this.onFullscreenChanged();
});
}
@ -138,4 +139,32 @@ class Popup {
invokeApi(action, params={}) {
this.container.contentWindow.postMessage({action, params}, '*');
}
observeFullscreen() {
const fullscreenEvents = [
'fullscreenchange',
'MSFullscreenChange',
'mozfullscreenchange',
'webkitfullscreenchange'
];
for (const eventName of fullscreenEvents) {
document.addEventListener(eventName, () => this.onFullscreenChanged(), false);
}
}
getFullscreenElement() {
return (
document.fullscreenElement ||
document.msFullscreenElement ||
document.mozFullScreenElement ||
document.webkitFullscreenElement
);
}
onFullscreenChanged() {
const parent = (this.getFullscreenElement() || document.body || null);
if (parent !== null && this.container.parentNode !== parent) {
parent.appendChild(this.container);
}
}
}