fix fullscreen switch logic

This commit is contained in:
Karl Chen 2017-12-24 09:54:34 +08:00 committed by GitHub
parent 7ac02c8303
commit 01bea4ac30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 10 deletions

View File

@ -8,6 +8,7 @@ class FullScreen {
this.player.resize();
});
this.player.events.on('webfullscreen_cancel', () => {
utils.setScrollPosition(this.lastScrollPosition);
this.player.resize();
});
@ -17,6 +18,7 @@ class FullScreen {
this.player.events.trigger('fullscreen');
}
else {
utils.setScrollPosition(this.lastScrollPosition);
this.player.events.trigger('fullscreen_cancel');
}
};
@ -34,7 +36,11 @@ class FullScreen {
}
}
request (type = 'browser') {
request (type = 'browser', switchmode) {
if (!switchmode) {
this.lastScrollPosition = utils.getScrollPosition();
}
switch (type) {
case 'browser':
if (this.player.container.requestFullscreen) {
@ -52,11 +58,7 @@ class FullScreen {
break;
case 'web':
this.player.container.classList.add('dplayer-fulled');
// record last position then hide scrollbars
this.lastScrollPosition = utils.getScrollPosition();
document.body.classList.add('dplayer-web-fullscreen-fix');
this.player.events.trigger('webfullscreen');
break;
}
@ -77,11 +79,7 @@ class FullScreen {
break;
case 'web':
this.player.container.classList.remove('dplayer-fulled');
// restore scrollbars and last position
document.body.classList.remove('dplayer-web-fullscreen-fix');
utils.setScrollPosition(this.lastScrollPosition);
this.player.events.trigger('webfullscreen_cancel');
break;
}
@ -92,11 +90,14 @@ class FullScreen {
this.cancel(type);
}
else {
this.request(type);
const anotherType = type === 'browser' ? 'web' : 'browser';
if (this.isFullScreen(anotherType)) {
this.request(type, true);
this.cancel(anotherType);
}
else {
this.request(type);
}
}
}
}