NodeViewBody.vue 7.9 KB

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