From ec02c39dbb1a3bddd8aa67d1fea255eb66fb6ca9 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Fri, 10 Feb 2023 09:47:29 +0800 Subject: [PATCH] MDL-77140 mod_lti: fix content item return for new TinyMCE versions --- mod/lti/amd/build/form-field.min.js | 2 +- mod/lti/amd/build/form-field.min.js.map | 2 +- mod/lti/amd/src/form-field.js | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mod/lti/amd/build/form-field.min.js b/mod/lti/amd/build/form-field.min.js index 3b05a05280c..66ef3c13f8d 100644 --- a/mod/lti/amd/build/form-field.min.js +++ b/mod/lti/amd/build/form-field.min.js @@ -6,6 +6,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since 3.2 */ -define("mod_lti/form-field",["jquery"],(function($){var FormField=function(name,type,resetIfUndefined,defaultValue){this.name=name,this.id="id_"+this.name,this.selector="#"+this.id,this.type=type,this.resetIfUndefined=resetIfUndefined,this.defaultValue=defaultValue};return FormField.TYPES={TEXT:1,SELECT:2,CHECKBOX:3,EDITOR:4},FormField.prototype.setFieldValue=function(value){if(null===value){if(!this.resetIfUndefined)return;value=this.defaultValue}switch(this.type){case FormField.TYPES.CHECKBOX:value?$(this.selector).prop("checked",!0):$(this.selector).prop("checked",!1);break;case FormField.TYPES.EDITOR:if(void 0!==value.text){var attoEditor=$(this.selector+"editable");attoEditor.length?attoEditor.html(value.text):"undefined"!=typeof tinyMCE&&tinyMCE.execInstanceCommand(this.id,"mceInsertContent",!1,value.text),$(this.selector).val(value.text)}break;default:$(this.selector).val(value)}},FormField})); +define("mod_lti/form-field",["jquery"],(function($){var FormField=function(name,type,resetIfUndefined,defaultValue){this.name=name,this.id="id_"+this.name,this.selector="#"+this.id,this.type=type,this.resetIfUndefined=resetIfUndefined,this.defaultValue=defaultValue};return FormField.TYPES={TEXT:1,SELECT:2,CHECKBOX:3,EDITOR:4},FormField.prototype.setFieldValue=function(value){if(null===value){if(!this.resetIfUndefined)return;value=this.defaultValue}switch(this.type){case FormField.TYPES.CHECKBOX:value?$(this.selector).prop("checked",!0):$(this.selector).prop("checked",!1);break;case FormField.TYPES.EDITOR:if(void 0!==value.text){var attoEditor=$(this.selector+"editable");attoEditor.length?attoEditor.html(value.text):"undefined"!=typeof tinyMCE&&("3"==tinyMCE.majorVersion?tinyMCE.execInstanceCommand(this.id,"mceInsertContent",!1,value.text):tinyMCE.get(this.id).setContent(value.text)),$(this.selector).val(value.text)}break;default:$(this.selector).val(value)}},FormField})); //# sourceMappingURL=form-field.min.js.map \ No newline at end of file diff --git a/mod/lti/amd/build/form-field.min.js.map b/mod/lti/amd/build/form-field.min.js.map index 12aba932959..b096ee3944c 100644 --- a/mod/lti/amd/build/form-field.min.js.map +++ b/mod/lti/amd/build/form-field.min.js.map @@ -1 +1 @@ -{"version":3,"file":"form-field.min.js","sources":["../src/form-field.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 * A module that enables the setting of form field values on the client side.\n *\n * @module mod_lti/form-field\n * @copyright 2016 Jun Pataleta \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.2\n */\ndefine(['jquery'],\n function($) {\n /**\n * Form field class.\n *\n * @param {string} name Field name.\n * @param {number} type The field type.\n * @param {boolean} resetIfUndefined Flag to reset the field to the default value if undefined in the return data.\n * @param {string|number|boolean} defaultValue The default value to use for the field.\n * @constructor\n */\n var FormField = function(name, type, resetIfUndefined, defaultValue) {\n this.name = name;\n this.id = 'id_' + this.name;\n this.selector = '#' + this.id;\n this.type = type;\n this.resetIfUndefined = resetIfUndefined;\n this.defaultValue = defaultValue;\n };\n\n /**\n * Form field types.\n *\n * @type {{TEXT: number, SELECT: number, CHECKBOX: number, EDITOR: number}}\n */\n FormField.TYPES = {\n TEXT: 1,\n SELECT: 2,\n CHECKBOX: 3,\n EDITOR: 4\n };\n\n /**\n * Sets the values for a form field.\n *\n * @param {string|boolean|number} value The value to be set into the field.\n */\n FormField.prototype.setFieldValue = function(value) {\n if (value === null) {\n if (this.resetIfUndefined) {\n value = this.defaultValue;\n } else {\n // No need set the field value if value is null and there's no need to reset the field.\n return;\n }\n }\n\n switch (this.type) {\n case FormField.TYPES.CHECKBOX:\n if (value) {\n $(this.selector).prop('checked', true);\n } else {\n $(this.selector).prop('checked', false);\n }\n break;\n case FormField.TYPES.EDITOR:\n if (typeof value.text !== 'undefined') {\n /* global tinyMCE:false */\n\n // Set text in editor's editable content, if applicable.\n // Check if it is an Atto editor.\n var attoEditor = $(this.selector + 'editable');\n if (attoEditor.length) {\n attoEditor.html(value.text);\n } else if (typeof tinyMCE !== 'undefined') {\n // If the editor is not Atto, try to fallback to TinyMCE.\n tinyMCE.execInstanceCommand(this.id, 'mceInsertContent', false, value.text);\n }\n\n // Set text to actual editor text area.\n $(this.selector).val(value.text);\n }\n break;\n default:\n $(this.selector).val(value);\n break;\n }\n };\n\n return FormField;\n }\n);\n"],"names":["define","$","FormField","name","type","resetIfUndefined","defaultValue","id","this","selector","TYPES","TEXT","SELECT","CHECKBOX","EDITOR","prototype","setFieldValue","value","prop","text","attoEditor","length","html","tinyMCE","execInstanceCommand","val"],"mappings":";;;;;;;;AAuBAA,4BAAO,CAAC,WACJ,SAASC,OAUDC,UAAY,SAASC,KAAMC,KAAMC,iBAAkBC,mBAC9CH,KAAOA,UACPI,GAAK,MAAQC,KAAKL,UAClBM,SAAW,IAAMD,KAAKD,QACtBH,KAAOA,UACPC,iBAAmBA,sBACnBC,aAAeA,qBAQxBJ,UAAUQ,MAAQ,CACdC,KAAM,EACNC,OAAQ,EACRC,SAAU,EACVC,OAAQ,GAQZZ,UAAUa,UAAUC,cAAgB,SAASC,UAC3B,OAAVA,MAAgB,KACZT,KAAKH,wBACLY,MAAQT,KAAKF,oBAObE,KAAKJ,WACJF,UAAUQ,MAAMG,SACbI,MACAhB,EAAEO,KAAKC,UAAUS,KAAK,WAAW,GAEjCjB,EAAEO,KAAKC,UAAUS,KAAK,WAAW,cAGpChB,UAAUQ,MAAMI,eACS,IAAfG,MAAME,KAAsB,KAK/BC,WAAanB,EAAEO,KAAKC,SAAW,YAC/BW,WAAWC,OACXD,WAAWE,KAAKL,MAAME,MACI,oBAAZI,SAEdA,QAAQC,oBAAoBhB,KAAKD,GAAI,oBAAoB,EAAOU,MAAME,MAI1ElB,EAAEO,KAAKC,UAAUgB,IAAIR,MAAME,oBAI/BlB,EAAEO,KAAKC,UAAUgB,IAAIR,SAK1Bf"} \ No newline at end of file +{"version":3,"file":"form-field.min.js","sources":["../src/form-field.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 * A module that enables the setting of form field values on the client side.\n *\n * @module mod_lti/form-field\n * @copyright 2016 Jun Pataleta \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.2\n */\ndefine(['jquery'],\n function($) {\n /**\n * Form field class.\n *\n * @param {string} name Field name.\n * @param {number} type The field type.\n * @param {boolean} resetIfUndefined Flag to reset the field to the default value if undefined in the return data.\n * @param {string|number|boolean} defaultValue The default value to use for the field.\n * @constructor\n */\n var FormField = function(name, type, resetIfUndefined, defaultValue) {\n this.name = name;\n this.id = 'id_' + this.name;\n this.selector = '#' + this.id;\n this.type = type;\n this.resetIfUndefined = resetIfUndefined;\n this.defaultValue = defaultValue;\n };\n\n /**\n * Form field types.\n *\n * @type {{TEXT: number, SELECT: number, CHECKBOX: number, EDITOR: number}}\n */\n FormField.TYPES = {\n TEXT: 1,\n SELECT: 2,\n CHECKBOX: 3,\n EDITOR: 4\n };\n\n /**\n * Sets the values for a form field.\n *\n * @param {string|boolean|number} value The value to be set into the field.\n */\n FormField.prototype.setFieldValue = function(value) {\n if (value === null) {\n if (this.resetIfUndefined) {\n value = this.defaultValue;\n } else {\n // No need set the field value if value is null and there's no need to reset the field.\n return;\n }\n }\n\n switch (this.type) {\n case FormField.TYPES.CHECKBOX:\n if (value) {\n $(this.selector).prop('checked', true);\n } else {\n $(this.selector).prop('checked', false);\n }\n break;\n case FormField.TYPES.EDITOR:\n if (typeof value.text !== 'undefined') {\n /* global tinyMCE:false */\n\n // Set text in editor's editable content, if applicable.\n // Check if it is an Atto editor.\n var attoEditor = $(this.selector + 'editable');\n if (attoEditor.length) {\n attoEditor.html(value.text);\n } else if (typeof tinyMCE !== 'undefined') {\n // If the editor is not Atto, try to fallback to TinyMCE.\n if (tinyMCE.majorVersion == \"3\") {\n // Tiny 3.\n tinyMCE.execInstanceCommand(this.id, 'mceInsertContent', false, value.text);\n } else {\n // Tiny 4+.\n tinyMCE.get(this.id).setContent(value.text);\n }\n }\n\n // Set text to actual editor text area.\n $(this.selector).val(value.text);\n }\n break;\n default:\n $(this.selector).val(value);\n break;\n }\n };\n\n return FormField;\n }\n);\n"],"names":["define","$","FormField","name","type","resetIfUndefined","defaultValue","id","this","selector","TYPES","TEXT","SELECT","CHECKBOX","EDITOR","prototype","setFieldValue","value","prop","text","attoEditor","length","html","tinyMCE","majorVersion","execInstanceCommand","get","setContent","val"],"mappings":";;;;;;;;AAuBAA,4BAAO,CAAC,WACJ,SAASC,OAUDC,UAAY,SAASC,KAAMC,KAAMC,iBAAkBC,mBAC9CH,KAAOA,UACPI,GAAK,MAAQC,KAAKL,UAClBM,SAAW,IAAMD,KAAKD,QACtBH,KAAOA,UACPC,iBAAmBA,sBACnBC,aAAeA,qBAQxBJ,UAAUQ,MAAQ,CACdC,KAAM,EACNC,OAAQ,EACRC,SAAU,EACVC,OAAQ,GAQZZ,UAAUa,UAAUC,cAAgB,SAASC,UAC3B,OAAVA,MAAgB,KACZT,KAAKH,wBACLY,MAAQT,KAAKF,oBAObE,KAAKJ,WACJF,UAAUQ,MAAMG,SACbI,MACAhB,EAAEO,KAAKC,UAAUS,KAAK,WAAW,GAEjCjB,EAAEO,KAAKC,UAAUS,KAAK,WAAW,cAGpChB,UAAUQ,MAAMI,eACS,IAAfG,MAAME,KAAsB,KAK/BC,WAAanB,EAAEO,KAAKC,SAAW,YAC/BW,WAAWC,OACXD,WAAWE,KAAKL,MAAME,MACI,oBAAZI,UAEc,KAAxBA,QAAQC,aAERD,QAAQE,oBAAoBjB,KAAKD,GAAI,oBAAoB,EAAOU,MAAME,MAGtEI,QAAQG,IAAIlB,KAAKD,IAAIoB,WAAWV,MAAME,OAK9ClB,EAAEO,KAAKC,UAAUmB,IAAIX,MAAME,oBAI/BlB,EAAEO,KAAKC,UAAUmB,IAAIX,SAK1Bf"} \ No newline at end of file diff --git a/mod/lti/amd/src/form-field.js b/mod/lti/amd/src/form-field.js index e723f784da0..68c632707e8 100644 --- a/mod/lti/amd/src/form-field.js +++ b/mod/lti/amd/src/form-field.js @@ -87,7 +87,13 @@ define(['jquery'], attoEditor.html(value.text); } else if (typeof tinyMCE !== 'undefined') { // If the editor is not Atto, try to fallback to TinyMCE. - tinyMCE.execInstanceCommand(this.id, 'mceInsertContent', false, value.text); + if (tinyMCE.majorVersion == "3") { + // Tiny 3. + tinyMCE.execInstanceCommand(this.id, 'mceInsertContent', false, value.text); + } else { + // Tiny 4+. + tinyMCE.get(this.id).setContent(value.text); + } } // Set text to actual editor text area. -- 2.11.4.GIT