From c0043004e1e11c146a1a54291c59ae60e2172933 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 19 May 2023 10:51:14 +0800 Subject: [PATCH] MDL-78316 core: Convert IconSystems to ESM --- lib/amd/build/icon_system.min.js | 9 +- lib/amd/build/icon_system.min.js.map | 2 +- lib/amd/build/icon_system_fontawesome.min.js | 9 +- .../build/icon_system_fontawesome.min.js.map | 2 +- lib/amd/build/icon_system_standard.min.js | 14 +- lib/amd/build/icon_system_standard.min.js.map | 2 +- lib/amd/src/icon_system.js | 57 +++-- lib/amd/src/icon_system_fontawesome.js | 206 +++++++++++------- lib/amd/src/icon_system_standard.js | 55 ++--- 9 files changed, 193 insertions(+), 163 deletions(-) diff --git a/lib/amd/build/icon_system.min.js b/lib/amd/build/icon_system.min.js index 2a2f5455cc8..de50eb600fd 100644 --- a/lib/amd/build/icon_system.min.js +++ b/lib/amd/build/icon_system.min.js @@ -1,10 +1,3 @@ -/** - * Icon System base module. - * - * @module core/icon_system - * @copyright 2017 Damyon Wiese - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -define("core/icon_system",["jquery"],(function($){var IconSystem=function(){};return IconSystem.prototype.init=function(){return $.when(this)},IconSystem.prototype.renderIcon=function(key,component,title,template){throw new Error("Abstract function not implemented.")},IconSystem.prototype.getTemplateName=function(){throw new Error("Abstract function not implemented.")},IconSystem})); +define("core/icon_system",["exports","core/config"],(function(_exports,_config){var obj;Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_config=(obj=_config)&&obj.__esModule?obj:{default:obj};var _systemImportTransformerGlobalIdentifier="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:{};class IconSystem{static async instance(){return this.iconSystemInstance||(this.iconSystemInstance=new Promise((async(resolve,reject)=>{const SystemClass=await("function"==typeof _systemImportTransformerGlobalIdentifier.define&&_systemImportTransformerGlobalIdentifier.define.amd?new Promise((function(resolve,reject){_systemImportTransformerGlobalIdentifier.require([_config.default.iconsystemmodule],resolve,reject)})):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&_systemImportTransformerGlobalIdentifier.require&&"component"===_systemImportTransformerGlobalIdentifier.require.loader?Promise.resolve(require(_config.default.iconsystemmodule)):Promise.resolve(_systemImportTransformerGlobalIdentifier[_config.default.iconsystemmodule])),instance=new SystemClass;if(!(instance instanceof IconSystem))throw Error("Invalid icon system specified ".concat(_config.default.iconsystemmodule,". Class is not an IconSystem."),SystemClass);try{resolve(instance.init())}catch(error){reject(error)}}))),await this.iconSystemInstance}init(){return Promise.resolve(this)}renderIcon(key,component,title,template){throw new Error("Abstract function not implemented.")}getTemplateName(){throw new Error("Abstract function not implemented.")}}return _exports.default=IconSystem,function(obj,key,value){key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value}(IconSystem,"iconSystemInstance",null),_exports.default})); //# sourceMappingURL=icon_system.min.js.map \ No newline at end of file diff --git a/lib/amd/build/icon_system.min.js.map b/lib/amd/build/icon_system.min.js.map index 094e4c0dccd..86ced303e5a 100644 --- a/lib/amd/build/icon_system.min.js.map +++ b/lib/amd/build/icon_system.min.js.map @@ -1 +1 @@ -{"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 .\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\ndefine(['jquery'], function($) {\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 */\n var IconSystem = function() {\n };\n\n /**\n * Initialise the icon system.\n *\n * @return {Promise}\n * @method init\n */\n IconSystem.prototype.init = function() {\n return $.when(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 * @return {String}\n * @method renderIcon\n */\n IconSystem.prototype.renderIcon = function(key, component, title, template) { // eslint-disable-line no-unused-vars\n throw new Error('Abstract function not implemented.');\n };\n\n /**\n * getTemplateName\n *\n * @return {String}\n * @method getTemplateName\n */\n IconSystem.prototype.getTemplateName = function() {\n throw new Error('Abstract function not implemented.');\n };\n\n return /** @alias module:core/icon_system */ IconSystem;\n});\n"],"names":["define","$","IconSystem","prototype","init","when","this","renderIcon","key","component","title","template","Error","getTemplateName"],"mappings":";;;;;;;AAuBAA,0BAAO,CAAC,WAAW,SAASC,OASpBC,WAAa,oBASjBA,WAAWC,UAAUC,KAAO,kBACjBH,EAAEI,KAAKC,OAmBlBJ,WAAWC,UAAUI,WAAa,SAASC,IAAKC,UAAWC,MAAOC,gBACxD,IAAIC,MAAM,uCASpBV,WAAWC,UAAUU,gBAAkB,iBAC7B,IAAID,MAAM,uCAGyBV"} \ No newline at end of file +{"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 .\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}\n */\n static iconSystemInstance = null;\n\n /**\n * Factory method to fetch the Icon System currently in use.\n *\n * @returns {Promise}\n */\n static async instance() {\n if (this.iconSystemInstance) {\n return await this.iconSystemInstance;\n }\n\n this.iconSystemInstance = new Promise(async(resolve, reject) => {\n const SystemClass = await import(config.iconsystemmodule);\n const instance = new SystemClass();\n if (!(instance instanceof IconSystem)) {\n throw Error(`Invalid icon system specified ${config.iconsystemmodule}. Class is not an IconSystem.`, SystemClass);\n }\n\n try {\n resolve(instance.init());\n } catch (error) {\n reject(error);\n }\n });\n\n return await this.iconSystemInstance;\n }\n\n /**\n * Initialise the icon system.\n *\n * @return {Promise}\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","Promise","async","resolve","reject","SystemClass","config","iconsystemmodule","instance","Error","init","error","renderIcon","key","component","title","template","getTemplateName"],"mappings":"wXAgCqBA,0CAeTC,KAAKC,0BAIJA,mBAAqB,IAAIC,SAAQC,MAAMC,QAASC,gBAC3CC,kOAA2BC,gBAAOC,4SAAPD,gBAAb,4EAAaA,gBAAOC,oBAClCC,SAAW,IAAIH,iBACfG,oBAAoBV,kBAChBW,8CAAuCH,gBAAOC,kDAAiDF,iBAIrGF,QAAQK,SAASE,QACnB,MAAOC,OACLP,OAAOO,kBAbEZ,KAAKC,mBAyB1BU,cACWT,QAAQE,QAAQJ,MAoB3Ba,WAAWC,IAAKC,UAAWC,MAAOC,gBACxB,IAAIP,MAAM,sCAUpBQ,wBACU,IAAIR,MAAM,oNA1EHX,gCAOW"} \ No newline at end of file diff --git a/lib/amd/build/icon_system_fontawesome.min.js b/lib/amd/build/icon_system_fontawesome.min.js index cb019c9c070..cb88167334c 100644 --- a/lib/amd/build/icon_system_fontawesome.min.js +++ b/lib/amd/build/icon_system_fontawesome.min.js @@ -1,10 +1,3 @@ -/** - * Competency rule points module. - * - * @module core/icon_system_fontawesome - * @copyright 2017 Damyon Wiese - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -define("core/icon_system_fontawesome",["core/icon_system","jquery","core/ajax","core/mustache","core/localstorage","core/url"],(function(IconSystem,$,Ajax,Mustache,LocalStorage,Url){var staticMap=null,fetchMap=null,IconSystemFontawesome=function(){IconSystem.apply(this,arguments)};return(IconSystemFontawesome.prototype=Object.create(IconSystem.prototype)).init=function(){var currTheme=M.cfg.theme;if(staticMap)return $.when(this);var map=LocalStorage.get("core_iconsystem/theme/"+currTheme+"/core/iconmap-fontawesome");return map&&(map=JSON.parse(map)),map?(staticMap=map,$.when(this)):(null===fetchMap&&(fetchMap=Ajax.call([{methodname:"core_output_load_fontawesome_icon_system_map",args:{themename:M.cfg.theme}}],!0,!1,!1,0,M.cfg.themerev)[0]),fetchMap.then(function(map){return staticMap={},$.each(map,(function(index,value){staticMap[value.component+"/"+value.pix]=value.to})),LocalStorage.set("core_iconsystem/theme/"+currTheme+"/core/iconmap-fontawesome",JSON.stringify(staticMap)),this}.bind(this)))},IconSystemFontawesome.prototype.renderIcon=function(key,component,title,template){var mappedIcon=staticMap[component+"/"+key],unmappedIcon=!1;void 0===mappedIcon&&(unmappedIcon={attributes:[{name:"src",value:Url.imageUrl(key,component)},{name:"alt",value:title},{name:"title",value:title}]});var context={key:mappedIcon,title:title,alt:title,unmappedIcon:unmappedIcon};return void 0!==title&&""!==title||(context["aria-hidden"]=!0),Mustache.render(template,context).trim()},IconSystemFontawesome.prototype.getTemplateName=function(){return"core/pix_icon_fontawesome"},IconSystemFontawesome})); +define("core/icon_system_fontawesome",["exports","./ajax","./localstorage","./icon_system","./mustache","./config","./url"],(function(_exports,_ajax,_localstorage,_icon_system,Mustache,Config,Url){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}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,_localstorage=_interopRequireDefault(_localstorage),_icon_system=_interopRequireDefault(_icon_system),Mustache=_interopRequireWildcard(Mustache),Config=_interopRequireWildcard(Config),Url=_interopRequireWildcard(Url);class IconSystemFontawesome extends _icon_system.default{init(){return IconSystemFontawesome.staticMap||this.getMapFromCache()?Promise.resolve(this):IconSystemFontawesome.fetchPromise?IconSystemFontawesome.fetchPromise:this.fetchMapFromServer()}getMapFromCache(){const map=_localstorage.default.get(IconSystemFontawesome.cacheKey);return map&&(IconSystemFontawesome.staticMap=new Map(JSON.parse(map))),IconSystemFontawesome.staticMap}_fetchMapFromServer(){return(0,_ajax.call)([{methodname:"core_output_load_fontawesome_icon_system_map",args:{themename:Config.theme}}],!0,!1,!1,0,Config.themerev)[0]}async fetchMapFromServer(){return IconSystemFontawesome.fetchPromise=new Promise((async resolve=>{const mapData=await this._fetchMapFromServer();IconSystemFontawesome.staticMap=new Map(Object.entries(mapData).map((_ref=>{let[,value]=_ref;return["".concat(value.component,"/").concat(value.pix),value.to]}))),_localstorage.default.set(IconSystemFontawesome.cacheKey,JSON.stringify(Array.from(IconSystemFontawesome.staticMap.entries()))),resolve(this)})),IconSystemFontawesome.fetchPromise}renderIcon(key,component,title,template){const iconKey="".concat(component,"/").concat(key),mappedIcon=IconSystemFontawesome.staticMap.get(iconKey),context={title:title,unmappedIcon:this.getUnmappedIcon(mappedIcon,key,component,title),alt:title,key:mappedIcon};return void 0!==title&&""!==title||(context["aria-hidden"]=!0),Mustache.render(template,context).trim()}getUnmappedIcon(mappedIcon,key,component,title){return mappedIcon?null:{attributes:[{name:"src",value:Url.imageUrl(key,component)},{name:"alt",value:title},{name:"title",value:title}]}}getTemplateName(){return"core/pix_icon_fontawesome"}}return _exports.default=IconSystemFontawesome,_defineProperty(IconSystemFontawesome,"staticMap",null),_defineProperty(IconSystemFontawesome,"fetchPromise",null),_defineProperty(IconSystemFontawesome,"cacheKey","core_iconsystem/theme/".concat(Config.theme,"/core/iconmap-fontawesome")),_exports.default})); //# sourceMappingURL=icon_system_fontawesome.min.js.map \ No newline at end of file diff --git a/lib/amd/build/icon_system_fontawesome.min.js.map b/lib/amd/build/icon_system_fontawesome.min.js.map index e77a3b70770..0cd46158c3a 100644 --- a/lib/amd/build/icon_system_fontawesome.min.js.map +++ b/lib/amd/build/icon_system_fontawesome.min.js.map @@ -1 +1 @@ -{"version":3,"file":"icon_system_fontawesome.min.js","sources":["../src/icon_system_fontawesome.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 * Competency rule points module.\n *\n * @module core/icon_system_fontawesome\n * @copyright 2017 Damyon Wiese\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['core/icon_system', 'jquery', 'core/ajax', 'core/mustache', 'core/localstorage', 'core/url'],\n function(IconSystem, $, Ajax, Mustache, LocalStorage, Url) {\n\n var staticMap = null;\n var fetchMap = null;\n\n /**\n * IconSystemFontawesome\n * @class core/icon_system_fontawesome\n */\n var IconSystemFontawesome = function() {\n IconSystem.apply(this, arguments);\n };\n IconSystemFontawesome.prototype = Object.create(IconSystem.prototype);\n\n /**\n * Prefetch resources so later calls to renderIcon can be resolved synchronously.\n *\n * @method init\n * @return {Promise}\n */\n IconSystemFontawesome.prototype.init = function() {\n var currTheme = M.cfg.theme;\n\n if (staticMap) {\n return $.when(this);\n }\n\n var map = LocalStorage.get('core_iconsystem/theme/' + currTheme + '/core/iconmap-fontawesome');\n if (map) {\n map = JSON.parse(map);\n }\n\n if (map) {\n staticMap = map;\n return $.when(this);\n }\n\n if (fetchMap === null) {\n fetchMap = Ajax.call([{\n methodname: 'core_output_load_fontawesome_icon_system_map',\n args: {\n themename: M.cfg.theme,\n },\n }], true, false, false, 0, M.cfg.themerev)[0];\n }\n\n return fetchMap.then(function(map) {\n staticMap = {};\n $.each(map, function(index, value) {\n staticMap[value.component + '/' + value.pix] = value.to;\n });\n LocalStorage.set('core_iconsystem/theme/' + currTheme + '/core/iconmap-fontawesome', JSON.stringify(staticMap));\n return this;\n }.bind(this));\n };\n\n /**\n * Render an icon.\n *\n * @param {String} key\n * @param {String} component\n * @param {String} title\n * @param {String} template\n * @return {String}\n * @method renderIcon\n */\n IconSystemFontawesome.prototype.renderIcon = function(key, component, title, template) {\n var mappedIcon = staticMap[component + '/' + key];\n var unmappedIcon = false;\n if (typeof mappedIcon === \"undefined\") {\n var url = Url.imageUrl(key, component);\n\n unmappedIcon = {\n attributes: [\n {name: 'src', value: url},\n {name: 'alt', value: title},\n {name: 'title', value: title}\n ]\n };\n }\n\n var context = {\n key: mappedIcon,\n title: title,\n alt: title,\n unmappedIcon: unmappedIcon\n };\n\n if (typeof title === \"undefined\" || title === '') {\n context['aria-hidden'] = true;\n }\n\n var result = Mustache.render(template, context);\n return result.trim();\n };\n\n /**\n * Get the name of the template to pre-cache for this icon system.\n *\n * @return {String}\n * @method getTemplateName\n */\n IconSystemFontawesome.prototype.getTemplateName = function() {\n return 'core/pix_icon_fontawesome';\n };\n\n return /** @alias module:core/icon_system_fontawesome */ IconSystemFontawesome;\n\n});\n"],"names":["define","IconSystem","$","Ajax","Mustache","LocalStorage","Url","staticMap","fetchMap","IconSystemFontawesome","apply","this","arguments","prototype","Object","create","init","currTheme","M","cfg","theme","when","map","get","JSON","parse","call","methodname","args","themename","themerev","then","each","index","value","component","pix","to","set","stringify","bind","renderIcon","key","title","template","mappedIcon","unmappedIcon","attributes","name","imageUrl","context","alt","render","trim","getTemplateName"],"mappings":";;;;;;;AAuBAA,sCAAO,CAAC,mBAAoB,SAAU,YAAa,gBAAiB,oBAAqB,aACjF,SAASC,WAAYC,EAAGC,KAAMC,SAAUC,aAAcC,SAEtDC,UAAY,KACZC,SAAW,KAMXC,sBAAwB,WACxBR,WAAWS,MAAMC,KAAMC,mBAE3BH,sBAAsBI,UAAYC,OAAOC,OAAOd,WAAWY,YAQ3BG,KAAO,eAC/BC,UAAYC,EAAEC,IAAIC,SAElBb,iBACOL,EAAEmB,KAAKV,UAGdW,IAAMjB,aAAakB,IAAI,yBAA2BN,UAAY,oCAC9DK,MACAA,IAAME,KAAKC,MAAMH,MAGjBA,KACAf,UAAYe,IACLpB,EAAEmB,KAAKV,QAGD,OAAbH,WACAA,SAAWL,KAAKuB,KAAK,CAAC,CAClBC,WAAY,+CACZC,KAAM,CACFC,UAAWX,EAAEC,IAAIC,UAErB,GAAM,GAAO,EAAO,EAAGF,EAAEC,IAAIW,UAAU,IAGxCtB,SAASuB,KAAK,SAAST,YAC1Bf,UAAY,GACZL,EAAE8B,KAAKV,KAAK,SAASW,MAAOC,OACxB3B,UAAU2B,MAAMC,UAAY,IAAMD,MAAME,KAAOF,MAAMG,MAEzDhC,aAAaiC,IAAI,yBAA2BrB,UAAY,4BAA6BO,KAAKe,UAAUhC,YAC7FI,MACT6B,KAAK7B,SAaXF,sBAAsBI,UAAU4B,WAAa,SAASC,IAAKP,UAAWQ,MAAOC,cACrEC,WAAatC,UAAU4B,UAAY,IAAMO,KACzCI,cAAe,OACO,IAAfD,aAGPC,aAAe,CACXC,WAAY,CACR,CAACC,KAAM,MAAOd,MAJZ5B,IAAI2C,SAASP,IAAKP,YAKpB,CAACa,KAAM,MAAOd,MAAOS,OACrB,CAACK,KAAM,QAASd,MAAOS,cAK/BO,QAAU,CACVR,IAAKG,WACLF,MAAOA,MACPQ,IAAKR,MACLG,aAAcA,0BAGG,IAAVH,OAAmC,KAAVA,QAChCO,QAAQ,gBAAiB,GAGhB9C,SAASgD,OAAOR,SAAUM,SACzBG,QASlB5C,sBAAsBI,UAAUyC,gBAAkB,iBACvC,6BAG8C7C"} \ No newline at end of file +{"version":3,"file":"icon_system_fontawesome.min.js","sources":["../src/icon_system_fontawesome.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 * An Icon System implementation for FontAwesome.\n *\n * @module core/icon_system_fontawesome\n * @copyright 2017 Damyon Wiese\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {call as fetchMany} from './ajax';\nimport LocalStorage from './localstorage';\nimport IconSystem from './icon_system';\nimport * as Mustache from './mustache';\nimport * as Config from './config';\nimport * as Url from './url';\n\n/**\n * The FontAwesome icon system.\n */\nexport default class IconSystemFontawesome extends IconSystem {\n /**\n * @var {Map} staticMap A map of icon names to FA Icon.\n * @private\n */\n static staticMap = null;\n\n /**\n * @var {Promise} fetchPromise The promise used when fetching the result\n * @private\n */\n static fetchPromise = null;\n\n /**\n * @var {string} cacheKey The key used to store the icon map in LocalStorage.\n * @private\n */\n static cacheKey = `core_iconsystem/theme/${Config.theme}/core/iconmap-fontawesome`;\n\n /**\n * Prefetch resources so later calls to renderIcon can be resolved synchronously.\n *\n * @returns {Promise}\n */\n init() {\n if (IconSystemFontawesome.staticMap) {\n return Promise.resolve(this);\n }\n\n if (this.getMapFromCache()) {\n return Promise.resolve(this);\n }\n\n if (IconSystemFontawesome.fetchPromise) {\n return IconSystemFontawesome.fetchPromise;\n }\n\n return this.fetchMapFromServer();\n }\n\n /**\n * Get the icon map from LocalStorage.\n *\n * @private\n * @returns {Map}\n */\n getMapFromCache() {\n const map = LocalStorage.get(IconSystemFontawesome.cacheKey);\n if (map) {\n IconSystemFontawesome.staticMap = new Map(JSON.parse(map));\n }\n return IconSystemFontawesome.staticMap;\n }\n\n /**\n * Fetch the map data from the server.\n *\n * @private\n * @returns {Promise}\n */\n _fetchMapFromServer() {\n return fetchMany([{\n methodname: 'core_output_load_fontawesome_icon_system_map',\n args: {\n themename: Config.theme,\n },\n }], true, false, false, 0, Config.themerev)[0];\n }\n\n /**\n * Fetch the map data from the server.\n *\n * @returns {Promise}\n * @private\n */\n async fetchMapFromServer() {\n IconSystemFontawesome.fetchPromise = new Promise(async(resolve) => {\n const mapData = await this._fetchMapFromServer();\n\n IconSystemFontawesome.staticMap = new Map(Object.entries(mapData).map(([, value]) => ([\n `${value.component}/${value.pix}`,\n value.to,\n ])));\n LocalStorage.set(\n IconSystemFontawesome.cacheKey,\n JSON.stringify(Array.from(IconSystemFontawesome.staticMap.entries())),\n );\n\n resolve(this);\n });\n\n return IconSystemFontawesome.fetchPromise;\n }\n\n /**\n * Render an icon.\n *\n * @param {string} key\n * @param {string} component\n * @param {string} title\n * @param {string} template\n * @return {string} The rendered HTML content\n */\n renderIcon(key, component, title, template) {\n const iconKey = `${component}/${key}`;\n const mappedIcon = IconSystemFontawesome.staticMap.get(iconKey);\n const unmappedIcon = this.getUnmappedIcon(mappedIcon, key, component, title);\n\n const context = {\n title,\n unmappedIcon,\n alt: title,\n key: mappedIcon,\n };\n\n if (typeof title === \"undefined\" || title === '') {\n context['aria-hidden'] = true;\n }\n\n return Mustache.render(template, context).trim();\n }\n\n /**\n * Get the unamapped icon content, if the icon is not mapped.\n *\n * @param {object>} mappedIcon\n * @param {string} key\n * @param {string} component\n * @param {StaticRange} title\n * @returns {object>|null}\n * @private\n */\n getUnmappedIcon(mappedIcon, key, component, title) {\n if (mappedIcon) {\n return null;\n }\n\n return {\n attributes: [\n {name: 'src', value: Url.imageUrl(key, component)},\n {name: 'alt', value: title},\n {name: 'title', value: title}\n ],\n };\n }\n\n /**\n * Get the name of the template to pre-cache for this icon system.\n *\n * @return {string}\n * @method getTemplateName\n */\n getTemplateName() {\n return 'core/pix_icon_fontawesome';\n }\n}\n"],"names":["IconSystemFontawesome","IconSystem","init","staticMap","this","getMapFromCache","Promise","resolve","fetchPromise","fetchMapFromServer","map","LocalStorage","get","cacheKey","Map","JSON","parse","_fetchMapFromServer","methodname","args","themename","Config","theme","themerev","async","mapData","Object","entries","_ref","value","component","pix","to","set","stringify","Array","from","renderIcon","key","title","template","iconKey","mappedIcon","context","unmappedIcon","getUnmappedIcon","alt","Mustache","render","trim","attributes","name","Url","imageUrl","getTemplateName"],"mappings":"iqDAiCqBA,8BAA8BC,qBAwB/CC,cACQF,sBAAsBG,WAItBC,KAAKC,kBAHEC,QAAQC,QAAQH,MAOvBJ,sBAAsBQ,aACfR,sBAAsBQ,aAG1BJ,KAAKK,qBAShBJ,wBACUK,IAAMC,sBAAaC,IAAIZ,sBAAsBa,iBAC/CH,MACAV,sBAAsBG,UAAY,IAAIW,IAAIC,KAAKC,MAAMN,OAElDV,sBAAsBG,UASjCc,6BACW,cAAU,CAAC,CACdC,WAAY,+CACZC,KAAM,CACFC,UAAWC,OAAOC,UAEtB,GAAM,GAAO,EAAO,EAAGD,OAAOE,UAAU,qCAU5CvB,sBAAsBQ,aAAe,IAAIF,SAAQkB,MAAAA,gBACvCC,cAAgBrB,KAAKa,sBAE3BjB,sBAAsBG,UAAY,IAAIW,IAAIY,OAAOC,QAAQF,SAASf,KAAIkB,YAAIC,kBAAY,WAC/EA,MAAMC,sBAAaD,MAAME,KAC5BF,MAAMG,8BAEGC,IACTjC,sBAAsBa,SACtBE,KAAKmB,UAAUC,MAAMC,KAAKpC,sBAAsBG,UAAUwB,aAG9DpB,QAAQH,SAGLJ,sBAAsBQ,aAYjC6B,WAAWC,IAAKR,UAAWS,MAAOC,gBACxBC,kBAAaX,sBAAaQ,KAC1BI,WAAa1C,sBAAsBG,UAAUS,IAAI6B,SAGjDE,QAAU,CACZJ,MAAAA,MACAK,aAJiBxC,KAAKyC,gBAAgBH,WAAYJ,IAAKR,UAAWS,OAKlEO,IAAKP,MACLD,IAAKI,wBAGY,IAAVH,OAAmC,KAAVA,QAChCI,QAAQ,gBAAiB,GAGtBI,SAASC,OAAOR,SAAUG,SAASM,OAa9CJ,gBAAgBH,WAAYJ,IAAKR,UAAWS,cACpCG,WACO,KAGJ,CACHQ,WAAY,CACR,CAACC,KAAM,MAAOtB,MAAOuB,IAAIC,SAASf,IAAKR,YACvC,CAACqB,KAAM,MAAOtB,MAAOU,OACrB,CAACY,KAAM,QAAStB,MAAOU,SAWnCe,wBACW,2FAzJMtD,kCAKE,sBALFA,qCAWK,sBAXLA,iEAiB0BqB,OAAOC"} \ No newline at end of file diff --git a/lib/amd/build/icon_system_standard.min.js b/lib/amd/build/icon_system_standard.min.js index 2fbf5ea242f..660e7a8cb09 100644 --- a/lib/amd/build/icon_system_standard.min.js +++ b/lib/amd/build/icon_system_standard.min.js @@ -1,10 +1,10 @@ +define("core/icon_system_standard",["exports","./icon_system","./url","./mustache"],(function(_exports,_icon_system,CoreUrl,Mustache){var obj; /** - * Competency rule points module. - * - * @module core/icon_system_standard - * @copyright 2017 Damyon Wiese - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -define("core/icon_system_standard",["core/icon_system","core/url","core/mustache"],(function(IconSystem,CoreUrl,Mustache){var IconSystemStandard=function(){IconSystem.apply(this,arguments)};return(IconSystemStandard.prototype=Object.create(IconSystem.prototype)).renderIcon=function(key,component,title,template){var templatecontext={attributes:[{name:"src",value:CoreUrl.imageUrl(key,component)},{name:"alt",value:title},{name:"title",value:title}]};return void 0!==title&&""!=title||templatecontext.attributes.push({name:"aria-hidden",value:"true"}),Mustache.render(template,templatecontext).trim()},IconSystemStandard.prototype.getTemplateName=function(){return"core/pix_icon"},IconSystemStandard})); + * The Standard icon system. + * + * @module core/icon_system_standard + * @copyright 2017 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_icon_system=(obj=_icon_system)&&obj.__esModule?obj:{default:obj},CoreUrl=_interopRequireWildcard(CoreUrl),Mustache=_interopRequireWildcard(Mustache);class IconSystemStandard extends _icon_system.default{renderIcon(key,component,title,template){const templatecontext={attributes:[{name:"src",value:CoreUrl.imageUrl(key,component)},{name:"alt",value:title},{name:"title",value:title}]};return void 0!==title&&""!=title||templatecontext.attributes.push({name:"aria-hidden",value:"true"}),Mustache.render(template,templatecontext).trim()}getTemplateName(){return"core/pix_icon"}}return _exports.default=IconSystemStandard,_exports.default})); //# sourceMappingURL=icon_system_standard.min.js.map \ No newline at end of file diff --git a/lib/amd/build/icon_system_standard.min.js.map b/lib/amd/build/icon_system_standard.min.js.map index 6165a20dc6f..f7ed8ee9080 100644 --- a/lib/amd/build/icon_system_standard.min.js.map +++ b/lib/amd/build/icon_system_standard.min.js.map @@ -1 +1 @@ -{"version":3,"file":"icon_system_standard.min.js","sources":["../src/icon_system_standard.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 * Competency rule points module.\n *\n * @module core/icon_system_standard\n * @copyright 2017 Damyon Wiese\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['core/icon_system', 'core/url', 'core/mustache'],\n function(IconSystem, CoreUrl, Mustache) {\n\n /**\n * IconSystemStandard\n *\n * @class core/icon_system_standard\n */\n var IconSystemStandard = function() {\n IconSystem.apply(this, arguments);\n };\n IconSystemStandard.prototype = Object.create(IconSystem.prototype);\n\n /**\n * Render an icon.\n *\n * @method renderIcon\n * @param {String} key\n * @param {String} component\n * @param {String} title\n * @param {String} template\n * @return {String}\n */\n IconSystemStandard.prototype.renderIcon = function(key, component, title, template) {\n var url = CoreUrl.imageUrl(key, component);\n\n var templatecontext = {\n attributes: [\n {name: 'src', value: url},\n {name: 'alt', value: title},\n {name: 'title', value: title}\n ]\n };\n if (typeof title === \"undefined\" || title == \"\") {\n templatecontext.attributes.push({name: 'aria-hidden', value: 'true'});\n }\n\n var result = Mustache.render(template, templatecontext);\n return result.trim();\n };\n\n /**\n * Get the name of the template to pre-cache for this icon system.\n *\n * @return {String}\n * @method getTemplateName\n */\n IconSystemStandard.prototype.getTemplateName = function() {\n return 'core/pix_icon';\n };\n\n return IconSystemStandard;\n});\n"],"names":["define","IconSystem","CoreUrl","Mustache","IconSystemStandard","apply","this","arguments","prototype","Object","create","renderIcon","key","component","title","template","templatecontext","attributes","name","value","imageUrl","push","render","trim","getTemplateName"],"mappings":";;;;;;;AAuBAA,mCAAO,CAAC,mBAAoB,WAAY,kBAChC,SAASC,WAAYC,QAASC,cAO9BC,mBAAqB,WACrBH,WAAWI,MAAMC,KAAMC,mBAE3BH,mBAAmBI,UAAYC,OAAOC,OAAOT,WAAWO,YAY3BG,WAAa,SAASC,IAAKC,UAAWC,MAAOC,cAGlEC,gBAAkB,CAClBC,WAAY,CACR,CAACC,KAAM,MAAOC,MAJZjB,QAAQkB,SAASR,IAAKC,YAKxB,CAACK,KAAM,MAAOC,MAAOL,OACrB,CAACI,KAAM,QAASC,MAAOL,qBAGV,IAAVA,OAAkC,IAATA,OAChCE,gBAAgBC,WAAWI,KAAK,CAACH,KAAM,cAAeC,MAAO,SAGpDhB,SAASmB,OAAOP,SAAUC,iBACzBO,QASlBnB,mBAAmBI,UAAUgB,gBAAkB,iBACpC,iBAGJpB"} \ No newline at end of file +{"version":3,"file":"icon_system_standard.min.js","sources":["../src/icon_system_standard.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 * The Standard icon system.\n *\n * @module core/icon_system_standard\n * @copyright 2017 Damyon Wiese\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport IconSystem from './icon_system';\nimport * as CoreUrl from './url';\nimport * as Mustache from './mustache';\n\n/**\n * The Standard icon system.\n */\nexport default class IconSystemStandard extends IconSystem {\n\n /**\n * Render an icon.\n *\n * @param {string} key\n * @param {string} component\n * @param {string} title\n * @param {string} template\n * @return {string}\n */\n renderIcon(key, component, title, template) {\n const url = CoreUrl.imageUrl(key, component);\n\n const templatecontext = {\n attributes: [\n {name: 'src', value: url},\n {name: 'alt', value: title},\n {name: 'title', value: title},\n ]\n };\n if (typeof title === \"undefined\" || title == \"\") {\n templatecontext.attributes.push({name: 'aria-hidden', value: 'true'});\n }\n\n return Mustache.render(template, templatecontext).trim();\n }\n\n /**\n * Get the name of the template to pre-cache for this icon system.\n *\n * @return {string}\n */\n getTemplateName() {\n return 'core/pix_icon';\n }\n}\n"],"names":["IconSystemStandard","IconSystem","renderIcon","key","component","title","template","templatecontext","attributes","name","value","CoreUrl","imageUrl","push","Mustache","render","trim","getTemplateName"],"mappings":";;;;;;;wqCA8BqBA,2BAA2BC,qBAW5CC,WAAWC,IAAKC,UAAWC,MAAOC,gBAGxBC,gBAAkB,CACpBC,WAAY,CACR,CAACC,KAAM,MAAOC,MAJVC,QAAQC,SAAST,IAAKC,YAK1B,CAACK,KAAM,MAAOC,MAAOL,OACrB,CAACI,KAAM,QAASC,MAAOL,qBAGV,IAAVA,OAAkC,IAATA,OAChCE,gBAAgBC,WAAWK,KAAK,CAACJ,KAAM,cAAeC,MAAO,SAG1DI,SAASC,OAAOT,SAAUC,iBAAiBS,OAQtDC,wBACW"} \ No newline at end of file diff --git a/lib/amd/src/icon_system.js b/lib/amd/src/icon_system.js index 902f9cccf9f..460b1f0c2fd 100644 --- a/lib/amd/src/icon_system.js +++ b/lib/amd/src/icon_system.js @@ -21,27 +21,24 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define(['jquery'], function($) { - - /** - * Icon System abstract class. - * - * Any icon system needs to define a module extending this one and return this module name from the php icon_system class. - * - * @class core/icon_system - */ - var IconSystem = function() { - }; +import config from 'core/config'; +/** + * Icon System abstract class. + * + * Any icon system needs to define a module extending this one and return this module name from the php icon_system class. + * + * @class core/icon_system + */ +export default class IconSystem { /** * Initialise the icon system. * - * @return {Promise} - * @method init + * @return {Promise} */ - IconSystem.prototype.init = function() { - return $.when(this); - }; + init() { + return Promise.resolve(this); + } /** * Render an icon. @@ -52,26 +49,26 @@ define(['jquery'], function($) { * template (which is unfortunately synchronous). To render the mustache template in this function call * core/mustache.render() directly and do not use any partials, blocks or helper functions in the template. * - * @param {String} key - * @param {String} component - * @param {String} title - * @param {String} template - * @return {String} + * @param {string} key + * @param {string} component + * @param {string} title + * @param {string} template + * @returns {string} * @method renderIcon */ - IconSystem.prototype.renderIcon = function(key, component, title, template) { // eslint-disable-line no-unused-vars + // eslint-disable-next-line no-unused-vars + renderIcon(key, component, title, template) { throw new Error('Abstract function not implemented.'); - }; + } /** - * getTemplateName + * Get the name of the template. * - * @return {String} + * @returns {string} * @method getTemplateName */ - IconSystem.prototype.getTemplateName = function() { + // eslint-disable-next-line no-unused-vars + getTemplateName() { throw new Error('Abstract function not implemented.'); - }; - - return /** @alias module:core/icon_system */ IconSystem; -}); + } +} diff --git a/lib/amd/src/icon_system_fontawesome.js b/lib/amd/src/icon_system_fontawesome.js index f148572c522..c0f62f7ea3d 100644 --- a/lib/amd/src/icon_system_fontawesome.js +++ b/lib/amd/src/icon_system_fontawesome.js @@ -14,120 +14,176 @@ // along with Moodle. If not, see . /** - * Competency rule points module. + * An Icon System implementation for FontAwesome. * * @module core/icon_system_fontawesome * @copyright 2017 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define(['core/icon_system', 'jquery', 'core/ajax', 'core/mustache', 'core/localstorage', 'core/url'], - function(IconSystem, $, Ajax, Mustache, LocalStorage, Url) { +import {call as fetchMany} from './ajax'; +import LocalStorage from './localstorage'; +import IconSystem from './icon_system'; +import * as Mustache from './mustache'; +import * as Config from './config'; +import * as Url from './url'; - var staticMap = null; - var fetchMap = null; +/** + * The FontAwesome icon system. + */ +export default class IconSystemFontawesome extends IconSystem { + /** + * @var {Map} staticMap A map of icon names to FA Icon. + * @private + */ + static staticMap = null; /** - * IconSystemFontawesome - * @class core/icon_system_fontawesome + * @var {Promise} fetchPromise The promise used when fetching the result + * @private */ - var IconSystemFontawesome = function() { - IconSystem.apply(this, arguments); - }; - IconSystemFontawesome.prototype = Object.create(IconSystem.prototype); + static fetchPromise = null; + + /** + * @var {string} cacheKey The key used to store the icon map in LocalStorage. + * @private + */ + static cacheKey = `core_iconsystem/theme/${Config.theme}/core/iconmap-fontawesome`; /** * Prefetch resources so later calls to renderIcon can be resolved synchronously. * - * @method init - * @return {Promise} + * @returns {Promise} */ - IconSystemFontawesome.prototype.init = function() { - var currTheme = M.cfg.theme; - - if (staticMap) { - return $.when(this); + init() { + if (IconSystemFontawesome.staticMap) { + return Promise.resolve(this); } - var map = LocalStorage.get('core_iconsystem/theme/' + currTheme + '/core/iconmap-fontawesome'); + if (this.getMapFromCache()) { + return Promise.resolve(this); + } + + if (IconSystemFontawesome.fetchPromise) { + return IconSystemFontawesome.fetchPromise; + } + + return this.fetchMapFromServer(); + } + + /** + * Get the icon map from LocalStorage. + * + * @private + * @returns {Map} + */ + getMapFromCache() { + const map = LocalStorage.get(IconSystemFontawesome.cacheKey); if (map) { - map = JSON.parse(map); + IconSystemFontawesome.staticMap = new Map(JSON.parse(map)); } + return IconSystemFontawesome.staticMap; + } - if (map) { - staticMap = map; - return $.when(this); - } + /** + * Fetch the map data from the server. + * + * @private + * @returns {Promise} + */ + _fetchMapFromServer() { + return fetchMany([{ + methodname: 'core_output_load_fontawesome_icon_system_map', + args: { + themename: Config.theme, + }, + }], true, false, false, 0, Config.themerev)[0]; + } - if (fetchMap === null) { - fetchMap = Ajax.call([{ - methodname: 'core_output_load_fontawesome_icon_system_map', - args: { - themename: M.cfg.theme, - }, - }], true, false, false, 0, M.cfg.themerev)[0]; - } + /** + * Fetch the map data from the server. + * + * @returns {Promise} + * @private + */ + async fetchMapFromServer() { + IconSystemFontawesome.fetchPromise = new Promise(async(resolve) => { + const mapData = await this._fetchMapFromServer(); - return fetchMap.then(function(map) { - staticMap = {}; - $.each(map, function(index, value) { - staticMap[value.component + '/' + value.pix] = value.to; - }); - LocalStorage.set('core_iconsystem/theme/' + currTheme + '/core/iconmap-fontawesome', JSON.stringify(staticMap)); - return this; - }.bind(this)); - }; + IconSystemFontawesome.staticMap = new Map(Object.entries(mapData).map(([, value]) => ([ + `${value.component}/${value.pix}`, + value.to, + ]))); + LocalStorage.set( + IconSystemFontawesome.cacheKey, + JSON.stringify(Array.from(IconSystemFontawesome.staticMap.entries())), + ); + + resolve(this); + }); + + return IconSystemFontawesome.fetchPromise; + } /** * Render an icon. * - * @param {String} key - * @param {String} component - * @param {String} title - * @param {String} template - * @return {String} - * @method renderIcon + * @param {string} key + * @param {string} component + * @param {string} title + * @param {string} template + * @return {string} The rendered HTML content */ - IconSystemFontawesome.prototype.renderIcon = function(key, component, title, template) { - var mappedIcon = staticMap[component + '/' + key]; - var unmappedIcon = false; - if (typeof mappedIcon === "undefined") { - var url = Url.imageUrl(key, component); + renderIcon(key, component, title, template) { + const iconKey = `${component}/${key}`; + const mappedIcon = IconSystemFontawesome.staticMap.get(iconKey); + const unmappedIcon = this.getUnmappedIcon(mappedIcon, key, component, title); - unmappedIcon = { - attributes: [ - {name: 'src', value: url}, - {name: 'alt', value: title}, - {name: 'title', value: title} - ] - }; - } - - var context = { - key: mappedIcon, - title: title, + const context = { + title, + unmappedIcon, alt: title, - unmappedIcon: unmappedIcon + key: mappedIcon, }; if (typeof title === "undefined" || title === '') { context['aria-hidden'] = true; } - var result = Mustache.render(template, context); - return result.trim(); - }; + return Mustache.render(template, context).trim(); + } + + /** + * Get the unamapped icon content, if the icon is not mapped. + * + * @param {object>} mappedIcon + * @param {string} key + * @param {string} component + * @param {StaticRange} title + * @returns {object>|null} + * @private + */ + getUnmappedIcon(mappedIcon, key, component, title) { + if (mappedIcon) { + return null; + } + + return { + attributes: [ + {name: 'src', value: Url.imageUrl(key, component)}, + {name: 'alt', value: title}, + {name: 'title', value: title} + ], + }; + } /** * Get the name of the template to pre-cache for this icon system. * - * @return {String} + * @return {string} * @method getTemplateName */ - IconSystemFontawesome.prototype.getTemplateName = function() { + getTemplateName() { return 'core/pix_icon_fontawesome'; - }; - - return /** @alias module:core/icon_system_fontawesome */ IconSystemFontawesome; - -}); + } +} diff --git a/lib/amd/src/icon_system_standard.js b/lib/amd/src/icon_system_standard.js index be2c7cf32f5..5c005f385a2 100644 --- a/lib/amd/src/icon_system_standard.js +++ b/lib/amd/src/icon_system_standard.js @@ -14,63 +14,54 @@ // along with Moodle. If not, see . /** - * Competency rule points module. + * The Standard icon system. * * @module core/icon_system_standard * @copyright 2017 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define(['core/icon_system', 'core/url', 'core/mustache'], - function(IconSystem, CoreUrl, Mustache) { +import IconSystem from './icon_system'; +import * as CoreUrl from './url'; +import * as Mustache from './mustache'; - /** - * IconSystemStandard - * - * @class core/icon_system_standard - */ - var IconSystemStandard = function() { - IconSystem.apply(this, arguments); - }; - IconSystemStandard.prototype = Object.create(IconSystem.prototype); +/** + * The Standard icon system. + */ +export default class IconSystemStandard extends IconSystem { /** * Render an icon. * - * @method renderIcon - * @param {String} key - * @param {String} component - * @param {String} title - * @param {String} template - * @return {String} + * @param {string} key + * @param {string} component + * @param {string} title + * @param {string} template + * @return {string} */ - IconSystemStandard.prototype.renderIcon = function(key, component, title, template) { - var url = CoreUrl.imageUrl(key, component); + renderIcon(key, component, title, template) { + const url = CoreUrl.imageUrl(key, component); - var templatecontext = { + const templatecontext = { attributes: [ {name: 'src', value: url}, {name: 'alt', value: title}, - {name: 'title', value: title} + {name: 'title', value: title}, ] }; if (typeof title === "undefined" || title == "") { templatecontext.attributes.push({name: 'aria-hidden', value: 'true'}); } - var result = Mustache.render(template, templatecontext); - return result.trim(); - }; + return Mustache.render(template, templatecontext).trim(); + } /** * Get the name of the template to pre-cache for this icon system. * - * @return {String} - * @method getTemplateName + * @return {string} */ - IconSystemStandard.prototype.getTemplateName = function() { + getTemplateName() { return 'core/pix_icon'; - }; - - return IconSystemStandard; -}); + } +}