Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for examples updating the comments counts after posting comment. #107

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion example/frontend/templates/article/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@

{% block scripts %}{{ block.super }}
<script type="text/javascript" src="{{ STATIC_URL }}fluent_comments/js/ajaxcomments.js"></script>
<script type="text/javascript">
var updateCommentsCount = function updateCommentsCount($) {
if ($ !== null) {
$.fn.ready(function () {
$(document).on('ajaxComplete', function () {
var $comments = $('#comment_count');
if ($comments) {
var currentCountStr = $comments.html().toString().split(' ');
var currentCount = parseInt(currentCountStr[0], 10);
var commentCount = $('.comment-item').length;
if (currentCount !== commentCount) {
currentCountStr[0] = commentCount.toString();
$comments.html(currentCountStr.join(' '));
}
return true;
}return false;
});
});
}
};

(function ($) {
updateCommentsCount($);
})(window.jQuery);
</script>
{% endblock %}

{% block main %}
Expand All @@ -33,7 +58,7 @@ <h1>{{ article.title }}</h1>

<div id="comments-wrapper">
{% if comments_count %}
<h3 class="has-comments-title">{% blocktrans with entry_title=article.title count comments_count=comments_count %}{{ comments_count }} comment to {{ entry_title }}{% plural %}{{ comments_count }} comments to {{ entry_title }}{% endblocktrans %}</h3>
<h3 id="comment_count" class="has-comments-title">{% blocktrans with entry_title=article.title count comments_count=comments_count %}{{ comments_count }} comment to {{ entry_title }}{% plural %}{{ comments_count }} comments to {{ entry_title }}{% endblocktrans %}</h3>
{% render_comment_list for object %}

{% if not article|comments_are_open %}
Expand Down
6 changes: 3 additions & 3 deletions example/frontend/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
<title>{% block headtitle %}{% endblock %}</title>
<link rel="stylesheet" href="{{ STATIC_URL }}vendor/bootstrap.css" type="text/css" />
{% block extrahead %}{% endblock %}
{% block scripts %}
<script type="text/javascript" src="{{ STATIC_URL }}vendor/jquery-2.2.0.min.js"></script>
{% endblock %}
</head>

<body id="{% block bodyid %}{% endblock %}" class="{% block bodyclass %}{% endblock %}">
Expand All @@ -39,5 +36,8 @@
{% block main %}{% endblock %}
</div>
</section>
{% block scripts %}
<script type="text/javascript" src="{{ STATIC_URL }}vendor/jquery-2.2.0.min.js"></script>
{% endblock %}
</body>
</html>