Newer
Older
<template>
<div class="cw-toolbar-wrapper">
<div id="cw-toolbar" class="cw-toolbar" :style="toolbarStyle">
<div v-if="showTools" class="cw-toolbar-tools" :class="{ unfold: unfold, hd: isHd, wqhd: isWqhd }">
<div class="cw-toolbar-button-wrapper">
<button
class="cw-toolbar-button"
:title="$gettext('Blöcke hinzufügen')"
@click="activateTool('blockAdder')"
>
{{ $gettext('Blöcke') }}
</button>
<button
class="cw-toolbar-button"
:title="$gettext('Abschnitte hinzufügen')"
@click="activateTool('containerAdder')"
>
{{ $gettext('Abschnitte') }}
</button>
<button
class="cw-toolbar-button"
:title="$gettext('Block Merkliste')"
@click="activateTool('clipboard')"
>
{{ $gettext('Merkliste') }}
</button>
<button
</div>
<courseware-toolbar-blocks v-if="activeTool === 'blockAdder'" />
<courseware-toolbar-containers v-if="activeTool === 'containerAdder'" />
<courseware-toolbar-clipboard v-if="activeTool === 'clipboard'" />
</div>
<div v-else class="cw-toolbar-folded-wrapper">
<button
class="cw-toolbar-button"
:title="$gettext('Werkzeugleiste ausklappen')"
@click="toggleToolbarActive"
>
<studip-icon shape="arr_2left" :size="24" />
</button>
<button
class="cw-toolbar-button"
:title="
hideEditLayout
? $gettext('Bearbeitungselemente anzeigen')
: $gettext('Bearbeitungselemente ausblenden')
"
@click="toggleHideEditLayout"
>
<studip-icon :shape="hideEditLayout ? 'visibility-checked' : 'visibility-invisible'" :size="24" />
</button>
</div>
<div class="cw-toolbar-spacer-right"></div>
</div>
</div>
</template>
<script>
import CoursewareToolbarBlocks from './CoursewareToolbarBlocks.vue';
import CoursewareToolbarContainers from './CoursewareToolbarContainers.vue';
import CoursewareToolbarClipboard from './CoursewareToolbarClipboard.vue';
import containerMixin from '@/vue/mixins/courseware/container.js';
import { mapActions, mapGetters } from 'vuex';
export default {
name: 'courseware-toolbar',
components: {
CoursewareToolbarBlocks,
CoursewareToolbarContainers,
},
data() {
return {
unfold: true,
showTools: true,
toolbarTop: 0,
activeTool: 'blockAdder',
windowWidth: window.outerWidth,
...mapGetters({
relatedContainers: 'courseware-containers/related',
structuralElementById: 'courseware-structural-elements/byId',
toolbarStyle() {
const scrollTopStyles = window.getComputedStyle(document.getElementById('scroll-to-top'));
const scrollTopHeight =
parseInt(scrollTopStyles['height'], 10) +
parseInt(scrollTopStyles['padding-top'], 10) +
parseInt(scrollTopStyles['padding-bottom'], 10) +
parseInt(scrollTopStyles['margin-bottom'], 10);
Math.min(this.windowInnerHeight * 0.9, this.windowInnerHeight - this.toolbarTop - scrollTopHeight)
);
return {
height: height + 'px',
minHeight: height + 'px',
top: this.toolbarTop + 'px',
};
},
parent: this.structuralElementById({ id: this.$route.params.id }),
relationship: 'containers',
toolbarHeader() {
let header = '';
if (this.activeTool === 'blockAdder') {
header = this.$gettext('Block hinzufügen');
}
if (this.activeTool === 'containerAdder') {
header = this.$gettext('Abschnitt hinzufügen');
}
return header;
},
isHd() {
return this.windowWidth >= 1920;
},
isWqhd() {
return this.windowWidth >= 2560;
},
},
methods: {
activateTool(tool) {
this.activeTool = tool;
},
updateToolbarTop() {
const responsiveContentbar = document.getElementById('responsive-contentbar');
if (responsiveContentbar) {
const contentbarRect = responsiveContentbar.getBoundingClientRect();
this.toolbarTop = contentbarRect.bottom + 25;
return;
}
const ribbon = document.getElementById('cw-ribbon') ?? document.getElementById('contentbar');
if (ribbon) {
const contentbarRect = ribbon.getBoundingClientRect();
this.toolbarTop = contentbarRect.bottom + 16;
} else {
this.toolbarTop = contentbarRect.bottom + 15;
}
}
},
onResize() {
this.windowWidth = window.outerWidth;
this.windowInnerHeight = window.innerHeight;
},
mounted() {
this.updateToolbarTop();
this.$nextTick(() => {
window.addEventListener('scroll', this.updateToolbarTop);
window.addEventListener('resize', this.onResize);
});
window.removeEventListener('scroll', this.updateToolbarTop);
let view = this;
if (newState) {
this.showTools = true;
setTimeout(() => {
view.unfold = true;
}, 10);
} else {
this.unfold = false;
setTimeout(() => {