PhotoPresenter.vue 2.4 KB

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