PhotoPresenter.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div v-if="status.sensitive == true" class="content-label-wrapper">
  3. <div class="text-light content-label">
  4. <p class="text-center">
  5. <i class="far fa-eye-slash fa-2x"></i>
  6. </p>
  7. <p class="h4 font-weight-bold text-center">
  8. Sensitive Content
  9. </p>
  10. <p class="text-center py-2">
  11. {{ status.spoiler_text ? status.spoiler_text : 'This post may contain sensitive content.'}}
  12. </p>
  13. <p class="mb-0">
  14. <button @click="toggleContentWarning()" class="btn btn-outline-light btn-block btn-sm font-weight-bold">See Post</button>
  15. </p>
  16. </div>
  17. <blur-hash-image
  18. width="32"
  19. height="32"
  20. :punch="1"
  21. :hash="status.media_attachments[0].blurhash"
  22. :alt="altText(status)"/>
  23. </div>
  24. <div v-else>
  25. <div :title="status.media_attachments[0].description" style="position: relative;">
  26. <img class="card-img-top"
  27. :src="status.media_attachments[0].url"
  28. loading="lazy"
  29. :alt="altText(status)"
  30. :width="width()"
  31. :height="height()"
  32. onerror="this.onerror=null;this.src='/storage/no-preview.png'"
  33. @click.prevent="toggleLightbox">
  34. <!-- <blur-hash-image
  35. class="card-img-top"
  36. width="32"
  37. height="32"
  38. :punch="1"
  39. :hash="status.media_attachments[0].blurhash"
  40. :src="status.media_attachments[0].url"
  41. :alt="altText(status)"
  42. @click.prevent="toggleLightbox"/> -->
  43. <p v-if="!status.sensitive && sensitive"
  44. @click="status.sensitive = true"
  45. style="
  46. margin-top: 0;
  47. padding: 10px;
  48. color: #fff;
  49. font-size: 10px;
  50. text-align: right;
  51. position: absolute;
  52. top: 0;
  53. right: 0;
  54. border-top-left-radius: 5px;
  55. cursor: pointer;
  56. background: linear-gradient(0deg, rgba(0,0,0,0.5), rgba(0,0,0,0.5));
  57. ">
  58. <i class="fas fa-eye-slash fa-lg"></i>
  59. </p>
  60. <p
  61. v-if="status.media_attachments[0].license"
  62. style="
  63. margin-bottom: 0;
  64. padding: 0 5px;
  65. color: #fff;
  66. font-size: 10px;
  67. text-align: right;
  68. position: absolute;
  69. bottom: 0;
  70. right: 0;
  71. border-top-left-radius: 5px;
  72. background: linear-gradient(0deg, rgba(0,0,0,0.5), rgba(0,0,0,0.5));
  73. "><a :href="status.url" class="font-weight-bold text-light">Photo</a> by <a :href="status.account.url" class="font-weight-bold text-light">&commat;{{status.account.username}}</a> licensed under <a :href="status.media_attachments[0].license.url" class="font-weight-bold text-light">{{status.media_attachments[0].license.title}}</a></p>
  74. </div>
  75. </div>
  76. </template>
  77. <style type="text/css" scoped>
  78. .card-img-top {
  79. border-top-left-radius: 0 !important;
  80. border-top-right-radius: 0 !important;
  81. }
  82. .content-label-wrapper {
  83. position: relative;
  84. }
  85. .content-label {
  86. margin: 0;
  87. position: absolute;
  88. top:50%;
  89. left:50%;
  90. transform: translate(-50%, -50%);
  91. display: flex;
  92. flex-direction: column;
  93. align-items: center;
  94. justify-content: center;
  95. width: 100%;
  96. height: 100%;
  97. z-index: 2;
  98. background: rgba(0, 0, 0, 0.2)
  99. }
  100. </style>
  101. <script type="text/javascript">
  102. import BigPicture from 'bigpicture';
  103. export default {
  104. props: ['status'],
  105. data() {
  106. return {
  107. sensitive: this.status.sensitive
  108. }
  109. },
  110. mounted() {
  111. },
  112. methods: {
  113. altText(status) {
  114. let desc = status.media_attachments[0].description;
  115. if(desc) {
  116. return desc;
  117. }
  118. return 'Photo was not tagged with any alt text.';
  119. },
  120. toggleContentWarning(status) {
  121. this.$emit('togglecw');
  122. },
  123. toggleLightbox(e) {
  124. BigPicture({
  125. el: e.target
  126. })
  127. },
  128. width() {
  129. if( !this.status.media_attachments[0].meta ||
  130. !this.status.media_attachments[0].meta.original ||
  131. !this.status.media_attachments[0].meta.original.width ) {
  132. return;
  133. }
  134. return this.status.media_attachments[0].meta.original.width;
  135. },
  136. height() {
  137. if( !this.status.media_attachments[0].meta ||
  138. !this.status.media_attachments[0].meta.original ||
  139. !this.status.media_attachments[0].meta.original.height ) {
  140. return;
  141. }
  142. return this.status.media_attachments[0].meta.original.height;
  143. }
  144. }
  145. }
  146. </script>