PhotoAlbumPresenter.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div v-if="status.sensitive == true">
  3. <details class="details-animated">
  4. <summary @click="loadSensitive">
  5. <p class="mb-0 lead font-weight-bold">{{ status.spoiler_text ? status.spoiler_text : 'CW / NSFW / Hidden Media'}}</p>
  6. <p class="font-weight-light">(click to show)</p>
  7. </summary>
  8. <carousel ref="carousel" :centerMode="true" :loop="false" :per-page="1" :paginationPosition="'bottom-overlay'" paginationActiveColor="#3897f0" paginationColor="#dbdbdb">
  9. <slide v-for="(img, index) in status.media_attachments" :key="'px-carousel-'+img.id + '-' + index" class="w-100 h-100 d-block mx-auto text-center" :title="img.description">
  10. <img :class="img.filter_class + ' img-fluid'" :src="img.url" :alt="altText(img)" onerror="this.onerror=null;this.src='/storage/no-preview.png'">
  11. <p
  12. v-if="status.media_attachments[0].license"
  13. style="
  14. margin-bottom: 0;
  15. padding: 0 5px;
  16. color: #fff;
  17. font-size: 10px;
  18. text-align: right;
  19. position: absolute;
  20. bottom: 0;
  21. right: 0;
  22. border-top-left-radius: 5px;
  23. background: linear-gradient(0deg, rgba(0,0,0,0.5), rgba(0,0,0,0.5));
  24. "><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>
  25. </slide>
  26. </carousel>
  27. </details>
  28. </div>
  29. <div v-else class="w-100 h-100 p-0">
  30. <carousel ref="carousel" :centerMode="true" :loop="false" :per-page="1" :paginationPosition="'bottom-overlay'" paginationActiveColor="#3897f0" paginationColor="#dbdbdb" class="p-0 m-0">
  31. <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">
  32. <img :class="img.filter_class + ' img-fluid w-100 p-0'" style="" :src="img.url" :alt="altText(img)" 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. </slide>
  48. </carousel>
  49. </div>
  50. </template>
  51. <style type="text/css" scoped>
  52. .card-img-top {
  53. border-top-left-radius: 0 !important;
  54. border-top-right-radius: 0 !important;
  55. }
  56. </style>
  57. <script type="text/javascript">
  58. export default {
  59. props: ['status'],
  60. data() {
  61. return {
  62. cursor: 0
  63. }
  64. },
  65. created() {
  66. // window.addEventListener("keydown", this.keypressNavigation);
  67. },
  68. beforeDestroy() {
  69. // window.removeEventListener("keydown", this.keypressNavigation);
  70. },
  71. methods: {
  72. loadSensitive() {
  73. this.$refs.carousel.onResize();
  74. this.$refs.carousel.goToPage(0);
  75. },
  76. altText(img) {
  77. let desc = img.description;
  78. if(desc) {
  79. return desc;
  80. }
  81. return 'Photo was not tagged with any alt text.';
  82. },
  83. keypressNavigation(e) {
  84. let ref = this.$refs.carousel;
  85. if (e.keyCode == "37") {
  86. e.preventDefault();
  87. let direction = "backward";
  88. ref.advancePage(direction);
  89. ref.$emit("navigation-click", direction);
  90. }
  91. if (e.keyCode == "39") {
  92. e.preventDefault();
  93. let direction = "forward";
  94. ref.advancePage(direction);
  95. ref.$emit("navigation-click", direction);
  96. }
  97. }
  98. }
  99. }
  100. </script>