PostComponent.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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="post-actions d-none">
  128. <div class="dropdown">
  129. <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">
  130. <span class="fas fa-ellipsis-v text-muted"></span>
  131. </button>
  132. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  133. <a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
  134. <div class="dropdown-divider"></div>
  135. <form method="post" action="/i/mute">
  136. <input type="hidden" name="_token" value="">
  137. <input type="hidden" name="type" value="user">
  138. <input type="hidden" name="item" value="">
  139. <button type="submit" class="dropdown-item btn btn-link font-weight-bold">Mute this user</button>
  140. </form>
  141. <form method="post" action="/i/block">
  142. <input type="hidden" name="_token" value="">
  143. <input type="hidden" name="type" value="user">
  144. <input type="hidden" name="item" value="">
  145. <button type="submit" class="dropdown-item btn btn-link font-weight-bold">Block this user</button>
  146. </form>
  147. </div>
  148. </div>
  149. </div>
  150. </div>
  151. </div>
  152. <div class="col-12 col-md-8 status-photo px-0">
  153. <div class="postPresenterLoader text-center">
  154. <div class="lds-ring"><div></div><div></div><div></div><div></div></div>
  155. </div>
  156. <div class="postPresenterContainer d-none">
  157. </div>
  158. </div>
  159. <div class="col-12 col-md-4 px-0 d-flex flex-column border-left border-md-left-0">
  160. <div class="d-md-flex d-none align-items-center justify-content-between card-header py-3 bg-white">
  161. <a :href="statusProfileUrl" class="d-flex align-items-center status-username text-truncate" data-toggle="tooltip" data-placement="bottom" :title="statusUsername">
  162. <div class="status-avatar mr-2">
  163. <img :src="statusAvatar" width="24px" height="24px" style="border-radius:12px;">
  164. </div>
  165. <div class="username">
  166. <span class="username-link font-weight-bold text-dark">{{ statusUsername }}</span>
  167. </div>
  168. </a>
  169. <div class="float-right">
  170. <div class="post-actions d-none">
  171. <div class="dropdown">
  172. <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">
  173. <span class="fas fa-ellipsis-v text-muted"></span>
  174. </button>
  175. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
  176. <a class="dropdown-item font-weight-bold" :href="reportUrl()">Report</a>
  177. <div class="dropdown-divider"></div>
  178. <form method="post" action="/i/mute">
  179. <input type="hidden" name="_token" value="">
  180. <input type="hidden" name="type" value="user">
  181. <input type="hidden" name="item" value="">
  182. <button type="submit" class="dropdown-item btn btn-link font-weight-bold">Mute this user</button>
  183. </form>
  184. <form method="post" action="/i/block">
  185. <input type="hidden" name="_token" value="">
  186. <input type="hidden" name="type" value="user">
  187. <input type="hidden" name="item" value="">
  188. <button type="submit" class="dropdown-item btn btn-link font-weight-bold">Block this user</button>
  189. </form>
  190. </div>
  191. </div>
  192. </div>
  193. </div>
  194. </div>
  195. <div class="d-flex flex-md-column flex-column-reverse h-100">
  196. <div class="card-body status-comments">
  197. <div class="status-comment">
  198. <p class="mb-1 read-more" style="overflow: hidden;">
  199. <span class="font-weight-bold pr-1">{{statusUsername}}</span>
  200. <span class="comment-text"></span>
  201. </p>
  202. <post-comments :user="this.user" :post-id="statusId" :post-username="statusUsername"></post-comments>
  203. </div>
  204. </div>
  205. <div class="card-body flex-grow-0 py-1">
  206. <div class="reactions my-1">
  207. <form class="d-inline-flex pr-3 like-form" method="post" action="/i/like" style="display: inline;" :data-id="statusId" data-action="like">
  208. <input type="hidden" name="_token" value="">
  209. <input type="hidden" name="item" :value="statusId">
  210. <button class="btn btn-link text-dark p-0 border-0" type="submit" title="Like!">
  211. <h3 class="status-heart m-0 far fa-heart text-dark"></h3>
  212. </button>
  213. </form>
  214. <h3 class="far fa-comment pr-3 m-0" title="Comment"></h3>
  215. <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">
  216. <input type="hidden" name="_token" value="">
  217. <input type="hidden" name="item" :value="statusId">
  218. <button class="btn btn-link text-dark p-0" type="submit" title="Share">
  219. <h3 class="m-0 far fa-share-square"></h3>
  220. </button>
  221. </form>
  222. <span class="float-right">
  223. <form class="d-inline-flex" method="post" action="/i/bookmark" style="display: inline;" data-id="#" data-action="bookmark" onclick="this.preventDefault()">
  224. <input type="hidden" name="_token" value="">
  225. <input type="hidden" name="item" value="#">
  226. <button class="btn btn-link text-dark p-0 border-0" type="submit" title="Save">
  227. <h3 class="m-0 far fa-bookmark"></h3>
  228. </button>
  229. </form>
  230. </span>
  231. </div>
  232. <div class="likes font-weight-bold mb-0">
  233. <span class="like-count">{{status.favourites_count || 0}}</span> likes
  234. </div>
  235. <div class="timestamp">
  236. <a v-bind:href="statusUrl" class="small text-muted">
  237. {{timestampFormat()}}
  238. </a>
  239. </div>
  240. </div>
  241. </div>
  242. <div class="card-footer bg-white sticky-md-bottom">
  243. <div class="comment-form-guest">
  244. <a href="/login">Login</a> to like or comment.
  245. </div>
  246. <form class="comment-form d-none" method="post" action="/i/comment" :data-id="statusId" data-truncate="false">
  247. <input type="hidden" name="_token" value="">
  248. <input type="hidden" name="item" :value="statusId">
  249. <input class="form-control" name="comment" placeholder="Add a comment..." autocomplete="off">
  250. </form>
  251. </div>
  252. </div>
  253. </div>
  254. </div>
  255. </div>
  256. </div>
  257. </template>
  258. <script>
  259. pixelfed.postComponent = {};
  260. pixelfed.presenter = {
  261. show: {
  262. image: function(container, media) {
  263. let wrapper = $('<div>');
  264. wrapper.addClass(media[0]['filter_class']);
  265. let el = $('<img>');
  266. el.attr('src', media[0]['url']);
  267. el.attr('title', media[0]['description']);
  268. wrapper.append(el);
  269. container.append(wrapper);
  270. },
  271. video: function(container, media) {
  272. let wrapper = $('<div>');
  273. wrapper.addClass('embed-responsive embed-responsive-4by3');
  274. let el = $('<video>');
  275. el.addClass('embed-responsive-item');
  276. el.attr('controls', '');
  277. el.attr('src', media[0]['url']);
  278. el.attr('title', media[0]['description']);
  279. wrapper.append(el);
  280. container.append(wrapper);
  281. },
  282. imageAlbum: function(container, media) {
  283. let wrapper = $('<div>');
  284. wrapper.addClass('carousel');
  285. let counter = $('<div>');
  286. counter.attr('class', 'counter');
  287. counter.attr('count', media.length);
  288. counter.text(' / ' + media.length);
  289. for(var i = media.length - 1; i >= 0; i--) {
  290. let item = media[i];
  291. let carouselItem = $('<div>').addClass('slide d-flex align-items-center');
  292. carouselItem.attr('slide', i + 1);
  293. carouselItem.attr('annot', item.description);
  294. let check = $('<input>');
  295. check.attr('type', 'checkbox');
  296. check.attr('class', 'carousel-slide');
  297. let img = $('<img>');
  298. img.addClass('img-fluid');
  299. img.attr('src', item['url']);
  300. carouselItem.append(img);
  301. wrapper.append(check);
  302. wrapper.append(carouselItem);
  303. }
  304. wrapper.append(counter);
  305. container.append(wrapper);
  306. }
  307. }
  308. };
  309. export default {
  310. props: ['status-id', 'status-username', 'status-template', 'status-url', 'status-profile-url', 'status-avatar'],
  311. data() {
  312. return {
  313. status: {},
  314. media: {},
  315. user: {}
  316. }
  317. },
  318. mounted() {
  319. let token = $('meta[name="csrf-token"]').attr('content');
  320. $('input[name="_token"]').each(function(k, v) {
  321. let el = $(v);
  322. el.val(token);
  323. });
  324. this.fetchData();
  325. pixelfed.hydrateLikes();
  326. this.authCheck();
  327. },
  328. methods: {
  329. authCheck() {
  330. let authed = $('body').hasClass('loggedIn');
  331. if(authed == true) {
  332. $('.comment-form-guest').addClass('d-none');
  333. $('.comment-form').removeClass('d-none');
  334. }
  335. },
  336. showMuteBlock() {
  337. let sid = this.status.account.id;
  338. let uid = this.user.id;
  339. if(sid != uid) {
  340. $('.post-actions').removeClass('d-none');
  341. }
  342. },
  343. reportUrl() {
  344. return '/i/report?type=post&id=' + this.status.id;
  345. },
  346. timestampFormat() {
  347. let ts = new Date(this.status.created_at);
  348. return ts.toDateString();
  349. },
  350. fetchData() {
  351. let url = '/api/v2/profile/'+this.statusUsername+'/status/'+this.statusId;
  352. axios.get(url)
  353. .then(response => {
  354. let self = this;
  355. self.status = response.data.status;
  356. self.user = response.data.user;
  357. self.media = self.status.media_attachments;
  358. this.buildPresenter();
  359. this.showMuteBlock();
  360. }).catch(error => {
  361. if(!error.response) {
  362. $('.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.');
  363. } else {
  364. switch(error.response.status) {
  365. case 401:
  366. $('.postPresenterLoader .lds-ring')
  367. .attr('style','width:100%')
  368. .addClass('pt-4 font-weight-bold text-muted')
  369. .text('Please login to view.');
  370. break;
  371. default:
  372. $('.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.');
  373. break;
  374. }
  375. }
  376. });
  377. },
  378. buildPresenter() {
  379. let container = $('.postPresenterContainer');
  380. let status = this.status;
  381. let media = this.media;
  382. $('input[name="item"]').each(function(k, v) {
  383. let el = $(v);
  384. el.val(status.account.id);
  385. });
  386. $('.status-comment .comment-text').html(status.content);
  387. if(container.children().length != 0) {
  388. return;
  389. }
  390. switch(this.statusTemplate) {
  391. case 'image':
  392. pixelfed.presenter.show.image(container, media);
  393. break;
  394. case 'album':
  395. pixelfed.presenter.show.imageAlbum(container, media);
  396. $('.carousel').carousel();
  397. break;
  398. case 'video':
  399. pixelfed.presenter.show.video(container, media);
  400. break;
  401. default:
  402. $('.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.');
  403. break;
  404. }
  405. if(container.children().length == 0) {
  406. $('.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.');
  407. return;
  408. }
  409. pixelfed.readmore();
  410. $('.postPresenterLoader').addClass('d-none');
  411. $('.postPresenterContainer').removeClass('d-none');
  412. },
  413. }
  414. }
  415. </script>