我正在开发一个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'
}";
答案 0 :(得分:0)
window.yourGlobalVariable = ...;
答案 1 :(得分:0)
谢谢大家,我在这里找到了答案:https://wordpress.stackexchange.com/questions/214652/insert-dynamic-listbox-options-in-tinymce-popup-editor
主要的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;}