简体   繁体   English

如何将TinyMCE JavaScript初始化设置移动到单独的文件?

[英]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. 我想采用这些init设置并将它们放在外部文件中,例如“ mce_settings.js”,并在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. 原因是我必须在各种模板中以这种方式进行初始化,并且如果设置发生更改,而不是在多个不同位置进行更新,则可以编辑“ mce_settings.js”文件。 What's the best way to accomplish this? 做到这一点的最佳方法是什么?

You can assign your config object to a variable and then just pass that variable to init() 您可以将您的配置对象分配给一个变量,然后将该变量传递给init()

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

tinyMCE.init( myTinyConfig );

Create a global configuration file holding all main parameters. 创建一个包含所有主要参数的全局配置文件。 Put your spezial configuration into a js file called tiny_mce_config.js: 将您的spezial配置放入一个名为tiny_mce_config.js的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. 使用以下代码,您可以使用全局配置,并仅添加/替换此唯一的tinymce编辑器实例所需的几个参数。

// 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM