PhotoPresenter.vue 4.9 KB

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