I already searched a lot but by google-fu'ing don't get me any results :(
I have an already initialized tinyMCE
editor which initialization process I cannot control, so code like the following don't work at all:
tinyMCE.init({
...
setup : function(ed) {
ed.onChange.add(function(ed, l) {
console.debug('Editor contents was modified. Contents: ' + l.content);
});
}
});
Code like the following doesn't work either since the jQuery tinymce plugin isn't defined:
$('textarea').tinymce({
setup: function(ed) {
ed.onClick.add(function(ed, e) {
alert('Editor was clicked: ' + e.target.nodeName);
});
}
});
I mean, it has to be using the tinymce.something
syntax.
How can I bind a callback function to whatever tinyMCE event after tinyMCE is already initialized?
Use tinymce. remove() method to remove TinyMCE editor from the HTML element and again call tinymce. init() on the selector to reinitialize.
The TinyMCE getContent and setContent methods You can do this using the getContent() API method. Let's say you have initialized the editor on a textarea with id=”myTextarea”. This will return the content in the editor marked up as HTML.
You can do this to check if the content is empty without parsing html: var content = tinymce. get('tinymceEditor'). getContent({format: 'text'}); if($.
Although this post is old now but I think other people will need this answer. I had the same problem and to fix it I did this:
tinyMCE.init({
...
init_instance_callback : "myCustomInitInstance"
});
Based on http://www.tinymce.com/wiki.php/Configuration3x:init_instance_callback
After hacking into the tinymce object with console.log(), I found a working solution:
setTimeout(function () {
for (var i = 0; i < tinymce.editors.length; i++) {
tinymce.editors[i].onChange.add(function (ed, e) {
// Update HTML view textarea (that is the one used to send the data to server).
ed.save();
});
}
}, 1000);
Inside that callback function one can set the whatever event binding one wants.
The setTimeout
call is to overcome the racing condition of tinymce
and jQuery
, since when the call to tinymce.editors[i].onChange.add()
is made tinymce wasn't initialized yet.
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