PostComponent.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <style>
  2. .carousel {
  3. position: relative;
  4. width: 600px;
  5. height: 400px;
  6. overflow: hidden;
  7. margin: 0 auto;
  8. }
  9. .carousel:hover .slide:after,
  10. .carousel:hover .counter,
  11. .carousel:hover .slide:before {
  12. opacity: 1;
  13. }
  14. .slide {
  15. float: right;
  16. position: absolute;
  17. z-index: 1;
  18. width: 600px;
  19. height: 400px;
  20. background-color: #fff;
  21. text-align: center;
  22. transition: opacity 0.4s;
  23. opacity: 1;
  24. }
  25. .slide:before {
  26. content: attr(annot);
  27. display: block;
  28. position: absolute;
  29. left: 20px;
  30. bottom: 20px;
  31. color: #fff;
  32. font-size: 14px;
  33. font-weight: bold;
  34. z-index: 12;
  35. opacity: 0;
  36. transition: opacity 0.3s;
  37. }
  38. .slide:after {
  39. content: attr(slide);
  40. display: block;
  41. position: absolute;
  42. bottom: 0;
  43. transition: opacity 0.3s;
  44. width: 100%;
  45. height: 80px;
  46. opacity: 0;
  47. background-image: linear-gradient(transparent, rgba(0,0,0,0.2));
  48. text-align: left;
  49. text-indent: 549px;
  50. line-height: 101px;
  51. font-size: 13px;
  52. color: #fff;
  53. font-weight: bold;
  54. }
  55. .counter {
  56. position: absolute;
  57. bottom: 20px;
  58. right: 2px;
  59. height: 20px;
  60. width: 60px;
  61. z-index: 2;
  62. text-align: center;
  63. color: #fff;
  64. line-height: 21px;
  65. font-size: 13px;
  66. font-weight: bold;
  67. opacity: 0;
  68. transition: opacity 0.3s;
  69. }
  70. .carousel-slide {
  71. top: 0;
  72. right: 0;
  73. float: right;
  74. position: absolute;
  75. margin-top: 0;
  76. z-index: 9;
  77. height: 100%;
  78. width: 100%;
  79. opacity: 0;
  80. cursor: pointer;
  81. }
  82. .carousel-slide:checked {
  83. z-index: 8;
  84. }
  85. .carousel-slide:checked + .slide {
  86. opacity: 0;
  87. }
  88. .carousel-slide:checked:nth-child(1):checked {
  89. z-index: 9;
  90. }
  91. .carousel-slide:nth-child(1):checked {
  92. float: left;
  93. z-index: 9;
  94. }
  95. .carousel-slide:nth-child(1):checked + .slide {
  96. opacity: 1;
  97. }
  98. .carousel-slide:nth-child(1):checked ~ .carousel-slide {
  99. float: left;
  100. z-index: 8;
  101. }
  102. .carousel-slide:nth-child(1):checked ~ .carousel-slide + .slide {
  103. opacity: 0;
  104. }
  105. .carousel-slide:nth-child(1):checked ~ .carousel-slide:checked {
  106. z-index: 9;
  107. }
  108. .carousel-slide:nth-child(1):checked ~ .carousel-slide:checked + .slide {
  109. opacity: 1;
  110. }
  111. </style>
  112. <template>
  113. <div class="postComponent">
  114. <div class="container px-0 mt-md-4">
  115. <div class="card card-md-rounded-0 status-container orientation-unknown">
  116. <div class="row mx-0">
  117. <div class="d-flex d-md-none align-items-center justify-content-between card-header bg-white w-100">
  118. <a :href="statusProfileUrl" class="d-flex align-items-center status-username text-truncate" data-toggle="tooltip" data-placement="bottom" :title="statusUsername">
  119. <div class="status-avatar mr-2">
  120. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;">
  121. </div>
  122. <div class="username">
  123. <span class="username-link font-weight-bold text-dark">{{ statusUsername }}</span>
  124. </div>
  125. </a>
  126. <div class="float-right">
  127. <!-- <div class="dropdown">
  128. <button class="btn btn-link text-dark no-caret dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Post options">
  129. <span class="fas fa-ellipsis-v text-muted"></span>
  130. </button>
  131. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  132. <a class="dropdown-item font-weight-bold" href="#">View Exif</a>
  133. <a class="dropdown-item font-weight-bold" href="{{$status->reportUrl()}}">Report</a>
  134. </div>
  135. </div> -->
  136. </div>
  137. </div>
  138. <div class="col-12 col-md-8 status-photo px-0">
  139. <div class="postPresenterLoader text-center">
  140. <div class="lds-ring"><div></div><div></div><div></div><div></div></div>
  141. </div>
  142. <div class="postPresenterContainer d-none">
  143. </div>
  144. </div>
  145. <div class="col-12 col-md-4 px-0 d-flex flex-column border-left border-md-left-0">
  146. <div class="d-md-flex d-none align-items-center justify-content-between card-header py-3 bg-white">
  147. <a :href="statusProfileUrl" class="d-flex align-items-center status-username text-truncate" data-toggle="tooltip" data-placement="bottom" :title="statusUsername">
  148. <div class="status-avatar mr-2">
  149. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;">
  150. </div>
  151. <div class="username">
  152. <span class="username-link font-weight-bold text-dark">{{ statusUsername }}</span>
  153. </div>
  154. </a>
  155. <div class="float-right">
  156. <div class="dropdown">
  157. <button class="btn btn-link text-dark no-caret dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Post options">
  158. <span class="fas fa-ellipsis-v text-muted"></span>
  159. </button>
  160. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  161. <a class="dropdown-item font-weight-bold show-exif">Show Exif</a>
  162. <a class="dropdown-item font-weight-bold" href="#">Report</a>
  163. </div>
  164. </div>
  165. </div>
  166. </div>
  167. <div class="d-flex flex-md-column flex-column-reverse h-100">
  168. <div class="card-body status-comments">
  169. <div class="status-comment">
  170. <p class="mb-1 read-more" style="overflow: hidden;">
  171. <span class="font-weight-bold pr-1">{{statusUsername}}</span>
  172. <span class="comment-text"></span>
  173. </p>
  174. <post-comments :post-id="statusId" :post-username="statusUsername"></post-comments>
  175. </div>
  176. </div>
  177. <div class="card-body flex-grow-0 py-1">
  178. <div class="reactions my-1">
  179. <form class="d-inline-flex pr-3 like-form" method="post" action="/i/like" style="display: inline;" :data-id="statusId" data-action="like">
  180. <input type="hidden" name="_token" value="">
  181. <input type="hidden" name="item" :value="statusId">
  182. <button class="btn btn-link text-dark p-0 border-0" type="submit" title="Like!">
  183. <h3 class="status-heart m-0 far fa-heart text-dark"></h3>
  184. </button>
  185. </form>
  186. <h3 class="far fa-comment pr-3 m-0" title="Comment"></h3>
  187. <form class="d-inline-flex share-form pr-3" method="post" action="/i/share" style="display: inline;" data-id="11todo" data-action="share" data-count="status.favourite_count">
  188. <input type="hidden" name="_token" value="">
  189. <input type="hidden" name="item" :value="statusId">
  190. <button class="btn btn-link text-dark p-0" type="submit" title="Share">
  191. <h3 class="m-0 far fa-share-square"></h3>
  192. </button>
  193. </form>
  194. <span class="float-right">
  195. <form class="d-inline-flex" method="post" action="/i/bookmark" style="display: inline;" data-id="#" data-action="bookmark" onclick="this.preventDefault()">
  196. <input type="hidden" name="_token" value="">
  197. <input type="hidden" name="item" value="#">
  198. <button class="btn btn-link text-dark p-0 border-0" type="submit" title="Save">
  199. <h3 class="m-0 far fa-bookmark"></h3>
  200. </button>
  201. </form>
  202. </span>
  203. </div>
  204. <div class="likes font-weight-bold mb-0">
  205. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  206. </div>
  207. <div class="timestamp">
  208. <a v-bind:href="statusUrl" class="small text-muted">
  209. {{timestampFormat()}}
  210. </a>
  211. </div>
  212. </div>
  213. </div>
  214. <div class="card-footer bg-white sticky-md-bottom">
  215. <form class="comment-form" method="post" action="/i/comment" :data-id="statusId" data-truncate="false">
  216. <input type="hidden" name="_token" value="">
  217. <input type="hidden" name="item" :value="statusId">
  218. <input class="form-control" name="comment" placeholder="Add a comment..." autocomplete="off">
  219. </form>
  220. </div>
  221. </div>
  222. </div>
  223. </div>
  224. </div>
  225. </div>
  226. </template>
  227. <script>
  228. pixelfed.postComponent = {};
  229. pixelfed.presenter = {
  230. show: {
  231. image: function(container, media) { console.log(234);
  232. let wrapper = $('<div>');
  233. wrapper.addClass(media[0]['filter_class']);
  234. let el = $('<img>');
  235. el.attr('src', media[0]['url']);
  236. el.attr('title', media[0]['description']);
  237. wrapper.append(el);
  238. container.append(wrapper);
  239. },
  240. video: function(container, media) {
  241. let wrapper = $('<div>');
  242. wrapper.addClass('embed-responsive embed-responsive-4by3');
  243. let el = $('<video>');
  244. el.addClass('embed-responsive-item');
  245. el.attr('controls', '');
  246. el.attr('src', media[0]['url']);
  247. el.attr('title', media[0]['description']);
  248. wrapper.append(el);
  249. container.append(wrapper);
  250. },
  251. imageAlbum: function(container, media) {
  252. let wrapper = $('<div>');
  253. wrapper.addClass('carousel');
  254. let counter = $('<div>');
  255. counter.attr('class', 'counter');
  256. counter.attr('count', media.length);
  257. counter.text(' / ' + media.length);
  258. for(var i = media.length - 1; i >= 0; i--) {
  259. let item = media[i];
  260. let carouselItem = $('<div>').addClass('slide d-flex align-items-center');
  261. carouselItem.attr('slide', i + 1);
  262. carouselItem.attr('annot', item.description);
  263. let check = $('<input>');
  264. check.attr('type', 'checkbox');
  265. check.attr('class', 'carousel-slide');
  266. let img = $('<img>');
  267. img.addClass('img-fluid');
  268. img.attr('src', item['url']);
  269. carouselItem.append(img);
  270. wrapper.append(check);
  271. wrapper.append(carouselItem);
  272. }
  273. wrapper.append(counter);
  274. container.append(wrapper);
  275. }
  276. }
  277. };
  278. export default {
  279. props: ['status-id', 'status-username', 'status-template', 'status-url', 'status-profile-url', 'status-avatar'],
  280. data() {
  281. return {
  282. status: {},
  283. media: {}
  284. }
  285. },
  286. mounted() {
  287. let token = $('meta[name="csrf-token"]').attr('content');
  288. $('input[name="_token"]').each(function(k, v) {
  289. let el = $(v);
  290. el.val(token);
  291. });
  292. this.fetchData();
  293. pixelfed.hydrateLikes();
  294. },
  295. methods: {
  296. timestampFormat() {
  297. let ts = new Date(this.status.created_at);
  298. return ts.toDateString();
  299. },
  300. fetchData() {
  301. let url = '/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId;
  302. axios.get(url)
  303. .then(response => {
  304. let self = this;
  305. self.status = response.data.status;
  306. self.media = self.status.media_attachments;
  307. this.buildPresenter();
  308. }).catch(error => {
  309. if(!error.response) {
  310. $('.postPresenterLoader .lds-ring').attr('style','width:100%').addClass('pt-4 font-weight-bold text-muted').text('An error occured, cannot fetch media. Please try again later.');
  311. } else {
  312. switch(error.response.status) {
  313. case 401:
  314. $('.postPresenterLoader .lds-ring')
  315. .attr('style','width:100%')
  316. .addClass('pt-4 font-weight-bold text-muted')
  317. .text('Please login to view.');
  318. break;
  319. default:
  320. $('.postPresenterLoader .lds-ring').attr('style','width:100%').addClass('pt-4 font-weight-bold text-muted').text('An error occured, cannot fetch media. Please try again later.');
  321. break;
  322. }
  323. }
  324. });
  325. },
  326. buildPresenter() {
  327. let container = $('.postPresenterContainer');
  328. let status = this.status;
  329. let media = this.media;
  330. $('.status-comment .comment-text').html(status.content);
  331. if(container.children().length != 0) {
  332. return;
  333. }
  334. switch(this.statusTemplate) {
  335. case 'image':
  336. pixelfed.presenter.show.image(container, media);
  337. break;
  338. case 'album':
  339. pixelfed.presenter.show.imageAlbum(container, media);
  340. $('.carousel').carousel();
  341. break;
  342. case 'video':
  343. pixelfed.presenter.show.video(container, media);
  344. break;
  345. default:
  346. $('.postPresenterLoader .lds-ring').attr('style','width:100%').addClass('pt-4 font-weight-bold text-muted').text('An error occured, cannot fetch media. Please try again later.');
  347. break;
  348. }
  349. if(container.children().length == 0) {
  350. $('.postPresenterLoader .lds-ring').attr('style','width:100%').addClass('pt-4 font-weight-bold text-muted').text('An error occured, cannot fetch media. Please try again later.');
  351. return;
  352. }
  353. pixelfed.readmore();
  354. $('.postPresenterLoader').addClass('d-none');
  355. $('.postPresenterContainer').removeClass('d-none');
  356. },
  357. }
  358. }
  359. </script>