PhotoPresenter.vue 3.1 KB

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