NodeViewBody.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. <embed-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="getLinkObj(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 hovered
  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. getLinkObj (link) {
  93. if (link.preTitle || link.italTitle) return link
  94. if (link.type === 'prod' && link.parents && link.parents.length) return link.parents[0]
  95. return link
  96. },
  97. addFootnotes () {
  98. const links = this.$el.querySelectorAll('a')
  99. links.forEach((link, i) => {
  100. const number = parseInt(link.hash.replace('#', ''))
  101. if (!isNaN(number)) {
  102. link.classList.add('footnote-link')
  103. link.id = `note-${this.node.id}-${number}`
  104. link.innerHTML = link.textContent
  105. if (link.parentElement.nodeName === 'SUP') {
  106. link.parentElement.replaceWith(link)
  107. }
  108. link.setAttribute('href', 'javascript:;')
  109. }
  110. })
  111. },
  112. hideFootnotes () {
  113. const links = this.$el.querySelectorAll('a')
  114. links.forEach((link, i) => {
  115. const number = parseInt(link.hash.replace('#', ''))
  116. if (!isNaN(number)) {
  117. link.classList.add('footnote-link')
  118. if (link.parentElement.nodeName === 'SUP') {
  119. link.parentElement.replaceWith(link)
  120. }
  121. }
  122. })
  123. },
  124. mountMedias () {
  125. const template = document.getElementById('expand-image-tmp')
  126. this.$el.querySelectorAll('.node-view-body-wrapper img').forEach(img => {
  127. const image = { id: img.dataset.entityUuid, url: img.src, alt: img.alt }
  128. const clone = document.importNode(template.content, true)
  129. const cloneImg = clone.querySelector('img')
  130. cloneImg.setAttribute('src', image.url)
  131. cloneImg.setAttribute('alt', image.alt)
  132. cloneImg.setAttribute('id', image.id)
  133. clone.querySelector('button').onclick = () => {
  134. this.onImageExpandClick(image)
  135. }
  136. img.parentElement.replaceWith(clone)
  137. })
  138. },
  139. onImageExpandClick (image) {
  140. this.image = image
  141. this.$bvModal.show('modal-image-' + this.node.id)
  142. },
  143. onFootnoteLinkClick (node, popoverBtnId) {
  144. this.$root.$emit('bv::hide::popover', popoverBtnId)
  145. this.$parent.$emit('open-node', getRelation(node))
  146. }
  147. },
  148. created () {
  149. if (this.mode === 'view' && this.node.notes) {
  150. // Query partial data for linked nodes in notes
  151. const ids = this.node.notes.filter(note => (note.links)).reduce((ids, note) => {
  152. note.links.forEach((link) => {
  153. ids.push(link.id)
  154. if (link.parents && link.parents.length) {
  155. ids.push(link.parents[0].id)
  156. }
  157. })
  158. return ids
  159. }, [])
  160. this.$store.dispatch('GET_NODES', { ids, dataLevel: 'initial' })
  161. }
  162. },
  163. mounted () {
  164. if (this.mode === 'view') {
  165. this.addFootnotes()
  166. this.mountMedias()
  167. } else {
  168. this.hideFootnotes()
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="scss">
  174. .node-view-body {
  175. width: 100%;
  176. img {
  177. display: block;
  178. max-width: 100%;
  179. max-height: 80vh;
  180. }
  181. font: {
  182. family: $font-family-text;
  183. line-height: inherit;
  184. }
  185. blockquote {
  186. padding-left: 2em;
  187. margin: 1.5em 0;
  188. font-size: .9em;
  189. @include media-breakpoint-up($size-bp) {
  190. font-size: .85em;
  191. }
  192. }
  193. pre {
  194. white-space: pre-wrap;
  195. }
  196. // Kit atelier
  197. &-wrapper ul:first-child {
  198. background-color: $black;
  199. color: $white;
  200. font-family: $font-family-base;
  201. font-size: 1rem;
  202. list-style: none;
  203. padding: .75rem;
  204. margin-top: 1rem;
  205. li {
  206. &:not(:last-of-type) {
  207. margin-bottom: .25rem;
  208. }
  209. p {
  210. margin: 0;
  211. }
  212. }
  213. }
  214. &-card &-wrapper ul:first-child {
  215. li {
  216. flex-basis: 100%;
  217. }
  218. strong {
  219. display: inline;
  220. }
  221. }
  222. @include media-breakpoint-up($size-bp) {
  223. font-size: 2rem;
  224. }
  225. &-view {
  226. padding: 0 $node-view-spacer-sm-x;
  227. font-size: 1.25rem;
  228. word-wrap: break-word;
  229. @include media-breakpoint-up($size-bp) {
  230. padding: 0 $node-view-spacer-x;
  231. &.node-view-body-ref {
  232. font-size: 2.6rem;
  233. }
  234. &.node-view-body-prod {
  235. font-size: 1.5rem;
  236. }
  237. }
  238. }
  239. &-card {
  240. padding: 0 $node-card-spacer-sm-x;
  241. font-size: 1.1rem;
  242. word-wrap: anywhere;
  243. @include media-breakpoint-up($size-bp) {
  244. font-size: 2rem;
  245. padding: 0 $node-card-spacer-x;
  246. }
  247. }
  248. &-card &-wrapper {
  249. @include line-clamp(3, 1.5em);
  250. }
  251. &-card#{&}-prod &-wrapper {
  252. @include line-clamp(4, 1.5em);
  253. }
  254. // To avoid weird ul rendering of kits extra infos
  255. .node-view-kit #{&}-card#{&}-prod &-wrapper {
  256. display: block;
  257. text-overflow: unset;
  258. }
  259. .footnote-link {
  260. display: inline-block;
  261. text-align: center;
  262. background-color: $black;
  263. color: $white;
  264. font-family: $font-family-text;
  265. font-weight: $font-weight-bold;
  266. font-size: 0.8em;
  267. text-decoration: none;
  268. border-radius: 1em;
  269. padding: 0 .5em;
  270. min-width: 1.25em;
  271. max-height: 1.4em;
  272. margin: 0 .2em;
  273. }
  274. &-card .footnote-link {
  275. display: none;
  276. }
  277. }
  278. .footnote {
  279. background-color: $black !important;
  280. color: $white;
  281. font-size: 1.25rem;
  282. @include media-breakpoint-up($size-bp) {
  283. font-size: 1.5rem;
  284. }
  285. h6 {
  286. font-size: inherit;
  287. }
  288. &-content,
  289. &-child-list {
  290. > :last-child {
  291. margin-bottom: 0;
  292. }
  293. }
  294. &-child-list {
  295. margin-top: .5rem;
  296. }
  297. }
  298. </style>