Skip to content

Commit 0aa6cf0

Browse files
committed
Add shared ViewerToolbar and integrate across all viewers
1 parent 7ba53c2 commit 0aa6cf0

11 files changed

Lines changed: 424 additions & 284 deletions

File tree

kolibri/plugins/bloompub_viewer/frontend/views/BloomPubRendererIndex.vue

Lines changed: 30 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,11 @@
66
:style="{ width: iframeWidth }"
77
@changeFullscreen="isInFullscreen = $event"
88
>
9-
<div
10-
class="fullscreen-header"
11-
:style="{ backgroundColor: $themePalette.grey.v_200 }"
12-
>
13-
<KButton
14-
:primary="false"
15-
appearance="flat-button"
16-
@click="$refs.bloompubViewer.toggleFullscreen()"
17-
>
18-
<KIcon
19-
v-if="isInFullscreen"
20-
icon="fullscreen_exit"
21-
class="fs-icon"
22-
/>
23-
<KIcon
24-
v-else
25-
icon="fullscreen"
26-
class="fs-icon"
27-
/>
28-
{{ fullscreenText }}
29-
</KButton>
30-
</div>
9+
<ViewerToolbar
10+
:isInFullscreen="isInFullscreen"
11+
:embedded="embedded"
12+
@toggleFullscreen="$refs.bloompubViewer.toggleFullscreen()"
13+
/>
3114
<div
3215
class="iframe-container"
3316
:style="containerStyle"
@@ -58,26 +41,45 @@
5841
import urls from 'kolibri/urls';
5942
import { now } from 'kolibri/utils/serverClock';
6043
import CoreFullscreen from 'kolibri-common/components/CoreFullscreen';
44+
import ViewerToolbar from 'kolibri-common/components/ViewerToolbar';
6145
import Sandbox from 'kolibri-sandbox';
46+
6247
import useContentViewer from 'kolibri/composables/useContentViewer';
6348
6449
const defaultContentHeight = '500px';
65-
const frameTopbarHeight = '37px';
50+
const frameTopbarHeight = '48px';
6651
export default {
6752
name: 'BloomPubRendererIndex',
6853
components: {
6954
CoreFullscreen,
55+
ViewerToolbar,
7056
},
7157
setup(props, context) {
72-
const { defaultFile, options, forceDurationBasedProgress, reportError } = useContentViewer(
73-
context,
74-
{ defaultDuration: 300 },
75-
);
58+
const {
59+
defaultFile,
60+
options,
61+
lang,
62+
forceDurationBasedProgress,
63+
reportError,
64+
embedded,
65+
extraFields,
66+
timeSpent,
67+
userId,
68+
userFullName,
69+
progress,
70+
} = useContentViewer(context, { defaultDuration: 300 });
7671
return {
7772
defaultFile,
7873
options,
74+
lang,
7975
forceDurationBasedProgress,
8076
reportError,
77+
embedded,
78+
extraFields,
79+
timeSpent,
80+
userId,
81+
userFullName,
82+
progress,
8183
};
8284
},
8385
data() {
@@ -94,9 +96,6 @@
9496
iframeWidth() {
9597
return (this.options && this.options.width) || 'auto';
9698
},
97-
fullscreenText() {
98-
return this.isInFullscreen ? this.$tr('exitFullscreen') : this.$tr('enterFullscreen');
99-
},
10099
userData() {
101100
return {
102101
userId: this.userId,
@@ -161,18 +160,6 @@
161160
}
162161
this.$emit('stopTracking');
163162
},
164-
$trs: {
165-
exitFullscreen: {
166-
message: 'Exit fullscreen',
167-
context:
168-
"Learners can use the Esc key or the 'exit fullscreen' button to close the fullscreen view on an html5 app.",
169-
},
170-
enterFullscreen: {
171-
message: 'Enter fullscreen',
172-
context:
173-
'Learners can use the full screen button in the upper right corner to open an html5 app in fullscreen view.\n',
174-
},
175-
},
176163
};
177164
178165
</script>
@@ -181,18 +168,7 @@
181168
<style lang="scss" scoped>
182169
183170
@import '~kolibri-design-system/lib/styles/definitions';
184-
$frame-topbar-height: 37px;
185-
186-
.fullscreen-header {
187-
text-align: right;
188-
}
189-
190-
.fs-icon {
191-
position: relative;
192-
top: 8px;
193-
width: 24px;
194-
height: 24px;
195-
}
171+
$frame-topbar-height: 48px;
196172
197173
.bloompub-viewer {
198174
position: relative;

kolibri/plugins/epub_viewer/frontend/views/EpubRendererIndex.vue

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,25 @@
1414

1515
<LoadingScreen v-else-if="!loaded" />
1616

17+
<TopBar
18+
ref="topBar"
19+
class="top-bar-component"
20+
:isInFullscreen="isInFullscreen"
21+
:embedded="embedded"
22+
:hideSearchButton="searchSideBarIsOpen"
23+
@tableOfContentsButtonClicked="handleTocToggle"
24+
@settingsButtonClicked="handleSettingToggle"
25+
@searchButtonClicked="handleSearchToggle"
26+
@fullscreenButtonClicked="$refs.epubViewer.toggleFullscreen()"
27+
/>
28+
1729
<div
1830
class="epub-viewer-content"
1931
:style="{ 'border-color': $themeTokens.fineLine }"
2032
:dir="contentDirection"
2133
@mousedown.stop="handleMouseDown"
2234
@keyup.esc="closeSideBar"
2335
>
24-
<TopBar
25-
ref="topBar"
26-
class="top-bar-component"
27-
:isInFullscreen="isInFullscreen"
28-
:hideSearchButton="searchSideBarIsOpen"
29-
@tableOfContentsButtonClicked="handleTocToggle"
30-
@settingsButtonClicked="handleSettingToggle"
31-
@searchButtonClicked="handleSearchToggle"
32-
@fullscreenButtonClicked="$refs.epubViewer.toggleFullscreen()"
33-
/>
34-
3536
<FocusLock
3637
:disabled="!tocSideBarIsOpen"
3738
:returnFocus="true"
@@ -99,7 +100,10 @@
99100
class="navigation-and-epubjs"
100101
:style="{ backgroundColor }"
101102
>
102-
<div class="column epubjs-navigation">
103+
<div
104+
v-show="!mobileEmbedded"
105+
class="column epubjs-navigation"
106+
>
103107
<NextButton
104108
v-if="contentIsRtl"
105109
v-show="!isAtEnd"
@@ -124,7 +128,10 @@
124128
class="column epubjs-parent"
125129
:style="{ backgroundColor }"
126130
></div>
127-
<div class="column epubjs-navigation">
131+
<div
132+
v-show="!mobileEmbedded"
133+
class="column epubjs-navigation"
134+
>
128135
<PreviousButton
129136
v-if="contentIsRtl"
130137
v-show="!isAtStart"
@@ -147,6 +154,7 @@
147154
</div>
148155

149156
<BottomBar
157+
v-show="!mobileEmbedded"
150158
class="bottom-bar"
151159
:locationsAreReady="locationsAreReady"
152160
:heading="bottomBarHeading"
@@ -171,6 +179,7 @@
171179
import Lockr from 'lockr';
172180
import FocusLock from 'vue-focus-lock';
173181
import CoreFullscreen from 'kolibri-common/components/CoreFullscreen';
182+
174183
import useKResponsiveWindow from 'kolibri-design-system/lib/composables/useKResponsiveWindow';
175184
import useContentViewer from 'kolibri/composables/useContentViewer';
176185
import { ref, computed } from 'vue';
@@ -208,6 +217,7 @@
208217
name: 'EpubRendererIndex',
209218
components: {
210219
CoreFullscreen,
220+
211221
TopBar,
212222
TableOfContentsSideBar,
213223
SettingsSideBar,
@@ -244,6 +254,7 @@
244254
contentDirection,
245255
contentIsRtl,
246256
reportLoadingError,
257+
embedded,
247258
} = useContentViewer(context, { defaultDuration });
248259
return {
249260
windowIsSmall,
@@ -255,6 +266,7 @@
255266
contentDirection,
256267
contentIsRtl,
257268
reportLoadingError,
269+
embedded,
258270
};
259271
},
260272
data() {
@@ -360,10 +372,17 @@
360372
searchSideBarIsOpen() {
361373
return this.sideBarOpen === SIDE_BARS.SEARCH;
362374
},
375+
mobileEmbedded() {
376+
return this.embedded && this.windowIsSmall;
377+
},
363378
epubViewerStyle() {
364-
return {
379+
const style = {
365380
backgroundColor: this.$themeTokens.surface,
366381
};
382+
if (this.embedded) {
383+
style.height = '25vh';
384+
}
385+
return style;
367386
},
368387
navigationButtonColor() {
369388
return darkThemeNames.some(themeName => isEqual(this.theme.name, themeName))
@@ -429,7 +448,7 @@
429448
},
430449
beforeMount() {
431450
global.ePub = Epub;
432-
this.book = new Epub(this.epubURL);
451+
this.book = new Epub(this.epubURL, { openAs: 'epub' });
433452
this.book.on(EVENTS.BOOK.OPEN_FAILED, err => {
434453
this.errorLoading = true;
435454
this.reportLoadingError(err);
@@ -811,16 +830,14 @@
811830
@import '~kolibri-design-system/lib/styles/definitions';
812831
@import './EpubStyles';
813832
814-
$top-bar-height: 36px;
833+
$top-bar-height: 48px;
815834
$bottom-bar-height: 54px;
816835
$navigation-button-small: 36px;
817836
$navigation-button-normal: 52px;
818837
819838
.epub-viewer {
820839
position: relative;
821-
// Counter-balance the padding to avoid unnecessary scroll
822840
height: calc(100vh - 64px);
823-
padding: 32px 24px;
824841
overflow: hidden;
825842
font-size: smaller;
826843
border-radius: $radius;
@@ -831,27 +848,23 @@
831848
padding: 0;
832849
}
833850
851+
.top-bar-component {
852+
flex-shrink: 0;
853+
}
854+
834855
.epub-viewer-content {
835856
position: relative;
836-
height: 100%;
857+
height: calc(100% - #{$top-bar-height});
837858
overflow: hidden;
838859
border: solid 1px;
839860
border-radius: $radius;
840861
}
841862
842-
.top-bar-component {
843-
position: absolute;
844-
top: 0;
845-
right: 0;
846-
left: 0;
847-
height: $top-bar-height;
848-
}
849-
850863
.side-bar {
851864
@extend %momentum-scroll;
852865
853866
position: absolute;
854-
top: $top-bar-height;
867+
top: 0;
855868
bottom: $bottom-bar-height;
856869
}
857870
@@ -909,7 +922,7 @@
909922
@extend %momentum-scroll;
910923
911924
position: absolute;
912-
top: $top-bar-height;
925+
top: 0;
913926
right: 0;
914927
bottom: $bottom-bar-height;
915928
left: 0;

0 commit comments

Comments
 (0)