Skip to content

Commit

Permalink
reintroduce show more button on 10 comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dionysius committed Mar 11, 2019
1 parent abf1c20 commit 5f8d9fc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion amd/build/studentquiz.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions amd/src/studentquiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ define(['jquery'], function($) {
* Binding action buttons after refresh comment list.
*/
function bindButtons() {
$('.studentquiz_behaviour .show_more').off('click').on('click', function() {
$('.studentquiz_behaviour .comment_list div').removeClass('hidden');
$(this).addClass('hidden');
$('.studentquiz_behaviour .show_less').removeClass('hidden');
});

$('.studentquiz_behaviour .show_less').off('click').on('click', function() {
$('.studentquiz_behaviour .comment_list > div').each(function(index) {
if (index > 10 && !$(this).hasClass('button_controls')) {
$(this).addClass('hidden');
}
});

$(this).addClass('hidden');
$('.studentquiz_behaviour .show_more').removeClass('hidden');
});

$('.studentquiz_behaviour .remove_action').off('click').on('click', function() {
var $cmidfield = $(this).closest('form').find('.cmid_field');
var cmid = $cmidfield.attr('value');
Expand Down
15 changes: 14 additions & 1 deletion locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ function mod_studentquiz_comment_renderer($comments, $userid, $cmid, $anonymize,
}
}

$num = 0;
$showmoreafter = 10;
// Output comments in chronically reverse order.
foreach (array_reverse($comments) as $comment) {
$canedit = $ismoderator || $comment->userid == $userid;
Expand Down Expand Up @@ -656,7 +658,18 @@ function mod_studentquiz_comment_renderer($comments, $userid, $cmid, $anonymize,
$comment->comment,
FORMAT_MOODLE,
array('context' => $cmid)
)
),
($num >= $showmoreafter) ? 'hidden' : ''
);
$num++;
}

if (count($comments) > $showmoreafter) {
$output .= html_writer::div(
html_writer::tag('button', get_string('show_more', $modname),
array('type' => 'button', 'class' => 'show_more btn btn-secondary'))
. html_writer::tag('button', get_string('show_less', $modname)
, array('type' => 'button', 'class' => 'show_less btn btn-secondary hidden')), 'button_controls'
);
}

Expand Down

0 comments on commit 5f8d9fc

Please sign in to comment.