NodeViewBody.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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.image"
  9. @expand-image="image = $event"
  10. :node="node"
  11. />
  12. <div class="node-view-body-wrapper" v-html="node.content" />
  13. <template v-if="mode === 'view'">
  14. <div v-if="node.images" class="mt-5">
  15. <div class="node-view-img-wrapper mt-3" v-for="img in node.images" :key="img.id">
  16. <img :src="img.url" :alt="img.alt">
  17. <button-expand @click="onImageExpandClick(img)" v-b-modal="'modal-image-' + node.id" />
  18. </div>
  19. </div>
  20. <div v-if="node.videos">
  21. <video
  22. v-for="video in node.videos" :key="video.url"
  23. :src="video.url" class="mt-3"
  24. />
  25. </div>
  26. <ul v-if="node.files">
  27. <h6>Fichiers:</h6>
  28. <li v-for="file in node.files" :key="file.fid">
  29. <b-button variant="dark" :href="file.url">
  30. {{ file.filename }}
  31. </b-button>
  32. </li>
  33. </ul>
  34. </template>
  35. <fullscreen-modal v-if="mode === 'view' && image" :image="image" :id="'modal-image-' + node.id" />
  36. <template v-if="mode === 'view'">
  37. <b-popover
  38. v-for="note in node.notes" :key="`note-${mode}-${node.id}-${note.number}`"
  39. custom-class="footnote"
  40. :target="`note-${node.id}-${note.number}`" :container="`node-${mode}-${node.id}`"
  41. placement="top" :fallback-placement="['bottom', 'right', 'left']"
  42. :triggers="['focus']"
  43. >
  44. <div class="footnote-content" v-html="note.content" />
  45. <div class="footnote-child-list" v-if="note.links">
  46. <node-view-title
  47. v-for="link in note.links" :key="link.id"
  48. :node="link.type === 'prod' && link.parents && link.parents.length ? link.parents[0] : link"
  49. link
  50. @open-node="onFootnoteLinkClick(link, `note-${node.id}-${note.number}`)"
  51. >
  52. <dot-button
  53. :variant="link.variant"
  54. class="mr-2"
  55. active
  56. >
  57. {{ $t('variants.' + link.variant) }}
  58. </dot-button>
  59. </node-view-title>
  60. </div>
  61. </b-popover>
  62. </template>
  63. </slot>
  64. </div>
  65. </template>
  66. <script>
  67. import { getRelation } from '@/store/utils'
  68. import { NodeViewTitle, NodeViewFigure } from '@/components/nodes'
  69. export default {
  70. name: 'NodeViewBody',
  71. components: {
  72. NodeViewTitle,
  73. NodeViewFigure
  74. },
  75. props: {
  76. node: { type: Object, required: true },
  77. type: { type: String, required: true },
  78. mode: { type: String, required: true }
  79. },
  80. data () {
  81. return {
  82. image: { id: '', url: '', alt: '' }
  83. }
  84. },
  85. methods: {
  86. addFootnotes () {
  87. const links = this.$el.querySelectorAll('a')
  88. links.forEach((link, i) => {
  89. const number = parseInt(link.hash.replace('#', ''))
  90. if (!isNaN(number)) {
  91. link.classList.add('footnote-link')
  92. link.id = `note-${this.node.id}-${number}`
  93. link.innerHTML = link.textContent
  94. if (link.parentElement.nodeName === 'SUP') {
  95. link.parentElement.replaceWith(link)
  96. }
  97. link.setAttribute('href', 'javascript:;')
  98. }
  99. })
  100. },
  101. hideFootnotes () {
  102. const links = this.$el.querySelectorAll('a')
  103. links.forEach((link, i) => {
  104. const number = parseInt(link.hash.replace('#', ''))
  105. if (!isNaN(number)) {
  106. link.classList.add('footnote-link')
  107. if (link.parentElement.nodeName === 'SUP') {
  108. link.parentElement.replaceWith(link)
  109. }
  110. }
  111. })
  112. },
  113. mountMedias () {
  114. const template = document.getElementById('expand-image-tmp')
  115. this.$el.querySelectorAll('.node-view-body-wrapper img').forEach(img => {
  116. const image = { id: img.dataset.entityUuid, url: img.src, alt: img.alt }
  117. const clone = document.importNode(template.content, true)
  118. const cloneImg = clone.querySelector('img')
  119. cloneImg.setAttribute('src', image.url)
  120. cloneImg.setAttribute('alt', image.alt)
  121. cloneImg.setAttribute('id', image.id)
  122. clone.querySelector('button').onclick = () => {
  123. this.onImageExpandClick(image)
  124. }
  125. img.parentElement.replaceWith(clone)
  126. })
  127. },
  128. onImageExpandClick (image) {
  129. this.image = image
  130. this.$bvModal.show('modal-image-' + this.node.id)
  131. },
  132. onFootnoteLinkClick (node, popoverBtnId) {
  133. this.$root.$emit('bv::hide::popover', popoverBtnId)
  134. this.$parent.$emit('open-node', getRelation(node))
  135. }
  136. },
  137. created () {
  138. if (this.mode === 'view' && this.node.notes) {
  139. // Query partial data for linked nodes in notes
  140. const ids = this.node.notes.filter(note => (note.links)).reduce((ids, note) => {
  141. return [...ids, ...note.links.map(link => link.id)]
  142. }, [])
  143. this.$store.dispatch('GET_NODES', { ids, dataLevel: 'initial' })
  144. }
  145. },
  146. mounted () {
  147. if (this.mode === 'view') {
  148. this.addFootnotes()
  149. this.mountMedias()
  150. } else {
  151. this.hideFootnotes()
  152. }
  153. }
  154. }
  155. </script>
  156. <style lang="scss">
  157. .node-view-body {
  158. width: 100%;
  159. img {
  160. display: block;
  161. max-width: 100%;
  162. max-height: 80vh;
  163. }
  164. font: {
  165. family: $font-family-text;
  166. line-height: inherit;
  167. }
  168. blockquote {
  169. padding-left: 2em;
  170. margin: 1.5em 0;
  171. font-size: .9em;
  172. @include media-breakpoint-up($size-bp) {
  173. font-size: .85em;
  174. }
  175. }
  176. pre {
  177. white-space: pre-wrap;
  178. }
  179. // Kit atelier
  180. &-wrapper ul:first-child {
  181. background-color: $black;
  182. color: $white;
  183. font-family: $font-family-base;
  184. font-size: 1rem;
  185. list-style: none;
  186. padding: .75rem;
  187. margin-top: 1rem;
  188. li {
  189. &:not(:last-of-type) {
  190. margin-bottom: .25rem;
  191. }
  192. p {
  193. margin: 0;
  194. }
  195. }
  196. }
  197. &-card &-wrapper ul:first-child {
  198. li {
  199. flex-basis: 100%;
  200. }
  201. strong {
  202. display: inline;
  203. }
  204. }
  205. @include media-breakpoint-up($size-bp) {
  206. font-size: 2rem;
  207. }
  208. &-view {
  209. padding: 0 $node-view-spacer-sm-x;
  210. font-size: 1.25rem;
  211. word-wrap: break-word;
  212. @include media-breakpoint-up($size-bp) {
  213. padding: 0 $node-view-spacer-x;
  214. &.node-view-body-ref {
  215. font-size: 2.6rem;
  216. }
  217. &.node-view-body-prod {
  218. font-size: 1.5rem;
  219. }
  220. }
  221. }
  222. &-card {
  223. padding: 0 $node-card-spacer-sm-x;
  224. font-size: 1.1rem;
  225. word-wrap: anywhere;
  226. @include media-breakpoint-up($size-bp) {
  227. font-size: 2rem;
  228. padding: 0 $node-card-spacer-x;
  229. }
  230. }
  231. &-card &-wrapper {
  232. @include line-clamp(3, 1.5em);
  233. }
  234. &-card#{&}-prod &-wrapper {
  235. @include line-clamp(4, 1.5em);
  236. }
  237. // To avoid weird ul rendering of kits extra infos
  238. .node-view-kit #{&}-card#{&}-prod &-wrapper {
  239. display: block;
  240. text-overflow: unset;
  241. }
  242. .footnote-link {
  243. display: inline-block;
  244. text-align: center;
  245. background-color: $black;
  246. color: $white;
  247. font-family: $font-family-text;
  248. font-weight: $font-weight-bold;
  249. font-size: 0.8em;
  250. text-decoration: none;
  251. border-radius: 1em;
  252. padding: 0 .5em;
  253. min-width: 1.25em;
  254. max-height: 1.4em;
  255. margin: 0 .2em;
  256. }
  257. &-card .footnote-link {
  258. display: none;
  259. }
  260. }
  261. .footnote {
  262. background-color: $black !important;
  263. color: $white;
  264. font-size: 1.25rem;
  265. @include media-breakpoint-up($size-bp) {
  266. font-size: 1.5rem;
  267. }
  268. h6 {
  269. font-size: inherit;
  270. }
  271. &-content,
  272. &-child-list {
  273. > :last-child {
  274. margin-bottom: 0;
  275. }
  276. }
  277. &-child-list {
  278. margin-top: .5rem;
  279. }
  280. }
  281. </style>