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?
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With