From 1827c152cd348d04a65a6016f7a03bd436ccbfe0 Mon Sep 17 00:00:00 2001 From: Stephan Robotta Date: Sat, 12 Oct 2024 17:28:41 +0200 Subject: [PATCH] Display the REGEX types on the Clozergx question only. --- amd/build/commands.min.js | 2 +- amd/build/commands.min.js.map | 2 +- amd/build/options.min.js | 4 ++-- amd/build/options.min.js.map | 2 +- amd/src/commands.js | 22 +++++++++++++++++----- amd/src/options.js | 3 ++- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/amd/build/commands.min.js b/amd/build/commands.min.js index 37e3c29..714a382 100644 --- a/amd/build/commands.min.js +++ b/amd/build/commands.min.js @@ -1,3 +1,3 @@ -define("tiny_cloze/commands",["exports","editor_tiny/utils","core/str","./common","./ui"],(function(_exports,_utils,_str,_common,_ui){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.getSetup=void 0;_exports.getSetup=async()=>{const[clozeButtonText,buttonImage]=await Promise.all([(0,_str.get_string)("pluginname",_common.component),(0,_utils.getButtonImage)("icon",_common.component)]);return editor=>{document.querySelector("body#page-question-type-multianswer form, body#page-question-type-multianswerwiris form,body#page-question-type-multianswerrgx form")&&-1!==editor.id.indexOf("questiontext")&&(editor.ui.registry.addIcon(_common.icon,buttonImage.html),editor.ui.registry.addToggleButton(_common.clozeeditButtonName,{icon:_common.icon,tooltip:clozeButtonText,onAction:()=>(0,_ui.displayDialogue)(),onSetup:api=>{editor.on("click",(()=>{api.setActive(!1!==(0,_ui.resolveSubquestion)())}))}}),editor.ui.registry.addMenuItem(_common.clozeeditButtonName,{icon:_common.icon,text:clozeButtonText,onAction:()=>(0,_ui.displayDialogue)()}),editor.on("init",(()=>(0,_ui.onInit)(editor))),editor.on("BeforeGetContent",(format=>(0,_ui.onBeforeGetContent)(format))),editor.on("submit",(()=>(0,_ui.onSubmit)())),editor.on("dblclick",(e=>(0,_ui.displayDialogueForEdit)(e.target))))}}})); +define("tiny_cloze/commands",["exports","editor_tiny/utils","core/str","./common","./ui","./options"],(function(_exports,_utils,_str,_common,_ui,_options){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.getSetup=void 0;_exports.getSetup=async()=>{const[clozeButtonText,buttonImage]=await Promise.all([(0,_str.get_string)("pluginname",_common.component),(0,_utils.getButtonImage)("icon",_common.component)]);return editor=>{const body=document.querySelector("body#page-question-type-multianswer, body#page-question-type-multianswerwiris,body#page-question-type-multianswerrgx");body&&-1!==editor.id.indexOf("questiontext")&&(-1===body.id.indexOf("multianswerrgx")&&(0,_options.disableQtypeMultianswerrgx)(editor),editor.ui.registry.addIcon(_common.icon,buttonImage.html),editor.ui.registry.addToggleButton(_common.clozeeditButtonName,{icon:_common.icon,tooltip:clozeButtonText,onAction:()=>(0,_ui.displayDialogue)(),onSetup:api=>{editor.on("click",(()=>{api.setActive(!1!==(0,_ui.resolveSubquestion)())}))}}),editor.ui.registry.addMenuItem(_common.clozeeditButtonName,{icon:_common.icon,text:clozeButtonText,onAction:()=>(0,_ui.displayDialogue)()}),editor.on("init",(()=>(0,_ui.onInit)(editor))),editor.on("BeforeGetContent",(format=>(0,_ui.onBeforeGetContent)(format))),editor.on("submit",(()=>(0,_ui.onSubmit)())),editor.on("dblclick",(e=>(0,_ui.displayDialogueForEdit)(e.target))))}}})); //# sourceMappingURL=commands.min.js.map \ No newline at end of file diff --git a/amd/build/commands.min.js.map b/amd/build/commands.min.js.map index a06b0ba..1a0c869 100644 --- a/amd/build/commands.min.js.map +++ b/amd/build/commands.min.js.map @@ -1 +1 @@ -{"version":3,"file":"commands.min.js","sources":["../src/commands.js"],"sourcesContent":["// This file is part of Moodle - https://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 * Commands helper for the Moodle tiny_cloze plugin.\n *\n * @module tiny_cloze/commands\n * @copyright 2023 MoodleDACH\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getButtonImage} from 'editor_tiny/utils';\nimport {get_string as getString} from 'core/str';\nimport {\n component,\n clozeeditButtonName,\n icon,\n} from './common';\nimport {displayDialogue, displayDialogueForEdit, resolveSubquestion, onInit, onBeforeGetContent, onSubmit} from './ui';\n\n/**\n * Get the setup function for the buttons.\n *\n * This is performed in an async function which ultimately returns the registration function as the\n * Tiny.AddOnManager.Add() function does not support async functions.\n *\n * @returns {function} The registration function to call within the Plugin.add function.\n */\nexport const getSetup = async() => {\n const [\n clozeButtonText,\n buttonImage,\n ] = await Promise.all([\n getString('pluginname', component),\n getButtonImage('icon', component),\n ]);\n\n return (editor) => {\n // Check whether we are editing a question.\n const body = document.querySelector('body#page-question-type-multianswer form, ' +\n 'body#page-question-type-multianswerwiris form,' +\n 'body#page-question-type-multianswerrgx form'\n );\n // And if the editor is used on the question text.\n if (!body || editor.id.indexOf('questiontext') === -1) {\n return;\n }\n // Only if both conditions are valid, then continue setting up the plugin.\n\n // Register the Moodle SVG as an icon suitable for use as a TinyMCE toolbar button.\n editor.ui.registry.addIcon(icon, buttonImage.html);\n\n // Register the clozeedit Toolbar Button.\n editor.ui.registry.addToggleButton(clozeeditButtonName, {\n icon,\n tooltip: clozeButtonText,\n onAction: () => displayDialogue(),\n onSetup: (api) => {\n editor.on('click', () => {\n api.setActive(resolveSubquestion() !== false);\n });\n }\n });\n\n // Register the menu item.\n editor.ui.registry.addMenuItem(clozeeditButtonName, {\n icon,\n text: clozeButtonText,\n onAction: () => displayDialogue(),\n });\n\n editor.on('init', () => onInit(editor));\n editor.on('BeforeGetContent', format => onBeforeGetContent(format));\n editor.on('submit', () => onSubmit());\n editor.on('dblclick', (e) => displayDialogueForEdit(e.target));\n };\n};\n"],"names":["async","clozeButtonText","buttonImage","Promise","all","component","editor","document","querySelector","id","indexOf","ui","registry","addIcon","icon","html","addToggleButton","clozeeditButtonName","tooltip","onAction","onSetup","api","on","setActive","addMenuItem","text","format","e","target"],"mappings":"yOAwCwBA,gBAEhBC,gBACAC,mBACMC,QAAQC,IAAI,EAClB,mBAAU,aAAcC,oBACxB,yBAAe,OAAQA,4BAGnBC,SAESC,SAASC,cAAc,yIAKgB,IAAvCF,OAAOG,GAAGC,QAAQ,kBAM/BJ,OAAOK,GAAGC,SAASC,QAAQC,aAAMZ,YAAYa,MAG7CT,OAAOK,GAAGC,SAASI,gBAAgBC,4BAAqB,CACpDH,KAAAA,aACAI,QAASjB,gBACTkB,SAAU,KAAM,yBAChBC,QAAUC,MACNf,OAAOgB,GAAG,SAAS,KACdD,IAAIE,WAAmC,KAAzB,mCAM3BjB,OAAOK,GAAGC,SAASY,YAAYP,4BAAqB,CAChDH,KAAAA,aACAW,KAAMxB,gBACNkB,SAAU,KAAM,2BAGpBb,OAAOgB,GAAG,QAAQ,KAAM,cAAOhB,UAC/BA,OAAOgB,GAAG,oBAAoBI,SAAU,0BAAmBA,UAC3DpB,OAAOgB,GAAG,UAAU,KAAM,oBAC1BhB,OAAOgB,GAAG,YAAaK,IAAM,8BAAuBA,EAAEC"} \ No newline at end of file +{"version":3,"file":"commands.min.js","sources":["../src/commands.js"],"sourcesContent":["// This file is part of Moodle - https://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 * Commands helper for the Moodle tiny_cloze plugin.\n *\n * @module tiny_cloze/commands\n * @copyright 2023 MoodleDACH\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getButtonImage} from 'editor_tiny/utils';\nimport {get_string as getString} from 'core/str';\nimport {\n component,\n clozeeditButtonName,\n icon,\n} from './common';\nimport {\n displayDialogue,\n displayDialogueForEdit,\n resolveSubquestion,\n onInit,\n onBeforeGetContent,\n onSubmit\n} from './ui';\nimport {disableQtypeMultianswerrgx} from './options';\n\n/**\n * Get the setup function for the buttons.\n *\n * This is performed in an async function which ultimately returns the registration function as the\n * Tiny.AddOnManager.Add() function does not support async functions.\n *\n * @returns {function} The registration function to call within the Plugin.add function.\n */\nexport const getSetup = async() => {\n const [\n clozeButtonText,\n buttonImage,\n ] = await Promise.all([\n getString('pluginname', component),\n getButtonImage('icon', component),\n ]);\n\n return (editor) => {\n // Check whether we are editing a question.\n const body = document.querySelector('body#page-question-type-multianswer, ' +\n 'body#page-question-type-multianswerwiris,' +\n 'body#page-question-type-multianswerrgx'\n );\n // And if the editor is used on the question text.\n if (!body || editor.id.indexOf('questiontext') === -1) {\n return;\n }\n // Only if all conditions are valid, then continue setting up the plugin.\n // However, if we have not a body#page-question-type-multianswerrgx then disable the regex types.\n if (body.id.indexOf('multianswerrgx') === -1) {\n disableQtypeMultianswerrgx(editor);\n }\n\n // Register the Moodle SVG as an icon suitable for use as a TinyMCE toolbar button.\n editor.ui.registry.addIcon(icon, buttonImage.html);\n\n // Register the clozeedit Toolbar Button.\n editor.ui.registry.addToggleButton(clozeeditButtonName, {\n icon,\n tooltip: clozeButtonText,\n onAction: () => displayDialogue(),\n onSetup: (api) => {\n editor.on('click', () => {\n api.setActive(resolveSubquestion() !== false);\n });\n }\n });\n\n // Register the menu item.\n editor.ui.registry.addMenuItem(clozeeditButtonName, {\n icon,\n text: clozeButtonText,\n onAction: () => displayDialogue(),\n });\n\n editor.on('init', () => onInit(editor));\n editor.on('BeforeGetContent', format => onBeforeGetContent(format));\n editor.on('submit', () => onSubmit());\n editor.on('dblclick', (e) => displayDialogueForEdit(e.target));\n };\n};\n"],"names":["async","clozeButtonText","buttonImage","Promise","all","component","editor","body","document","querySelector","id","indexOf","ui","registry","addIcon","icon","html","addToggleButton","clozeeditButtonName","tooltip","onAction","onSetup","api","on","setActive","addMenuItem","text","format","e","target"],"mappings":"8PAgDwBA,gBAEhBC,gBACAC,mBACMC,QAAQC,IAAI,EAClB,mBAAU,aAAcC,oBACxB,yBAAe,OAAQA,4BAGnBC,eAEEC,KAAOC,SAASC,cAAc,wHAK/BF,OAA+C,IAAvCD,OAAOI,GAAGC,QAAQ,mBAKY,IAAvCJ,KAAKG,GAAGC,QAAQ,2DACWL,QAI/BA,OAAOM,GAAGC,SAASC,QAAQC,aAAMb,YAAYc,MAG7CV,OAAOM,GAAGC,SAASI,gBAAgBC,4BAAqB,CACpDH,KAAAA,aACAI,QAASlB,gBACTmB,SAAU,KAAM,yBAChBC,QAAUC,MACNhB,OAAOiB,GAAG,SAAS,KACdD,IAAIE,WAAmC,KAAzB,mCAM3BlB,OAAOM,GAAGC,SAASY,YAAYP,4BAAqB,CAChDH,KAAAA,aACAW,KAAMzB,gBACNmB,SAAU,KAAM,2BAGpBd,OAAOiB,GAAG,QAAQ,KAAM,cAAOjB,UAC/BA,OAAOiB,GAAG,oBAAoBI,SAAU,0BAAmBA,UAC3DrB,OAAOiB,GAAG,UAAU,KAAM,oBAC1BjB,OAAOiB,GAAG,YAAaK,IAAM,8BAAuBA,EAAEC"} \ No newline at end of file diff --git a/amd/build/options.min.js b/amd/build/options.min.js index f7743df..dc96050 100644 --- a/amd/build/options.min.js +++ b/amd/build/options.min.js @@ -1,4 +1,4 @@ -define("tiny_cloze/options",["exports","editor_tiny/options","./common"],(function(_exports,_options,_common){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.register=_exports.hasQtypeMultianswerrgx=void 0; +define("tiny_cloze/options",["exports","editor_tiny/options","./common"],(function(_exports,_options,_common){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.register=_exports.hasQtypeMultianswerrgx=_exports.disableQtypeMultianswerrgx=void 0; /** * Options helper for tiny_cloze plugin. * @@ -6,6 +6,6 @@ define("tiny_cloze/options",["exports","editor_tiny/options","./common"],(functi * @copyright 2024 Stephan Robotta * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -const multianswerrgx=(0,_options.getPluginOptionName)(_common.pluginName,"multianswerrgx");_exports.register=editor=>{editor.options.register(multianswerrgx,{processor:"boolean",default:!1})};_exports.hasQtypeMultianswerrgx=editor=>editor.options.get(multianswerrgx)})); +const multianswerrgx=(0,_options.getPluginOptionName)(_common.pluginName,"multianswerrgx");_exports.register=editor=>{editor.options.register(multianswerrgx,{processor:"boolean",default:!1})};_exports.hasQtypeMultianswerrgx=editor=>editor.options.get(multianswerrgx);_exports.disableQtypeMultianswerrgx=editor=>editor.options.set(multianswerrgx,!1)})); //# sourceMappingURL=options.min.js.map \ No newline at end of file diff --git a/amd/build/options.min.js.map b/amd/build/options.min.js.map index fe396e5..229dcb0 100644 --- a/amd/build/options.min.js.map +++ b/amd/build/options.min.js.map @@ -1 +1 @@ -{"version":3,"file":"options.min.js","sources":["../src/options.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 * Options helper for tiny_cloze plugin.\n *\n * @module tiny_cloze\n * @copyright 2024 Stephan Robotta \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getPluginOptionName} from 'editor_tiny/options';\nimport {pluginName} from './common';\n\nconst multianswerrgx = getPluginOptionName(pluginName, 'multianswerrgx');\n\n/**\n * Register the options for the Tiny Cloze question plugin.\n *\n * @param {tinymce.Editor} editor\n */\nexport const register = (editor) => {\n editor.options.register(multianswerrgx, {\n processor: 'boolean',\n \"default\": false,\n });\n};\n\nexport const hasQtypeMultianswerrgx = (editor) => editor.options.get(multianswerrgx);"],"names":["multianswerrgx","pluginName","editor","options","register","processor","get"],"mappings":";;;;;;;;MA0BMA,gBAAiB,gCAAoBC,mBAAY,oCAO9BC,SACrBA,OAAOC,QAAQC,SAASJ,eAAgB,CACpCK,UAAW,mBACA,qCAIoBH,QAAWA,OAAOC,QAAQG,IAAIN"} \ No newline at end of file +{"version":3,"file":"options.min.js","sources":["../src/options.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 * Options helper for tiny_cloze plugin.\n *\n * @module tiny_cloze\n * @copyright 2024 Stephan Robotta \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getPluginOptionName} from 'editor_tiny/options';\nimport {pluginName} from './common';\n\nconst multianswerrgx = getPluginOptionName(pluginName, 'multianswerrgx');\n\n/**\n * Register the options for the Tiny Cloze question plugin.\n *\n * @param {tinymce.Editor} editor\n */\nexport const register = (editor) => {\n editor.options.register(multianswerrgx, {\n processor: 'boolean',\n \"default\": false,\n });\n};\n\nexport const hasQtypeMultianswerrgx = (editor) => editor.options.get(multianswerrgx);\nexport const disableQtypeMultianswerrgx = (editor) => editor.options.set(multianswerrgx, false);"],"names":["multianswerrgx","pluginName","editor","options","register","processor","get","set"],"mappings":";;;;;;;;MA0BMA,gBAAiB,gCAAoBC,mBAAY,oCAO9BC,SACrBA,OAAOC,QAAQC,SAASJ,eAAgB,CACpCK,UAAW,mBACA,qCAIoBH,QAAWA,OAAOC,QAAQG,IAAIN,oDAC1BE,QAAWA,OAAOC,QAAQI,IAAIP,gBAAgB"} \ No newline at end of file diff --git a/amd/src/commands.js b/amd/src/commands.js index 534296e..ac40930 100644 --- a/amd/src/commands.js +++ b/amd/src/commands.js @@ -28,7 +28,15 @@ import { clozeeditButtonName, icon, } from './common'; -import {displayDialogue, displayDialogueForEdit, resolveSubquestion, onInit, onBeforeGetContent, onSubmit} from './ui'; +import { + displayDialogue, + displayDialogueForEdit, + resolveSubquestion, + onInit, + onBeforeGetContent, + onSubmit +} from './ui'; +import {disableQtypeMultianswerrgx} from './options'; /** * Get the setup function for the buttons. @@ -49,15 +57,19 @@ export const getSetup = async() => { return (editor) => { // Check whether we are editing a question. - const body = document.querySelector('body#page-question-type-multianswer form, ' + - 'body#page-question-type-multianswerwiris form,' + - 'body#page-question-type-multianswerrgx form' + const body = document.querySelector('body#page-question-type-multianswer, ' + + 'body#page-question-type-multianswerwiris,' + + 'body#page-question-type-multianswerrgx' ); // And if the editor is used on the question text. if (!body || editor.id.indexOf('questiontext') === -1) { return; } - // Only if both conditions are valid, then continue setting up the plugin. + // Only if all conditions are valid, then continue setting up the plugin. + // However, if we have not a body#page-question-type-multianswerrgx then disable the regex types. + if (body.id.indexOf('multianswerrgx') === -1) { + disableQtypeMultianswerrgx(editor); + } // Register the Moodle SVG as an icon suitable for use as a TinyMCE toolbar button. editor.ui.registry.addIcon(icon, buttonImage.html); diff --git a/amd/src/options.js b/amd/src/options.js index 65c939a..7baa34e 100644 --- a/amd/src/options.js +++ b/amd/src/options.js @@ -38,4 +38,5 @@ export const register = (editor) => { }); }; -export const hasQtypeMultianswerrgx = (editor) => editor.options.get(multianswerrgx); \ No newline at end of file +export const hasQtypeMultianswerrgx = (editor) => editor.options.get(multianswerrgx); +export const disableQtypeMultianswerrgx = (editor) => editor.options.set(multianswerrgx, false); \ No newline at end of file