diff --git a/resources/assets/js/components/commentform.js b/resources/assets/js/components/commentform.js new file mode 100644 index 000000000..fb61e9e89 --- /dev/null +++ b/resources/assets/js/components/commentform.js @@ -0,0 +1,25 @@ +$(document).ready(function() { + + $('.comment-form').submit(function(e, data) { + e.preventDefault(); + + let el = $(this); + let id = el.data('id'); + let commentform = el.find('input[name="comment"]'); + let commenttext = commentform.val(); + let item = {item: id, comment: commenttext}; + try { + axios.post('/i/comment', item); + var comments = el.parent().parent().find('.comments'); + var comment = '

' + pixelfed.user.username + ''+ commenttext + '

'; + comments.prepend(comment); + + commentform.val(''); + commentform.blur(); + return true; + } catch(e) { + return false; + } + }); + +}); \ No newline at end of file