PhotoAlbumPresenter.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 album 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 class="w-100 h-100 p-0 album-wrapper">
  25. <carousel ref="carousel" :centerMode="true" :loop="false" :per-page="1" :paginationPosition="'bottom-overlay'" paginationActiveColor="#3897f0" paginationColor="#dbdbdb" class="p-0 m-0" :id="'carousel-' + status.id">
  26. <slide v-for="(img, index) in status.media_attachments" :key="'px-carousel-'+img.id + '-' + index" class="" style="background: #000; display: flex;align-items: center;" :title="img.description">
  27. <img
  28. :class="img.filter_class + ' img-fluid w-100 p-0'"
  29. style=""
  30. :src="img.url"
  31. :alt="altText(img)"
  32. loading="lazy"
  33. :data-bp="img.url"
  34. onerror="this.onerror=null;this.src='/storage/no-preview.png'">
  35. </slide>
  36. </carousel>
  37. <div class="album-overlay">
  38. <p v-if="!status.sensitive && sensitive"
  39. @click="status.sensitive = true"
  40. style="
  41. margin-top: 0;
  42. padding: 10px;
  43. color: #fff;
  44. font-size: 10px;
  45. text-align: right;
  46. position: absolute;
  47. top: 0;
  48. right: 0;
  49. border-top-left-radius: 5px;
  50. cursor: pointer;
  51. background: linear-gradient(0deg, rgba(0,0,0,0.5), rgba(0,0,0,0.5));
  52. ">
  53. <i class="fas fa-eye-slash fa-lg"></i>
  54. </p>
  55. <p @click.prevent="toggleLightbox"
  56. style="
  57. margin-top: 0;
  58. padding: 10px;
  59. color: #fff;
  60. font-size: 10px;
  61. text-align: right;
  62. position: absolute;
  63. left: 0;
  64. top: 0;
  65. border-bottom-right-radius: 5px;
  66. cursor: pointer;
  67. background: linear-gradient(0deg, rgba(0,0,0,0.5), rgba(0,0,0,0.5));
  68. ">
  69. <i class="fas fa-expand fa-lg"></i>
  70. </p>
  71. <p
  72. v-if="status.media_attachments[0].license"
  73. style="
  74. margin-bottom: 0;
  75. padding: 0 5px;
  76. color: #fff;
  77. font-size: 10px;
  78. text-align: right;
  79. position: absolute;
  80. bottom: 0;
  81. right: 0;
  82. border-top-left-radius: 5px;
  83. background: linear-gradient(0deg, rgba(0,0,0,0.5), rgba(0,0,0,0.5));
  84. ">
  85. <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>
  86. </p>
  87. </div>
  88. </div>
  89. </template>
  90. <script type="text/javascript">
  91. import BigPicture from 'bigpicture';
  92. export default {
  93. props: ['status'],
  94. data() {
  95. return {
  96. sensitive: this.status.sensitive,
  97. cursor: 0
  98. }
  99. },
  100. created() {
  101. // window.addEventListener("keydown", this.keypressNavigation);
  102. },
  103. beforeDestroy() {
  104. // window.removeEventListener("keydown", this.keypressNavigation);
  105. },
  106. methods: {
  107. toggleContentWarning(status) {
  108. this.$emit('togglecw');
  109. },
  110. toggleLightbox(e) {
  111. BigPicture({
  112. el: e.target,
  113. gallery: '#carousel-' + this.status.id,
  114. position: this.$refs.carousel.currentPage
  115. })
  116. },
  117. altText(img) {
  118. let desc = img.description;
  119. if(desc) {
  120. return desc;
  121. }
  122. return 'Photo was not tagged with any alt text.';
  123. },
  124. keypressNavigation(e) {
  125. let ref = this.$refs.carousel;
  126. if (e.keyCode == "37") {
  127. e.preventDefault();
  128. let direction = "backward";
  129. ref.advancePage(direction);
  130. ref.$emit("navigation-click", direction);
  131. }
  132. if (e.keyCode == "39") {
  133. e.preventDefault();
  134. let direction = "forward";
  135. ref.advancePage(direction);
  136. ref.$emit("navigation-click", direction);
  137. }
  138. }
  139. }
  140. }
  141. </script>
  142. <style type="text/css" scoped>
  143. .card-img-top {
  144. border-top-left-radius: 0 !important;
  145. border-top-right-radius: 0 !important;
  146. }
  147. .content-label-wrapper {
  148. position: relative;
  149. }
  150. .content-label {
  151. margin: 0;
  152. position: absolute;
  153. top:50%;
  154. left:50%;
  155. transform: translate(-50%, -50%);
  156. display: flex;
  157. flex-direction: column;
  158. align-items: center;
  159. justify-content: center;
  160. width: 100%;
  161. height: 100%;
  162. z-index: 2;
  163. background: rgba(0, 0, 0, 0.2)
  164. }
  165. .album-wrapper {
  166. position: relative;
  167. }
  168. </style>