1
0
Fork 0
pixelfed/resources/assets/js/components/commentform.js

51 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-05-20 03:11:01 +00:00
$(document).ready(function() {
2018-08-10 03:54:12 +00:00
$('.status-card > .card-footer').each(function() {
$(this).addClass('d-none');
});
$(document).on('click', '.status-comment-focus', function(el) {
var form = $(this).parents().eq(2).find('.card-footer');
form.removeClass('d-none');
2018-06-04 02:20:45 +00:00
var el = $(this).parents().eq(2).find('input[name="comment"]');
el.focus();
});
$(document).on('submit', '.comment-form', function(e, data) {
2018-05-20 03:11:01 +00:00
e.preventDefault();
let el = $(this);
let id = el.data('id');
let commentform = el.find('input[name="comment"]');
2018-06-18 05:28:34 +00:00
let commenttext = commentform.val();
2018-05-20 03:11:01 +00:00
let item = {item: id, comment: commenttext};
2018-06-14 05:36:21 +00:00
commentform.prop('disabled', true);
2018-06-04 02:20:45 +00:00
axios.post('/i/comment', item)
.then(function (res) {
var username = res.data.username;
var permalink = res.data.url;
var profile = res.data.profile;
2018-06-18 05:28:34 +00:00
var reply = res.data.comment;
2018-06-04 02:20:45 +00:00
if($('.status-container').length == 1) {
var comments = el.parents().eq(3).find('.comments');
} else {
2018-06-04 05:40:17 +00:00
var comments = el.parents().eq(1).find('.comments');
2018-06-04 02:20:45 +00:00
}
2018-06-18 05:28:34 +00:00
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">'+ reply + '</span><span class="float-right"><a href="' + permalink + '" class="text-dark small font-weight-bold">1s</a></span></p>';
2018-06-04 02:20:45 +00:00
2018-08-10 03:54:12 +00:00
comments.append(comment);
2018-06-04 02:20:45 +00:00
2018-05-20 03:11:01 +00:00
commentform.val('');
commentform.blur();
2018-06-14 05:36:21 +00:00
commentform.prop('disabled', false);
2018-06-04 02:20:45 +00:00
})
.catch(function (res) {
});
2018-05-20 03:11:01 +00:00
});
});