PhotoPresenter.vue 3.6 KB

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