Bizarre request I know, but, I've been asked if it is possible to reverse the order of comments, ie.e. have the most recent at the top?
You can do that client-side with a quick JavaScript hack...
Browse to Confluence Admin | Look & Feel | Custom HTML
Add this to At the end of the HEAD:
<script> AJS.toInit(function () { $comments = AJS.$('#page-comments'); $comments.children().each(function (i,li) { $comments.prepend(li); }); }); </script>
Check the related blogpost for more tips
Thanks Dave, that did it.
Cheers
Norman
No problem. If it worked, please mark it as correct :-)
Also, if you want to allow the sort order to be changed, update the JavaScript to something like...
function reverseCommentOrder () { var $comments = AJS.$('#page-comments'); $comments.children().each(function(i,li){$comments.prepend(li)}); } AJS.toInit(function ($) { reverseCommentOrder(); $('#comments-section-title').append( '<a id="page-comments-reverse" href="#">(Reverse Order)</a>' ); $('#page-comments-reverse') .css({ 'color':'#999','font-size':'0.65em'}) .click(function (e) { reverseCommentOrder(); e.preventDefault(); }); });
If you want to do this per space simply wrap it in {html} tags and place it in the custom header area: Space Admin -> Look And Feel -> Themes -> Configure Theme -> Header.
{html} <script> AJS.toInit(function(){ $comments = AJS.$('#page-comments'); $comments.children().each(function(i,li){$comments.prepend(li)}) }); </script> {html}
Hi, I am using confluence V3.5 .
I tried to use David's solution which worked great but now it seems that
I am unable to reply on an existing comment using rich text editor, only by wiki markup (test on Chrome).
did someone else had this issue? is there a solution for this?
I've not tried this in Confluence 3.5 only 4.x. Sorry.
I am having the same issue with the Documentation theme in Confluence 4.1.9. I cannot edit comments. It brings up the editor, does not show the existing comment an does not give you a cursor. The preview button does not work either.
Try this to fix the comment edit/reply problem...
<script> AJS.toInit(function ($) { if ($('meta[name=ajs-form-name]').attr("content") != "editcommentform"){ // Only reverse comments if you're not editing one of them $comments = $('#page-comments'); $comments.children() .each(function (i, li) { $comments.prepend(li); }); } }); </script>
This is excellent David. Seems to work.
So the complete script is:
<script> function reverseCommentOrder(){ if (AJS.$('meta[name=ajs-form-name]').attr("content") != "editcommentform"){ // Only reverse comments if you're not editing one of them $comments = AJS.$('#page-comments'); $comments.children().each(function(i,li){$comments.prepend(li)}); } } AJS.toInit(function(){ reverseCommentOrder(); AJS.$('#comments-section-title').append('<a id="page-comments-reverse" href="#">(Reverse Order)</a>'); AJS.$('#page-comments-reverse').css({ 'color':'#999','font-size':'0.65em'}).click(function(e){ reverseCommentOrder(); e.preventDefault(); }); }); </script>
This still has issues when you try and reply to a comment. Can anyone help?
Is there an issue to have Atlassian make this part of the code functionality?
Thanks
This works great for the first comment, but what about the subcomments underneath if people reply?
This solution will handle new comments and replies to those comments
<script> AJS.toInit(function(){ if (AJS.$('meta[name=ajs-form-name]').attr("content") != "editcommentform" && AJS.$('meta[name=ajs-form-name]').attr("content") != "threadedcommentform"){ // Only reverse comments if you're not editing one of them $comments = AJS.$('#page-comments'); $comments.children().each(function(i,li){$comments.prepend(li)}); } }); </script>
Is it possible to reverse the comments order in the On Demand version of Confluence? We have 145 comments On one of our meeting notes page that grows daily… Scrolling to the bottom is becoming a bit of a pain. Thanks, Robert
Indeed, the above solution only sorts the top level comments, not the sub comments. The reason is that only the top comment container has an identifier ("page-comments"). Such a global identifier can only be assigned to something that is always present. That is not the case for the sub-comments. So the sub-comments IDs are created on the fly and a solution like the above cannot know them beforehand of course.
Also, inserting the toggle link into the comment block has the flaw that it is removed when Confluence re-creates it after a new comment is added. Only a page refresh will make it appear again.
Other than that it works. Here is a solution how you can do this with a user macro so you can apply it to certain pages only by adding it onto the page.
## Macro title: Reverse Comments ## Macro body processing: No macro body ## ## Created by: George Lewe ## Created on: 2015-11-06 ## ## This macro toggles page comments sort order ## ## @noparams <script> function rev(i, el) { $comments = AJS.$('#page-comments'); $comments.prepend(el) } function reverseCommentOrder() { if (AJS.$('meta[name=ajs-form-name]').attr("content") != "editcommentform"){ $comments = AJS.$('#page-comments'); $comments.children().each(rev) } } AJS.toInit(function() { if($("#page-comments-reverse").length == 0) { AJS.$('#comments-section-title').append('<a id="page-comments-reverse" href="#" onclick="reverseCommentOrder();" style="color: #999; font-size: 0.65em;">[Toggle order...]</a>;'); } }); </script>
Can I do that at just the Space Level, not a a global change?
Using v 5.7.1 Space Admin -> Look And Feel -> Themes -> Configure Theme -> Header does not exist. I get the option of current theme or choose new theme and confirm.
I notice there is a Blog Layout in the Space Tool->Look and Feel->Blog Post Layout
Guess I can just put that in there?
where do would I insert this in a Space?
I am using 5.7.1.
Thanks!
Hi Robert,
Any update on this issue . Please let us know, we are also searching for the same
No, Karthik.
We have found no solution for reversing the sort order in the On Demand/cloud version of confluence. This is just one of the many limitations that we found since moving to the cloud instance. Seems like it should be a relatively minor thing to fix. Apparently, it's not high on the Atlassian scorecard.
But we need to get by adding java script on header side, I think It is also not work out. We are finding any changes. Please suggest if you have any alternate method.
The solution above is a page macro. It only applies to the page when you insert it. It is not space-wide.
I have placed the above code in the template of my user macro but when I save the page where the macro is it spits out the code and thus not ordering the comments?
How can I make the code be executed and not spit on the page?
I'm not sure if this thread is still alive. I tried all the codes above, they all work. The thing is, everytime i enter a new comment, it is still displayed at the bottom. Any possible way that the newly entered comment(without refreshing the page) can appear on top as well?
Is this still viable for v 6.15.9 and above?
The Custom HTML inserted via the Admin console - does not seem to be working, but per space it does!
Try now. I've just updated my old answers from 2012 - when Atlassian migrated the content from the old community (answers.atlassian.com), some html was mistakenly escaped.
Thanks David!
Really appreciate that!
Is that the same for the one with the choice of sort order? add <script> tags?
V
Thank you Ronald !
It looks like you're new here. Sign in or register to get started.