From 07e23ce830d06c3d4c66524f4cd2aa9256692ba6 Mon Sep 17 00:00:00 2001 From: axolotle Date: Tue, 6 Jul 2021 20:40:23 +0200 Subject: [PATCH] mount expand button on inline body images --- public/index.html | 13 ++++++ src/assets/scss/app.scss | 1 + src/assets/scss/classes/_img-wrapper.scss | 42 +++++++++++++++++++ src/components/nodes/NodeView.vue | 2 +- src/components/nodes/NodeViewBody.vue | 49 ++++++++++++++++++----- src/components/nodes/NodeViewFooter.vue | 2 +- src/pages/_partials/NodesHistory.vue | 2 +- src/store/nodes.js | 4 ++ 8 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 src/assets/scss/classes/_img-wrapper.scss diff --git a/public/index.html b/public/index.html index a582c08..f5096d2 100644 --- a/public/index.html +++ b/public/index.html @@ -11,6 +11,19 @@ +
+ + diff --git a/src/assets/scss/app.scss b/src/assets/scss/app.scss index 8a63ce3..50923c9 100644 --- a/src/assets/scss/app.scss +++ b/src/assets/scss/app.scss @@ -6,6 +6,7 @@ @import 'base/bootstrap-overrides'; @import 'classes/nodes-grid'; +@import 'classes/img-wrapper'; @import 'classes/misc'; @import 'fonts/noto-sans'; diff --git a/src/assets/scss/classes/_img-wrapper.scss b/src/assets/scss/classes/_img-wrapper.scss new file mode 100644 index 0000000..463fd49 --- /dev/null +++ b/src/assets/scss/classes/_img-wrapper.scss @@ -0,0 +1,42 @@ +.node-view-img-wrapper { + display: inline-block; + position: relative; + + &:not(:hover) .btn-expand { + display: none; + } + + .btn-expand { + position: absolute; + top: 0; + right: 0; + + padding: 0; + width: 75px; + height: 70px; + border: 0; + border-radius: 0 !important; + line-height: 0; + + &:hover, + &:focus { + path { + stroke: $black; + } + } + + svg { + width: 100%; + height: 100%; + pointer-events: none; + } + + path { + fill: none; + stroke: lighten($black, 20%); + stroke-width: 4px; + stroke-linejoin: round; + stroke-linecap: round; + } + } +} diff --git a/src/components/nodes/NodeView.vue b/src/components/nodes/NodeView.vue index b7f44ec..762cb80 100644 --- a/src/components/nodes/NodeView.vue +++ b/src/components/nodes/NodeView.vue @@ -10,7 +10,7 @@ class="node-view-header" /> - + -
+
+ + @@ -49,13 +51,17 @@ export default { }, props: { - content: { type: String, default: null }, - notes: { type: Array, default: null }, - nodeId: { type: Number, required: true }, + node: { type: Object, required: true }, type: { type: String, required: true }, mode: { type: String, required: true } }, + data () { + return { + image: { id: '', url: '', alt: '' } + } + }, + methods: { addFootnotes () { const links = this.$el.querySelectorAll('a') @@ -73,6 +79,25 @@ export default { }) }, + mountMedias () { + const template = document.getElementById('expand-image-tmp') + this.$el.querySelectorAll('.node-view-body-wrapper img').forEach(img => { + const image = { id: img.dataset.entityUuid, url: img.src, alt: img.alt } + + const clone = document.importNode(template.content, true) + const cloneImg = clone.querySelector('img') + cloneImg.setAttribute('src', image.url) + cloneImg.setAttribute('alt', image.alt) + cloneImg.setAttribute('id', image.id) + clone.querySelector('button').onclick = () => { + this.image = image + this.$bvModal.show('modal-image-' + this.node.id) + } + + img.parentElement.replaceWith(clone) + }) + }, + onFootnoteLinkClick (node, popoverBtnId) { this.$root.$emit('bv::hide::popover', popoverBtnId) this.$parent.$emit('open-node', getRelation(node)) @@ -80,9 +105,9 @@ export default { }, created () { - if (this.mode === 'view' && this.notes) { + if (this.mode === 'view' && this.node.notes) { // Query partial data for linked nodes in notes - const ids = this.notes.filter(note => (note.links)).reduce((ids, note) => { + const ids = this.node.notes.filter(note => (note.links)).reduce((ids, note) => { return [...ids, ...note.links.map(link => link.id)] }, []) this.$store.dispatch('GET_NODES', { ids, dataLevel: 'initial' }) @@ -90,8 +115,12 @@ export default { }, mounted () { - if (this.mode === 'view' && this.notes) this.addFootnotes() - this.$el.querySelectorAll('img, video, audio').forEach(elem => elem.parentElement.classList.add('media-container')) + if (this.mode === 'view') { + if (this.node.notes) { + this.addFootnotes() + } + this.mountMedias() + } } } diff --git a/src/components/nodes/NodeViewFooter.vue b/src/components/nodes/NodeViewFooter.vue index eade76c..c8ca42f 100644 --- a/src/components/nodes/NodeViewFooter.vue +++ b/src/components/nodes/NodeViewFooter.vue @@ -31,7 +31,7 @@ @open-node="onOpenSibling(sibling.id, 'siblings-' + node.id)" />