itsmikem itsmikem - 3 months ago 38
Javascript Question

initializing multiple instances of tinymce

I can't figure out how to initialize two instances of

tinymce
on my page.

I've tried the answer from this question but no luck. Do I need to use a timeout if it takes some time to finish initializing the first one (io) before starting to initialize the second one (co)?

var io = {
selector:"#auth_info_intro textarea",
...,
setup:function(ed){
ed.on("init",function(e){
tinyMCE.activeEditor.setContent(obj.INFO.INTRO.TEXT);
});
}
};
var co = {
selector:"#auth_info_conclude textarea",
...,
setup:function(ed){
ed.on("init",function(e){
tinyMCE.activeEditor.setContent(obj.INFO.CONCLUDE.TEXT);
});
}
};
tinymce.init(io);
tinymce.init(co);


The above throws
Uncaught TypeError: Cannot read property 'body' of undefined
.
What am I missing?

Answer

Apparently, it takes some amount of time to initialize the first instance, so I set a timeout within the setup parameter of the initialization object of the first instance, instead of just immediately attempting to initialize the second instance. This worked:

 var io = {};
 io.selector = "textarea[name=intro]";
 io.setup = function(ed){
     ed.on("init",function(e){
          tinyMCE.activeEditor.setContent(obj.INFO.INTRO.TEXT);              
          setTimeout(function(){
                var co = {};
                co.selector = "textarea[name=conclude]";
                co.setup = function(ed){
                    ed.on("init",function(e){tinyMCE.activeEditor.setContent(obj.INFO.CONCLUDE.TEXT);});                        
                }
                tinymce.init(co);
          },1000);              
     });
tinymce.init(io);