From c086cff36e7a93dcbcfd847a8904e4d9ccf62689 Mon Sep 17 00:00:00 2001 From: Pablo Vazquez Date: Thu, 23 Nov 2017 16:40:58 +0100 Subject: [PATCH] Comments: Only load JS for post/edit comments if we can actually comment --- .../nodes/custom/comment/list_embed.pug | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/templates/nodes/custom/comment/list_embed.pug b/src/templates/nodes/custom/comment/list_embed.pug index aac1bd0e..79b167c2 100644 --- a/src/templates/nodes/custom/comment/list_embed.pug +++ b/src/templates/nodes/custom/comment/list_embed.pug @@ -73,32 +73,6 @@ | {% block comment_scripts %} script. - // If there's a comment link in the URL, scroll there - function scrollToLinkedComment() { - var scrollToId = location.hash; - if (scrollToId.length <= 1) return; - - $(scrollToId) - .addClass('comment-linked') - .scrollHere(); - } - $(scrollToLinkedComment); - - - $('#comment_field').autoResize(); - - // Initialize Markdown to later convert comment as we type - var convert = new Markdown.getSanitizingConverter(); - Markdown.Extra.init(convert); - convert = convert.makeHtml; - - // Submit new comment - $(document) - .off('click','body .comment-action-submit') - .on( 'click','body .comment-action-submit', function(e){ - post_comment($(this)); - }); - {% if show_comments %} $('body') .off('pillar:comment-posted') @@ -111,9 +85,37 @@ script. $('#' + comment_node_id).scrollHere(); }); }); + + // If there's a comment link in the URL, scroll there + function scrollToLinkedComment() { + var scrollToId = location.hash; + if (scrollToId.length <= 1) return; + + $(scrollToId) + .addClass('comment-linked') + .scrollHere(); + } + $(scrollToLinkedComment); + {% endif %} + {% if can_post_comments %} + + // If we can actually comment, load the tools to do it + + // Initialize Markdown to later convert comment as we type + var convert = new Markdown.getSanitizingConverter(); + Markdown.Extra.init(convert); + convert = convert.makeHtml; + + // Submit new comment + $(document) + .off('click','body .comment-action-submit') + .on( 'click','body .comment-action-submit', function(e){ + post_comment($(this)); + }); + // Writing comment // Markdown convert as we type in the textarea $(document) @@ -142,6 +144,9 @@ script. } }); + // Autoresize the textarea as we type + $('#comment_field').autoResize(); + // Edit comment // Enter edit mode @@ -218,4 +223,6 @@ script. }); }); + {% endif %} + | {% endblock %}