Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tinyMCE textarea focusout event?

I am working on existing project. I have to detect tinyMCE focusout/blur event to save it automatically via AJAX. I found following existing working code:

// reinit tinymce
$($("#chapterBill div:.module-container")[indexAfter]).find('textarea').each(function(i){
   editorId = $(this).attr('id');
   tinymce.EditorManager.execCommand('mceAddControl',true, editorId);
});

Can someone tell me that how to capture tinyMCE textarea focusout/blur event ?

Thanks

like image 402
Awan Avatar asked Jan 09 '12 16:01

Awan


People also ask

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 I reinitialize TinyMCE?

Use tinymce. remove() method to remove TinyMCE editor from the HTML element and again call tinymce. init() on the selector to reinitialize.


1 Answers

You do not want to capture textarea focus/blur. Tinymce hides the former textarea and creates a contenteditable iframe in which you can enter/edit content. This content gets written to the former hidden textarea from time to time (eventbased).

In order to capture focusout/blur on the editor you need to set a handler for this on the editors iframe.

Put this code into your tinymce init

setup : function(ed) {
    ed.onInit.add(function(ed, evt) {
        tinymce.dom.Event.add(ed.getDoc(), 'blur', function(e) {
            // Do something when the editor window is blured.
            alert('blur!!!');
        });
    });
},
like image 131
Thariama Avatar answered Sep 29 '22 18:09

Thariama