PhotoPresenter.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. <p v-if="!status.sensitive && sensitive"
  35. @click="status.sensitive = true"
  36. style="
  37. margin-top: 0;
  38. padding: 10px;
  39. color: #fff;
  40. font-size: 10px;
  41. text-align: right;
  42. position: absolute;
  43. top: 0;
  44. right: 0;
  45. border-top-left-radius: 5px;
  46. cursor: pointer;
  47. background: linear-gradient(0deg, rgba(0,0,0,0.5), rgba(0,0,0,0.5));
  48. ">
  49. <i class="fas fa-eye-slash fa-lg"></i>
  50. </p>
  51. <p
  52. v-if="status.media_attachments[0].license"
  53. style="
  54. margin-bottom: 0;
  55. padding: 0 5px;
  56. color: #fff;
  57. font-size: 10px;
  58. text-align: right;
  59. position: absolute;
  60. bottom: 0;
  61. right: 0;
  62. border-top-left-radius: 5px;
  63. background: linear-gradient(0deg, rgba(0,0,0,0.5), rgba(0,0,0,0.5));
  64. "><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>
  65. </div>
  66. </div>
  67. </template>
  68. <style type="text/css" scoped>
  69. .card-img-top {
  70. border-top-left-radius: 0 !important;
  71. border-top-right-radius: 0 !important;
  72. }
  73. .content-label-wrapper {
  74. position: relative;
  75. }
  76. .content-label {
  77. margin: 0;
  78. position: absolute;
  79. top:50%;
  80. left:50%;
  81. transform: translate(-50%, -50%);
  82. display: flex;
  83. flex-direction: column;
  84. align-items: center;
  85. justify-content: center;
  86. width: 100%;
  87. height: 100%;
  88. z-index: 2;
  89. background: rgba(0, 0, 0, 0.2)
  90. }
  91. </style>
  92. <script type="text/javascript">
  93. export default {
  94. props: ['status'],
  95. data() {
  96. return {
  97. sensitive: this.status.sensitive
  98. }
  99. },
  100. methods: {
  101. altText(status) {
  102. let desc = status.media_attachments[0].description;
  103. if(desc) {
  104. return desc;
  105. }
  106. return 'Photo was not tagged with any alt text.';
  107. },
  108. toggleContentWarning(status) {
  109. this.$emit('togglecw');
  110. },
  111. toggleLightbox() {
  112. this.$emit('lightbox');
  113. },
  114. width() {
  115. if( !this.status.media_attachments[0].meta ||
  116. !this.status.media_attachments[0].meta.original ||
  117. !this.status.media_attachments[0].meta.original.width ) {
  118. return;
  119. }
  120. return this.status.media_attachments[0].meta.original.width;
  121. },
  122. height() {
  123. if( !this.status.media_attachments[0].meta ||
  124. !this.status.media_attachments[0].meta.original ||
  125. !this.status.media_attachments[0].meta.original.height ) {
  126. return;
  127. }
  128. return this.status.media_attachments[0].meta.original.height;
  129. }
  130. }
  131. }
  132. </script>