From f35d755b808052b58d71714b1ebfba9e6359c964 Mon Sep 17 00:00:00 2001 From: joytun-sultana Date: Fri, 13 Dec 2024 14:56:06 +0600 Subject: [PATCH] form js issue --- amd/build/commands.min.js.map | 2 +- amd/build/plugin.min.js | 2 +- amd/build/plugin.min.js.map | 2 +- amd/build/qrcodemodal.min.js | 2 +- amd/build/qrcodemodal.min.js.map | 2 +- amd/src/plugin.js | 2 +- amd/src/qrcodemodal.js | 18 +++++++++-- externallib.php | 2 -- lang/en/deprecated.txt | 7 ----- lang/en/tiny_qrcode.php | 1 + pix/qrcode.svg | 53 +++++++++++++++++++++++--------- version.php | 2 +- 12 files changed, 62 insertions(+), 33 deletions(-) diff --git a/amd/build/commands.min.js.map b/amd/build/commands.min.js.map index 18e5895..44fe861 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 - 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 * Generate the QR code.\n *\n * @module tiny_qrcode/commands\n * @copyright 2024 Brain Station 23 Ltd. \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n *\n */\n\nimport { qrcodeButtonName } from './common';\nimport QrcodeImage from './qrcode';\n\n\nconst registerImageCommand = (editor, qrcodeButtonText) => {\n const imageIcon = 'qrcode';\n\n const handleImageAction = async () => {\n // Store a reference to the current editor when the QR code dialogue is opened\n window.currentQRCodeEditor = editor;\n const qrcodeImage = new QrcodeImage(editor);\n qrcodeImage.displayDialogue();\n };\n\n editor.ui.registry.addToggleButton(qrcodeButtonName, {\n icon: imageIcon,\n tooltip: qrcodeButtonText,\n onAction: handleImageAction,\n onSetup: (api) => {\n return editor.selection.selectorChangedWithUnbind(\n 'img:not([data-mce-object]):not([data-mce-placeholder]),figure.image',\n api.setActive\n ).unbind;\n },\n });\n};\nexport const getSetup = async () => {\n return (editor) => {\n const qrcodeButtonText = 'Insert QR Code';\n registerImageCommand(editor, qrcodeButtonText);\n };\n};\n\nexport default { getSetup };"],"names":["getSetup","async","editor","qrcodeButtonText","ui","registry","addToggleButton","qrcodeButtonName","icon","tooltip","onAction","window","currentQRCodeEditor","QrcodeImage","displayDialogue","onSetup","api","selection","selectorChangedWithUnbind","setActive","unbind","registerImageCommand"],"mappings":";;;;;;;;qKAkDaA,SAAWC,SACZC,SAvBiB,EAACA,OAAQC,oBAUlCD,OAAOE,GAAGC,SAASC,gBAAgBC,yBAAkB,CACjDC,KAVc,SAWdC,QAASN,iBACTO,SAVsBT,UAEtBU,OAAOC,oBAAsBV,OACT,IAAIW,gBAAYX,QACxBY,mBAOZC,QAAUC,KACCd,OAAOe,UAAUC,0BACpB,sEACAF,IAAIG,WACNC,UAONC,CAAqBnB,OADI,2DAKlB,CAAEF,SAAAA"} \ No newline at end of file +{"version":3,"file":"commands.min.js","sources":["../src/commands.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 * Generate the QR code.\n *\n * @module tiny_qrcode/commands\n * @copyright 2024 Brain Station 23 Ltd. \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n *\n */\n\nimport { qrcodeButtonName } from './common';\nimport QrcodeImage from './qrcode';\n\n\nconst registerImageCommand = (editor, qrcodeButtonText) => {\n const imageIcon = 'qrcode';\n\n const handleImageAction = async () => {\n // Store a reference to the current editor when the QR code dialogue is opened\n window.currentQRCodeEditor = editor;\n const qrcodeImage = new QrcodeImage(editor);\n qrcodeImage.displayDialogue();\n \n };\n\n editor.ui.registry.addToggleButton(qrcodeButtonName, {\n icon: imageIcon,\n tooltip: qrcodeButtonText,\n onAction: handleImageAction,\n onSetup: (api) => {\n return editor.selection.selectorChangedWithUnbind(\n 'img:not([data-mce-object]):not([data-mce-placeholder]),figure.image',\n api.setActive\n ).unbind;\n },\n });\n};\nexport const getSetup = async () => {\n return (editor) => {\n const qrcodeButtonText = 'Insert QR Code';\n registerImageCommand(editor, qrcodeButtonText);\n };\n};\n\nexport default { getSetup };"],"names":["getSetup","async","editor","qrcodeButtonText","ui","registry","addToggleButton","qrcodeButtonName","icon","tooltip","onAction","window","currentQRCodeEditor","QrcodeImage","displayDialogue","onSetup","api","selection","selectorChangedWithUnbind","setActive","unbind","registerImageCommand"],"mappings":";;;;;;;;qKAmDaA,SAAWC,SACZC,SAxBiB,EAACA,OAAQC,oBAWlCD,OAAOE,GAAGC,SAASC,gBAAgBC,yBAAkB,CACjDC,KAXc,SAYdC,QAASN,iBACTO,SAXsBT,UAEtBU,OAAOC,oBAAsBV,OACT,IAAIW,gBAAYX,QACxBY,mBAQZC,QAAUC,KACCd,OAAOe,UAAUC,0BACpB,sEACAF,IAAIG,WACNC,UAONC,CAAqBnB,OADI,2DAKlB,CAAEF,SAAAA"} \ No newline at end of file diff --git a/amd/build/plugin.min.js b/amd/build/plugin.min.js index 3c298f0..513e4b3 100644 --- a/amd/build/plugin.min.js +++ b/amd/build/plugin.min.js @@ -6,6 +6,6 @@ define("tiny_qrcode/plugin",["exports","editor_tiny/loader","editor_tiny/utils", * @copyright 2024 Brain Station 23 Ltd. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,Commands=_interopRequireWildcard(Commands),Configuration=_interopRequireWildcard(Configuration);var _default=new Promise((async resolve=>{const[tinyMCE,setupCommands,pluginMetadata]=await Promise.all([(0,_loader.getTinyMCE)(),Commands.getSetup(),(0,_utils.getPluginMetadata)(_common.component,_common.pluginName)]);tinyMCE.PluginManager.add("".concat(_common.component,"/plugin"),(editor=>(editor.ui.registry.addIcon("qrcode",' '),setupCommands(editor),pluginMetadata))),resolve(["".concat(_common.component,"/plugin"),Configuration])}));return _exports.default=_default,_exports.default})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,Commands=_interopRequireWildcard(Commands),Configuration=_interopRequireWildcard(Configuration);var _default=new Promise((async resolve=>{const[tinyMCE,setupCommands,pluginMetadata]=await Promise.all([(0,_loader.getTinyMCE)(),Commands.getSetup(),(0,_utils.getPluginMetadata)(_common.component,_common.pluginName)]);tinyMCE.PluginManager.add("".concat(_common.component,"/plugin"),(editor=>(editor.ui.registry.addIcon("qrcode",' '),setupCommands(editor),pluginMetadata))),resolve(["".concat(_common.component,"/plugin"),Configuration])}));return _exports.default=_default,_exports.default})); //# sourceMappingURL=plugin.min.js.map \ No newline at end of file diff --git a/amd/build/plugin.min.js.map b/amd/build/plugin.min.js.map index 8a666a0..5dc0d16 100644 --- a/amd/build/plugin.min.js.map +++ b/amd/build/plugin.min.js.map @@ -1 +1 @@ -{"version":3,"file":"plugin.min.js","sources":["../src/plugin.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 * Generate the QR code.\n *\n * @module tiny_qrcode/plugin\n * @copyright 2024 Brain Station 23 Ltd. \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n *\n */\n\nimport {getTinyMCE} from 'editor_tiny/loader';\nimport {getPluginMetadata} from 'editor_tiny/utils';\n\nimport {component, pluginName} from './common';\nimport * as Commands from './commands';\nimport * as Configuration from './configuration';\n\n// eslint-disable-next-line no-async-promise-executor\nexport default new Promise(async(resolve) => {\n const [\n tinyMCE,\n setupCommands,\n pluginMetadata,\n ] = await Promise.all([\n getTinyMCE(),\n Commands.getSetup(),\n getPluginMetadata(component, pluginName),\n ]);\n\n tinyMCE.PluginManager.add(`${component}/plugin`, (editor) => {\n //To add a simple triangle icon:\n editor.ui.registry.addIcon('qrcode', ' ');\n\n\n // Setup the Commands (buttons, menu items, and so on).\n setupCommands(editor);\n\n return pluginMetadata;\n });\n\n // Resolve the Qrcode Plugin and include configuration.\n resolve([`${component}/plugin`, Configuration]);\n});\n\n\n/// NEEED"],"names":["Promise","async","tinyMCE","setupCommands","pluginMetadata","all","Commands","getSetup","component","pluginName","PluginManager","add","editor","ui","registry","addIcon","resolve","Configuration"],"mappings":";;;;;;;;kMAgCe,IAAIA,SAAQC,MAAAA,gBAEnBC,QACAC,cACAC,sBACMJ,QAAQK,IAAI,EAClB,wBACAC,SAASC,YACT,4BAAkBC,kBAAWC,sBAGjCP,QAAQQ,cAAcC,cAAOH,8BAAqBI,SAE9CA,OAAOC,GAAGC,SAASC,QAAQ,SAAU,q1BAIrCZ,cAAcS,QAEPR,kBAIXY,QAAQ,WAAIR,6BAAoBS"} \ No newline at end of file +{"version":3,"file":"plugin.min.js","sources":["../src/plugin.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 * Generate the QR code.\n *\n * @module tiny_qrcode/plugin\n * @copyright 2024 Brain Station 23 Ltd. \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n *\n */\n\nimport {getTinyMCE} from 'editor_tiny/loader';\nimport {getPluginMetadata} from 'editor_tiny/utils';\n\nimport {component, pluginName} from './common';\nimport * as Commands from './commands';\nimport * as Configuration from './configuration';\n\n// eslint-disable-next-line no-async-promise-executor\nexport default new Promise(async(resolve) => {\n const [\n tinyMCE,\n setupCommands,\n pluginMetadata,\n ] = await Promise.all([\n getTinyMCE(),\n Commands.getSetup(),\n getPluginMetadata(component, pluginName),\n ]);\n\n tinyMCE.PluginManager.add(`${component}/plugin`, (editor) => {\n //To add a simple triangle icon:\n editor.ui.registry.addIcon('qrcode', ' ');\n\n\n // Setup the Commands (buttons, menu items, and so on).\n setupCommands(editor);\n\n return pluginMetadata;\n });\n\n // Resolve the Qrcode Plugin and include configuration.\n resolve([`${component}/plugin`, Configuration]);\n});\n\n\n/// NEEED"],"names":["Promise","async","tinyMCE","setupCommands","pluginMetadata","all","Commands","getSetup","component","pluginName","PluginManager","add","editor","ui","registry","addIcon","resolve","Configuration"],"mappings":";;;;;;;;kMAgCe,IAAIA,SAAQC,MAAAA,gBAEnBC,QACAC,cACAC,sBACMJ,QAAQK,IAAI,EAClB,wBACAC,SAASC,YACT,4BAAkBC,kBAAWC,sBAGjCP,QAAQQ,cAAcC,cAAOH,8BAAqBI,SAE9CA,OAAOC,GAAGC,SAASC,QAAQ,SAAU,8tDAIrCZ,cAAcS,QAEPR,kBAIXY,QAAQ,WAAIR,6BAAoBS"} \ No newline at end of file diff --git a/amd/build/qrcodemodal.min.js b/amd/build/qrcodemodal.min.js index 39467bd..e0da48a 100644 --- a/amd/build/qrcodemodal.min.js +++ b/amd/build/qrcodemodal.min.js @@ -1,3 +1,3 @@ -define("tiny_qrcode/qrcodemodal",["exports","core/modal","./common","core/ajax"],(function(_exports,_modal,_common,_ajax){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_modal=_interopRequireDefault(_modal),_ajax=_interopRequireDefault(_ajax);class QrcodeModal extends _modal.default{registerEventListeners(){super.registerEventListeners();const attachSubmitHandler=()=>{const qrcodeForm=window.document.getElementById("qrcode-submit");qrcodeForm?qrcodeForm.dataset.listenerAttached||(qrcodeForm.addEventListener("click",(event=>{var _document$querySelect,_document$querySelect2;event.preventDefault();const hexToRgba=function(hex){let alpha=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;hex=hex.replace(/^#/,"");const bigint=parseInt(hex,16),r=bigint>>16&255,g=bigint>>8&255,b=255&bigint;return{r:r,g:g,b:b,a:alpha}},formData={content:document.querySelector("#qrcodecontent").value,size:parseInt(document.querySelector("#qrcode_size").value),margin:parseInt(document.querySelector("#qrcode_margin").value),bgColor:hexToRgba(document.querySelector("#bgtemplateColor").value,parseFloat((null===(_document$querySelect=document.querySelector("#bgcolor_a"))||void 0===_document$querySelect?void 0:_document$querySelect.value)||1)),fgColor:hexToRgba(document.querySelector("#templateColor").value,parseFloat((null===(_document$querySelect2=document.querySelector("#color_a"))||void 0===_document$querySelect2?void 0:_document$querySelect2.value)||1))};_ajax.default.call([{methodname:"tiny_qrcode_generate_qr_code",args:{data:JSON.stringify({content:formData.content,size:formData.size,margin:formData.margin,bgColor:formData.bgColor,fgColor:formData.fgColor})},done:function(response){if(response.status){const targetEditor=window.currentQRCodeEditor;targetEditor?targetEditor.insertContent('QR Code for ').concat(formData.content,'')):console.error("No target editor found")}else console.error("QR Code generation failed");window.currentQRCodeEditor=null},fail:function(ex){console.error("Web service call failed",ex),window.currentQRCodeEditor=null}}]),this.destroy()})),qrcodeForm.dataset.listenerAttached=!0):(console.warn("Form not found. Retrying..."),setTimeout(attachSubmitHandler,500))};attachSubmitHandler()}configure(modalConfig){modalConfig.show=!0,super.configure(modalConfig)}}return _exports.default=QrcodeModal,_defineProperty(QrcodeModal,"TYPE","".concat(_common.component,"/qrcodemodal")),_defineProperty(QrcodeModal,"TEMPLATE","".concat(_common.component,"/insert_qrcode_modal")),_exports.default})); +define("tiny_qrcode/qrcodemodal",["exports","core/modal","./common","core/ajax"],(function(_exports,_modal,_common,_ajax){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_modal=_interopRequireDefault(_modal),_ajax=_interopRequireDefault(_ajax);class QrcodeModal extends _modal.default{registerEventListeners(){const attachSubmitHandler=()=>{const qrcodeForm=window.document.getElementById("qrcode-submit"),closebtn=window.document.querySelector("div.modal div.modal-content div.modal-header button.btn-close");closebtn&&closebtn.addEventListener("click",(event=>{this.destroy()})),qrcodeForm?qrcodeForm.dataset.listenerAttached||(qrcodeForm.addEventListener("click",(event=>{event.preventDefault();const contentInput=window.document.querySelector("#qrcodecontent");if(""!==contentInput.value.trim()){var _document$querySelect,_document$querySelect2;const hexToRgba=function(hex){let alpha=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;hex=hex.replace(/^#/,"");const bigint=parseInt(hex,16),r=bigint>>16&255,g=bigint>>8&255,b=255&bigint;return{r:r,g:g,b:b,a:alpha}},formData={content:document.querySelector("#qrcodecontent").value,size:parseInt(document.querySelector("#qrcode_size").value),margin:parseInt(document.querySelector("#qrcode_margin").value),bgColor:hexToRgba(document.querySelector("#bgtemplateColor").value,parseFloat((null===(_document$querySelect=document.querySelector("#bgcolor_a"))||void 0===_document$querySelect?void 0:_document$querySelect.value)||1)),fgColor:hexToRgba(document.querySelector("#templateColor").value,parseFloat((null===(_document$querySelect2=document.querySelector("#color_a"))||void 0===_document$querySelect2?void 0:_document$querySelect2.value)||1))};_ajax.default.call([{methodname:"tiny_qrcode_generate_qr_code",args:{data:JSON.stringify({content:formData.content,size:formData.size,margin:formData.margin,bgColor:formData.bgColor,fgColor:formData.fgColor})},done:function(response){if(response.status){const targetEditor=window.currentQRCodeEditor;targetEditor?targetEditor.insertContent('QR Code for ').concat(formData.content,'')):console.error("No target editor found")}else console.error("QR Code generation failed");window.currentQRCodeEditor=null},fail:function(ex){console.error("Web service call failed",ex),window.currentQRCodeEditor=null}}]),this.destroy()}else contentInput.style.border="2px solid red"})),qrcodeForm.dataset.listenerAttached=!0):(console.warn("Form not found. Retrying..."),setTimeout(attachSubmitHandler,500))};attachSubmitHandler()}configure(modalConfig){modalConfig.show=!0,super.configure(modalConfig)}}return _exports.default=QrcodeModal,_defineProperty(QrcodeModal,"TYPE","".concat(_common.component,"/qrcodemodal")),_defineProperty(QrcodeModal,"TEMPLATE","".concat(_common.component,"/insert_qrcode_modal")),_exports.default})); //# sourceMappingURL=qrcodemodal.min.js.map \ No newline at end of file diff --git a/amd/build/qrcodemodal.min.js.map b/amd/build/qrcodemodal.min.js.map index 229ae7e..c23f934 100644 --- a/amd/build/qrcodemodal.min.js.map +++ b/amd/build/qrcodemodal.min.js.map @@ -1 +1 @@ -{"version":3,"file":"qrcodemodal.min.js","sources":["../src/qrcodemodal.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 * Generate the QR code.\n *\n * @module tiny_qrcode/qrcodemodal\n * @copyright 2024 Brain Station 23 Ltd. \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n *\n */\n\nimport Modal from 'core/modal';\nimport {component} from './common';\nimport AJAX from 'core/ajax';\n\nexport default class QrcodeModal extends Modal {\n\n static TYPE = `${component}/qrcodemodal`;\n static TEMPLATE = `${component}/insert_qrcode_modal`;\n\n registerEventListeners() {\n // Call the parent registration.\n super.registerEventListeners();\n\n const attachSubmitHandler = () => {\n const qrcodeForm = window.document.getElementById('qrcode-submit');\n if (qrcodeForm) {\n if (!qrcodeForm.dataset.listenerAttached) {\n qrcodeForm.addEventListener( 'click', (event) => {\n event.preventDefault();\n const hexToRgba = (hex, alpha = 1) => {\n hex = hex.replace(/^#/, '');\n const bigint = parseInt(hex, 16);\n const r = (bigint >> 16) & 255;\n const g = (bigint >> 8) & 255;\n const b = bigint & 255;\n return {\n r: r,\n g: g,\n b: b,\n a: alpha\n };\n };\n // Prepare form data for submission\n const formData = {\n content: document.querySelector('#qrcodecontent').value,\n size: parseInt(document.querySelector('#qrcode_size').value),\n margin: parseInt(document.querySelector('#qrcode_margin').value),\n bgColor: hexToRgba(\n document.querySelector('#bgtemplateColor').value,\n parseFloat(document.querySelector('#bgcolor_a')?.value || 1)\n ),\n fgColor: hexToRgba(\n document.querySelector('#templateColor').value,\n parseFloat(document.querySelector('#color_a')?.value || 1)\n ),\n };\n // Moodle AJAX call to web service\n AJAX.call([{\n methodname: 'tiny_qrcode_generate_qr_code',\n args: {data: JSON.stringify({\n content: formData.content,\n size: formData.size,\n margin: formData.margin,\n bgColor: formData.bgColor,\n fgColor: formData.fgColor,\n })},\n done: function(response) {\n if (response.status) {\n const targetEditor = window.currentQRCodeEditor;\n if (targetEditor) {\n targetEditor.insertContent(`\"QR`);\n } else {\n console.error('No target editor found');\n }\n } else {\n console.error('QR Code generation failed');\n }\n // Clean up the stored editor reference\n window.currentQRCodeEditor = null;\n },\n fail: function(ex) {\n console.error('Web service call failed', ex);\n // Clean up the stored editor reference\n window.currentQRCodeEditor = null;\n }\n }]);\n this.destroy();\n });\n qrcodeForm.dataset.listenerAttached = true;\n }\n } else {\n console.warn('Form not found. Retrying...');\n setTimeout(attachSubmitHandler, 500);\n }\n };\n // Attach the submit handler\n attachSubmitHandler();\n }\n configure(modalConfig) {\n modalConfig.show = true;\n super.configure(modalConfig);\n }\n}\n"],"names":["QrcodeModal","Modal","registerEventListeners","attachSubmitHandler","qrcodeForm","window","document","getElementById","dataset","listenerAttached","addEventListener","event","preventDefault","hexToRgba","hex","alpha","replace","bigint","parseInt","r","g","b","a","formData","content","querySelector","value","size","margin","bgColor","parseFloat","fgColor","call","methodname","args","data","JSON","stringify","done","response","status","targetEditor","currentQRCodeEditor","insertContent","datauri","console","error","fail","ex","destroy","warn","setTimeout","configure","modalConfig","show","component"],"mappings":"ghBA4BqBA,oBAAoBC,eAKrCC,+BAEUA,+BAEAC,oBAAsB,WAClBC,WAAaC,OAAOC,SAASC,eAAe,iBAC9CH,WACKA,WAAWI,QAAQC,mBACpBL,WAAWM,iBAAkB,SAAUC,yDACnCA,MAAMC,uBACAC,UAAY,SAACC,SAAKC,6DAAQ,EAC5BD,IAAMA,IAAIE,QAAQ,KAAM,UAClBC,OAASC,SAASJ,IAAK,IACvBK,EAAKF,QAAU,GAAM,IACrBG,EAAKH,QAAU,EAAK,IACpBI,EAAa,IAATJ,aACH,CACHE,EAAGA,EACHC,EAAGA,EACHC,EAAGA,EACHC,EAAGP,QAILQ,SAAW,CACbC,QAASlB,SAASmB,cAAc,kBAAkBC,MAClDC,KAAMT,SAASZ,SAASmB,cAAc,gBAAgBC,OACtDE,OAAQV,SAASZ,SAASmB,cAAc,kBAAkBC,OAC1DG,QAAShB,UACLP,SAASmB,cAAc,oBAAoBC,MAC3CI,0CAAWxB,SAASmB,cAAc,4EAAeC,QAAS,IAE9DK,QAASlB,UACLP,SAASmB,cAAc,kBAAkBC,MACzCI,2CAAWxB,SAASmB,cAAc,4EAAaC,QAAS,mBAI3DM,KAAK,CAAC,CACPC,WAAY,+BACZC,KAAM,CAACC,KAAMC,KAAKC,UAAU,CACxBb,QAASD,SAASC,QAClBG,KAAMJ,SAASI,KACfC,OAAQL,SAASK,OACjBC,QAASN,SAASM,QAClBE,QAASR,SAASQ,WAEtBO,KAAM,SAASC,aACPA,SAASC,OAAQ,OACXC,aAAepC,OAAOqC,oBACxBD,aACAA,aAAaE,kCAA2BJ,SAASK,sCAA6BrB,SAASC,iBAEvFqB,QAAQC,MAAM,+BAGlBD,QAAQC,MAAM,6BAGlBzC,OAAOqC,oBAAsB,MAEjCK,KAAM,SAASC,IACXH,QAAQC,MAAM,0BAA2BE,IAEzC3C,OAAOqC,oBAAsB,cAGhCO,aAET7C,WAAWI,QAAQC,kBAAmB,IAG1CoC,QAAQK,KAAK,+BACbC,WAAWhD,oBAAqB,OAIxCA,sBAEJiD,UAAUC,aACNA,YAAYC,MAAO,QACbF,UAAUC,kEAtFHrD,6BAEAuD,mDAFAvD,iCAGIuD"} \ No newline at end of file +{"version":3,"file":"qrcodemodal.min.js","sources":["../src/qrcodemodal.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 * Generate the QR code.\n *\n * @module tiny_qrcode/qrcodemodal\n * @copyright 2024 Brain Station 23 Ltd. \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n *\n */\n\nimport Modal from 'core/modal';\nimport {component} from './common';\nimport AJAX from 'core/ajax';\n\nexport default class QrcodeModal extends Modal {\n\n static TYPE = `${component}/qrcodemodal`;\n static TEMPLATE = `${component}/insert_qrcode_modal`;\n\n registerEventListeners() {\n\n const attachSubmitHandler = () => {\n const qrcodeForm = window.document.getElementById('qrcode-submit');\n const closebtn= window.document.querySelector('div.modal div.modal-content div.modal-header button.btn-close');\n if (closebtn){\n closebtn.addEventListener( 'click', (event) => {\n this.destroy();\n\n });}\n\n if (qrcodeForm) {\n if (!qrcodeForm.dataset.listenerAttached) {\n qrcodeForm.addEventListener( 'click', (event) => {\n event.preventDefault();\n const contentInput = window.document.querySelector('#qrcodecontent');\n if(contentInput.value.trim() !== ''){\n const hexToRgba = (hex, alpha = 1) => {\n hex = hex.replace(/^#/, '');\n const bigint = parseInt(hex, 16);\n const r = (bigint >> 16) & 255;\n const g = (bigint >> 8) & 255;\n const b = bigint & 255;\n return {\n r: r,\n g: g,\n b: b,\n a: alpha\n };\n };\n // Prepare form data for submission\n const formData = {\n content: document.querySelector('#qrcodecontent').value,\n size: parseInt(document.querySelector('#qrcode_size').value),\n margin: parseInt(document.querySelector('#qrcode_margin').value),\n bgColor: hexToRgba(\n document.querySelector('#bgtemplateColor').value,\n parseFloat(document.querySelector('#bgcolor_a')?.value || 1)\n ),\n fgColor: hexToRgba(\n document.querySelector('#templateColor').value,\n parseFloat(document.querySelector('#color_a')?.value || 1)\n ),\n };\n // Moodle AJAX call to web service\n AJAX.call([{\n methodname: 'tiny_qrcode_generate_qr_code',\n args: {data: JSON.stringify({\n content: formData.content,\n size: formData.size,\n margin: formData.margin,\n bgColor: formData.bgColor,\n fgColor: formData.fgColor,\n })},\n done: function(response) {\n if (response.status) {\n const targetEditor = window.currentQRCodeEditor;\n if (targetEditor) {\n targetEditor.insertContent(`\"QR`);\n } else {\n console.error('No target editor found');\n }\n } else {\n console.error('QR Code generation failed');\n }\n // Clean up the stored editor reference\n window.currentQRCodeEditor = null;\n },\n fail: function(ex) {\n console.error('Web service call failed', ex);\n // Clean up the stored editor reference\n window.currentQRCodeEditor = null;\n }\n }]);\n this.destroy();\n }\n else{\n // alert('Enter value in QR Code Contest');\n contentInput.style.border = '2px solid red';\n \n return;\n }\n });\n qrcodeForm.dataset.listenerAttached = true;\n }\n } else {\n console.warn('Form not found. Retrying...');\n setTimeout(attachSubmitHandler, 500);\n }\n };\n // Attach the submit handler\n attachSubmitHandler();\n }\n configure(modalConfig) {\n modalConfig.show = true;\n super.configure(modalConfig);\n }\n}\n"],"names":["QrcodeModal","Modal","registerEventListeners","attachSubmitHandler","qrcodeForm","window","document","getElementById","closebtn","querySelector","addEventListener","event","destroy","dataset","listenerAttached","preventDefault","contentInput","value","trim","hexToRgba","hex","alpha","replace","bigint","parseInt","r","g","b","a","formData","content","size","margin","bgColor","parseFloat","fgColor","call","methodname","args","data","JSON","stringify","done","response","status","targetEditor","currentQRCodeEditor","insertContent","datauri","console","error","fail","ex","style","border","warn","setTimeout","configure","modalConfig","show","component"],"mappings":"ghBA4BqBA,oBAAoBC,eAKrCC,+BAEUC,oBAAsB,WAClBC,WAAaC,OAAOC,SAASC,eAAe,iBAC5CC,SAAUH,OAAOC,SAASG,cAAc,iEAC1CD,UACAA,SAASE,iBAAkB,SAAUC,aAC5BC,aAITR,WACKA,WAAWS,QAAQC,mBACpBV,WAAWM,iBAAkB,SAAUC,QACnCA,MAAMI,uBACAC,aAAeX,OAAOC,SAASG,cAAc,qBAClB,KAA9BO,aAAaC,MAAMC,OAAc,wDAC9BC,UAAY,SAACC,SAAKC,6DAAQ,EAC5BD,IAAMA,IAAIE,QAAQ,KAAM,UAClBC,OAASC,SAASJ,IAAK,IACvBK,EAAKF,QAAU,GAAM,IACrBG,EAAKH,QAAU,EAAK,IACpBI,EAAa,IAATJ,aACH,CACHE,EAAGA,EACHC,EAAGA,EACHC,EAAGA,EACHC,EAAGP,QAILQ,SAAW,CACbC,QAASxB,SAASG,cAAc,kBAAkBQ,MAClDc,KAAMP,SAASlB,SAASG,cAAc,gBAAgBQ,OACtDe,OAAQR,SAASlB,SAASG,cAAc,kBAAkBQ,OAC1DgB,QAASd,UACLb,SAASG,cAAc,oBAAoBQ,MAC3CiB,0CAAW5B,SAASG,cAAc,4EAAeQ,QAAS,IAE9DkB,QAAShB,UACLb,SAASG,cAAc,kBAAkBQ,MACzCiB,2CAAW5B,SAASG,cAAc,4EAAaQ,QAAS,mBAI3DmB,KAAK,CAAC,CACPC,WAAY,+BACZC,KAAM,CAACC,KAAMC,KAAKC,UAAU,CACxBX,QAASD,SAASC,QAClBC,KAAMF,SAASE,KACfC,OAAQH,SAASG,OACjBC,QAASJ,SAASI,QAClBE,QAASN,SAASM,WAEtBO,KAAM,SAASC,aACPA,SAASC,OAAQ,OACXC,aAAexC,OAAOyC,oBACxBD,aACAA,aAAaE,kCAA2BJ,SAASK,sCAA6BnB,SAASC,iBAEvFmB,QAAQC,MAAM,+BAGlBD,QAAQC,MAAM,6BAGlB7C,OAAOyC,oBAAsB,MAEjCK,KAAM,SAASC,IACXH,QAAQC,MAAM,0BAA2BE,IAEzC/C,OAAOyC,oBAAsB,cAGhClC,eAINI,aAAaqC,MAAMC,OAAS,mBAK/BlD,WAAWS,QAAQC,kBAAmB,IAG1CmC,QAAQM,KAAK,+BACbC,WAAWrD,oBAAqB,OAIxCA,sBAEJsD,UAAUC,aACNA,YAAYC,MAAO,QACbF,UAAUC,kEApGH1D,6BAEA4D,mDAFA5D,iCAGI4D"} \ No newline at end of file diff --git a/amd/src/plugin.js b/amd/src/plugin.js index 4091c42..f1a5caa 100755 --- a/amd/src/plugin.js +++ b/amd/src/plugin.js @@ -43,7 +43,7 @@ export default new Promise(async(resolve) => { tinyMCE.PluginManager.add(`${component}/plugin`, (editor) => { //To add a simple triangle icon: - editor.ui.registry.addIcon('qrcode', ' '); + editor.ui.registry.addIcon('qrcode', ' '); // Setup the Commands (buttons, menu items, and so on). diff --git a/amd/src/qrcodemodal.js b/amd/src/qrcodemodal.js index 1cd5896..478d398 100755 --- a/amd/src/qrcodemodal.js +++ b/amd/src/qrcodemodal.js @@ -32,15 +32,22 @@ export default class QrcodeModal extends Modal { static TEMPLATE = `${component}/insert_qrcode_modal`; registerEventListeners() { - // Call the parent registration. - super.registerEventListeners(); const attachSubmitHandler = () => { const qrcodeForm = window.document.getElementById('qrcode-submit'); + const closebtn= window.document.querySelector('div.modal div.modal-content div.modal-header button.btn-close'); + if (closebtn){ + closebtn.addEventListener( 'click', (event) => { + this.destroy(); + + });} + if (qrcodeForm) { if (!qrcodeForm.dataset.listenerAttached) { qrcodeForm.addEventListener( 'click', (event) => { event.preventDefault(); + const contentInput = window.document.querySelector('#qrcodecontent'); + if(contentInput.value.trim() !== ''){ const hexToRgba = (hex, alpha = 1) => { hex = hex.replace(/^#/, ''); const bigint = parseInt(hex, 16); @@ -99,6 +106,13 @@ export default class QrcodeModal extends Modal { } }]); this.destroy(); + } + else{ + // alert('Enter value in QR Code Contest'); + contentInput.style.border = '2px solid red'; + + return; + } }); qrcodeForm.dataset.listenerAttached = true; } diff --git a/externallib.php b/externallib.php index 6ee3ad5..44876f4 100644 --- a/externallib.php +++ b/externallib.php @@ -31,7 +31,6 @@ use core_external\external_api; -use context_system; use core_external\external_function_parameters; use core_external\external_value; use core_external\external_single_structure; @@ -110,7 +109,6 @@ public static function generate_qr_code($data) { ]; } } - /** * Parameters description for web service * diff --git a/lang/en/deprecated.txt b/lang/en/deprecated.txt index ce52328..e69de29 100755 --- a/lang/en/deprecated.txt +++ b/lang/en/deprecated.txt @@ -1,7 +0,0 @@ -alignment,tiny_qrcode -alignment_bottom,tiny_qrcode -alignment_left,tiny_qrcode -alignment_middle,tiny_qrcode -alignment_right,tiny_qrcode -alignment_top,tiny_qrcode -helplinktext,tiny_qrcode diff --git a/lang/en/tiny_qrcode.php b/lang/en/tiny_qrcode.php index 1b675a1..1d130e2 100755 --- a/lang/en/tiny_qrcode.php +++ b/lang/en/tiny_qrcode.php @@ -33,6 +33,7 @@ $string['insertqrcode'] = 'Insert QR Code'; $string['invalid_color_values'] = 'Invalid color values. Please ensure values are within range.'; $string['pluginname'] = 'QR code'; + $string['privacy:metadata'] = 'The QR code plugin for TinyMCE does not store any personal data.'; $string['qrcode_insert_failed'] = 'Failed to insert QR Code. Please try again.'; $string['qrcode_management'] = 'QrCode Generator'; $string['qrcode_margin'] = 'QR Code Margin'; diff --git a/pix/qrcode.svg b/pix/qrcode.svg index 38dcd0f..75d5ad9 100644 --- a/pix/qrcode.svg +++ b/pix/qrcode.svg @@ -1,18 +1,41 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/version.php b/version.php index 051bff9..3faf560 100755 --- a/version.php +++ b/version.php @@ -25,6 +25,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024110126; +$plugin->version = 2024110200; $plugin->requires = 2022112800; $plugin->component = 'tiny_qrcode';