How I can add multi TinyMCE editors with different config for each one?

蹲街弑〆低调 提交于 2019-12-22 11:06:34

问题


I want to add multi TinyMCE editors and each one has its own configuration in one page?

How I can do it?


回答1:


You could do something like this:

jQuery version:

$('textarea.editor1').tinymce(
{
    script_url : '../admin/tiny_mce/tiny_mce.js',
    theme : "simple",
    plugins : "", // put plugins here
    setup : function(ed) 
    {
         ed.onInit.add(function(ed)
        {

        });             
    }
});

$('textarea.editor2').tinymce(
{
    script_url : '../admin/tiny_mce/tiny_mce.js',
    theme : "simple",
    plugins : "", // put plugins here
    setup : function(ed) 
    {
         ed.onInit.add(function(ed)
        {

        });             
    }
});

Non-jQuery version:

tinyMCE.init(
{
    mode : "textareas",
    theme : "simple",
    editor_selector : "editor1"
});

tinyMCE.init(
   {
       mode : "textareas",
    theme : "simple",
    editor_selector : "editor2"

   });



回答2:


This is easy to achieve. I use the jQuery lib to save code, but it is easy to create this code without jQuery. Supposed you have html elements (i.e. textareas) with ids "my_id1" and "my_id1", that you wish to get a tinymce for all you need to do is:

var config_tinymce_1 = {

        plugins :"save",

        theme_advanced_buttons1 : "bold,italic,underline,save",
        theme_advanced_buttons2 : "",
        ...
};


var config_tinymce_2 = {

        plugins :"save",

        theme_advanced_buttons1 : "save",
        theme_advanced_buttons2 : "",
        ...
};

$(document).ready(function(){
        init_obj_1 = {element_id:'my_id1', window: window};
        $.extend(true, init_obj_1, config_tinymce_1);
        tinyMCE.execCommand('mceAddFrameControl',false, init_obj_1);

        init_obj_2 = {element_id:'my_id2', window: window};
        $.extend(true, init_obj_2, config_tinymce_2);
        tinyMCE.execCommand('mceAddFrameControl',false, init_obj_2);
});


来源:https://stackoverflow.com/questions/5029077/how-i-can-add-multi-tinymce-editors-with-different-config-for-each-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!