Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait for TinyMCE to load

Tags:

jquery

tinymce

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

like image 623
Pit Digger Avatar asked Sep 13 '11 21:09

Pit Digger


People also ask

How do you reload TinyMCE?

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.

How do you get data from TinyMCE text editor?

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.

How do you get the cursor position in TinyMCE editor?

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.


2 Answers

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

like image 136
Red Taz Avatar answered Sep 28 '22 21:09

Red Taz


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

like image 24
Camille Descombes Avatar answered Sep 28 '22 21:09

Camille Descombes