Skip to content

Commit 39b4f79

Browse files
Mimics fullscreen when fullscreen api is not supported
1 parent 89df288 commit 39b4f79

File tree

4 files changed

+117
-25
lines changed

4 files changed

+117
-25
lines changed

kolibri/plugins/document_pdf_render/assets/src/views/index.vue

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<template>
22

3-
<div ref="container" class="container" allowfullscreen>
3+
<div
4+
ref="container"
5+
class="container"
6+
:class="{ 'container-mimic-fullscreen': mimicFullscreen }">
47
<icon-button
58
class="btn"
6-
v-if="fullscreenAllowed && supportsPDFs"
7-
:text="isFullScreen ? $tr('exitFullscreen') : $tr('enterFullscreen')"
8-
@click="toggleFullScreen"
9+
v-if="supportsPDFs"
10+
:text="isFullscreen ? $tr('exitFullscreen') : $tr('enterFullscreen')"
11+
@click="toggleFullscreen"
912
:primary="true">
10-
<mat-svg v-if="isFullScreen" class="icon" category="navigation" name="fullscreen_exit"/>
13+
<mat-svg v-if="isFullscreen" class="icon" category="navigation" name="fullscreen_exit"/>
1114
<mat-svg v-else class="icon" category="navigation" name="fullscreen"/>
1215
</icon-button>
1316
<div ref="pdfcontainer" class="pdfcontainer"></div>
@@ -27,17 +30,29 @@
2730
data: () => ({
2831
supportsPDFs: PDFobject.supportsPDFs,
2932
timeout: null,
30-
isFullScreen: false,
33+
isFullscreen: false,
3134
}),
3235
computed: {
3336
fullscreenAllowed() {
3437
return ScreenFull.enabled;
3538
},
39+
mimicFullscreen() {
40+
return !this.fullscreenAllowed && this.isFullscreen;
41+
},
3642
},
3743
methods: {
38-
toggleFullScreen() {
39-
ScreenFull.toggle(this.$refs.container);
40-
this.isFullScreen = ScreenFull.isFullscreen;
44+
toggleFullscreen() {
45+
if (this.isFullscreen) {
46+
if (this.fullscreenAllowed) {
47+
ScreenFull.toggle(this.$refs.container);
48+
}
49+
this.isFullscreen = false;
50+
} else {
51+
if (this.fullscreenAllowed) {
52+
ScreenFull.toggle(this.$refs.container);
53+
}
54+
this.isFullscreen = true;
55+
}
4156
},
4257
},
4358
mounted() {
@@ -82,6 +97,18 @@
8297
min-height: inherit
8398
max-height: inherit
8499
100+
.container-mimic-fullscreen
101+
position: fixed
102+
top: 0
103+
right: 0
104+
bottom: 0
105+
left: 0
106+
z-index: 24
107+
max-width: 100%
108+
max-height: 100%
109+
width: 100%
110+
height: 100%
111+
85112
.pdfcontainer
86113
height: 100%
87114

kolibri/plugins/html5_app_renderer/assets/src/views/index.vue

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<template>
22

3-
<div ref="container" class="container" allowfullscreen>
3+
<div
4+
ref="container"
5+
class="container"
6+
:class="{ 'container-mimic-fullscreen': mimicFullscreen }"
7+
allowfullscreen>
48
<icon-button
59
class="btn"
6-
v-if="fullscreenAllowed"
7-
:text="isFullScreen ? $tr('exitFullscreen') : $tr('enterFullscreen')"
8-
@click="toggleFullScreen"
10+
:text="isFullscreen ? $tr('exitFullscreen') : $tr('enterFullscreen')"
11+
@click="toggleFullscreen"
912
:primary="true">
10-
<mat-svg v-if="isFullScreen" class="icon" category="navigation" name="fullscreen_exit"/>
13+
<mat-svg v-if="isFullscreen" class="icon" category="navigation" name="fullscreen_exit"/>
1114
<mat-svg v-else class="icon" category="navigation" name="fullscreen"/>
1215
</icon-button>
1316
<iframe ref="sandbox" class="sandbox" :src="rooturl" sandbox="allow-scripts"></iframe>
@@ -28,19 +31,31 @@
2831
required: true,
2932
},
3033
},
31-
data: () => ({ isFullScreen: false }),
34+
data: () => ({ isFullscreen: false }),
3235
computed: {
3336
rooturl() {
3437
return this.defaultFile.storage_url;
3538
},
3639
fullscreenAllowed() {
3740
return ScreenFull.enabled;
3841
},
42+
mimicFullscreen() {
43+
return !this.fullscreenAllowed && this.isFullscreen;
44+
},
3945
},
4046
methods: {
41-
toggleFullScreen() {
42-
ScreenFull.toggle(this.$refs.container);
43-
this.isFullScreen = ScreenFull.isFullscreen;
47+
toggleFullscreen() {
48+
if (this.isFullscreen) {
49+
if (this.fullscreenAllowed) {
50+
ScreenFull.toggle(this.$refs.container);
51+
}
52+
this.isFullscreen = false;
53+
} else {
54+
if (this.fullscreenAllowed) {
55+
ScreenFull.toggle(this.$refs.container);
56+
}
57+
this.isFullscreen = true;
58+
}
4459
},
4560
},
4661
mounted() {
@@ -86,6 +101,18 @@
86101
min-height: inherit
87102
max-height: inherit
88103
104+
.container-mimic-fullscreen
105+
position: fixed
106+
top: 0
107+
right: 0
108+
bottom: 0
109+
left: 0
110+
z-index: 24
111+
max-width: 100%
112+
max-height: 100%
113+
width: 100%
114+
height: 100%
115+
89116
.sandbox
90117
height: 100%
91118
width: 100%
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import videojs from 'video.js';
22

33
const videojsButton = videojs.getComponent('Button');
4+
const videojsFullscreenToggle = videojs.getComponent('FullscreenToggle');
45

56
export class ReplayButton extends videojsButton {
67
buildCSSClass() {
@@ -21,3 +22,9 @@ export class ForwardButton extends videojsButton {
2122
player.currentTime(Math.min(player.duration(), player.currentTime() + 10));
2223
}
2324
}
25+
26+
export class MimicFullscreenToggle extends videojsFullscreenToggle {
27+
handleClick() {
28+
this.player().trigger('mimicFullscreenToggled');
29+
}
30+
}

kolibri/plugins/media_player/assets/src/views/index.vue

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
<div v-show="loading" class="fill-space">
55
<loading-spinner/>
66
</div>
7-
<div v-show="!loading" class="fill-space">
7+
<div
8+
v-show="!loading"
9+
class="fill-space"
10+
:class="{ 'mimic-fullscreen': mimicFullscreen }">
811
<video v-if="isVideo" ref="player" class="video-js custom-skin">
912
<template v-for="video in videoSources">
1013
<source :src="video.storage_url" :type="`video/${video.extension}`">
@@ -30,11 +33,12 @@
3033
import vue from 'kolibri.lib.vue';
3134
import videojs from 'video.js';
3235
import LangLookup from './languagelookup';
33-
import * as customButtons from './videojs-replay-forward-btns';
36+
import { ReplayButton, ForwardButton, MimicFullscreenToggle } from './customButtons';
3437
import throttle from 'lodash/throttle';
3538
import Lockr from 'lockr';
3639
import loadingSpinner from 'kolibri.coreVue.components.loadingSpinner';
3740
import ResponsiveElement from 'kolibri.coreVue.mixins.responsiveElement';
41+
import ScreenFull from 'screenfull';
3842
3943
const GlobalLangCode = vue.locale;
4044
@@ -66,6 +70,7 @@
6670
playerMuted: false,
6771
playerRate: 1.0,
6872
videoLang: GlobalLangCode,
73+
mimicFullscreen: false,
6974
}),
7075
7176
computed: {
@@ -96,6 +101,9 @@
96101
isVideo() {
97102
return this.videoSources.length;
98103
},
104+
fullscreenAllowed() {
105+
return ScreenFull.enabled;
106+
},
99107
},
100108
methods: {
101109
getLangName(langCode) {
@@ -137,7 +145,6 @@
137145
},
138146
{ name: 'playbackRateMenuButton' },
139147
{ name: 'captionsButton' },
140-
{ name: 'fullscreenToggle' },
141148
],
142149
},
143150
};
@@ -146,6 +153,14 @@
146153
videojsConfig.poster = this.posterSource;
147154
}
148155
156+
// Add appropriate fullscreen button
157+
if (this.fullscreenAllowed) {
158+
videojsConfig.controlBar.children.push({ name: 'fullscreenToggle' });
159+
} else {
160+
videojs.registerComponent('MimicFullscreenToggle', MimicFullscreenToggle);
161+
videojsConfig.controlBar.children.push({ name: 'MimicFullscreenToggle' });
162+
}
163+
149164
this.$nextTick(() => {
150165
this.player = videojs(this.$refs.player, videojsConfig);
151166
this.player.on('loadedmetadata', this.handleReadyPlayer);
@@ -162,6 +177,9 @@
162177
this.player.on('play', () => this.setPlayState(true));
163178
this.player.on('pause', () => this.setPlayState(false));
164179
this.player.on('ended', () => this.setPlayState(false));
180+
this.player.on('mimicFullscreenToggled', () => {
181+
this.mimicFullscreen = !this.mimicFullscreen;
182+
});
165183
this.$watch('elSize.width', this.updatePlayerSizeClass);
166184
this.updatePlayerSizeClass();
167185
this.resizePlayer();
@@ -261,10 +279,10 @@
261279
},
262280
},
263281
created() {
264-
customButtons.ReplayButton.prototype.controlText_ = this.$tr('replay');
265-
customButtons.ForwardButton.prototype.controlText_ = this.$tr('forward');
266-
videojs.registerComponent('ReplayButton', customButtons.ReplayButton);
267-
videojs.registerComponent('ForwardButton', customButtons.ForwardButton);
282+
ReplayButton.prototype.controlText_ = this.$tr('replay');
283+
ForwardButton.prototype.controlText_ = this.$tr('forward');
284+
videojs.registerComponent('ReplayButton', ReplayButton);
285+
videojs.registerComponent('ForwardButton', ForwardButton);
268286
this.videoLang = Lockr.get('videoLang') || this.videoLang;
269287
},
270288
mounted() {
@@ -299,6 +317,19 @@
299317
width: 100%
300318
height: 100%
301319
320+
.mimic-fullscreen
321+
position: fixed
322+
top: 0
323+
right: 0
324+
bottom: 0
325+
left: 0
326+
z-index: 24
327+
max-width: calc(100vh * (16/9))
328+
max-height: 100%
329+
width: 100%
330+
height: 100%
331+
background-color: black
332+
302333
</style>
303334

304335

0 commit comments

Comments
 (0)