PageView.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template lang="html">
  2. <div class="page" :class="'page-' + slug">
  3. <div class="btn-close-wrapper">
  4. <button-close @click="$emit('close')" />
  5. </div>
  6. <div class="page-wrapper" v-html="page.content" />
  7. </div>
  8. </template>
  9. <script>
  10. export default {
  11. name: 'PageView',
  12. props: {
  13. page: { type: Object, default: undefined },
  14. slug: { type: String, required: true }
  15. },
  16. methods: {
  17. addFootnotes () {
  18. const links = this.$el.querySelectorAll('.page-wrapper a')
  19. links.forEach((link, i) => {
  20. const number = parseInt(link.hash.replace('#', ''))
  21. if (!isNaN(number) && this.page.notes.find(note => note.number === number)) {
  22. link.classList.add('page-footnote-link')
  23. link.id = `footnote-${this.slug}-${number}`
  24. link.setAttribute('href', 'javascript:;')
  25. link.dataset.number = number
  26. link.textContent = i + 1
  27. if (link.parentElement.nodeName === 'SUP') {
  28. link.parentElement.replaceWith(link)
  29. }
  30. link.onclick = this.onFootnoteLinkClick
  31. this.addFootnoteContent(link, number)
  32. }
  33. })
  34. },
  35. addFootnoteContent (link, i) {
  36. const noteContainer = document.createElement('DIV')
  37. noteContainer.classList.add('page-footnote-content')
  38. noteContainer.id = link.id + '-content'
  39. noteContainer.innerHTML = this.page.notes.find(note => note.number === i).content
  40. link.insertAdjacentElement('afterend', noteContainer)
  41. },
  42. onFootnoteLinkClick (e) {
  43. const container = document.getElementById(e.target.id + '-content')
  44. if (container) {
  45. container.classList.toggle('show')
  46. }
  47. }
  48. },
  49. mounted () {
  50. if (this.page.notes) this.addFootnotes()
  51. }
  52. }
  53. </script>
  54. <style lang="scss">
  55. .page {
  56. font-size: 1rem;
  57. position: relative;
  58. .btn-close-wrapper {
  59. position: sticky;
  60. z-index: 2;
  61. float: right;
  62. height: 0;
  63. right: 0;
  64. top: $node-view-spacer-sm-y;
  65. @include media-breakpoint-up($size-bp) {
  66. top: $node-view-spacer-y;
  67. }
  68. .btn-close {
  69. position: absolute;
  70. padding: 0.5rem;
  71. width: 2.25rem;
  72. height: 2.25rem;
  73. top: -.5rem;
  74. right: -.5rem;
  75. background-color: $white;
  76. }
  77. }
  78. @include media-breakpoint-up($size-bp) {
  79. font-size: 1.5rem;
  80. }
  81. padding: $node-view-spacer-sm-y $node-view-spacer-sm-x;
  82. @include media-breakpoint-up($size-bp) {
  83. padding: $node-view-spacer-y $node-view-spacer-x;
  84. }
  85. p {
  86. margin-bottom: 1em;
  87. }
  88. blockquote {
  89. margin: 0 0 50px 50px;
  90. @include media-breakpoint-up($size-bp) {
  91. margin: 50px 0 110px 180px;
  92. }
  93. }
  94. &-footnote-link {
  95. display: inline-block;
  96. text-align: center;
  97. background-color: $black;
  98. color: $white;
  99. font-weight: $font-weight-bold;
  100. font-size: 0.8em;
  101. font-style: normal;
  102. text-decoration: none;
  103. border-radius: 1em;
  104. padding: 0 .5em;
  105. min-width: 1.25em;
  106. max-height: 1.4em;
  107. margin: 0 .2em;
  108. &:hover,
  109. &:active {
  110. color: $white;
  111. text-decoration: none;
  112. }
  113. }
  114. &-footnote-content {
  115. background-color: $black;
  116. color: $white;
  117. font-size: 1.5rem;
  118. font-style: normal;
  119. padding: $node-view-spacer-sm-y $node-view-spacer-sm-x;
  120. margin: $node-view-spacer-sm-y 0;
  121. @include media-breakpoint-up($size-bp) {
  122. padding: $node-view-spacer-y $node-view-spacer-x;
  123. margin: $node-view-spacer-y 0;
  124. }
  125. // @include media-breakpoint-up(lg) {
  126. // max-width: 50%;
  127. // }
  128. &:not(.show) {
  129. display: none;
  130. }
  131. p:last-of-type {
  132. margin-bottom: 0;
  133. }
  134. blockquote {
  135. margin: 0 0 1em 2em;
  136. }
  137. }
  138. }
  139. </style>