I have these two lines of code one after another.
tinymce.execCommand('mceAddControl',true,'email_body'); tinyMCE.activeEditor.setContent(data.tplCustom.htmltemplate);
Second line tries to set content even before the tinymce is done . I think cause of that I am getting " tinyMCE.activeEditor is null" error.
Is there any way to wait until its loaded ? Thanks
You need to use the remove() API to detach TinyMCE from the DOM before you close your Modal window. You can then use init() again when the modal is recreated.
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.
Setting the cursor position You can also hold down shift and then move the cursor with the arrow keys on the keyboard to select content. It has the same effect. The TinyMCE bookmarks this location with the Bookmark Manager API, and then loads the selected location later.
Version 4 of TinyMCE uses a slightly different event binding method.
Version 3
// v3.x tinymce.init({ setup : function(ed) { ed.onInit.add(function(ed) { console.debug('Editor is done: ' + ed.id); }); } });
Version 4
// v4.x tinymce.init({ setup: function (ed) { ed.on('init', function(args) { console.debug(args.target.id); }); } });
Reference: http://www.tinymce.com/wiki.php/API3:event.tinymce.Editor.onInit http://www.tinymce.com/wiki.php/Tutorial:Migration_guide_from_3.x
If you cannot access to the tinymce.init({...})
declaration (like in WordPress for example), you can also use addeditor
event :
/// Fires when an editor is added to the EditorManager collection. tinymce.on('addeditor', function( event ) { var editor = event.editor; var $textarea = $('#' + editor.id); console.log($textarea.val()); }, true );
TinyMCE 'addeditor' event documentation
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