diff --git a/amd/build/icon_system_fontawesome.min.js b/amd/build/icon_system_fontawesome.min.js index d7ca6ba..25f84d4 100644 --- a/amd/build/icon_system_fontawesome.min.js +++ b/amd/build/icon_system_fontawesome.min.js @@ -1,17 +1,5 @@ define("theme_foundation/icon_system_fontawesome",["exports","core/ajax","core/localstorage","core/icon_system","core/mustache","core/config","core/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}} -/** - * Foundation theme. - * - * An Icon System implementation for FontAwesome based on core/icon_system_fontawesome by - * Damyon Wiese. - * - * @module theme_foundation/icon_system_fontawesome - * @copyright 2017 Damyon Wiese - * @copyright 2019 G J Barnard. - * @author G J Barnard - - * {@link https://moodle.org/user/profile.php?id=442195} - * {@link https://gjbarnard.co.uk} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. - */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{static staticMap=null;static fetchPromise=null;static cacheKey=`core_iconsystem/theme/${Config.theme}/core/iconmap-fontawesome`;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:"theme_foundation_output_load_fontawesome_icon_map",args:{}}],!0,!1,!1,0,Config.themerev)[0]}async fetchMapFromServer(){return IconSystemFontawesome.fetchPromise=(async()=>{const mapData=await this._fetchMapFromServer();return IconSystemFontawesome.staticMap=new Map(Object.entries(mapData).map((_ref=>{let[,value]=_ref;return[`${value.component}/${value.pix}`,value.to]}))),_localstorage.default.set(IconSystemFontawesome.cacheKey,JSON.stringify(Array.from(IconSystemFontawesome.staticMap.entries()))),this})(),IconSystemFontawesome.fetchPromise}renderIcon(key,component,title,template){const iconKey=`${component}/${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"theme_foundation/pix_icon_fontawesome"}}return _exports.default=IconSystemFontawesome,_exports.default})); +// @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. +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{static staticMap=null;static fetchPromise=null;static cacheKey=`core_iconsystem/theme/${Config.theme}/core/iconmap-fontawesome`;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:"theme_foundation_output_load_fontawesome_icon_map",args:{}}],!0,!1,!1,0,Config.themerev)[0]}async fetchMapFromServer(){return IconSystemFontawesome.fetchPromise=(async()=>{const mapData=await this._fetchMapFromServer();return IconSystemFontawesome.staticMap=new Map(Object.entries(mapData).map((_ref=>{let[,value]=_ref;return[`${value.component}/${value.pix}`,value.to]}))),_localstorage.default.set(IconSystemFontawesome.cacheKey,JSON.stringify(Array.from(IconSystemFontawesome.staticMap.entries()))),this})(),IconSystemFontawesome.fetchPromise}renderIcon(key,component,title,template){const iconKey=`${component}/${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"theme_foundation/pix_icon_fontawesome"}}return _exports.default=IconSystemFontawesome,_exports.default})); //# sourceMappingURL=icon_system_fontawesome.min.js.map \ No newline at end of file diff --git a/amd/build/icon_system_fontawesome.min.js.map b/amd/build/icon_system_fontawesome.min.js.map new file mode 100644 index 0000000..005a9dd --- /dev/null +++ b/amd/build/icon_system_fontawesome.min.js.map @@ -0,0 +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// Foundation theme.\n//\n// An Icon System implementation for FontAwesome based on core/icon_system_fontawesome by\n// Damyon Wiese.\n//\n// @module theme_foundation/icon_system_fontawesome\n// @copyright 2017 Damyon Wiese\n// @copyright 2019 G J Barnard.\n// @author G J Barnard -\n// {@link https://moodle.org/user/profile.php?id=442195}\n// {@link https://gjbarnard.co.uk}\n// @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.\n//\n\nimport {call as fetchMany} from 'core/ajax';\nimport LocalStorage from 'core/localstorage';\nimport IconSystem from 'core/icon_system';\nimport * as Mustache from 'core/mustache';\nimport * as Config from 'core/config';\nimport * as Url from 'core/url';\n\n/**\n * An set of properties for an icon.\n * @typedef {object} IconProperties\n * @property {array} attributes\n * @private\n */\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: 'theme_foundation_output_load_fontawesome_icon_map',\n args: {\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 = (async () => {\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 return 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 unmapped icon content, if the icon is not mapped.\n *\n * @param {IconProperties} mappedIcon\n * @param {string} key\n * @param {string} component\n * @param {string} title\n * @returns {IconProperties|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 'theme_foundation/pix_icon_fontawesome';\n }\n}\n"],"names":["IconSystemFontawesome","IconSystem","Config","theme","init","staticMap","this","getMapFromCache","Promise","resolve","fetchPromise","fetchMapFromServer","map","LocalStorage","get","cacheKey","Map","JSON","parse","_fetchMapFromServer","methodname","args","themerev","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":";;+SA+CqBA,8BAA8BC,sCAK5B,yBAMG,qBAMH,yBAAwBC,OAAOC,iCAOlDC,cACQJ,sBAAsBK,WAItBC,KAAKC,kBAHEC,QAAQC,QAAQH,MAOvBN,sBAAsBU,aACfV,sBAAsBU,aAG1BJ,KAAKK,qBAShBJ,wBACUK,IAAMC,sBAAaC,IAAId,sBAAsBe,iBAC/CH,MACAZ,sBAAsBK,UAAY,IAAIW,IAAIC,KAAKC,MAAMN,OAElDZ,sBAAsBK,UASjCc,6BACW,cAAU,CAAC,CACdC,WAAY,oDACZC,KAAM,MAEN,GAAM,GAAO,EAAO,EAAGnB,OAAOoB,UAAU,qCAU5CtB,sBAAsBU,aAAe,iBAC3Ba,cAAgBjB,KAAKa,6BAE3BnB,sBAAsBK,UAAY,IAAIW,IAAIQ,OAAOC,QAAQF,SAASX,KAAIc,YAAIC,kBAAY,CACjF,GAAEA,MAAMC,aAAaD,MAAME,MAC5BF,MAAMG,8BAEGC,IACT/B,sBAAsBe,SACtBE,KAAKe,UAAUC,MAAMC,KAAKlC,sBAAsBK,UAAUoB,aAGvDnB,MAZ0B,GAe9BN,sBAAsBU,aAYjCyB,WAAWC,IAAKR,UAAWS,MAAOC,gBACxBC,QAAW,GAAEX,aAAaQ,MAC1BI,WAAaxC,sBAAsBK,UAAUS,IAAIyB,SAGjDE,QAAU,CACZJ,MAAAA,MACAK,aAJiBpC,KAAKqC,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"} \ No newline at end of file diff --git a/amd/src/icon_system_fontawesome.js b/amd/src/icon_system_fontawesome.js index b069c78..46b05cb 100644 --- a/amd/src/icon_system_fontawesome.js +++ b/amd/src/icon_system_fontawesome.js @@ -13,20 +13,20 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Foundation theme. - * - * An Icon System implementation for FontAwesome based on core/icon_system_fontawesome by - * Damyon Wiese. - * - * @module theme_foundation/icon_system_fontawesome - * @copyright 2017 Damyon Wiese - * @copyright 2019 G J Barnard. - * @author G J Barnard - - * {@link https://moodle.org/user/profile.php?id=442195} - * {@link https://gjbarnard.co.uk} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. - */ +// +// Foundation theme. +// +// An Icon System implementation for FontAwesome based on core/icon_system_fontawesome by +// Damyon Wiese. +// +// @module theme_foundation/icon_system_fontawesome +// @copyright 2017 Damyon Wiese +// @copyright 2019 G J Barnard. +// @author G J Barnard - +// {@link https://moodle.org/user/profile.php?id=442195} +// {@link https://gjbarnard.co.uk} +// @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. +// import {call as fetchMany} from 'core/ajax'; import LocalStorage from 'core/localstorage';