NodeViewBody.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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
  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. return [...ids, ...note.links.map(link => link.id)]
  153. }, [])
  154. this.$store.dispatch('GET_NODES', { ids, dataLevel: 'initial' })
  155. }
  156. },
  157. mounted () {
  158. if (this.mode === 'view') {
  159. this.addFootnotes()
  160. this.mountMedias()
  161. } else {
  162. this.hideFootnotes()
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss">
  168. .node-view-body {
  169. width: 100%;
  170. img {
  171. display: block;
  172. max-width: 100%;
  173. max-height: 80vh;
  174. }
  175. font: {
  176. family: $font-family-text;
  177. line-height: inherit;
  178. }
  179. blockquote {
  180. padding-left: 2em;
  181. margin: 1.5em 0;
  182. font-size: .9em;
  183. @include media-breakpoint-up($size-bp) {
  184. font-size: .85em;
  185. }
  186. }
  187. pre {
  188. white-space: pre-wrap;
  189. }
  190. // Kit atelier
  191. &-wrapper ul:first-child {
  192. background-color: $black;
  193. color: $white;
  194. font-family: $font-family-base;
  195. font-size: 1rem;
  196. list-style: none;
  197. padding: .75rem;
  198. margin-top: 1rem;
  199. li {
  200. &:not(:last-of-type) {
  201. margin-bottom: .25rem;
  202. }
  203. p {
  204. margin: 0;
  205. }
  206. }
  207. }
  208. &-card &-wrapper ul:first-child {
  209. li {
  210. flex-basis: 100%;
  211. }
  212. strong {
  213. display: inline;
  214. }
  215. }
  216. @include media-breakpoint-up($size-bp) {
  217. font-size: 2rem;
  218. }
  219. &-view {
  220. padding: 0 $node-view-spacer-sm-x;
  221. font-size: 1.25rem;
  222. word-wrap: break-word;
  223. @include media-breakpoint-up($size-bp) {
  224. padding: 0 $node-view-spacer-x;
  225. &.node-view-body-ref {
  226. font-size: 2.6rem;
  227. }
  228. &.node-view-body-prod {
  229. font-size: 1.5rem;
  230. }
  231. }
  232. }
  233. &-card {
  234. padding: 0 $node-card-spacer-sm-x;
  235. font-size: 1.1rem;
  236. word-wrap: anywhere;
  237. @include media-breakpoint-up($size-bp) {
  238. font-size: 2rem;
  239. padding: 0 $node-card-spacer-x;
  240. }
  241. }
  242. &-card &-wrapper {
  243. @include line-clamp(3, 1.5em);
  244. }
  245. &-card#{&}-prod &-wrapper {
  246. @include line-clamp(4, 1.5em);
  247. }
  248. // To avoid weird ul rendering of kits extra infos
  249. .node-view-kit #{&}-card#{&}-prod &-wrapper {
  250. display: block;
  251. text-overflow: unset;
  252. }
  253. .footnote-link {
  254. display: inline-block;
  255. text-align: center;
  256. background-color: $black;
  257. color: $white;
  258. font-family: $font-family-text;
  259. font-weight: $font-weight-bold;
  260. font-size: 0.8em;
  261. text-decoration: none;
  262. border-radius: 1em;
  263. padding: 0 .5em;
  264. min-width: 1.25em;
  265. max-height: 1.4em;
  266. margin: 0 .2em;
  267. }
  268. &-card .footnote-link {
  269. display: none;
  270. }
  271. }
  272. .footnote {
  273. background-color: $black !important;
  274. color: $white;
  275. font-size: 1.25rem;
  276. @include media-breakpoint-up($size-bp) {
  277. font-size: 1.5rem;
  278. }
  279. h6 {
  280. font-size: inherit;
  281. }
  282. &-content,
  283. &-child-list {
  284. > :last-child {
  285. margin-bottom: 0;
  286. }
  287. }
  288. &-child-list {
  289. margin-top: .5rem;
  290. }
  291. }
  292. </style>