我正在开发一个tinyMCE插件,它必须显示FontAwesome图标的完整列表。为了显示它们,代码是(简化的)如下:
{
type: 'listbox',
name: 'caixa_icone',
label: 'Icon²',
'values': [
{
text:'address-book',
value:'address-book',
icon:' fa fa-address-book'
},
{
text:'address-book-o',
value:'address-book-o',
icon:' fa fa-address-book-o'
},
{
text:'anchor',
value:'anchor',
icon:' fa fa-anchor'
},
{
text:'archive',
value:'archive',
icon:' fa fa-archive'
},
{
text:'area-chart',
value:'area-chart',
icon:' fa fa-area-chart'
},
// ETC...所有显示图标的值都会产生大约5k行的代码。如果可能,我如何存储这些值以便在脚本中的任何地方重用?
示例(结构化的,当然不起作用):
var variables = "{
text:'address-book',
value:'address-book',
icon:' fa fa-address-book'
},
{
text:'address-book-o',
value:'address-book-o',
icon:' fa fa-address-book-o'
}";发布于 2017-01-19 02:50:26
window.yourGlobalVariable = ...;发布于 2017-01-19 07:04:14
谢谢大家,我在这里找到了我的答案:https://wordpress.stackexchange.com/questions/214652/insert-dynamic-listbox-options-in-tinymce-popup-editor
在main tinymce函数中:
var textt = new Array('');
var variables = [
"address-book", "address-book-o", "gear", "user" // ETC
];
var arrayLength = variables.length;
function get_icon_list() {
var result = [];
var res = [];
for (var i = 0; i < arrayLength; i++) {
textt.push("{text:'"+ variables[i] +"', value:'"+ variables[i] +"', icon:' fa fa-"+ variables[i] +"'}");
res[i] = {};
res[i]['text'] = variables[i];
res[i]['value'] = variables[i];
res[i]['icon'] = ' fa fa-'+variables[i];
result.push(res[i]);
}
return result;
}任何显示图标的列表框都将是:
{
type: 'listbox',
name: 'caixa_icone',
label: 'Icon²',
'values': get_icon_list(),
}和一些CSS:
.mce-menu-has-icons i.mce-ico:before {font: 15px FontAwesome;}https://stackoverflow.com/questions/41727141
复制相似问题