Skip to content

Commit

Permalink
MDL-82309 comment: preserve link text property during AJAX requests.
Browse files Browse the repository at this point in the history
We really only need to update the count value that follows the link
text content, so do that rather than overwriting the entire thing.
  • Loading branch information
paulholden committed Jul 9, 2024
1 parent 7d7a871 commit c8d32c2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
18 changes: 9 additions & 9 deletions comment/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ M.core_comment = {
var newcomment = Y.Node.create(result.html);
container.appendChild(newcomment);
var ids = result.ids;
var linkText = Y.one('#comment-link-text-' + cid);
if (linkText) {
linkText.set('innerHTML', M.util.get_string('commentscount', 'moodle', obj.count));
var linkTextCount = Y.one('#comment-link-text-' + cid + ' .comment-link-count');
if (linkTextCount) {
linkTextCount.set('innerHTML', obj.count);
}
for(var i in ids) {
var attributes = {
Expand Down Expand Up @@ -249,9 +249,9 @@ M.core_comment = {
scope: scope,
params: params,
callback: async function(id, ret, args) {
var linkText = Y.one('#comment-link-text-' + scope.client_id);
if (ret.count && linkText) {
linkText.set('innerHTML', M.util.get_string('commentscount', 'moodle', ret.count));
var linkTextCount = Y.one('#comment-link-text-' + scope.client_id + ' .comment-link-count');
if (linkTextCount) {
linkTextCount.set('innerHTML', ret.count);
}
var container = Y.one('#comment-list-'+scope.client_id);
var pagination = Y.one('#comment-pagination-'+scope.client_id);
Expand Down Expand Up @@ -284,10 +284,10 @@ M.core_comment = {
params = {'commentid': id};
function remove_dom(type, anim, cmt) {
cmt.remove();
var linkText = Y.one('#comment-link-text-' + cid),
var linkTextCount = Y.one('#comment-link-text-' + cid + ' .comment-link-count'),
comments = Y.all('#comment-list-' + cid + ' li');
if (linkText && comments) {
linkText.set('innerHTML', M.util.get_string('commentscount', 'moodle', comments.size()));
if (linkTextCount) {
linkTextCount.set('innerHTML', comments.size());
}
}
this.request({
Expand Down
3 changes: 1 addition & 2 deletions comment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ public static function init(moodle_page $page = null) {
$page->requires->strings_for_js(array(
'addcomment',
'comments',
'commentscount',
'commentsrequirelogin',
'deletecommentbyon'
),
Expand Down Expand Up @@ -454,7 +453,7 @@ public function output($return = true) {
// comments open and closed
$countstring = '';
if ($this->displaytotalcount) {
$countstring = '('.$this->count().')';
$countstring = '(' . html_writer::span($this->count(), 'comment-link-count') . ')';
}
$collapsedimage= 't/collapsed';
if (right_to_left()) {
Expand Down
2 changes: 1 addition & 1 deletion lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@
$string['comebacklater'] = 'Please come back later.';
$string['commentincontext'] = 'Find this comment in context';
$string['comments'] = 'Comments';
$string['commentscount'] = 'Comments ({$a})';
$string['commentsnotenabled'] = 'Comments feature is not enabled';
$string['commentsrequirelogin'] = 'You need to log in to view the comments.';
$string['comparelanguage'] = 'Compare and edit current language';
Expand Down Expand Up @@ -2521,4 +2520,5 @@
* -word - don\'t include results containing this word.';

// Deprecated since Moodle 4.5.
$string['commentscount'] = 'Comments ({$a})';
$string['datechanged'] = 'Date changed';

0 comments on commit c8d32c2

Please sign in to comment.