Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"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 <http://www.gnu.org/licenses/>.\n\n/**\n * Tiny Premium plugin for Moodle.\n *\n * @module      tiny_premium/plugin\n * @copyright   2023 David Woloszyn <david.woloszyn@moodle.com>\n * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getTinyMCE} from 'editor_tiny/loader';\nimport {getPluginMetadata} from 'editor_tiny/utils';\nimport {component, pluginName} from 'tiny_premium/common';\nimport * as Configuration from 'tiny_premium/configuration';\nimport {getApiKey} from 'tiny_premium/external';\nimport Config from 'core/config';\n\nconst currentContextId = Config.contextid;\n\n// eslint-disable-next-line no-async-promise-executor\nexport default new Promise(async(resolve) => {\n    const [\n        tinyMCE,\n        pluginMetadata,\n        externalData\n    ] = await Promise.all([\n        getTinyMCE(),\n        getPluginMetadata(component, pluginName),\n        getApiKey(currentContextId)\n    ]);\n\n    tinyMCE.PluginManager.add(`${component}/plugin`, () => {\n        return pluginMetadata;\n    });\n\n    // Load the Tiny Premium script using the provided API key.\n    await getTinyPremium(tinyMCE, externalData.apikey);\n\n    resolve([`${component}/plugin`, Configuration]);\n});\n\nlet tinyPremiumPromise;\n\n/**\n * Promise for Tiny Premium plugins script.\n *\n * @param {TinyMCE} tinyMCE\n * @param {string} apikey\n * @return {Promise}\n */\nconst getTinyPremium = (tinyMCE, apikey) => {\n    if (tinyPremiumPromise) {\n        return tinyPremiumPromise;\n    }\n\n    tinyPremiumPromise = new Promise((resolve, reject) => {\n        const head = document.querySelector('head');\n        const script = document.createElement('script');\n        const tinyVersion = `${tinyMCE.majorVersion}.${tinyMCE.minorVersion}`;\n\n        script.dataset.tinymce = 'premium';\n        script.src = `https://cdn.tiny.cloud/1/${apikey}/tinymce/${tinyVersion}/plugins.min.js`;\n        script.referrerpolicy = \"origin\";\n\n        script.addEventListener('load', () => {\n            resolve();\n        }, false);\n\n        script.addEventListener('error', (err) => {\n            reject(err);\n        }, false);\n\n        head.append(script);\n    });\n\n    return tinyPremiumPromise;\n};\n"],"names":["currentContextId","contextid","Promise","async","tinyMCE","pluginMetadata","externalData","all","component","pluginName","PluginManager","add","getTinyPremium","apikey","resolve","Configuration","tinyPremiumPromise","reject","head","document","querySelector","script","createElement","tinyVersion","majorVersion","minorVersion","dataset","tinymce","src","referrerpolicy","addEventListener","err","append"],"mappings":";;;;;;;2BA8BMA,mFAA0BC,uBAGjB,IAAIC,SAAQC,MAAAA,gBAEnBC,QACAC,eACAC,oBACMJ,QAAQK,IAAI,EAClB,yBACA,4BAAkBC,kBAAWC,qBAC7B,uBAAUT,oBAGdI,QAAQM,cAAcC,cAAOH,8BAAoB,IACtCH,uBAILO,eAAeR,QAASE,aAAaO,QAE3CC,QAAQ,WAAIN,6BAAoBO,uBAGhCC,mDASEJ,eAAiB,CAACR,QAASS,SACzBG,qBAIJA,mBAAqB,IAAId,SAAQ,CAACY,QAASG,gBACjCC,KAAOC,SAASC,cAAc,QAC9BC,OAASF,SAASG,cAAc,UAChCC,sBAAiBnB,QAAQoB,yBAAgBpB,QAAQqB,cAEvDJ,OAAOK,QAAQC,QAAU,UACzBN,OAAOO,uCAAkCf,2BAAkBU,+BAC3DF,OAAOQ,eAAiB,SAExBR,OAAOS,iBAAiB,QAAQ,KAC5BhB,aACD,GAEHO,OAAOS,iBAAiB,SAAUC,MAC9Bd,OAAOc,QACR,GAEHb,KAAKc,OAAOX,WAGTL"}