PhotoPresenter.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 {
  56. margin: 0;
  57. position: absolute;
  58. top:50%;
  59. left:50%;
  60. z-index: 2;
  61. transform: translate(-50%, -50%);
  62. display: flex;
  63. flex-direction: column;
  64. align-items: center;
  65. justify-content: center;
  66. width: 100%;
  67. height: 100%;
  68. z-index: 2;
  69. background: rgba(0, 0, 0, 0.2)
  70. }
  71. </style>
  72. <script type="text/javascript">
  73. export default {
  74. props: ['status'],
  75. methods: {
  76. altText(status) {
  77. let desc = status.media_attachments[0].description;
  78. if(desc) {
  79. return desc;
  80. }
  81. return 'Photo was not tagged with any alt text.';
  82. },
  83. toggleContentWarning(status) {
  84. this.$emit('togglecw');
  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>