From ff2f94e80385256e005da76908997b41b0f5f483 Mon Sep 17 00:00:00 2001 From: Joytun-Sultana Date: Wed, 1 Jan 2025 19:13:23 +0600 Subject: [PATCH] js error and lang --- amd/build/commands.min.js | 4 ++-- amd/build/commands.min.js.map | 2 +- amd/build/qrcode.min.js | 2 +- amd/build/qrcode.min.js.map | 2 +- amd/build/qrcodemodal.min.js | 2 +- amd/build/qrcodemodal.min.js.map | 2 +- amd/src/commands.js | 5 +++-- amd/src/qrcode.js | 4 ++-- amd/src/qrcodemodal.js | 21 ++++++++++----------- lang/en/tiny_qrcode.php | 2 ++ templates/insert_qrcode_modal.mustache | 4 ++-- 11 files changed, 26 insertions(+), 24 deletions(-) diff --git a/amd/build/commands.min.js b/amd/build/commands.min.js index ca8d528..4775f45 100644 --- a/amd/build/commands.min.js +++ b/amd/build/commands.min.js @@ -1,4 +1,4 @@ -define("tiny_qrcode/commands",["exports","./common","./qrcode"],(function(_exports,_common,_qrcode){var obj; +define("tiny_qrcode/commands",["exports","./common","./qrcode","core/str"],(function(_exports,_common,_qrcode,_str){var obj; /** * Generate the QR code. * @@ -6,6 +6,6 @@ define("tiny_qrcode/commands",["exports","./common","./qrcode"],(function(_expor * @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.getSetup=_exports.default=void 0,_qrcode=(obj=_qrcode)&&obj.__esModule?obj:{default:obj};const getSetup=async()=>editor=>{((editor,qrcodeButtonText)=>{editor.ui.registry.addToggleButton(_common.qrcodeButtonName,{icon:"qrcode",tooltip:qrcodeButtonText,onAction:async()=>{window.currentQRCodeEditor=editor,new _qrcode.default(editor).displayDialogue()},onSetup:api=>editor.selection.selectorChangedWithUnbind("img:not([data-mce-object]):not([data-mce-placeholder]),figure.image",api.setActive).unbind})})(editor,"Insert QR Code")};_exports.getSetup=getSetup;var _default={getSetup:getSetup};return _exports.default=_default,_exports.default})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.getSetup=_exports.default=void 0,_qrcode=(obj=_qrcode)&&obj.__esModule?obj:{default:obj};const getSetup=async()=>{const qrcodeButtonText=await(0,_str.getString)("insertqrcode",_common.component);return editor=>{((editor,qrcodeButtonText)=>{editor.ui.registry.addToggleButton(_common.qrcodeButtonName,{icon:"qrcode",tooltip:qrcodeButtonText,onAction:async()=>{window.currentQRCodeEditor=editor,new _qrcode.default(editor).displayDialogue()},onSetup:api=>editor.selection.selectorChangedWithUnbind("img:not([data-mce-object]):not([data-mce-placeholder]),figure.image",api.setActive).unbind})})(editor,qrcodeButtonText)}};_exports.getSetup=getSetup;var _default={getSetup:getSetup};return _exports.default=_default,_exports.default})); //# 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 18e5895..e48e1ea 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, component } from './common';\nimport QrcodeImage from './qrcode';\nimport {getString} from 'core/str';\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 const qrcodeButtonText = await getString('insertqrcode', component);\n return (editor) => {\n registerImageCommand(editor, qrcodeButtonText);\n };\n};\n\nexport default { getSetup };"],"names":["getSetup","async","qrcodeButtonText","component","editor","ui","registry","addToggleButton","qrcodeButtonName","icon","tooltip","onAction","window","currentQRCodeEditor","QrcodeImage","displayDialogue","onSetup","api","selection","selectorChangedWithUnbind","setActive","unbind","registerImageCommand"],"mappings":";;;;;;;;qKAmDaA,SAAWC,gBACdC,uBAAyB,kBAAU,eAAgBC,0BACjDC,SAxBiB,EAACA,OAAQF,oBAUlCE,OAAOC,GAAGC,SAASC,gBAAgBC,yBAAkB,CACjDC,KAVc,SAWdC,QAASR,iBACTS,SAVsBV,UAEtBW,OAAOC,oBAAsBT,OACT,IAAIU,gBAAYV,QACxBW,mBAOZC,QAAUC,KACCb,OAAOc,UAAUC,0BACpB,sEACAF,IAAIG,WACNC,UAONC,CAAqBlB,OAAQF,4DAItB,CAAEF,SAAAA"} \ No newline at end of file diff --git a/amd/build/qrcode.min.js b/amd/build/qrcode.min.js index 7e19092..21a0462 100644 --- a/amd/build/qrcode.min.js +++ b/amd/build/qrcode.min.js @@ -1,3 +1,3 @@ -define("tiny_qrcode/qrcode",["exports","./qrcodemodal"],(function(_exports,_qrcodemodal){var 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,_qrcodemodal=(obj=_qrcodemodal)&&obj.__esModule?obj:{default:obj};return _exports.default=class{constructor(editor){_defineProperty(this,"editor",null),_defineProperty(this,"currentModal",null),_defineProperty(this,"root",null),this.editor=editor}async displayDialogue(){this.currentModal=await _qrcodemodal.default.create({title:"Insert Qrcode Code"})}},_exports.default})); +define("tiny_qrcode/qrcode",["exports","./qrcodemodal","core/str"],(function(_exports,_qrcodemodal,_str){var 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,_qrcodemodal=(obj=_qrcodemodal)&&obj.__esModule?obj:{default:obj};return _exports.default=class{constructor(editor){_defineProperty(this,"editor",null),_defineProperty(this,"currentModal",null),_defineProperty(this,"root",null),this.editor=editor}async displayDialogue(){this.currentModal=await _qrcodemodal.default.create({title:await(0,_str.getString)("title","tiny_qrcode")})}},_exports.default})); //# sourceMappingURL=qrcode.min.js.map \ No newline at end of file diff --git a/amd/build/qrcode.min.js.map b/amd/build/qrcode.min.js.map index 18b39bd..ea80145 100644 --- a/amd/build/qrcode.min.js.map +++ b/amd/build/qrcode.min.js.map @@ -1 +1 @@ -{"version":3,"file":"qrcode.min.js","sources":["../src/qrcode.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/qrcode\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 QrcodeModal from './qrcodemodal';\n\n\nexport default class QrcodeImage {\n editor = null;\n currentModal = null;\n /**\n * @type {HTMLElement|null} The root element.\n */\n root = null;\n\n constructor(editor) {\n this.editor = editor;\n }\n async displayDialogue() {\n this.currentModal = await QrcodeModal.create({\n title: \"Insert Qrcode Code\",\n });\n }\n}\n"],"names":["constructor","editor","currentModal","QrcodeModal","create","title"],"mappings":"qbAmCIA,YAAYC,sCAPH,0CACM,kCAIR,WAGEA,OAASA,oCAGTC,mBAAqBC,qBAAYC,OAAO,CACzCC,MAAO"} \ No newline at end of file +{"version":3,"file":"qrcode.min.js","sources":["../src/qrcode.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/qrcode\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 QrcodeModal from './qrcodemodal';\nimport {getString} from 'core/str';\n\nexport default class QrcodeImage {\n editor = null;\n currentModal = null;\n /**\n * @type {HTMLElement|null} The root element.\n */\n root = null;\n\n constructor(editor) {\n this.editor = editor;\n }\n async displayDialogue() {\n this.currentModal = await QrcodeModal.create({\n title: await getString('title', 'tiny_qrcode'),\n });\n }\n}\n"],"names":["constructor","editor","currentModal","QrcodeModal","create","title"],"mappings":"qcAmCIA,YAAYC,sCAPH,0CACM,kCAIR,WAGEA,OAASA,oCAGTC,mBAAqBC,qBAAYC,OAAO,CACzCC,YAAa,kBAAU,QAAS"} \ No newline at end of file diff --git a/amd/build/qrcodemodal.min.js b/amd/build/qrcodemodal.min.js index 9feab01..3967bad 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(){const attachSubmitHandler=()=>{const qrcodeForm=window.document.getElementById("qrcode-submit"),closebtn=window.document.querySelector("div.modal div.modal-content div.modal-header button.btn-close"),closebtn1=window.document.querySelector("div.modal div.modal-content div.modal-header button.close");closebtn&&closebtn.addEventListener("click",(event=>{this.destroy()})),closebtn1&&closebtn1.addEventListener("click",(event=>{this.destroy()})),qrcodeForm?qrcodeForm.dataset.listenerAttached||(qrcodeForm.addEventListener("click",(event=>{event.preventDefault();let flag=0;const qrsize=window.document.querySelector("#qrcode_size").value;qrsize>1e3||qrsize<25?(window.document.querySelector("#qrcode_size").style.border="2px solid red",flag=1):window.document.querySelector("#qrcode_size").style.border="1px solid black";const qrmargin=window.document.querySelector("#qrcode_margin").value;qrmargin>100||qrmargin<5?(window.document.querySelector("#qrcode_margin").style.border="2px solid red",flag=1):window.document.querySelector("#qrcode_margin").style.border="1px solid black";const contentInput=window.document.querySelector("#qrcodecontent");if(""===contentInput.value.trim()?(contentInput.style.border="2px solid red",flag=1):contentInput.style.border="1px solid black",!flag)if(flag=0,""!==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})); +define("tiny_qrcode/qrcodemodal",["exports","core/modal","./common","core/ajax","core/str"],(function(_exports,_modal,_common,_ajax,_str){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=async()=>{const altTextPrefix=await(0,_str.getString)("altTextPrefix","tiny_qrcode"),qrcodeForm=window.document.getElementById("qrcode-submit"),closebtn=window.document.querySelector("div.modal div.modal-content div.modal-header button.btn-close"),closebtn1=window.document.querySelector("div.modal div.modal-content div.modal-header button.close");closebtn&&closebtn.addEventListener("click",(event=>{this.destroy()})),closebtn1&&closebtn1.addEventListener("click",(event=>{this.destroy()})),qrcodeForm?qrcodeForm.dataset.listenerAttached||(qrcodeForm.addEventListener("click",(event=>{event.preventDefault();let flag=0;const qrsize=window.document.querySelector("#qrcode_size").value;qrsize>1e3||qrsize<25?(window.document.querySelector("#qrcode_size").style.border="2px solid red",flag=1):window.document.querySelector("#qrcode_size").style.border="1px solid black";const qrmargin=window.document.querySelector("#qrcode_margin").value;qrmargin>100||qrmargin<5?(window.document.querySelector("#qrcode_margin").style.border="2px solid red",flag=1):window.document.querySelector("#qrcode_margin").style.border="1px solid black";const contentInput=window.document.querySelector("#qrcodecontent");if(""===contentInput.value.trim()?(contentInput.style.border="2px solid red",flag=1):contentInput.style.border="1px solid black",!flag)if(flag=0,""!==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('').concat(altTextPrefix,'))}window.currentQRCodeEditor=null},fail:function(){window.currentQRCodeEditor=null}}]),this.destroy()}else contentInput.style.border="2px solid red"})),qrcodeForm.dataset.listenerAttached=!0):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 23e8382..7b81c77 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\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 const closebtn1= window.document.querySelector('div.modal div.modal-content div.modal-header button.close');\n if (closebtn){\n closebtn.addEventListener( 'click', (event) => {\n this.destroy();\n });}\n if (closebtn1){\n closebtn1.addEventListener( 'click', (event) => {\n this.destroy();\n });}\n \n if (qrcodeForm) {\n if (!qrcodeForm.dataset.listenerAttached) {\n qrcodeForm.addEventListener( 'click', (event) => {\n event.preventDefault();\n let flag=0;\n\n const qrsize = window.document.querySelector('#qrcode_size').value;\n if(qrsize > 1000 || qrsize < 25){\n window.document.querySelector('#qrcode_size').style.border = '2px solid red';\n flag=1;\n } else{\n window.document.querySelector('#qrcode_size').style.border = '1px solid black';\n }\n\n const qrmargin = window.document.querySelector('#qrcode_margin').value;\n if(qrmargin> 100 || qrmargin < 5){\n window.document.querySelector('#qrcode_margin').style.border = '2px solid red';\n flag=1;\n } else {\n window.document.querySelector('#qrcode_margin').style.border = '1px solid black';\n }\n\n const contentInput = window.document.querySelector('#qrcodecontent');\n if(contentInput.value.trim() === ''){\n contentInput.style.border = '2px solid red';\n flag=1;\n }else{\n contentInput.style.border = '1px solid black';\n }\n\n if(flag) return;\n flag=0;\n\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 contentInput.style.border = '2px solid red';\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","closebtn1","addEventListener","event","destroy","dataset","listenerAttached","preventDefault","flag","qrsize","value","style","border","qrmargin","contentInput","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","warn","setTimeout","configure","modalConfig","show","component"],"mappings":"ghBA4BqBA,oBAAoBC,eAKrCC,+BAEUC,oBAAsB,WAClBC,WAAaC,OAAOC,SAASC,eAAe,iBAC5CC,SAAUH,OAAOC,SAASG,cAAc,iEACxCC,UAAWL,OAAOC,SAASG,cAAc,6DAC3CD,UACAA,SAASG,iBAAkB,SAAUC,aAC5BC,aAETH,WACAA,UAAUC,iBAAkB,SAAUC,aAC7BC,aAGTT,WACKA,WAAWU,QAAQC,mBACpBX,WAAWO,iBAAkB,SAAUC,QACnCA,MAAMI,qBACFC,KAAK,QAEHC,OAASb,OAAOC,SAASG,cAAc,gBAAgBU,MAC1DD,OAAS,KAAQA,OAAS,IACzBb,OAAOC,SAASG,cAAc,gBAAgBW,MAAMC,OAAS,gBAC7DJ,KAAK,GAELZ,OAAOC,SAASG,cAAc,gBAAgBW,MAAMC,OAAS,wBAG3DC,SAAWjB,OAAOC,SAASG,cAAc,kBAAkBU,MAC9DG,SAAU,KAAOA,SAAW,GAC3BjB,OAAOC,SAASG,cAAc,kBAAkBW,MAAMC,OAAS,gBAC/DJ,KAAK,GAELZ,OAAOC,SAASG,cAAc,kBAAkBW,MAAMC,OAAS,wBAG7DE,aAAelB,OAAOC,SAASG,cAAc,qBAClB,KAA9Bc,aAAaJ,MAAMK,QAClBD,aAAaH,MAAMC,OAAS,gBAC5BJ,KAAK,GAELM,aAAaH,MAAMC,OAAS,mBAG7BJ,QACHA,KAAK,EAE4B,KAA9BM,aAAaJ,MAAMK,OAAc,wDAC1BC,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,QAAS9B,SAASG,cAAc,kBAAkBU,MAClDkB,KAAMP,SAASxB,SAASG,cAAc,gBAAgBU,OACtDmB,OAAQR,SAASxB,SAASG,cAAc,kBAAkBU,OAC1DoB,QAASd,UACLnB,SAASG,cAAc,oBAAoBU,MAC3CqB,0CAAWlC,SAASG,cAAc,4EAAeU,QAAS,IAE9DsB,QAAShB,UACLnB,SAASG,cAAc,kBAAkBU,MACzCqB,2CAAWlC,SAASG,cAAc,4EAAaU,QAAS,mBAI3DuB,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,aAAe9C,OAAO+C,oBACxBD,aACAA,aAAaE,kCAA2BJ,SAASK,sCAA6BnB,SAASC,iBAEvFmB,QAAQC,MAAM,+BAGlBD,QAAQC,MAAM,6BAGlBnD,OAAO+C,oBAAsB,MAEjCK,KAAM,SAASC,IACXH,QAAQC,MAAM,0BAA2BE,IAEzCrD,OAAO+C,oBAAsB,cAGhCvC,eAGLU,aAAaH,MAAMC,OAAS,mBAIpCjB,WAAWU,QAAQC,kBAAmB,IAG1CwC,QAAQI,KAAK,+BACbC,WAAWzD,oBAAqB,OAIxCA,sBAEJ0D,UAAUC,aACNA,YAAYC,MAAO,QACbF,UAAUC,kEAlIH9D,6BAEAgE,mDAFAhE,iCAGIgE"} \ 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';\nimport {getString} from 'core/str';\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 = async() => {\n const altTextPrefix = await getString('altTextPrefix', 'tiny_qrcode');\n\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 const closebtn1= window.document.querySelector('div.modal div.modal-content div.modal-header button.close');\n if (closebtn){\n closebtn.addEventListener( 'click', (event) => {\n this.destroy();\n });}\n if (closebtn1){\n closebtn1.addEventListener( 'click', (event) => {\n this.destroy();\n });}\n\n if (qrcodeForm) {\n if (!qrcodeForm.dataset.listenerAttached) {\n qrcodeForm.addEventListener( 'click', (event) => {\n event.preventDefault();\n let flag=0;\n\n const qrsize = window.document.querySelector('#qrcode_size').value;\n if(qrsize > 1000 || qrsize < 25){\n window.document.querySelector('#qrcode_size').style.border = '2px solid red';\n flag=1;\n } else{\n window.document.querySelector('#qrcode_size').style.border = '1px solid black';\n }\n\n const qrmargin = window.document.querySelector('#qrcode_margin').value;\n if(qrmargin> 100 || qrmargin < 5){\n window.document.querySelector('#qrcode_margin').style.border = '2px solid red';\n flag=1;\n } else {\n window.document.querySelector('#qrcode_margin').style.border = '1px solid black';\n }\n\n const contentInput = window.document.querySelector('#qrcodecontent');\n if(contentInput.value.trim() === ''){\n contentInput.style.border = '2px solid red';\n flag=1;\n }else{\n contentInput.style.border = '1px solid black';\n }\n\n if(flag){\n return;\n }\n flag=0;\n\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(`\"${altTextPrefix}`);\n }\n }\n // Clean up the stored editor reference\n window.currentQRCodeEditor = null;\n },\n fail: function() {\n // Clean up the stored editor reference\n window.currentQRCodeEditor = null;\n }\n }]);\n this.destroy();\n }\n else{\n contentInput.style.border = '2px solid red';\n // return;\n }\n });\n qrcodeForm.dataset.listenerAttached = true;\n }\n } else {\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","async","altTextPrefix","qrcodeForm","window","document","getElementById","closebtn","querySelector","closebtn1","addEventListener","event","destroy","dataset","listenerAttached","preventDefault","flag","qrsize","value","style","border","qrmargin","contentInput","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","fail","setTimeout","configure","modalConfig","show","component"],"mappings":"giBA6BqBA,oBAAoBC,eAKrCC,+BAEUC,oBAAsBC,gBAClBC,oBAAsB,kBAAU,gBAAiB,eAEjDC,WAAaC,OAAOC,SAASC,eAAe,iBAC5CC,SAAUH,OAAOC,SAASG,cAAc,iEACxCC,UAAWL,OAAOC,SAASG,cAAc,6DAC3CD,UACAA,SAASG,iBAAkB,SAAUC,aAC5BC,aAETH,WACAA,UAAUC,iBAAkB,SAAUC,aAC7BC,aAGTT,WACKA,WAAWU,QAAQC,mBACpBX,WAAWO,iBAAkB,SAAUC,QACnCA,MAAMI,qBACFC,KAAK,QAEHC,OAASb,OAAOC,SAASG,cAAc,gBAAgBU,MAC1DD,OAAS,KAAQA,OAAS,IACzBb,OAAOC,SAASG,cAAc,gBAAgBW,MAAMC,OAAS,gBAC7DJ,KAAK,GAELZ,OAAOC,SAASG,cAAc,gBAAgBW,MAAMC,OAAS,wBAG3DC,SAAWjB,OAAOC,SAASG,cAAc,kBAAkBU,MAC9DG,SAAU,KAAOA,SAAW,GAC3BjB,OAAOC,SAASG,cAAc,kBAAkBW,MAAMC,OAAS,gBAC/DJ,KAAK,GAELZ,OAAOC,SAASG,cAAc,kBAAkBW,MAAMC,OAAS,wBAG7DE,aAAelB,OAAOC,SAASG,cAAc,qBAClB,KAA9Bc,aAAaJ,MAAMK,QAClBD,aAAaH,MAAMC,OAAS,gBAC5BJ,KAAK,GAELM,aAAaH,MAAMC,OAAS,mBAG7BJ,QAGHA,KAAK,EAE4B,KAA9BM,aAAaJ,MAAMK,OAAc,wDAC1BC,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,QAAS9B,SAASG,cAAc,kBAAkBU,MAClDkB,KAAMP,SAASxB,SAASG,cAAc,gBAAgBU,OACtDmB,OAAQR,SAASxB,SAASG,cAAc,kBAAkBU,OAC1DoB,QAASd,UACLnB,SAASG,cAAc,oBAAoBU,MAC3CqB,0CAAWlC,SAASG,cAAc,4EAAeU,QAAS,IAE9DsB,QAAShB,UACLnB,SAASG,cAAc,kBAAkBU,MACzCqB,2CAAWlC,SAASG,cAAc,4EAAaU,QAAS,mBAI3DuB,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,aAAe9C,OAAO+C,oBACxBD,cACAA,aAAaE,kCAA2BJ,SAASK,0BAAiBnD,2BAAkBgC,SAASC,iBAIrG/B,OAAO+C,oBAAsB,MAEjCG,KAAM,WAEFlD,OAAO+C,oBAAsB,cAGhCvC,eAGLU,aAAaH,MAAMC,OAAS,mBAIpCjB,WAAWU,QAAQC,kBAAmB,GAG1CyC,WAAWvD,oBAAqB,MAIxCA,sBAEJwD,UAAUC,aACNA,YAAYC,MAAO,QACbF,UAAUC,kEAhIH5D,6BAEA8D,mDAFA9D,iCAGI8D"} \ No newline at end of file diff --git a/amd/src/commands.js b/amd/src/commands.js index 177c41d..9652efa 100755 --- a/amd/src/commands.js +++ b/amd/src/commands.js @@ -22,8 +22,9 @@ * */ -import { qrcodeButtonName } from './common'; +import { qrcodeButtonName, component } from './common'; import QrcodeImage from './qrcode'; +import {getString} from 'core/str'; const registerImageCommand = (editor, qrcodeButtonText) => { @@ -49,8 +50,8 @@ const registerImageCommand = (editor, qrcodeButtonText) => { }); }; export const getSetup = async () => { + const qrcodeButtonText = await getString('insertqrcode', component); return (editor) => { - const qrcodeButtonText = 'Insert QR Code'; registerImageCommand(editor, qrcodeButtonText); }; }; diff --git a/amd/src/qrcode.js b/amd/src/qrcode.js index dcc7dc4..d705690 100755 --- a/amd/src/qrcode.js +++ b/amd/src/qrcode.js @@ -23,7 +23,7 @@ */ import QrcodeModal from './qrcodemodal'; - +import {getString} from 'core/str'; export default class QrcodeImage { editor = null; @@ -38,7 +38,7 @@ export default class QrcodeImage { } async displayDialogue() { this.currentModal = await QrcodeModal.create({ - title: "Insert Qrcode Code", + title: await getString('title', 'tiny_qrcode'), }); } } diff --git a/amd/src/qrcodemodal.js b/amd/src/qrcodemodal.js index 5530927..0e52314 100755 --- a/amd/src/qrcodemodal.js +++ b/amd/src/qrcodemodal.js @@ -25,6 +25,7 @@ import Modal from 'core/modal'; import {component} from './common'; import AJAX from 'core/ajax'; +import {getString} from 'core/str'; export default class QrcodeModal extends Modal { @@ -33,7 +34,9 @@ export default class QrcodeModal extends Modal { registerEventListeners() { - const attachSubmitHandler = () => { + const attachSubmitHandler = async() => { + const altTextPrefix = await getString('altTextPrefix', 'tiny_qrcode'); + const qrcodeForm = window.document.getElementById('qrcode-submit'); const closebtn= window.document.querySelector('div.modal div.modal-content div.modal-header button.btn-close'); const closebtn1= window.document.querySelector('div.modal div.modal-content div.modal-header button.close'); @@ -45,7 +48,7 @@ export default class QrcodeModal extends Modal { closebtn1.addEventListener( 'click', (event) => { this.destroy(); });} - + if (qrcodeForm) { if (!qrcodeForm.dataset.listenerAttached) { qrcodeForm.addEventListener( 'click', (event) => { @@ -76,7 +79,9 @@ export default class QrcodeModal extends Modal { contentInput.style.border = '1px solid black'; } - if(flag) return; + if(flag){ + return; + } flag=0; if(contentInput.value.trim() !== ''){ @@ -121,18 +126,13 @@ export default class QrcodeModal extends Modal { if (response.status) { const targetEditor = window.currentQRCodeEditor; if (targetEditor) { - targetEditor.insertContent(`QR Code for ${formData.content}`); - } else { - console.error('No target editor found'); + targetEditor.insertContent(`${altTextPrefix}  ${formData.content}`); } - } else { - console.error('QR Code generation failed'); } // Clean up the stored editor reference window.currentQRCodeEditor = null; }, - fail: function(ex) { - console.error('Web service call failed', ex); + fail: function() { // Clean up the stored editor reference window.currentQRCodeEditor = null; } @@ -147,7 +147,6 @@ export default class QrcodeModal extends Modal { qrcodeForm.dataset.listenerAttached = true; } } else { - console.warn('Form not found. Retrying...'); setTimeout(attachSubmitHandler, 500); } }; diff --git a/lang/en/tiny_qrcode.php b/lang/en/tiny_qrcode.php index 1d130e2..a3d31c9 100755 --- a/lang/en/tiny_qrcode.php +++ b/lang/en/tiny_qrcode.php @@ -24,6 +24,7 @@ */ $string['alpha'] = 'Alpha'; + $string['altTextPrefix'] = 'QR Code for'; $string['backgroundcolor'] = 'Background Color'; $string['backgroundcolor_required'] = 'Background color values are required.'; $string['blue'] = 'Blue'; @@ -43,3 +44,4 @@ $string['qrcodecontent'] = 'QR Code Content'; $string['qrcodecontent_required'] = 'QR Code content is required.'; $string['red'] = 'Red'; + $string['title'] = 'Insert Qrcode Code'; diff --git a/templates/insert_qrcode_modal.mustache b/templates/insert_qrcode_modal.mustache index 9030ee0..41ca905 100755 --- a/templates/insert_qrcode_modal.mustache +++ b/templates/insert_qrcode_modal.mustache @@ -42,13 +42,13 @@ - +
- +