diff --git a/apps/common/main/lib/view/Plugins.js b/apps/common/main/lib/view/Plugins.js index 13a1f1774e..4bdae0842b 100644 --- a/apps/common/main/lib/view/Plugins.js +++ b/apps/common/main/lib/view/Plugins.js @@ -237,158 +237,14 @@ define([ if (typeof result === 'string') { if (result.indexOf('%') === -1) return [icons, icons]; - /* - valid params: - theme-type - {string} theme type (light|dark|common) - theme-name - {string} the name of theme - state - {string} state of icons for different situations (normal|hover|active) - scale - {string} list of avaliable scales (100|125|150|175|200|default|extended) - extension - {string} use it after symbol "." (png|jpeg|svg) - - Example: "resources/%theme-type%(light|dark)/%state%(normal)icon%scale%(default).%extension%(png)" - */ - let scaleValue = { - '100%' : '.', - '125%' : '@1.25x.', - '150%' : '@1.5x.', - '175%' : '@1.75x.', - '200%' : '@2x.' - } - let arrParams = ['theme-type', 'theme-name' ,'state', 'scale', 'extension'], - start = result.indexOf('%'), - template = result.substring(start).replace(/[/.]/g, ('')), - commonPart = result.substring(0, start), - end = 0, - param = null, - values = null, - iconName = '', - tempObj = {}; - - result = []; - - for (let index = 0; index < arrParams.length; index++) { - param = arrParams[index]; - start = template.indexOf(param) - 1; - if (start < 0 ) - continue; - - end = param.length + 2; - template = template.substring(0, start) + template.substring(start + end); - start = template.indexOf('(', 0); - end = template.indexOf(')', 0); - values = template.substring((start + 1), end); - template = template.substring(0, start) + template.substring(++end); - tempObj[param] = values.split('|'); - } - - if (template.length) { - iconName = template; - } else { - let arr = commonPart.split('/'); - iconName = arr.pop().replace(/\./g, ''); - commonPart = arr.join('/') + '/'; - } - - // we don't work with svg yet. Change it when we will work with it (extended variant). - if (tempObj['scale'] && (tempObj['scale'] == 'default' || tempObj['scale'] == 'extended') ) { - tempObj['scale'] = ['100', '125', '150', '175', '200']; - } else if (!tempObj['scale']) { - tempObj['scale'] = ['100']; - } - - if (!tempObj['state']) { - tempObj['state'] = ['normal']; - } - - if (!iconName) { - iconName = 'icon'; - } - - let bHasName = !!tempObj['theme-name']; - let bHasType = (tempObj['theme-type'] && tempObj['theme-type'][0] !== 'common'); - let arrThemes = bHasName ? tempObj['theme-name'] : (bHasType ? tempObj['theme-type'] : []); - let paramName = bHasName ? 'theme' : 'style'; - if (arrThemes.length) { - for (let thInd = 0; thInd < arrThemes.length; thInd++) { - let obj = {}; - obj[paramName] = arrThemes[thInd]; - result.push(obj); - } - } else { - result.push({}); - } - - for (let index = 0; index < result.length; index++) { - for (let scaleInd = 0; scaleInd < tempObj['scale'].length; scaleInd++) { - let themePath = (result[index][paramName] || 'img') + '/'; - let scale = tempObj['scale'][scaleInd] + '%'; - let obj = {}; - for (let stateInd = 0; stateInd < tempObj['state'].length; stateInd++) { - let state = tempObj['state'][stateInd]; - obj[state] = commonPart + themePath + (state == 'normal' ? '' : (state + '_')) + iconName + (scaleValue[scale] || '.') + tempObj['extension'][0]; - } - result[index][scale] = obj; - } - } + return Common.UI.iconsStr2IconsObj(icons); } return result; }, parseIcons: function(icons) { icons = this.iconsStr2IconsObj(icons); - if (icons.length && typeof icons[0] !== 'string') { - var theme = Common.UI.Themes.currentThemeId().toLowerCase(), - style = Common.UI.Themes.isDarkTheme() ? 'dark' : 'light', - idx = -1; - for (var i=0; i0.01 && defUrl) && (bestUrl = defUrl); - return { - 'normal': bestUrl ? bestUrl['normal'] : '', - 'hover': bestUrl ? bestUrl['hover'] || bestUrl['normal'] : '', - 'active': bestUrl ? bestUrl['active'] || bestUrl['normal'] : '' - }; - } else { // old version - var url = icons[((Common.Utils.applicationPixelRatio() > 1 && icons.length > 1) ? 1 : 0) + (icons.length > 2 ? 2 : 0)]; - return { - 'normal': url, - 'hover': url, - 'active': url - }; - } + return Common.UI.getSuitableIcons(icons); }, updatePluginIcons: function(model) {