user1074378
user1074378

Reputation: 1445

How to move TinyMCE javascript init settings to separate file?

I have this configuration:

tinyMCE.init({
        theme : "advanced",
        mode : "textareas"
});

There are more init settings than just "theme" and "mode". I'd like to take these init settings and put them in an external file, something like "mce_settings.js" and call that during init.

Basically like:

 tinyMCE.init({
        mce_settings.js
});

Reason being is I have to initialize this way in a variety of templates, and if a setting changes, rather than updating it in a bunch of different spots, I can just edit the "mce_settings.js" file. What's the best way to accomplish this?

Upvotes: 1

Views: 638

Answers (2)

Thariama
Thariama

Reputation: 50832

Create a global configuration file holding all main parameters. Put your spezial configuration into a js file called tiny_mce_config.js:

window.config_tinymce_1 = {
     theme : "advanced",
     mode : "textareas"
}

Load this file on your page along with the global one. Using the following code you are able to use the global configuration and add/replace just the few parameters you need for this unique tinymce editor instance.

// create an initialization object
window.init_obj_1 = {element_id:'my_textarea_dom_id', window: window};
$.extend(true, window.config_tinymce_1, window.tiny_mce_global_config, window.config_tinymce_1);

    // tinymce3
    tinyMCE.execCommand('mceAddFrameControl',false, init_obj_1);

    // tinymce4
    new tinymce.Editor('my_textarea_dom_id', window.init_obj_1, tinymce.EditorManager).render();

Upvotes: 0

charlietfl
charlietfl

Reputation: 171679

You can assign your config object to a variable and then just pass that variable to init()

var myTinyConfig ={
     theme : "advanced",
     mode : "textareas"
};

tinyMCE.init( myTinyConfig );

Upvotes: 1

Related Questions