commentform.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. $(document).ready(function() {
  2. $('.status-comment-focus').on('click', function(el) {
  3. var el = $(this).parents().eq(2).find('input[name="comment"]');
  4. el.focus();
  5. });
  6. $(document).on('submit', '.comment-form', function(e, data) {
  7. e.preventDefault();
  8. let el = $(this);
  9. let id = el.data('id');
  10. let commentform = el.find('input[name="comment"]');
  11. let commenttext = commentform.val();
  12. let item = {item: id, comment: commenttext};
  13. commentform.prop('disabled', true);
  14. axios.post('/i/comment', item)
  15. .then(function (res) {
  16. var username = res.data.username;
  17. var permalink = res.data.url;
  18. var profile = res.data.profile;
  19. if($('.status-container').length == 1) {
  20. var comments = el.parents().eq(3).find('.comments');
  21. } else {
  22. var comments = el.parents().eq(1).find('.comments');
  23. }
  24. 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">'+ commenttext + '</span><span class="float-right"><a href="' + permalink + '" class="text-dark small font-weight-bold">1s</a></span></p>';
  25. comments.prepend(comment);
  26. commentform.val('');
  27. commentform.blur();
  28. commentform.prop('disabled', false);
  29. })
  30. .catch(function (res) {
  31. });
  32. });
  33. });