diff --git a/amd/build/spellcheck.min.js b/amd/build/spellcheck.min.js index 59438d0..3fa7313 100644 --- a/amd/build/spellcheck.min.js +++ b/amd/build/spellcheck.min.js @@ -6,6 +6,6 @@ define("qtype_aitext/spellcheck",["exports","qtype_aitext/diff","core_form/modal * @copyright 2024, ISB Bayern * @author Dr. Peter Mayer * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */(Diff),_modalform=(obj=_modalform)&&obj.__esModule?obj:{default:obj};_exports.init=(cmid,readonlyareaselector,spellcheckeditbuttonselector)=>{renderDiff(readonlyareaselector),document.querySelector(spellcheckeditbuttonselector)&&document.querySelector(spellcheckeditbuttonselector).addEventListener("click",(async event=>{event.preventDefault(),await showModalForm(cmid,readonlyareaselector)}))};const renderDiff=readonlyareaselector=>{const studentanswer=document.querySelector(readonlyareaselector).innerHTML,spellcheck=document.querySelector(readonlyareaselector).dataset.spellcheck;let span=null;const diff=Diff.diffChars(studentanswer,spellcheck),fragment=document.createElement("div");let fullspellcheck="";diff.forEach((part=>{part.value=part.value.replace(/ /g," ");const parser=new DOMParser;part.value=parser.parseFromString(part.value,"text/html");const cls=part.added?"qtype_aitext_spellcheck_new":part.removed?"qtype_aitext_spellcheck_wrong":"";part.added||part.removed?(span=document.createElement("span"),span.classList=cls,span.appendChild(part.value.documentElement),fullspellcheck+=span.outerHTML):fullspellcheck+=part.value.documentElement.textContent})),fragment.innerHTML=fullspellcheck,document.querySelector(readonlyareaselector).replaceChildren(fragment)};_exports.renderDiff=renderDiff;const showModalForm=async(cmid,readonlyareaselector)=>{const attemptstepid=document.querySelector(readonlyareaselector).dataset.spellcheckattemptstepid,answerstepid=document.querySelector(readonlyareaselector).dataset.spellcheckattemptstepanswerid,title=await(0,_str.getString)("spellcheckedit","qtype_aitext"),modalForm=new _modalform.default({formClass:"qtype_aitext\\form\\edit_spellcheck",args:{attemptstepid:attemptstepid,answerstepid:answerstepid,cmid:cmid},modalConfig:{title:title}});modalForm.addEventListener(modalForm.events.FORM_SUBMITTED,reloadpage),await modalForm.show()};_exports.showModalForm=showModalForm;const reloadpage=()=>{location.reload()}})); + */(Diff),_modalform=(obj=_modalform)&&obj.__esModule?obj:{default:obj};_exports.init=(readonlyareaselector,spellcheckeditbuttonselector)=>{renderDiff(readonlyareaselector),document.querySelector(spellcheckeditbuttonselector)&&document.querySelector(spellcheckeditbuttonselector).addEventListener("click",(async event=>{event.preventDefault(),await showModalForm(readonlyareaselector)}))};const renderDiff=readonlyareaselector=>{const studentanswer=document.querySelector(readonlyareaselector).innerHTML,spellcheck=document.querySelector(readonlyareaselector).dataset.spellcheck;let span=null;const diff=Diff.diffChars(studentanswer,spellcheck),fragment=document.createElement("div");let fullspellcheck="";diff.forEach((part=>{part.value=part.value.replace(/ /g," ");const parser=new DOMParser;part.value=parser.parseFromString(part.value,"text/html");const cls=part.added?"qtype_aitext_spellcheck_new":part.removed?"qtype_aitext_spellcheck_wrong":"";part.added||part.removed?(span=document.createElement("span"),span.classList=cls,span.appendChild(part.value.documentElement),fullspellcheck+=span.outerHTML):fullspellcheck+=part.value.documentElement.textContent})),fragment.innerHTML=fullspellcheck,document.querySelector(readonlyareaselector).replaceChildren(fragment)};_exports.renderDiff=renderDiff;const showModalForm=async readonlyareaselector=>{const attemptstepid=document.querySelector(readonlyareaselector).dataset.spellcheckattemptstepid,answerstepid=document.querySelector(readonlyareaselector).dataset.spellcheckattemptstepanswerid,title=await(0,_str.getString)("spellcheckedit","qtype_aitext"),modalForm=new _modalform.default({formClass:"qtype_aitext\\form\\edit_spellcheck",args:{attemptstepid:attemptstepid,answerstepid:answerstepid},modalConfig:{title:title}});modalForm.addEventListener(modalForm.events.FORM_SUBMITTED,reloadpage),await modalForm.show()};_exports.showModalForm=showModalForm;const reloadpage=()=>{location.reload()}})); //# sourceMappingURL=spellcheck.min.js.map \ No newline at end of file diff --git a/amd/build/spellcheck.min.js.map b/amd/build/spellcheck.min.js.map index d77dc9c..cbc2565 100644 --- a/amd/build/spellcheck.min.js.map +++ b/amd/build/spellcheck.min.js.map @@ -1 +1 @@ -{"version":3,"file":"spellcheck.min.js","sources":["../src/spellcheck.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 * Generates the spellcheck diff view.\n *\n * @module qtype_aitext/spellcheck\n * @copyright 2024, ISB Bayern\n * @author Dr. Peter Mayer\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as Diff from 'qtype_aitext/diff';\nimport ModalForm from 'core_form/modalform';\nimport {getString as getString} from 'core/str';\n\n/**\n * Init the module.\n *\n * @param {int} cmid the course module id of the quiz.\n * @param {string} readonlyareaselector the selector for the readonly area to apply the spellchecking\n * @param {string} spellcheckeditbuttonselector the selector for the spell check edit button\n */\nexport const init = (cmid, readonlyareaselector, spellcheckeditbuttonselector) => {\n renderDiff(readonlyareaselector);\n\n if (!document.querySelector(spellcheckeditbuttonselector)) {\n return;\n }\n document.querySelector(spellcheckeditbuttonselector).addEventListener('click',\n async(event) => {\n event.preventDefault();\n await showModalForm(cmid, readonlyareaselector);\n });\n};\n\n/**\n * Render the spell check highlighting.\n *\n * @param {string} readonlyareaselector the selector for the readonly area to apply the spell check diff to\n */\nexport const renderDiff = (readonlyareaselector) => {\n const studentanswer = document.querySelector(readonlyareaselector).innerHTML;\n const spellcheck = document.querySelector(readonlyareaselector).dataset.spellcheck;\n let span = null;\n\n const diff = Diff.diffChars(studentanswer, spellcheck);\n const fragment = document.createElement('div');\n\n let fullspellcheck = '';\n\n diff.forEach(part => {\n // We need to replace the whitespaces, because otherwise they will be removed by\n // calling parseFromString of the DOMParser.\n part.value = part.value.replace(/ /g, ' ');\n const parser = new DOMParser();\n part.value = parser.parseFromString(part.value, 'text/html');\n const cls = part.added ? 'qtype_aitext_spellcheck_new' :\n part.removed ? 'qtype_aitext_spellcheck_wrong' : '';\n if (part.added || part.removed) {\n span = document.createElement('span');\n span.classList = cls;\n span.appendChild(part.value.documentElement);\n fullspellcheck += span.outerHTML;\n } else {\n fullspellcheck += part.value.documentElement.textContent;\n }\n });\n\n fragment.innerHTML = fullspellcheck;\n document.querySelector(readonlyareaselector).replaceChildren(fragment);\n};\n\n/**\n * Show the dynamic spellcheck form.\n *\n * @param {int} cmid the course module id of the quiz\n * @param {string} readonlyareaselector the selector for the readonly area\n */\nexport const showModalForm = async(cmid, readonlyareaselector) => {\n const attemptstepid = document.querySelector(readonlyareaselector).dataset.spellcheckattemptstepid;\n const answerstepid = document.querySelector(readonlyareaselector).dataset.spellcheckattemptstepanswerid;\n const title = await getString('spellcheckedit', 'qtype_aitext');\n const modalForm = new ModalForm({\n formClass: \"qtype_aitext\\\\form\\\\edit_spellcheck\",\n args: {\n attemptstepid,\n answerstepid,\n cmid\n },\n modalConfig: {title},\n });\n modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, reloadpage);\n await modalForm.show();\n};\n\n/**\n * Reload the page.\n *\n * This is not nice, but easy :-) .\n */\nconst reloadpage = () => {\n location.reload();\n};\n"],"names":["cmid","readonlyareaselector","spellcheckeditbuttonselector","renderDiff","document","querySelector","addEventListener","async","event","preventDefault","showModalForm","studentanswer","innerHTML","spellcheck","dataset","span","diff","Diff","diffChars","fragment","createElement","fullspellcheck","forEach","part","value","replace","parser","DOMParser","parseFromString","cls","added","removed","classList","appendChild","documentElement","outerHTML","textContent","replaceChildren","attemptstepid","spellcheckattemptstepid","answerstepid","spellcheckattemptstepanswerid","title","modalForm","ModalForm","formClass","args","modalConfig","events","FORM_SUBMITTED","reloadpage","show","location","reload"],"mappings":";;;;;;;;wFAmCoB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","sources":["../src/spellcheck.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 * Generates the spellcheck diff view.\n *\n * @module qtype_aitext/spellcheck\n * @copyright 2024, ISB Bayern\n * @author Dr. Peter Mayer\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as Diff from 'qtype_aitext/diff';\nimport ModalForm from 'core_form/modalform';\nimport {getString as getString} from 'core/str';\n\n/**\n * Init the module.\n *\n * @param {string} readonlyareaselector the selector for the readonly area to apply the spellchecking\n * @param {string} spellcheckeditbuttonselector the selector for the spell check edit button\n */\nexport const init = (readonlyareaselector, spellcheckeditbuttonselector) => {\n renderDiff(readonlyareaselector);\n\n if (!document.querySelector(spellcheckeditbuttonselector)) {\n return;\n }\n document.querySelector(spellcheckeditbuttonselector).addEventListener('click',\n async(event) => {\n event.preventDefault();\n await showModalForm(readonlyareaselector);\n });\n};\n\n/**\n * Render the spell check highlighting.\n *\n * @param {string} readonlyareaselector the selector for the readonly area to apply the spell check diff to\n */\nexport const renderDiff = (readonlyareaselector) => {\n const studentanswer = document.querySelector(readonlyareaselector).innerHTML;\n const spellcheck = document.querySelector(readonlyareaselector).dataset.spellcheck;\n let span = null;\n\n const diff = Diff.diffChars(studentanswer, spellcheck);\n const fragment = document.createElement('div');\n\n let fullspellcheck = '';\n\n diff.forEach(part => {\n // We need to replace the whitespaces, because otherwise they will be removed by\n // calling parseFromString of the DOMParser.\n part.value = part.value.replace(/ /g, ' ');\n const parser = new DOMParser();\n part.value = parser.parseFromString(part.value, 'text/html');\n const cls = part.added ? 'qtype_aitext_spellcheck_new' :\n part.removed ? 'qtype_aitext_spellcheck_wrong' : '';\n if (part.added || part.removed) {\n span = document.createElement('span');\n span.classList = cls;\n span.appendChild(part.value.documentElement);\n fullspellcheck += span.outerHTML;\n } else {\n fullspellcheck += part.value.documentElement.textContent;\n }\n });\n\n fragment.innerHTML = fullspellcheck;\n document.querySelector(readonlyareaselector).replaceChildren(fragment);\n};\n\n/**\n * Show the dynamic spellcheck form.\n *\n * @param {string} readonlyareaselector the selector for the readonly area\n */\nexport const showModalForm = async(readonlyareaselector) => {\n const attemptstepid = document.querySelector(readonlyareaselector).dataset.spellcheckattemptstepid;\n const answerstepid = document.querySelector(readonlyareaselector).dataset.spellcheckattemptstepanswerid;\n const title = await getString('spellcheckedit', 'qtype_aitext');\n const modalForm = new ModalForm({\n formClass: \"qtype_aitext\\\\form\\\\edit_spellcheck\",\n args: {\n attemptstepid,\n answerstepid\n },\n modalConfig: {title},\n });\n modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, reloadpage);\n await modalForm.show();\n};\n\n/**\n * Reload the page.\n *\n * This is not nice, but easy :-) .\n */\nconst reloadpage = () => {\n location.reload();\n};\n"],"names":["readonlyareaselector","spellcheckeditbuttonselector","renderDiff","document","querySelector","addEventListener","async","event","preventDefault","showModalForm","studentanswer","innerHTML","spellcheck","dataset","span","diff","Diff","diffChars","fragment","createElement","fullspellcheck","forEach","part","value","replace","parser","DOMParser","parseFromString","cls","added","removed","classList","appendChild","documentElement","outerHTML","textContent","replaceChildren","attemptstepid","spellcheckattemptstepid","answerstepid","spellcheckattemptstepanswerid","title","modalForm","ModalForm","formClass","args","modalConfig","events","FORM_SUBMITTED","reloadpage","show","location","reload"],"mappings":";;;;;;;;wFAkCoB,CAACA,qBAAsBC,gCACvCC,WAAWF,sBAENG,SAASC,cAAcH,+BAG5BE,SAASC,cAAcH,8BAA8BI,iBAAiB,SAClEC,MAAAA,QACIC,MAAMC,uBACAC,cAAcT,gCASnBE,WAAcF,6BACjBU,cAAgBP,SAASC,cAAcJ,sBAAsBW,UAC7DC,WAAaT,SAASC,cAAcJ,sBAAsBa,QAAQD,eACpEE,KAAO,WAELC,KAAOC,KAAKC,UAAUP,cAAeE,YACrCM,SAAWf,SAASgB,cAAc,WAEpCC,eAAiB,GAErBL,KAAKM,SAAQC,OAGTA,KAAKC,MAAQD,KAAKC,MAAMC,QAAQ,KAAM,gBAChCC,OAAS,IAAIC,UACnBJ,KAAKC,MAAQE,OAAOE,gBAAgBL,KAAKC,MAAO,mBAC1CK,IAAMN,KAAKO,MAAQ,8BACrBP,KAAKQ,QAAU,gCAAkC,GACjDR,KAAKO,OAASP,KAAKQ,SACnBhB,KAAOX,SAASgB,cAAc,QAC9BL,KAAKiB,UAAYH,IACjBd,KAAKkB,YAAYV,KAAKC,MAAMU,iBAC5Bb,gBAAkBN,KAAKoB,WAEvBd,gBAAkBE,KAAKC,MAAMU,gBAAgBE,eAIrDjB,SAASP,UAAYS,eACrBjB,SAASC,cAAcJ,sBAAsBoC,gBAAgBlB,gDAQpDT,cAAgBH,MAAAA,6BACnB+B,cAAgBlC,SAASC,cAAcJ,sBAAsBa,QAAQyB,wBACrEC,aAAepC,SAASC,cAAcJ,sBAAsBa,QAAQ2B,8BACpEC,YAAc,kBAAU,iBAAkB,gBAC1CC,UAAY,IAAIC,mBAAU,CAC5BC,UAAW,sCACXC,KAAM,CACFR,cAAAA,cACAE,aAAAA,cAEJO,YAAa,CAACL,MAAAA,SAElBC,UAAUrC,iBAAiBqC,UAAUK,OAAOC,eAAgBC,kBACtDP,UAAUQ,mDAQdD,WAAa,KACfE,SAASC"} \ No newline at end of file diff --git a/amd/src/spellcheck.js b/amd/src/spellcheck.js index f6afa16..a46c1f2 100644 --- a/amd/src/spellcheck.js +++ b/amd/src/spellcheck.js @@ -29,11 +29,10 @@ import {getString as getString} from 'core/str'; /** * Init the module. * - * @param {int} cmid the course module id of the quiz. * @param {string} readonlyareaselector the selector for the readonly area to apply the spellchecking * @param {string} spellcheckeditbuttonselector the selector for the spell check edit button */ -export const init = (cmid, readonlyareaselector, spellcheckeditbuttonselector) => { +export const init = (readonlyareaselector, spellcheckeditbuttonselector) => { renderDiff(readonlyareaselector); if (!document.querySelector(spellcheckeditbuttonselector)) { @@ -42,7 +41,7 @@ export const init = (cmid, readonlyareaselector, spellcheckeditbuttonselector) = document.querySelector(spellcheckeditbuttonselector).addEventListener('click', async(event) => { event.preventDefault(); - await showModalForm(cmid, readonlyareaselector); + await showModalForm(readonlyareaselector); }); }; @@ -86,10 +85,9 @@ export const renderDiff = (readonlyareaselector) => { /** * Show the dynamic spellcheck form. * - * @param {int} cmid the course module id of the quiz * @param {string} readonlyareaselector the selector for the readonly area */ -export const showModalForm = async(cmid, readonlyareaselector) => { +export const showModalForm = async(readonlyareaselector) => { const attemptstepid = document.querySelector(readonlyareaselector).dataset.spellcheckattemptstepid; const answerstepid = document.querySelector(readonlyareaselector).dataset.spellcheckattemptstepanswerid; const title = await getString('spellcheckedit', 'qtype_aitext'); @@ -97,8 +95,7 @@ export const showModalForm = async(cmid, readonlyareaselector) => { formClass: "qtype_aitext\\form\\edit_spellcheck", args: { attemptstepid, - answerstepid, - cmid + answerstepid }, modalConfig: {title}, }); diff --git a/classes/form/edit_spellcheck.php b/classes/form/edit_spellcheck.php index 9584503..83b40e2 100644 --- a/classes/form/edit_spellcheck.php +++ b/classes/form/edit_spellcheck.php @@ -41,9 +41,6 @@ public function definition() { $mform = &$this->_form; - $mform->addElement('hidden', 'cmid'); - $mform->setType('cmid', PARAM_INT); - $mform->addElement('hidden', 'attemptstepid'); $mform->setType('attemptstepid', PARAM_INT); @@ -141,7 +138,6 @@ public function set_data_for_dynamic_submission(): void { 'test' => $spellcheckrecord->value, 'spellcheck_editor' => ['text' => $spellcheckrecord->value, 'format' => FORMAT_HTML, 'itemid' => $draftitemid], 'attemptstepid' => $this->optional_param('attemptstepid', 0, PARAM_INT), - 'cmid' => $this->optional_param('cmid', 0, PARAM_INT), 'student_answer' => $answerrecord->value, ]); } diff --git a/renderer.php b/renderer.php index 30cb24a..2902cc6 100755 --- a/renderer.php +++ b/renderer.php @@ -292,7 +292,7 @@ public function response_area_read_only($name, $qa, $step, $lines, $context) { if ($question->spellcheck) { $this->page->requires->js_call_amd('qtype_aitext/diff'); $this->page->requires->js_call_amd('qtype_aitext/spellcheck', 'init', - [$this->get_page()->cm->id, '#' . $readonlyareaid, '#' . $spellcheckeditbuttonid]); + ['#' . $readonlyareaid, '#' . $spellcheckeditbuttonid]); $stepspellcheck = $qa->get_last_step_with_qt_var('-spellcheckresponse'); $stepanswer = $qa->get_last_step_with_qt_var('answer'); }