commentform.js 738 B

12345678910111213141516171819202122232425
  1. $(document).ready(function() {
  2. $('.comment-form').submit(function(e, data) {
  3. e.preventDefault();
  4. let el = $(this);
  5. let id = el.data('id');
  6. let commentform = el.find('input[name="comment"]');
  7. let commenttext = commentform.val();
  8. let item = {item: id, comment: commenttext};
  9. try {
  10. axios.post('/i/comment', item);
  11. var comments = el.parent().parent().find('.comments');
  12. var comment = '<p class="mb-0"><span class="font-weight-bold pr-1">' + pixelfed.user.username + '</span><span class="comment-text">'+ commenttext + '</span></p>';
  13. comments.prepend(comment);
  14. commentform.val('');
  15. commentform.blur();
  16. return true;
  17. } catch(e) {
  18. return false;
  19. }
  20. });
  21. });