MDL-40759 icons: Refactor to allow theme icon systems
[moodle.git] / lib / amd / src / icon_system.js
CommitLineData
95b06c13
DW
1// This file is part of Moodle - http://moodle.org/
2//
3// Moodle is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// Moodle is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15
16/**
17 * Icon System base module.
18 *
19 * @package core
20 * @copyright 2017 Damyon Wiese
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
23
24define(['jquery'], function($) {
25
26 /**
27 * Icon System abstract class.
28 *
e330b1c2 29 * Any icon system needs to define a module extending this one and return this module name from the php icon_system class.
95b06c13
DW
30 */
31 var IconSystem = function() {
32 };
33
34 /**
35 * Initialise the icon system.
36 *
37 * @return {Promise}
38 * @method init
39 */
40 IconSystem.prototype.init = function() {
e330b1c2 41 return $.when(this);
95b06c13
DW
42 };
43
44 /**
45 * Render an icon.
46 *
e330b1c2
DW
47 * The key, component and title come from either the pix mustache helper tag, or the call to templates.renderIcon.
48 * The template is the pre-loaded template string matching the template from getTemplateName() in this class.
49 * This function must return a string (not a promise) because it is used during the internal rendering of the mustache
50 * template (which is unfortunately synchronous). To render the mustache template in this function call
51 * core/mustache.render() directly and do not use any partials, blocks or helper functions in the template.
52 *
95b06c13
DW
53 * @param {String} key
54 * @param {String} component
55 * @param {String} title
56 * @param {String} template
57 * @return {String}
58 * @method renderIcon
59 */
60 IconSystem.prototype.renderIcon = function(key, component, title, template) { //eslint-disable-line no-unused-vars
61 throw new Error('Abstract function not implemented.');
62 };
63
e330b1c2
DW
64 /**
65 * getTemplateName
66 *
67 * @return {String}
68 * @method getTemplateName
69 */
70 IconSystem.prototype.getTemplateName = function() {
71 throw new Error('Abstract function not implemented.');
72 };
73
95b06c13
DW
74 return /** @alias module:core/icon_system */ IconSystem;
75});