bc922033bb8d451ef653299082d3495b025e6aa4
2 * This file is part of the TYPO3 CMS project.
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with DocumentHeader source code.
11 * The TYPO3 project - inspiring people to share!
15 * Module: TYPO3/CMS/Backend/Icons
16 * Uses the icon API of the core to fetch icons via AJAX.
18 define(['jquery'], function($) {
23 * @type {{cache: {}, sizes: {small: string, default: string, large: string, overlay: string}, states: {default: string, disabled: string}}}
24 * @exports TYPO3/CMS/Backend/Icons
41 * Get the icon by its identifier.
43 * @param {String} identifier
44 * @param {String} size
45 * @param {String} overlayIdentifier
46 * @param {String} state
47 * @return {Promise<Array>}
49 Icons
.getIcon = function(identifier
, size
, overlayIdentifier
, state
) {
50 return $.when(Icons
.fetch(identifier
, size
, overlayIdentifier
, state
));
54 * Performs the AJAX request to fetch the icon.
56 * @param {string} identifier
57 * @param {string} size
58 * @param {string} overlayIdentifier
59 * @param {string} state
60 * @return {String|Promise}
63 Icons
.fetch = function(identifier
, size
, overlayIdentifier
, state
) {
69 * 2: overlayIdentifier
72 size
= size
|| Icons
.sizes
.default;
73 state
= state
|| Icons
.states
.default;
75 var icon
= [identifier
, size
, overlayIdentifier
, state
],
76 cacheIdentifier
= icon
.join('_');
78 if (Icons
.isCached(cacheIdentifier
)) {
79 return Icons
.getFromCache(cacheIdentifier
);
83 url
: TYPO3
.settings
.ajaxUrls
['icons'],
86 icon
: JSON
.stringify(icon
)
88 success: function(markup
) {
89 Icons
.putInCache(cacheIdentifier
, markup
);
95 * Check whether icon was fetched already
97 * @param {String} cacheIdentifier
101 Icons
.isCached = function(cacheIdentifier
) {
102 return typeof Icons
.cache
[cacheIdentifier
] !== 'undefined';
106 * Get icon from cache
108 * @param {String} cacheIdentifier
112 Icons
.getFromCache = function(cacheIdentifier
) {
113 return Icons
.cache
[cacheIdentifier
];
117 * Put icon into cache
119 * @param {String} cacheIdentifier
120 * @param {Object} markup
123 Icons
.putInCache = function(cacheIdentifier
, markup
) {
124 Icons
.cache
[cacheIdentifier
] = markup
;