commentform.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. $(document).ready(function() {
  2. $('.status-card > .card-footer').each(function() {
  3. $(this).addClass('d-none');
  4. });
  5. $(document).on('click', '.status-comment-focus', function(el) {
  6. var form = $(this).parents().eq(2).find('.card-footer');
  7. form.removeClass('d-none');
  8. var el = $(this).parents().eq(2).find('input[name="comment"]');
  9. el.focus();
  10. });
  11. $(document).on('submit', '.comment-form', function(e, data) {
  12. e.preventDefault();
  13. let el = $(this);
  14. let id = el.data('id');
  15. let commentform = el.find('input[name="comment"]');
  16. let commenttext = commentform.val();
  17. let item = {item: id, comment: commenttext};
  18. commentform.prop('disabled', true);
  19. axios.post('/i/comment', item)
  20. .then(function (res) {
  21. var username = res.data.username;
  22. var permalink = res.data.url;
  23. var profile = res.data.profile;
  24. var reply = res.data.comment;
  25. if($('.status-container').length == 1) {
  26. var comments = el.parents().eq(3).find('.comments');
  27. } else {
  28. var comments = el.parents().eq(1).find('.comments');
  29. }
  30. var comment = '<p class="mb-0"><span class="font-weight-bold pr-1"><bdi><a class="text-dark" href="' + profile + '">' + username + '</a></bdi></span><span class="comment-text">'+ reply + '</span></p>';
  31. comments.prepend(comment);
  32. commentform.val('');
  33. commentform.blur();
  34. commentform.prop('disabled', false);
  35. })
  36. .catch(function (res) {
  37. });
  38. });
  39. });