1

I'm working on a tinyMCE plugin, and it has to show a full list of FontAwesome icons. To show them, the code is (reduced) this:

    {
    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...

All values to show icons will result in something like 5k lines of code. How can I, if possible, store those values to reuse anywhere inside the script?

Example (structural, of course not working):

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'
}";
1

2 Answers 2

0
window.yourGlobalVariable = ...;

Here's the thread Define global variable in a JavaScript function

Sign up to request clarification or add additional context in comments.

Comments

0

Thank you all, I found my answer with a not so little help from here: https://wordpress.stackexchange.com/questions/214652/insert-dynamic-listbox-options-in-tinymce-popup-editor

THIS in the main tinymce function:

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;
}

Any listbox showing icons will be:

{
    type: 'listbox',
    name: 'caixa_icone',
    label: 'Icon²',
    'values': get_icon_list(),
}

And some CSS:

.mce-menu-has-icons i.mce-ico:before {font: 15px FontAwesome;}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.