Reloading comment list via event 'pillar:comment-posted' on body element.

This commit is contained in:
2016-11-02 16:11:31 +01:00
parent 80601f75ed
commit 4ec3268a23
2 changed files with 16 additions and 10 deletions

View File

@@ -34,6 +34,8 @@
} }
$.fn.scrollHere = function(scroll_duration_msec) { $.fn.scrollHere = function(scroll_duration_msec) {
if ($(this).length == 0) return;
$('html, body').animate({ $('html, body').animate({
scrollTop: this.offset().top scrollTop: this.offset().top
}, scroll_duration_msec); }, scroll_duration_msec);

View File

@@ -101,19 +101,23 @@ script.
} }
}) })
.done(function(comment_node_id) { .done(function(comment_node_id) {
$button
.removeClass('submitting')
.html('Post Comment');
$('#comment_field').val('');
$('body').trigger('pillar:comment-posted', [comment_node_id]);
});
});
{% if show_comments %} {% if show_comments %}
$('body').on('pillar:comment-posted', function(e, comment_node_id) {
var commentsUrl = "{{ url_for('nodes.comments_for_node', node_id=node_id) }}"; var commentsUrl = "{{ url_for('nodes.comments_for_node', node_id=node_id) }}";
loadComments(commentsUrl) loadComments(commentsUrl)
.done(function() { .done(function() {
$('#' + comment_node_id).scrollHere(); $('#' + comment_node_id).scrollHere();
}); });
{% else %} });
// TODO: implement something here
console.log('Comment posted succesfully, reload the page to see it.');
{% endif %} {% endif %}
});
});
/* Edit comment */ /* Edit comment */