diff --git a/amd/build/studentquiz.min.js b/amd/build/studentquiz.min.js index b3a97994..68f36b05 100644 --- a/amd/build/studentquiz.min.js +++ b/amd/build/studentquiz.min.js @@ -5,6 +5,6 @@ * @copyright 2017 HSR (http://www.hsr.ch) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("mod_studentquiz/studentquiz",["jquery"],(function($){return{initialise:function(forcerating,forcecommenting,isanswered){var ratingElements=$(".studentquiz_behaviour .rate .rating .rateable");ratingElements.off("click").on("click",(function(){addRating(this)})),ratingElements.on("keypress",(function(e){13!==e.keyCode&&32!==e.keyCode||(e.preventDefault(),addRating(this))})),$('input[name="next"], input[name="previous"], input[name="finish"]').off("click").on("click",(function(){var $that=$(this);if(isanswered){var hasrated=$(".rating span").hasClass("star"),hascommented=$(".studentquiz-comment-container").hasClass("has-comment");return forcerating&&!hasrated&&$(".studentquiz_behaviour > .rate > .rate_error").removeClass("hide"),forcecommenting&&!hascommented&&$(".studentquiz_behaviour > .comments .comment-error").removeClass("hide"),forcerating&&!hasrated?$(".studentquiz_behaviour .rate .rating .rateable:first-child").focus():forcecommenting&&!hascommented&&$(".studentquiz_behaviour .comments .studentquiz-comment-container .editor_atto_content").focus(),!(forcerating&&!hasrated||forcecommenting&&!hascommented)&&($that.submit(),!0)}return $that.submit(),!0}))},setFocus:function(){$(document).ready((function(){var sortIcon=$("#categoryquestions .iconsort");sortIcon&&sortIcon.parent().focus()}))},selectAllQuestions:function(){let headerCheckbox=document.getElementById("qbheadercheckbox");require(["core/checkbox-toggleall"],(()=>{headerCheckbox.checked||headerCheckbox.click()}))}};function addRating(element){var $element=$(element),rate=$element.attr("data-rate"),$that=$element,cmid=$element.closest("form").find(".cmid_field").attr("value");$.post(M.cfg.wwwroot+"/mod/studentquiz/save.php",{save:"rate",cmid:cmid,studentquizquestionid:$element.attr("data-studentquizquestionid"),sesskey:M.cfg.sesskey,rate:rate},(function(){var $ratingStars=$that.closest(".rating").children("span");$ratingStars.removeClass("star"),$ratingStars.addClass("star-empty"),$ratingStars.each((function(){$(this).attr("data-rate")<=rate&&($(this).removeClass("star-empty"),$(this).addClass("star"))})),$(".studentquiz_behaviour > .rate > .rate_error").addClass("hide")}))}})); +define("mod_studentquiz/studentquiz",["jquery"],(function($){return{initialise:function(forcerating,forcecommenting,isanswered){var ratingElements=$(".studentquiz_behaviour .rate .rating .rateable");ratingElements.off("click").on("click",(function(){addRating(this)})),ratingElements.on("keypress",(function(e){13!==e.keyCode&&32!==e.keyCode||(e.preventDefault(),addRating(this))})),$('input[name="next"], input[name="previous"], input[name="finish"]').off("click").on("click",(function(){var $that=$(this);if(isanswered){var hasrated=$(".rating span").hasClass("star"),hascommented=$(".studentquiz-comment-container").hasClass("has-comment");if(forcerating&&!hasrated&&$(".studentquiz_behaviour > .rate > .rate_error").removeClass("hide"),forcecommenting&&!hascommented&&$(".studentquiz_behaviour > .comments .comment-error").removeClass("hide"),forcerating&&!hasrated)$(".studentquiz_behaviour .rate .rating .rateable:first-child").focus();else if(forcecommenting&&!hascommented){const attoEditorSelector=$(".studentquiz_behaviour .comments .studentquiz-comment-container .editor_atto_content"),tinyMceEditorSelector=$(".studentquiz_behaviour .comments .studentquiz-comment-container .tox-edit-area"),textareaSelector=$('textarea[id^="id_editor_question_"]');if(attoEditorSelector.length>0)attoEditorSelector.focus();else if(tinyMceEditorSelector.length>0){const tinyEditorId=textareaSelector.attr("id");window.tinymce.get(tinyEditorId).focus()}else textareaSelector.focus()}return!(forcerating&&!hasrated||forcecommenting&&!hascommented)&&($that.submit(),!0)}return $that.submit(),!0}))},setFocus:function(){$(document).ready((function(){var sortIcon=$("#categoryquestions .iconsort");sortIcon&&sortIcon.parent().focus()}))},selectAllQuestions:function(){let headerCheckbox=document.getElementById("qbheadercheckbox");require(["core/checkbox-toggleall"],(()=>{headerCheckbox.checked||headerCheckbox.click()}))}};function addRating(element){var $element=$(element),rate=$element.attr("data-rate"),$that=$element,cmid=$element.closest("form").find(".cmid_field").attr("value");$.post(M.cfg.wwwroot+"/mod/studentquiz/save.php",{save:"rate",cmid:cmid,studentquizquestionid:$element.attr("data-studentquizquestionid"),sesskey:M.cfg.sesskey,rate:rate},(function(){var $ratingStars=$that.closest(".rating").children("span");$ratingStars.removeClass("star"),$ratingStars.addClass("star-empty"),$ratingStars.each((function(){$(this).attr("data-rate")<=rate&&($(this).removeClass("star-empty"),$(this).addClass("star"))})),$(".studentquiz_behaviour > .rate > .rate_error").addClass("hide")}))}})); //# sourceMappingURL=studentquiz.min.js.map \ No newline at end of file diff --git a/amd/build/studentquiz.min.js.map b/amd/build/studentquiz.min.js.map index 32566a04..fc26b48c 100644 --- a/amd/build/studentquiz.min.js.map +++ b/amd/build/studentquiz.min.js.map @@ -1 +1 @@ -{"version":3,"file":"studentquiz.min.js","sources":["../src/studentquiz.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Javascript for save rating and save, remove and listing comments\n *\n * @module mod_studentquiz/studentquiz\n * @copyright 2017 HSR (http://www.hsr.ch)\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/* jshint latedef:nofunc */\n\ndefine(['jquery'], function($) {\n return {\n initialise: function(forcerating, forcecommenting, isanswered) {\n\n var ratingElements = $(\".studentquiz_behaviour .rate .rating .rateable\");\n // Ajax request POST on CLICK for add rating.\n ratingElements.off(\"click\").on(\"click\", function() {\n addRating(this);\n });\n // Ajax request POST for add rating when \"Enter\" or \"Space\" is pressed.\n ratingElements.on(\"keypress\", function(e) {\n if (e.keyCode === 13 || e.keyCode === 32) {\n e.preventDefault();\n addRating(this);\n }\n });\n\n // On CLICK check if student submitted result and has rated if not abort and show error for rating.\n $('input[name=\"next\"], input[name=\"previous\"], input[name=\"finish\"]').off('click').on('click', function() {\n var $that = $(this);\n\n if (isanswered) {\n var hasrated = $('.rating span').hasClass('star');\n var hascommented = $('.studentquiz-comment-container').hasClass('has-comment');\n\n if (forcerating && !hasrated) {\n $('.studentquiz_behaviour > .rate > .rate_error').removeClass('hide');\n }\n if (forcecommenting && !hascommented) {\n $('.studentquiz_behaviour > .comments .comment-error').removeClass('hide');\n }\n\n // Set focus.\n if (forcerating && !hasrated) {\n // Set focus to the first star.\n $('.studentquiz_behaviour .rate .rating .rateable:first-child').focus();\n } else if (forcecommenting && !hascommented) {\n // Set focus to atto editor.\n $('.studentquiz_behaviour .comments .studentquiz-comment-container .editor_atto_content').focus();\n }\n\n if ((!forcerating || hasrated) && (!forcecommenting || hascommented)) {\n $that.submit();\n return true;\n }\n return false;\n } else {\n $that.submit();\n return true;\n }\n });\n },\n\n // Set focus to sorted head of question table.\n setFocus: function() {\n $(document).ready(function() {\n var sortIcon = $('#categoryquestions .iconsort');\n if (sortIcon) {\n sortIcon.parent().focus();\n }\n });\n },\n\n // Select all questions.\n selectAllQuestions: function() {\n let headerCheckbox = document.getElementById('qbheadercheckbox');\n\n require(['core/checkbox-toggleall'], () => {\n if (!headerCheckbox.checked) {\n headerCheckbox.click();\n }\n });\n }\n };\n\n /**\n * Add rating to question.\n *\n * @param {DOM} element\n */\n function addRating(element) {\n var $element = $(element);\n var rate = $element.attr('data-rate');\n var $that = $element;\n var $cmIdField = $element.closest('form').find('.cmid_field');\n var cmid = $cmIdField.attr('value');\n $.post(M.cfg.wwwroot + '/mod/studentquiz/save.php',\n {\n save: 'rate',\n cmid: cmid,\n studentquizquestionid: $element.attr('data-studentquizquestionid'),\n sesskey: M.cfg.sesskey,\n rate: rate\n },\n function() {\n var $ratingStars = $that.closest('.rating').children('span');\n $ratingStars.removeClass('star');\n $ratingStars.addClass('star-empty');\n $ratingStars.each(function() {\n if ($(this).attr('data-rate') <= rate) {\n $(this).removeClass('star-empty');\n $(this).addClass('star');\n }\n });\n $('.studentquiz_behaviour > .rate > .rate_error').addClass('hide');\n }\n );\n }\n});\n"],"names":["define","$","initialise","forcerating","forcecommenting","isanswered","ratingElements","off","on","addRating","this","e","keyCode","preventDefault","$that","hasrated","hasClass","hascommented","removeClass","focus","submit","setFocus","document","ready","sortIcon","parent","selectAllQuestions","headerCheckbox","getElementById","require","checked","click","element","$element","rate","attr","cmid","closest","find","post","M","cfg","wwwroot","save","studentquizquestionid","sesskey","$ratingStars","children","addClass","each"],"mappings":";;;;;;;AAyBAA,qCAAO,CAAC,WAAW,SAASC,SACjB,CACHC,WAAY,SAASC,YAAaC,gBAAiBC,gBAE3CC,eAAiBL,EAAE,kDAEvBK,eAAeC,IAAI,SAASC,GAAG,SAAS,WACpCC,UAAUC,SAGdJ,eAAeE,GAAG,YAAY,SAASG,GACjB,KAAdA,EAAEC,SAAgC,KAAdD,EAAEC,UACtBD,EAAEE,iBACFJ,UAAUC,UAKlBT,EAAE,oEAAoEM,IAAI,SAASC,GAAG,SAAS,eACvFM,MAAQb,EAAES,SAEVL,WAAY,KACRU,SAAWd,EAAE,gBAAgBe,SAAS,QACtCC,aAAehB,EAAE,kCAAkCe,SAAS,sBAE5Db,cAAgBY,UAChBd,EAAE,gDAAgDiB,YAAY,QAE9Dd,kBAAoBa,cACpBhB,EAAE,qDAAqDiB,YAAY,QAInEf,cAAgBY,SAEhBd,EAAE,8DAA8DkB,QACzDf,kBAAoBa,cAE3BhB,EAAE,wFAAwFkB,UAGxFhB,cAAeY,UAAeX,kBAAmBa,gBACnDH,MAAMM,UACC,UAIXN,MAAMM,UACC,MAMnBC,SAAU,WACNpB,EAAEqB,UAAUC,OAAM,eACVC,SAAWvB,EAAE,gCACbuB,UACAA,SAASC,SAASN,YAM9BO,mBAAoB,eACZC,eAAiBL,SAASM,eAAe,oBAE7CC,QAAQ,CAAC,4BAA4B,KAC5BF,eAAeG,SAChBH,eAAeI,sBAWtBtB,UAAUuB,aACXC,SAAWhC,EAAE+B,SACbE,KAAOD,SAASE,KAAK,aACrBrB,MAAQmB,SAERG,KADaH,SAASI,QAAQ,QAAQC,KAAK,eACzBH,KAAK,SAC3BlC,EAAEsC,KAAKC,EAAEC,IAAIC,QAAU,4BACnB,CACIC,KAAM,OACNP,KAAMA,KACNQ,sBAAuBX,SAASE,KAAK,8BACrCU,QAASL,EAAEC,IAAII,QACfX,KAAMA,OAEV,eACQY,aAAehC,MAAMuB,QAAQ,WAAWU,SAAS,QACrDD,aAAa5B,YAAY,QACzB4B,aAAaE,SAAS,cACtBF,aAAaG,MAAK,WACVhD,EAAES,MAAMyB,KAAK,cAAgBD,OAC7BjC,EAAES,MAAMQ,YAAY,cACpBjB,EAAES,MAAMsC,SAAS,YAGzB/C,EAAE,gDAAgD+C,SAAS"} \ No newline at end of file +{"version":3,"file":"studentquiz.min.js","sources":["../src/studentquiz.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Javascript for save rating and save, remove and listing comments\n *\n * @module mod_studentquiz/studentquiz\n * @copyright 2017 HSR (http://www.hsr.ch)\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/* jshint latedef:nofunc */\n\ndefine(['jquery'], function($) {\n return {\n initialise: function(forcerating, forcecommenting, isanswered) {\n\n var ratingElements = $(\".studentquiz_behaviour .rate .rating .rateable\");\n // Ajax request POST on CLICK for add rating.\n ratingElements.off(\"click\").on(\"click\", function() {\n addRating(this);\n });\n // Ajax request POST for add rating when \"Enter\" or \"Space\" is pressed.\n ratingElements.on(\"keypress\", function(e) {\n if (e.keyCode === 13 || e.keyCode === 32) {\n e.preventDefault();\n addRating(this);\n }\n });\n\n // On CLICK check if student submitted result and has rated if not abort and show error for rating.\n $('input[name=\"next\"], input[name=\"previous\"], input[name=\"finish\"]').off('click').on('click', function() {\n var $that = $(this);\n\n if (isanswered) {\n var hasrated = $('.rating span').hasClass('star');\n var hascommented = $('.studentquiz-comment-container').hasClass('has-comment');\n\n if (forcerating && !hasrated) {\n $('.studentquiz_behaviour > .rate > .rate_error').removeClass('hide');\n }\n if (forcecommenting && !hascommented) {\n $('.studentquiz_behaviour > .comments .comment-error').removeClass('hide');\n }\n\n // Set focus.\n if (forcerating && !hasrated) {\n // Set focus to the first star.\n $('.studentquiz_behaviour .rate .rating .rateable:first-child').focus();\n } else if (forcecommenting && !hascommented) {\n const attoEditorSelector = $(\n '.studentquiz_behaviour .comments .studentquiz-comment-container .editor_atto_content'\n );\n const tinyMceEditorSelector = $(\n '.studentquiz_behaviour .comments .studentquiz-comment-container .tox-edit-area'\n );\n const textareaSelector = $('textarea[id^=\"id_editor_question_\"]');\n if (attoEditorSelector.length > 0) {\n // Set focus to atto editor.\n attoEditorSelector.focus();\n } else if (tinyMceEditorSelector.length > 0) {\n const tinyEditorId = textareaSelector.attr('id');\n // Set focus to TinyMCE editor.\n window.tinymce.get(tinyEditorId).focus();\n } else {\n // Set focus to textarea.\n textareaSelector.focus();\n }\n }\n\n if ((!forcerating || hasrated) && (!forcecommenting || hascommented)) {\n $that.submit();\n return true;\n }\n return false;\n } else {\n $that.submit();\n return true;\n }\n });\n },\n\n // Set focus to sorted head of question table.\n setFocus: function() {\n $(document).ready(function() {\n var sortIcon = $('#categoryquestions .iconsort');\n if (sortIcon) {\n sortIcon.parent().focus();\n }\n });\n },\n\n // Select all questions.\n selectAllQuestions: function() {\n let headerCheckbox = document.getElementById('qbheadercheckbox');\n\n require(['core/checkbox-toggleall'], () => {\n if (!headerCheckbox.checked) {\n headerCheckbox.click();\n }\n });\n }\n };\n\n /**\n * Add rating to question.\n *\n * @param {DOM} element\n */\n function addRating(element) {\n var $element = $(element);\n var rate = $element.attr('data-rate');\n var $that = $element;\n var $cmIdField = $element.closest('form').find('.cmid_field');\n var cmid = $cmIdField.attr('value');\n $.post(M.cfg.wwwroot + '/mod/studentquiz/save.php',\n {\n save: 'rate',\n cmid: cmid,\n studentquizquestionid: $element.attr('data-studentquizquestionid'),\n sesskey: M.cfg.sesskey,\n rate: rate\n },\n function() {\n var $ratingStars = $that.closest('.rating').children('span');\n $ratingStars.removeClass('star');\n $ratingStars.addClass('star-empty');\n $ratingStars.each(function() {\n if ($(this).attr('data-rate') <= rate) {\n $(this).removeClass('star-empty');\n $(this).addClass('star');\n }\n });\n $('.studentquiz_behaviour > .rate > .rate_error').addClass('hide');\n }\n );\n }\n});\n"],"names":["define","$","initialise","forcerating","forcecommenting","isanswered","ratingElements","off","on","addRating","this","e","keyCode","preventDefault","$that","hasrated","hasClass","hascommented","removeClass","focus","attoEditorSelector","tinyMceEditorSelector","textareaSelector","length","tinyEditorId","attr","window","tinymce","get","submit","setFocus","document","ready","sortIcon","parent","selectAllQuestions","headerCheckbox","getElementById","require","checked","click","element","$element","rate","cmid","closest","find","post","M","cfg","wwwroot","save","studentquizquestionid","sesskey","$ratingStars","children","addClass","each"],"mappings":";;;;;;;AAyBAA,qCAAO,CAAC,WAAW,SAASC,SACjB,CACHC,WAAY,SAASC,YAAaC,gBAAiBC,gBAE3CC,eAAiBL,EAAE,kDAEvBK,eAAeC,IAAI,SAASC,GAAG,SAAS,WACpCC,UAAUC,SAGdJ,eAAeE,GAAG,YAAY,SAASG,GACjB,KAAdA,EAAEC,SAAgC,KAAdD,EAAEC,UACtBD,EAAEE,iBACFJ,UAAUC,UAKlBT,EAAE,oEAAoEM,IAAI,SAASC,GAAG,SAAS,eACvFM,MAAQb,EAAES,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cACpBjB,EAAES,MAAM8C,SAAS,YAGzBvD,EAAE,gDAAgDuD,SAAS"} \ No newline at end of file diff --git a/amd/src/studentquiz.js b/amd/src/studentquiz.js index 3f93582a..4d04a5a4 100644 --- a/amd/src/studentquiz.js +++ b/amd/src/studentquiz.js @@ -60,8 +60,24 @@ define(['jquery'], function($) { // Set focus to the first star. $('.studentquiz_behaviour .rate .rating .rateable:first-child').focus(); } else if (forcecommenting && !hascommented) { - // Set focus to atto editor. - $('.studentquiz_behaviour .comments .studentquiz-comment-container .editor_atto_content').focus(); + const attoEditorSelector = $( + '.studentquiz_behaviour .comments .studentquiz-comment-container .editor_atto_content' + ); + const tinyMceEditorSelector = $( + '.studentquiz_behaviour .comments .studentquiz-comment-container .tox-edit-area' + ); + const textareaSelector = $('textarea[id^="id_editor_question_"]'); + if (attoEditorSelector.length > 0) { + // Set focus to atto editor. + attoEditorSelector.focus(); + } else if (tinyMceEditorSelector.length > 0) { + const tinyEditorId = textareaSelector.attr('id'); + // Set focus to TinyMCE editor. + window.tinymce.get(tinyEditorId).focus(); + } else { + // Set focus to textarea. + textareaSelector.focus(); + } } if ((!forcerating || hasrated) && (!forcecommenting || hascommented)) {