Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tinyMCE setup callback versus onAddEditor

Tags:

tinymce

When you initialize a tinyMCE editor I have noticed two different ways to get called when the editor is created.

One way is using the setup callback that is part of tinyMCE.init:

tinyMCE.init({
   ...
   setup : function(ed) {
      // do things with editor ed
   }
});

The other way is to hook up to the onAddEditor event:

tinyMCE.onAddEditor.add(function(mgr,ed) {
    // do things with editor ed
});

What are the differences between using these two methods?

Is the editor in a different state in one versus the other? For example, are things not yet loaded if I try to access properties on the editor object.

What are reasons to use one over the other?

like image 577
Matthew Manela Avatar asked Jan 05 '11 17:01

Matthew Manela


2 Answers

The difference here is that tinyMCE.onAddEditor adds code to be executed onthe AddEditor event and fires when a new editor instance is added to the tinymce collection while the setup setting lets you add events to the editor. It gets executed before the editor instances gets rendered.

One other difference is that setup is to be set inside the tinymce initialization call (the configuration setting) while onAddEditor usually gets called inside a tinymce plugin (but you may also set it inside the setup function).

like image 167
Thariama Avatar answered Oct 11 '22 21:10

Thariama


onAddEditor.add gives warning in the latest TinyMCE 4:

Deprecated TinyMCE API call: <target>.onAddEditor.add(..)

.on(nameofevent, function(){...} ) is the proper way to do this in MCE4 if you don't have the backward-compatibility plugin.

like image 31
NoBugs Avatar answered Oct 11 '22 22:10

NoBugs