diff --git a/README.rst b/README.rst index d85482e..47e48be 100644 --- a/README.rst +++ b/README.rst @@ -173,6 +173,17 @@ It can be enabled using the following settings:: The templates and admin interface adapt themselves automatically to show the threaded comments. +Other settings +-------------- + +For reversing the order of the comments (new comments are appended +at the top of the list, rather than at the end), use the following +option. + + FLUENT_COMMENTS_ORDER_REVERSED = True + +Currently, this supports only simple comments (no threads). This also +blocks the scrolling for newly posted comments. Contributing ------------ diff --git a/fluent_comments/appsettings.py b/fluent_comments/appsettings.py index 69b1cc7..da80740 100644 --- a/fluent_comments/appsettings.py +++ b/fluent_comments/appsettings.py @@ -19,6 +19,8 @@ FLUENT_COMMENTS_EXCLUDE_FIELDS = getattr(settings, 'FLUENT_COMMENTS_EXCLUDE_FIELDS', ()) or () +FLUENT_COMMENTS_ORDER_REVERSED = getattr(settings, 'FLUENT_COMMENTS_ORDER_REVERSED', False) + if FLUENT_COMMENTS_AKISMET_ACTION not in ('moderate', 'delete'): raise ImproperlyConfigured("FLUENT_COMMENTS_AKISMET_ACTION can be 'moderate' or 'delete'") diff --git a/fluent_comments/static/fluent_comments/js/ajaxcomments.js b/fluent_comments/static/fluent_comments/js/ajaxcomments.js index 5b727d4..804edc1 100644 --- a/fluent_comments/static/fluent_comments/js/ajaxcomments.js +++ b/fluent_comments/static/fluent_comments/js/ajaxcomments.js @@ -112,7 +112,7 @@ function scrollToComment(id, speed) { - if( ! ENABLE_COMMENT_SCROLL ) { + if( (! ENABLE_COMMENT_SCROLL) || data['order_reversed'] ) { return; } @@ -133,7 +133,7 @@ function scrollToElement( $element, speed, offset ) { - if( ! ENABLE_COMMENT_SCROLL ) { + if( (! ENABLE_COMMENT_SCROLL) || data['order_reversed'] ) { return; } @@ -287,7 +287,15 @@ { // data contains the server-side response. var $newCommentTarget = addCommentWrapper(data, '') - $newCommentTarget.append(data['html']).removeClass('empty'); + + // prepend or append the comment depending on the settings + if (data['order_reversed']) { + $newCommentTarget.prepend(data['html']).removeClass('empty'); + } + else { + $newCommentTarget.append(data['html']).removeClass('empty'); + } + return $("#c" + parseInt(data.comment_id)); } diff --git a/fluent_comments/templates/fluent_comments/templatetags/flat_list.html b/fluent_comments/templates/fluent_comments/templatetags/flat_list.html index ae8fd3b..551746e 100644 --- a/fluent_comments/templates/fluent_comments/templatetags/flat_list.html +++ b/fluent_comments/templates/fluent_comments/templatetags/flat_list.html @@ -8,5 +8,9 @@ {% endcomment %}