From 5f40f394351fbbb01b3059db1ca949b721f8d2f8 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 19 May 2018 21:11:01 -0600 Subject: [PATCH] Add commentform.js --- resources/assets/js/components/commentform.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 resources/assets/js/components/commentform.js 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