diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-06-16 23:02:11 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-06-16 23:02:11 +0300 |
commit | de26dde98d3bfe501574d7deb19614e42dc95af8 (patch) | |
tree | a47f4d456b91fcde21d9d66e0a58b13a838203b4 /src/mixins | |
parent | 31bb4603c8e37931b94e01a54c8e4d77fde7b04b (diff) |
Avoid duplicate callback on DOMContentLoaded
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'src/mixins')
-rw-r--r-- | src/mixins/menubar.js | 129 |
1 files changed, 1 insertions, 128 deletions
diff --git a/src/mixins/menubar.js b/src/mixins/menubar.js index 1bb61e61a..855e61de7 100644 --- a/src/mixins/menubar.js +++ b/src/mixins/menubar.js @@ -20,9 +20,7 @@ * */ -import Vue from 'vue' - -const icons = [ +export default [ { label: t('text', 'Undo'), class: 'icon-undo', @@ -154,128 +152,3 @@ const icons = [ } } ] - -const iconBar = { - beforeMount() { - this.redrawMenuBar() - }, - mounted() { - window.addEventListener('resize', this.getWindowWidth) - }, - beforeDestroy() { - window.removeEventListener('resize', this.getWindowWidth) - }, - data: () => { - return { - windowWidth: 0, - windowHeight: 0, - forceRecompute: 0, - submenuVisibility: {}, - icons: [...icons] - } - }, - methods: { - redrawMenuBar() { - this.$nextTick(() => { - this.getWindowWidth() - this.forceRecompute++ - }) - }, - clickIcon(commands, icon) { - return icon.action(commands) - }, - getWindowWidth(event) { - this.windowWidth = document.documentElement.clientWidth - }, - getWindowHeight(event) { - this.windowHeight = document.documentElement.clientHeight - }, - showChildMenu(icon) { - Vue.set(this.submenuVisibility, icon.label, true) - this.redrawMenuBar() - }, - hideChildMenu(icon) { - Vue.set(this.submenuVisibility, icon.label, false) - this.redrawMenuBar() - }, - toggleChildMenu(icon) { - const lastValue = this.submenuVisibility.hasOwnProperty(icon.label) ? this.submenuVisibility[icon.label] : false - Vue.set(this.submenuVisibility, icon.label, !lastValue) - // TODO properly fix this - // setting the submenuVisibility doesn't trigger updating for some reason - this.redrawMenuBar() - } - }, - computed: { - getIconClasses() { - return (isActive, icon) => { - let classes = { - 'is-active': icon.isActive(isActive) - } - classes[icon.class] = true - return classes - } - }, - isChildMenuVisible() { - return (icon) => { - return this.submenuVisibility.hasOwnProperty(icon.label) ? this.submenuVisibility[icon.label] : false - } - }, - allIcons() { - if (this.isPublic) { - return this.icons - } - return [...this.icons, { - label: 'Insert image', - class: 'icon-image', - isActive: () => { - }, - action: (commands) => { - this.showImagePrompt(commands.image) - } - }] - }, - iconsToShow() { - return this.allIcons.slice(0, (this.iconCount - 1 > 0) ? this.iconCount - 1 : 0) - }, - iconsToShowInMenu() { - return this.allIcons.slice((this.iconCount - 1 > 0) ? this.iconCount - 1 : 0, this.allIcons.length) - }, - childPopoverMenu() { - return (isActive, commands, icons, parent) => { - let popoverMenuItems = [] - for (const index in icons) { - popoverMenuItems.push({ - text: icons[index].label, - icon: icons[index].class, - action: () => { - icons[index].action(commands) - this.hideChildMenu(parent) - }, - active: icons[index].isActive(isActive) - }) - } - return popoverMenuItems - } - }, - childIconClass() { - return (isActive, icons) => { - for (const index in icons) { - var icon = icons[index] - if (icon.isActive(isActive)) { - return icon.class - } - } - return 'icon-h1' - } - }, - iconCount() { - this.forceRecompute // eslint-disable-line - this.windowWidth // eslint-disable-line - const menuBarWidth = this.$refs.menubar ? this.$refs.menubar.clientWidth : this.windowWidth - 200 - const iconCount = Math.max((Math.floor(menuBarWidth / 44) - 1), 0) - return iconCount - } - } -} -export { icons, iconBar } |