Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"icon_system.min.js","sources":["../src/icon_system.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 * Icon System base module.\n *\n * @module core/icon_system\n * @copyright  2017 Damyon Wiese\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport config from 'core/config';\n\n/**\n * Icon System abstract class.\n *\n * Any icon system needs to define a module extending this one and return this module name from the php icon_system class.\n *\n * @class core/icon_system\n */\nexport default class IconSystem {\n    /**\n     * A Promise which resolves to the Icon System instance.\n     *\n     * @private\n     * @var {Promise<IconSystem>}\n     */\n    static iconSystemInstance = null;\n\n    /**\n     * Factory method to fetch the Icon System currently in use.\n     *\n     * @returns {Promise<IconSystem>}\n     */\n    static async instance() {\n        if (this.iconSystemInstance) {\n            return await this.iconSystemInstance;\n        }\n\n        this.iconSystemInstance = (async () => {\n            const SystemClass = await import(config.iconsystemmodule);\n            const instance = new SystemClass();\n            if (!(instance instanceof IconSystem)) {\n                window.console.error('Class is not an IconSystem', SystemClass);\n                throw Error(`Invalid icon system specified ${config.iconsystemmodule}. Class is not an IconSystem.`);\n            }\n\n            return await instance.init();\n        })();\n\n        return await this.iconSystemInstance;\n    }\n\n    /**\n     * Initialise the icon system.\n     *\n     * @return {Promise<IconSystem>}\n     */\n    init() {\n        return Promise.resolve(this);\n    }\n\n    /**\n     * Render an icon.\n     *\n     * The key, component and title come from either the pix mustache helper tag, or the call to templates.renderIcon.\n     * The template is the pre-loaded template string matching the template from getTemplateName() in this class.\n     * This function must return a string (not a promise) because it is used during the internal rendering of the mustache\n     * template (which is unfortunately synchronous). To render the mustache template in this function call\n     * core/mustache.render() directly and do not use any partials, blocks or helper functions in the template.\n     *\n     * @param {string} key\n     * @param {string} component\n     * @param {string} title\n     * @param {string} template\n     * @returns {string}\n     * @method renderIcon\n     */\n    // eslint-disable-next-line no-unused-vars\n    renderIcon(key, component, title, template) {\n        throw new Error('Abstract function not implemented.');\n    }\n\n    /**\n     * Get the name of the template.\n     *\n     * @returns {string}\n     * @method getTemplateName\n     */\n    // eslint-disable-next-line no-unused-vars\n    getTemplateName() {\n        throw new Error('Abstract function not implemented.');\n    }\n}\n"],"names":["IconSystem","this","iconSystemInstance","SystemClass","config","iconsystemmodule","instance","window","console","error","Error","init","Promise","resolve","renderIcon","key","component","title","template","getTemplateName"],"mappings":"wXAgCqBA,0CAeTC,KAAKC,0BAIJA,mBAAqB,iBAChBC,kOAA2BC,gBAAOC,4SAAPD,gBAAb,4EAAaA,gBAAOC,oBAClCC,SAAW,IAAIH,iBACfG,oBAAoBN,kBACtBO,OAAOC,QAAQC,MAAM,6BAA8BN,aAC7CO,8CAAuCN,gBAAOC,gEAG3CC,SAASK,QARA,UAHTV,KAAKC,mBAsB1BS,cACWC,QAAQC,QAAQZ,MAoB3Ba,WAAWC,IAAKC,UAAWC,MAAOC,gBACxB,IAAIR,MAAM,sCAUpBS,wBACU,IAAIT,MAAM,oNAvEHV,gCAOW"}