1
0

commentform.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. axios.post('/i/comment', item)
  14. .then(function (res) {
  15. var username = res.data.username;
  16. var permalink = res.data.url;
  17. var profile = res.data.profile;
  18. if($('.status-container').length == 1) {
  19. var comments = el.parents().eq(3).find('.comments');
  20. } else {
  21. var comments = el.parents().eq(1).find('.comments');
  22. }
  23. 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>';
  24. comments.prepend(comment);
  25. commentform.val('');
  26. commentform.blur();
  27. })
  28. .catch(function (res) {
  29. });
  30. });
  31. });