From 4ec3268a234698a225541eb52de0e41379b12e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 2 Nov 2016 16:11:31 +0100 Subject: [PATCH] Reloading comment list via event 'pillar:comment-posted' on body element. --- src/scripts/tutti/6_jquery_extensions.js | 2 ++ .../nodes/custom/comment/list_embed.jade | 24 +++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/scripts/tutti/6_jquery_extensions.js b/src/scripts/tutti/6_jquery_extensions.js index e5940b93..02136bae 100644 --- a/src/scripts/tutti/6_jquery_extensions.js +++ b/src/scripts/tutti/6_jquery_extensions.js @@ -34,6 +34,8 @@ } $.fn.scrollHere = function(scroll_duration_msec) { + if ($(this).length == 0) return; + $('html, body').animate({ scrollTop: this.offset().top }, scroll_duration_msec); diff --git a/src/templates/nodes/custom/comment/list_embed.jade b/src/templates/nodes/custom/comment/list_embed.jade index 83f1e9f2..39444302 100644 --- a/src/templates/nodes/custom/comment/list_embed.jade +++ b/src/templates/nodes/custom/comment/list_embed.jade @@ -101,19 +101,23 @@ script. } }) .done(function(comment_node_id) { - {% if show_comments %} - var commentsUrl = "{{ url_for('nodes.comments_for_node', node_id=node_id) }}"; - loadComments(commentsUrl) - .done(function() { - $('#' + comment_node_id).scrollHere(); - }); - {% else %} - // TODO: implement something here - console.log('Comment posted succesfully, reload the page to see it.'); - {% endif %} + $button + .removeClass('submitting') + .html('Post Comment'); + $('#comment_field').val(''); + $('body').trigger('pillar:comment-posted', [comment_node_id]); }); }); + {% 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) }}"; + loadComments(commentsUrl) + .done(function() { + $('#' + comment_node_id).scrollHere(); + }); + }); + {% endif %} /* Edit comment */