diff --git a/grade/grading/form/guide/amd/build/comment_chooser.min.js b/grade/grading/form/guide/amd/build/comment_chooser.min.js index 7ebae3ed2d0..ad0cf9fb413 100644 --- a/grade/grading/form/guide/amd/build/comment_chooser.min.js +++ b/grade/grading/form/guide/amd/build/comment_chooser.min.js @@ -5,6 +5,6 @@ * @copyright 2015 Jun Pataleta * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("gradingform_guide/comment_chooser",["jquery","core/templates","core/notification","core/yui"],(function($,templates,notification){return{initialise:function(criterionId,buttonId,remarkId,commentOptions){function generateCommentsChooser(){var context={criterionId:criterionId,comments:commentOptions};templates.render("gradingform_guide/comment_chooser",context).done((function(compiledSource){!function(compiledSource,comments){var titleLabel="",cancelButtonId="comment-chooser-"+criterionId+"-cancel",cancelButton='",chooserDialog=new M.core.dialogue({modal:!0,headerContent:titleLabel,bodyContent:compiledSource,footerContent:cancelButton,focusAfterHide:"#"+remarkId,id:"comments-chooser-dialog-"+criterionId});$("#"+cancelButtonId).click((function(){chooserDialog.hide()})),$.each(comments,(function(index,comment){var commentOptionId="#comment-option-"+criterionId+"-"+comment.id;$(commentOptionId).click((function(){var remarkTextArea=$("#"+remarkId),remarkText=remarkTextArea.val();""!==remarkText.trim()&&(remarkText+="\n"),remarkText+=comment.description,remarkTextArea.val(remarkText),chooserDialog.hide()})),$(document).off("keypress",commentOptionId).on("keypress",commentOptionId,(function(){var keyCode=event.which||event.keyCode;13!=keyCode&&32!=keyCode||$(commentOptionId).click()}))})),chooserDialog.after("visibleChange",(function(e){e.prevVal&&!e.newVal&&this.destroy()}),chooserDialog),chooserDialog.show()}(compiledSource,commentOptions)})).fail(notification.exception)}$("#"+buttonId).click((function(e){e.preventDefault(),generateCommentsChooser()}))}}})); +define("gradingform_guide/comment_chooser",["jquery","core/templates","core/key_codes","core/notification","core/yui"],(function($,templates,keycodes,notification){return{initialise:function(criterionId,buttonId,remarkId,commentOptions){function generateCommentsChooser(){var context={criterionId:criterionId,comments:commentOptions};templates.render("gradingform_guide/comment_chooser",context).done((function(compiledSource){!function(compiledSource,comments){var titleLabel="",cancelButtonId="comment-chooser-"+criterionId+"-cancel",cancelButton='",chooserDialog=new M.core.dialogue({modal:!0,headerContent:titleLabel,bodyContent:compiledSource,footerContent:cancelButton,focusAfterHide:"#"+remarkId,id:"comments-chooser-dialog-"+criterionId});$("#"+cancelButtonId).click((function(){chooserDialog.hide()})),$.each(comments,(function(index,comment){var commentOptionId="#comment-option-"+criterionId+"-"+comment.id;$(commentOptionId).click((function(){var remarkTextArea=$("#"+remarkId),remarkText=remarkTextArea.val();""!==remarkText.trim()&&(remarkText+="\n"),remarkText+=comment.description,remarkTextArea.val(remarkText),chooserDialog.hide()})),$(document).off("keypress",commentOptionId).on("keypress",commentOptionId,(function(){(event.which||event.keyCode)===keycodes.space&&$(commentOptionId).click()}))})),chooserDialog.after("visibleChange",(function(e){e.prevVal&&!e.newVal&&this.destroy()}),chooserDialog),chooserDialog.show()}(compiledSource,commentOptions)})).fail(notification.exception)}$("#"+buttonId).click((function(e){e.preventDefault(),generateCommentsChooser()}))}}})); //# sourceMappingURL=comment_chooser.min.js.map \ No newline at end of file diff --git a/grade/grading/form/guide/amd/build/comment_chooser.min.js.map b/grade/grading/form/guide/amd/build/comment_chooser.min.js.map index a29415b08cb..02f58e31677 100644 --- a/grade/grading/form/guide/amd/build/comment_chooser.min.js.map +++ b/grade/grading/form/guide/amd/build/comment_chooser.min.js.map @@ -1 +1 @@ -{"version":3,"file":"comment_chooser.min.js","sources":["../src/comment_chooser.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 * AMD code for the frequently used comments chooser for the marking guide grading form.\n *\n * @module gradingform_guide/comment_chooser\n * @copyright 2015 Jun Pataleta \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/templates', 'core/notification', 'core/yui'], function($, templates, notification) {\n\n // Private variables and functions.\n\n return /** @alias module:gradingform_guide/comment_chooser */ {\n // Public variables and functions.\n /**\n * Initialises the module.\n *\n * Basically, it performs the binding and handling of the button click event for\n * the 'Insert frequently used comment' button.\n *\n * @param {Integer} criterionId The criterion ID.\n * @param {String} buttonId The element ID of the button which the handler will be bound to.\n * @param {String} remarkId The element ID of the remark text area where the text of the selected comment will be copied to.\n * @param {Array} commentOptions The array of frequently used comments to be used as options.\n */\n initialise: function(criterionId, buttonId, remarkId, commentOptions) {\n /**\n * Display the chooser dialog using the compiled HTML from the mustache template\n * and binds onclick events for the generated comment options.\n *\n * @param {String} compiledSource The compiled HTML from the mustache template\n * @param {Array} comments Array containing comments.\n */\n function displayChooserDialog(compiledSource, comments) {\n var titleLabel = '';\n var cancelButtonId = 'comment-chooser-' + criterionId + '-cancel';\n var cancelButton = '';\n\n // Set dialog's body content.\n var chooserDialog = new M.core.dialogue({\n modal: true,\n headerContent: titleLabel,\n bodyContent: compiledSource,\n footerContent: cancelButton,\n focusAfterHide: '#' + remarkId,\n id: \"comments-chooser-dialog-\" + criterionId\n });\n\n // Bind click event to the cancel button.\n $(\"#\" + cancelButtonId).click(function() {\n chooserDialog.hide();\n });\n\n // Loop over each comment item and bind click events.\n $.each(comments, function(index, comment) {\n var commentOptionId = '#comment-option-' + criterionId + '-' + comment.id;\n\n // Delegate click event for the generated option link.\n $(commentOptionId).click(function() {\n var remarkTextArea = $('#' + remarkId);\n var remarkText = remarkTextArea.val();\n\n // Add line break if the current value of the remark text is not empty.\n if (remarkText.trim() !== '') {\n remarkText += '\\n';\n }\n remarkText += comment.description;\n\n remarkTextArea.val(remarkText);\n\n chooserDialog.hide();\n });\n\n // Handle keypress on list items.\n $(document).off('keypress', commentOptionId).on('keypress', commentOptionId, function() {\n var keyCode = event.which || event.keyCode;\n\n // Enter or space key.\n if (keyCode == 13 || keyCode == 32) {\n // Trigger click event.\n $(commentOptionId).click();\n }\n });\n });\n\n // Destroy the dialog when it is hidden to allow the grading section to\n // be loaded as a fragment multiple times within the same page.\n chooserDialog.after('visibleChange', function(e) {\n // Going from visible to hidden.\n if (e.prevVal && !e.newVal) {\n this.destroy();\n }\n }, chooserDialog);\n\n // Show dialog.\n chooserDialog.show();\n }\n\n /**\n * Generates the comments chooser dialog from the grading_form/comment_chooser mustache template.\n */\n function generateCommentsChooser() {\n // Template context.\n var context = {\n criterionId: criterionId,\n comments: commentOptions\n };\n\n // Render the template and display the comment chooser dialog.\n templates.render('gradingform_guide/comment_chooser', context)\n .done(function(compiledSource) {\n displayChooserDialog(compiledSource, commentOptions);\n })\n .fail(notification.exception);\n }\n\n // Bind click event for the comments chooser button.\n $(\"#\" + buttonId).click(function(e) {\n e.preventDefault();\n generateCommentsChooser();\n });\n }\n };\n});\n"],"names":["define","$","templates","notification","initialise","criterionId","buttonId","remarkId","commentOptions","generateCommentsChooser","context","comments","render","done","compiledSource","titleLabel","M","util","get_string","cancelButtonId","cancelButton","chooserDialog","core","dialogue","modal","headerContent","bodyContent","footerContent","focusAfterHide","id","click","hide","each","index","comment","commentOptionId","remarkTextArea","remarkText","val","trim","description","document","off","on","keyCode","event","which","after","e","prevVal","newVal","destroy","show","displayChooserDialog","fail","exception","preventDefault"],"mappings":";;;;;;;AAsBAA,2CAAO,CAAC,SAAU,iBAAkB,oBAAqB,aAAa,SAASC,EAAGC,UAAWC,oBAI3B,CAa1DC,WAAY,SAASC,YAAaC,SAAUC,SAAUC,yBA4EzCC,8BAEDC,QAAU,CACVL,YAAaA,YACbM,SAAUH,gBAIdN,UAAUU,OAAO,oCAAqCF,SACjDG,MAAK,SAASC,0BA7EOA,eAAgBH,cACtCI,WAAa,UAAYC,EAAEC,KAAKC,WAAW,gBAAiB,qBAAuB,WACnFC,eAAiB,mBAAqBd,YAAc,UACpDe,aAAe,eAAiBD,eAAiB,KAAOH,EAAEC,KAAKC,WAAW,SAAU,UAAY,YAGhGG,cAAgB,IAAIL,EAAEM,KAAKC,SAAS,CACpCC,OAAO,EACPC,cAAeV,WACfW,YAAaZ,eACba,cAAeP,aACfQ,eAAgB,IAAMrB,SACtBsB,GAAI,2BAA6BxB,cAIrCJ,EAAE,IAAMkB,gBAAgBW,OAAM,WAC1BT,cAAcU,UAIlB9B,EAAE+B,KAAKrB,UAAU,SAASsB,MAAOC,aACzBC,gBAAkB,mBAAqB9B,YAAc,IAAM6B,QAAQL,GAGvE5B,EAAEkC,iBAAiBL,OAAM,eACjBM,eAAiBnC,EAAE,IAAMM,UACzB8B,WAAaD,eAAeE,MAGN,KAAtBD,WAAWE,SACXF,YAAc,MAElBA,YAAcH,QAAQM,YAEtBJ,eAAeE,IAAID,YAEnBhB,cAAcU,UAIlB9B,EAAEwC,UAAUC,IAAI,WAAYP,iBAAiBQ,GAAG,WAAYR,iBAAiB,eACrES,QAAUC,MAAMC,OAASD,MAAMD,QAGpB,IAAXA,SAA4B,IAAXA,SAEjB3C,EAAEkC,iBAAiBL,cAO/BT,cAAc0B,MAAM,iBAAiB,SAASC,GAEtCA,EAAEC,UAAYD,EAAEE,aACXC,YAEV9B,eAGHA,cAAc+B,OAgBNC,CAAqBvC,eAAgBN,mBAExC8C,KAAKnD,aAAaoD,WAI3BtD,EAAE,IAAMK,UAAUwB,OAAM,SAASkB,GAC7BA,EAAEQ,iBACF/C"} \ No newline at end of file +{"version":3,"file":"comment_chooser.min.js","sources":["../src/comment_chooser.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 * AMD code for the frequently used comments chooser for the marking guide grading form.\n *\n * @module gradingform_guide/comment_chooser\n * @copyright 2015 Jun Pataleta \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/templates', 'core/key_codes', 'core/notification', 'core/yui'],\n function($, templates, keycodes, notification) {\n\n // Private variables and functions.\n\n return /** @alias module:gradingform_guide/comment_chooser */ {\n // Public variables and functions.\n /**\n * Initialises the module.\n *\n * Basically, it performs the binding and handling of the button click event for\n * the 'Insert frequently used comment' button.\n *\n * @param {Integer} criterionId The criterion ID.\n * @param {String} buttonId The element ID of the button which the handler will be bound to.\n * @param {String} remarkId The element ID of the remark text area where the text of the selected comment will be copied to.\n * @param {Array} commentOptions The array of frequently used comments to be used as options.\n */\n initialise: function(criterionId, buttonId, remarkId, commentOptions) {\n /**\n * Display the chooser dialog using the compiled HTML from the mustache template\n * and binds onclick events for the generated comment options.\n *\n * @param {String} compiledSource The compiled HTML from the mustache template\n * @param {Array} comments Array containing comments.\n */\n function displayChooserDialog(compiledSource, comments) {\n var titleLabel = '';\n var cancelButtonId = 'comment-chooser-' + criterionId + '-cancel';\n var cancelButton = '';\n\n // Set dialog's body content.\n var chooserDialog = new M.core.dialogue({\n modal: true,\n headerContent: titleLabel,\n bodyContent: compiledSource,\n footerContent: cancelButton,\n focusAfterHide: '#' + remarkId,\n id: \"comments-chooser-dialog-\" + criterionId\n });\n\n // Bind click event to the cancel button.\n $(\"#\" + cancelButtonId).click(function() {\n chooserDialog.hide();\n });\n\n // Loop over each comment item and bind click events.\n $.each(comments, function(index, comment) {\n var commentOptionId = '#comment-option-' + criterionId + '-' + comment.id;\n\n // Delegate click event for the generated option link.\n $(commentOptionId).click(function() {\n var remarkTextArea = $('#' + remarkId);\n var remarkText = remarkTextArea.val();\n\n // Add line break if the current value of the remark text is not empty.\n if (remarkText.trim() !== '') {\n remarkText += '\\n';\n }\n remarkText += comment.description;\n\n remarkTextArea.val(remarkText);\n\n chooserDialog.hide();\n });\n\n // Handle keypress on list items.\n $(document).off('keypress', commentOptionId).on('keypress', commentOptionId, function() {\n var keyCode = event.which || event.keyCode;\n\n // Trigger click event when user presses space.\n if (keyCode === keycodes.space) {\n $(commentOptionId).click();\n }\n });\n });\n\n // Destroy the dialog when it is hidden to allow the grading section to\n // be loaded as a fragment multiple times within the same page.\n chooserDialog.after('visibleChange', function(e) {\n // Going from visible to hidden.\n if (e.prevVal && !e.newVal) {\n this.destroy();\n }\n }, chooserDialog);\n\n // Show dialog.\n chooserDialog.show();\n }\n\n /**\n * Generates the comments chooser dialog from the grading_form/comment_chooser mustache template.\n */\n function generateCommentsChooser() {\n // Template context.\n var context = {\n criterionId: criterionId,\n comments: commentOptions\n };\n\n // Render the template and display the comment chooser dialog.\n templates.render('gradingform_guide/comment_chooser', context)\n .done(function(compiledSource) {\n displayChooserDialog(compiledSource, commentOptions);\n })\n .fail(notification.exception);\n }\n\n // Bind click event for the comments chooser button.\n $(\"#\" + buttonId).click(function(e) {\n e.preventDefault();\n generateCommentsChooser();\n });\n }\n };\n});\n"],"names":["define","$","templates","keycodes","notification","initialise","criterionId","buttonId","remarkId","commentOptions","generateCommentsChooser","context","comments","render","done","compiledSource","titleLabel","M","util","get_string","cancelButtonId","cancelButton","chooserDialog","core","dialogue","modal","headerContent","bodyContent","footerContent","focusAfterHide","id","click","hide","each","index","comment","commentOptionId","remarkTextArea","remarkText","val","trim","description","document","off","on","event","which","keyCode","space","after","e","prevVal","newVal","destroy","show","displayChooserDialog","fail","exception","preventDefault"],"mappings":";;;;;;;AAsBAA,2CAAO,CAAC,SAAU,iBAAkB,iBAAkB,oBAAqB,aACnE,SAASC,EAAGC,UAAWC,SAAUC,oBAIyB,CAa1DC,WAAY,SAASC,YAAaC,SAAUC,SAAUC,yBA2EzCC,8BAEDC,QAAU,CACVL,YAAaA,YACbM,SAAUH,gBAIdP,UAAUW,OAAO,oCAAqCF,SACjDG,MAAK,SAASC,0BA5EOA,eAAgBH,cACtCI,WAAa,UAAYC,EAAEC,KAAKC,WAAW,gBAAiB,qBAAuB,WACnFC,eAAiB,mBAAqBd,YAAc,UACpDe,aAAe,eAAiBD,eAAiB,KAAOH,EAAEC,KAAKC,WAAW,SAAU,UAAY,YAGhGG,cAAgB,IAAIL,EAAEM,KAAKC,SAAS,CACpCC,OAAO,EACPC,cAAeV,WACfW,YAAaZ,eACba,cAAeP,aACfQ,eAAgB,IAAMrB,SACtBsB,GAAI,2BAA6BxB,cAIrCL,EAAE,IAAMmB,gBAAgBW,OAAM,WAC1BT,cAAcU,UAIlB/B,EAAEgC,KAAKrB,UAAU,SAASsB,MAAOC,aACzBC,gBAAkB,mBAAqB9B,YAAc,IAAM6B,QAAQL,GAGvE7B,EAAEmC,iBAAiBL,OAAM,eACjBM,eAAiBpC,EAAE,IAAMO,UACzB8B,WAAaD,eAAeE,MAGN,KAAtBD,WAAWE,SACXF,YAAc,MAElBA,YAAcH,QAAQM,YAEtBJ,eAAeE,IAAID,YAEnBhB,cAAcU,UAIlB/B,EAAEyC,UAAUC,IAAI,WAAYP,iBAAiBQ,GAAG,WAAYR,iBAAiB,YAC3DS,MAAMC,OAASD,MAAME,WAGnB5C,SAAS6C,OACrB/C,EAAEmC,iBAAiBL,cAO/BT,cAAc2B,MAAM,iBAAiB,SAASC,GAEtCA,EAAEC,UAAYD,EAAEE,aACXC,YAEV/B,eAGHA,cAAcgC,OAgBNC,CAAqBxC,eAAgBN,mBAExC+C,KAAKpD,aAAaqD,WAI3BxD,EAAE,IAAMM,UAAUwB,OAAM,SAASmB,GAC7BA,EAAEQ,iBACFhD"} \ No newline at end of file diff --git a/grade/grading/form/guide/amd/src/comment_chooser.js b/grade/grading/form/guide/amd/src/comment_chooser.js index 23a5ccc8757..c8498e8db66 100644 --- a/grade/grading/form/guide/amd/src/comment_chooser.js +++ b/grade/grading/form/guide/amd/src/comment_chooser.js @@ -20,7 +20,8 @@ * @copyright 2015 Jun Pataleta * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define(['jquery', 'core/templates', 'core/notification', 'core/yui'], function($, templates, notification) { +define(['jquery', 'core/templates', 'core/key_codes', 'core/notification', 'core/yui'], + function($, templates, keycodes, notification) { // Private variables and functions. @@ -89,9 +90,8 @@ define(['jquery', 'core/templates', 'core/notification', 'core/yui'], function($ $(document).off('keypress', commentOptionId).on('keypress', commentOptionId, function() { var keyCode = event.which || event.keyCode; - // Enter or space key. - if (keyCode == 13 || keyCode == 32) { - // Trigger click event. + // Trigger click event when user presses space. + if (keyCode === keycodes.space) { $(commentOptionId).click(); } });