NodeViewBody.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <div
  3. class="node-view-body"
  4. :class="['node-view-body-' + mode, 'node-view-body-' + type]"
  5. >
  6. <slot name="default">
  7. <node-view-figure
  8. v-if="mode === 'view' && type === 'prod' && node.title"
  9. @expand-image="image = $event"
  10. :node="node"
  11. />
  12. <div class="node-view-body-wrapper" v-html="node.content" />
  13. <fullscreen-modal v-if="image" :image="image" :id="'modal-image-' + node.id" />
  14. <template v-if="mode === 'view'">
  15. <b-popover
  16. v-for="note in node.notes" :key="`note-${mode}-${node.id}-${note.number}`"
  17. custom-class="footnote"
  18. :target="`note-${node.id}-${note.number}`" :container="`node-${mode}-${node.id}`"
  19. placement="top" :fallback-placement="['bottom', 'right', 'left']"
  20. :triggers="['focus']"
  21. >
  22. <div class="footnote-content" v-html="note.content" />
  23. <div class="footnote-child-list" v-if="note.links">
  24. <node-view-title
  25. v-for="link in note.links" :key="link.id"
  26. :node="link.type === 'prod' && link.parents && link.parents.length ? link.parents[0] : link"
  27. link
  28. @open-node="onFootnoteLinkClick(link, `note-${node.id}-${note.number}`)"
  29. >
  30. <dot-button
  31. :variant="link.variant"
  32. class="mr-2"
  33. active
  34. >
  35. {{ $t('variants.' + link.variant) }}
  36. </dot-button>
  37. </node-view-title>
  38. </div>
  39. </b-popover>
  40. </template>
  41. </slot>
  42. </div>
  43. </template>
  44. <script>
  45. import { getRelation } from '@/store/utils'
  46. import { NodeViewTitle, NodeViewFigure } from '@/components/nodes'
  47. export default {
  48. name: 'NodeViewBody',
  49. components: {
  50. NodeViewTitle,
  51. NodeViewFigure
  52. },
  53. props: {
  54. node: { type: Object, required: true },
  55. type: { type: String, required: true },
  56. mode: { type: String, required: true }
  57. },
  58. data () {
  59. return {
  60. image: { id: '', url: '', alt: '' }
  61. }
  62. },
  63. methods: {
  64. addFootnotes () {
  65. const links = this.$el.querySelectorAll('a')
  66. links.forEach((link, i) => {
  67. const number = parseInt(link.hash.replace('#', ''))
  68. if (!isNaN(number)) {
  69. link.classList.add('footnote-link')
  70. link.id = `note-${this.node.id}-${number}`
  71. link.innerHTML = link.textContent
  72. if (link.parentElement.nodeName === 'SUP') {
  73. link.parentElement.replaceWith(link)
  74. }
  75. link.setAttribute('href', 'javascript:;')
  76. }
  77. })
  78. },
  79. hideFootnotes () {
  80. const links = this.$el.querySelectorAll('a')
  81. links.forEach((link, i) => {
  82. const number = parseInt(link.hash.replace('#', ''))
  83. if (!isNaN(number)) {
  84. link.classList.add('footnote-link')
  85. if (link.parentElement.nodeName === 'SUP') {
  86. link.parentElement.replaceWith(link)
  87. }
  88. }
  89. })
  90. },
  91. mountMedias () {
  92. const template = document.getElementById('expand-image-tmp')
  93. this.$el.querySelectorAll('.node-view-body-wrapper img').forEach(img => {
  94. const image = { id: img.dataset.entityUuid, url: img.src, alt: img.alt }
  95. const clone = document.importNode(template.content, true)
  96. const cloneImg = clone.querySelector('img')
  97. cloneImg.setAttribute('src', image.url)
  98. cloneImg.setAttribute('alt', image.alt)
  99. cloneImg.setAttribute('id', image.id)
  100. clone.querySelector('button').onclick = () => {
  101. this.image = image
  102. this.$bvModal.show('modal-image-' + this.node.id)
  103. }
  104. img.parentElement.replaceWith(clone)
  105. })
  106. },
  107. onFootnoteLinkClick (node, popoverBtnId) {
  108. this.$root.$emit('bv::hide::popover', popoverBtnId)
  109. this.$parent.$emit('open-node', getRelation(node))
  110. }
  111. },
  112. created () {
  113. if (this.mode === 'view' && this.node.notes) {
  114. // Query partial data for linked nodes in notes
  115. const ids = this.node.notes.filter(note => (note.links)).reduce((ids, note) => {
  116. return [...ids, ...note.links.map(link => link.id)]
  117. }, [])
  118. this.$store.dispatch('GET_NODES', { ids, dataLevel: 'initial' })
  119. }
  120. },
  121. mounted () {
  122. if (this.mode === 'view') {
  123. this.addFootnotes()
  124. this.mountMedias()
  125. } else {
  126. this.hideFootnotes()
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss">
  132. .node-view-body {
  133. width: 100%;
  134. img {
  135. display: block;
  136. max-width: 100%;
  137. max-height: 80vh;
  138. }
  139. font: {
  140. family: $font-family-text;
  141. line-height: inherit;
  142. }
  143. @include media-breakpoint-up($size-bp) {
  144. font-size: 2rem;
  145. }
  146. &-view {
  147. padding: 0 $node-view-spacer-sm-x;
  148. font-size: 1.25rem;
  149. word-wrap: break-word;
  150. @include media-breakpoint-up($size-bp) {
  151. padding: 0 $node-view-spacer-x;
  152. &.node-view-body-ref {
  153. font-size: 2.6rem;
  154. }
  155. &.node-view-body-prod {
  156. font-size: 1.5rem;
  157. }
  158. }
  159. }
  160. &-card {
  161. padding: 0 $node-card-spacer-sm-x;
  162. font-size: 1.1rem;
  163. word-wrap: anywhere;
  164. @include media-breakpoint-up($size-bp) {
  165. font-size: 2rem;
  166. padding: 0 $node-card-spacer-x;
  167. }
  168. }
  169. &-card &-wrapper {
  170. @include line-clamp(3, 1.5em);
  171. }
  172. &-card#{&}-prod &-wrapper {
  173. @include line-clamp(4, 1.5em);
  174. }
  175. .footnote-link {
  176. display: inline-block;
  177. text-align: center;
  178. background-color: $black;
  179. color: $white;
  180. font-family: $font-family-text;
  181. font-weight: $font-weight-bold;
  182. font-size: 0.8em;
  183. text-decoration: none;
  184. border-radius: 1em;
  185. padding: 0 .5em;
  186. min-width: 1.25em;
  187. max-height: 1.4em;
  188. margin: 0 .2em;
  189. }
  190. &-card .footnote-link {
  191. display: none;
  192. }
  193. }
  194. .footnote {
  195. background-color: $black !important;
  196. color: $white;
  197. font-size: 1.25rem;
  198. @include media-breakpoint-up($size-bp) {
  199. font-size: 1.5rem;
  200. }
  201. h6 {
  202. font-size: inherit;
  203. }
  204. &-content,
  205. &-child-list {
  206. > :last-child {
  207. margin-bottom: 0;
  208. }
  209. }
  210. &-child-list {
  211. margin-top: .5rem;
  212. }
  213. }
  214. </style>