diff --git a/amd/build/studentquiz.min.js b/amd/build/studentquiz.min.js index c218c034..aeb4f6b1 100644 --- a/amd/build/studentquiz.min.js +++ b/amd/build/studentquiz.min.js @@ -1 +1 @@ -define(["jquery"],function(a){function b(){a(".studentquiz_behaviour .remove_action").off("click").on("click",function(){var b=a(this).closest("form").find(".cmid_field"),d=b.attr("value"),e=a(this).attr("data-question_id"),f=a(this).closest(".comments").children(".comment_list");a.post(M.cfg.wwwroot+"/mod/studentquiz/remove.php",{id:a(this).attr("data-id"),cmid:d,sesskey:M.cfg.sesskey},function(){c(e,f,d)})})}function c(c,d,e){var f=M.cfg.wwwroot+"/mod/studentquiz/comment_list.php?questionid=";f+=c+"&cmid="+e+"&sesskey="+M.cfg.sesskey,a.get(f,function(a){d.html(a),b()})}function d(){""!=a(".add_comment_field").val()?e():f()}function e(){a(window).on("beforeunload",function(){return a(".studentquiz_behaviour > .comments > .comment_error").removeClass("hide"),!0})}function f(){a(".studentquiz_behaviour > .comments > .comment_error").addClass("hide"),a(window).off("beforeunload")}return{initialise:function(){a(".studentquiz_behaviour .add_comment").off("click").on("click",function(){var b=a(this).closest(".comments"),d=b.find(".add_comment_field"),e=d.attr("name").substr(1),f=a(this).closest("form").find(".cmid_field"),g=f.attr("value"),h=b.children(".comment_list");a.post(M.cfg.wwwroot+"/mod/studentquiz/save.php",{save:"comment",cmid:g,questionid:e,sesskey:M.cfg.sesskey,text:d.val()},function(){d.val(""),d.trigger("keyup"),c(e,h,g)})}),a(".studentquiz_behaviour .rate .rating .rateable").off("click").on("click",function(){var b=a(this).attr("data-rate"),c=a(this),d=a(this).closest("form").find(".cmid_field"),e=d.attr("value");a.post(M.cfg.wwwroot+"/mod/studentquiz/save.php",{save:"rate",cmid:e,questionid:a(this).attr("data-questionid"),sesskey:M.cfg.sesskey,rate:b},function(){var d=c.closest(".rating").children("span");d.removeClass("star"),d.addClass("star-empty"),d.each(function(){a(this).attr("data-rate")<=b&&(a(this).removeClass("star-empty"),a(this).addClass("star"))}),a(".studentquiz_behaviour > .rate > .rate_error").addClass("hide")})}),a('input[name="next"], input[name="previous"], input[name="finish"]').off("click").on("click",function(){var b=a(this);if(!a('.im-controls input[type="submit"]').length||a('.im-controls input[type="submit"]').filter(function(){return this.name.match(/^q.+-submit$/)}).is(":disabled")){var c=!1;return a(".rating span").each(function(){a(this).hasClass("star")&&(c=!0)}),c?(b.submit(),!0):(a(".studentquiz_behaviour > .rate > .rate_error").removeClass("hide"),!1)}return b.submit(),!0}),a(".add_comment_field").on("keyup",d),b()}}}); \ No newline at end of file +define(["jquery"],function(a){function b(){a(".studentquiz_behaviour .show_more").off("click").on("click",function(){a(".studentquiz_behaviour .comment_list div").removeClass("hidden"),a(this).addClass("hidden"),a(".studentquiz_behaviour .show_less").removeClass("hidden")}),a(".studentquiz_behaviour .show_less").off("click").on("click",function(){a(".studentquiz_behaviour .comment_list > div").each(function(b){b>10&&!a(this).hasClass("button_controls")&&a(this).addClass("hidden")}),a(this).addClass("hidden"),a(".studentquiz_behaviour .show_more").removeClass("hidden")}),a(".studentquiz_behaviour .remove_action").off("click").on("click",function(){var b=a(this).closest("form").find(".cmid_field"),d=b.attr("value"),e=a(this).attr("data-question_id"),f=a(this).closest(".comments").children(".comment_list");a.post(M.cfg.wwwroot+"/mod/studentquiz/remove.php",{id:a(this).attr("data-id"),cmid:d,sesskey:M.cfg.sesskey},function(){c(e,f,d)})})}function c(c,d,e){var f=M.cfg.wwwroot+"/mod/studentquiz/comment_list.php?questionid=";f+=c+"&cmid="+e+"&sesskey="+M.cfg.sesskey,a.get(f,function(a){d.html(a),b()})}function d(){""!=a(".add_comment_field").val()?e():f()}function e(){a(window).on("beforeunload",function(){return a(".studentquiz_behaviour > .comments > .comment_error").removeClass("hide"),!0})}function f(){a(".studentquiz_behaviour > .comments > .comment_error").addClass("hide"),a(window).off("beforeunload")}return{initialise:function(){a(".studentquiz_behaviour .add_comment").off("click").on("click",function(){var b=a(this).closest(".comments"),d=b.find(".add_comment_field"),e=d.attr("name").substr(1),f=a(this).closest("form").find(".cmid_field"),g=f.attr("value"),h=b.children(".comment_list");a.post(M.cfg.wwwroot+"/mod/studentquiz/save.php",{save:"comment",cmid:g,questionid:e,sesskey:M.cfg.sesskey,text:d.val()},function(){d.val(""),d.trigger("keyup"),c(e,h,g)})}),a(".studentquiz_behaviour .rate .rating .rateable").off("click").on("click",function(){var b=a(this).attr("data-rate"),c=a(this),d=a(this).closest("form").find(".cmid_field"),e=d.attr("value");a.post(M.cfg.wwwroot+"/mod/studentquiz/save.php",{save:"rate",cmid:e,questionid:a(this).attr("data-questionid"),sesskey:M.cfg.sesskey,rate:b},function(){var d=c.closest(".rating").children("span");d.removeClass("star"),d.addClass("star-empty"),d.each(function(){a(this).attr("data-rate")<=b&&(a(this).removeClass("star-empty"),a(this).addClass("star"))}),a(".studentquiz_behaviour > .rate > .rate_error").addClass("hide")})}),a('input[name="next"], input[name="previous"], input[name="finish"]').off("click").on("click",function(){var b=a(this);if(!a('.im-controls input[type="submit"]').length||a('.im-controls input[type="submit"]').filter(function(){return this.name.match(/^q.+-submit$/)}).is(":disabled")){var c=!1;return a(".rating span").each(function(){a(this).hasClass("star")&&(c=!0)}),c?(b.submit(),!0):(a(".studentquiz_behaviour > .rate > .rate_error").removeClass("hide"),!1)}return b.submit(),!0}),a(".add_comment_field").on("keyup",d),b()}}}); \ No newline at end of file diff --git a/amd/src/studentquiz.js b/amd/src/studentquiz.js index a441b965..7d7d9294 100644 --- a/amd/src/studentquiz.js +++ b/amd/src/studentquiz.js @@ -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'); diff --git a/locallib.php b/locallib.php index 928a6681..1a65c3ab 100644 --- a/locallib.php +++ b/locallib.php @@ -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; @@ -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' ); }