NodeViewBody.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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="mode === 'view' && 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. blockquote {
  144. padding-left: 2em;
  145. margin: 1.5em 0;
  146. font-size: .9em;
  147. @include media-breakpoint-up($size-bp) {
  148. font-size: .85em;
  149. }
  150. }
  151. pre {
  152. white-space: pre-wrap;
  153. }
  154. // Kit atelier
  155. &-wrapper ul:first-child {
  156. background-color: $black;
  157. color: $white;
  158. font-family: $font-family-base;
  159. font-size: 1rem;
  160. list-style: none;
  161. padding: .75rem;
  162. margin-top: 1rem;
  163. li {
  164. &:not(:last-of-type) {
  165. margin-bottom: .25rem;
  166. }
  167. p {
  168. margin: 0;
  169. }
  170. }
  171. }
  172. &-card &-wrapper ul:first-child {
  173. li {
  174. flex-basis: 100%;
  175. }
  176. strong {
  177. display: inline;
  178. }
  179. }
  180. @include media-breakpoint-up($size-bp) {
  181. font-size: 2rem;
  182. }
  183. &-view {
  184. padding: 0 $node-view-spacer-sm-x;
  185. font-size: 1.25rem;
  186. word-wrap: break-word;
  187. @include media-breakpoint-up($size-bp) {
  188. padding: 0 $node-view-spacer-x;
  189. &.node-view-body-ref {
  190. font-size: 2.6rem;
  191. }
  192. &.node-view-body-prod {
  193. font-size: 1.5rem;
  194. }
  195. }
  196. }
  197. &-card {
  198. padding: 0 $node-card-spacer-sm-x;
  199. font-size: 1.1rem;
  200. word-wrap: anywhere;
  201. @include media-breakpoint-up($size-bp) {
  202. font-size: 2rem;
  203. padding: 0 $node-card-spacer-x;
  204. }
  205. }
  206. &-card &-wrapper {
  207. @include line-clamp(3, 1.5em);
  208. }
  209. &-card#{&}-prod &-wrapper {
  210. @include line-clamp(4, 1.5em);
  211. }
  212. // To avoid weird ul rendering of kits extra infos
  213. .node-view-kit #{&}-card#{&}-prod &-wrapper {
  214. display: block;
  215. text-overflow: unset;
  216. }
  217. .footnote-link {
  218. display: inline-block;
  219. text-align: center;
  220. background-color: $black;
  221. color: $white;
  222. font-family: $font-family-text;
  223. font-weight: $font-weight-bold;
  224. font-size: 0.8em;
  225. text-decoration: none;
  226. border-radius: 1em;
  227. padding: 0 .5em;
  228. min-width: 1.25em;
  229. max-height: 1.4em;
  230. margin: 0 .2em;
  231. }
  232. &-card .footnote-link {
  233. display: none;
  234. }
  235. }
  236. .footnote {
  237. background-color: $black !important;
  238. color: $white;
  239. font-size: 1.25rem;
  240. @include media-breakpoint-up($size-bp) {
  241. font-size: 1.5rem;
  242. }
  243. h6 {
  244. font-size: inherit;
  245. }
  246. &-content,
  247. &-child-list {
  248. > :last-child {
  249. margin-bottom: 0;
  250. }
  251. }
  252. &-child-list {
  253. margin-top: .5rem;
  254. }
  255. }
  256. </style>