views:

402

answers:

3

I am trying to detect when the user has left the tinyMCE editor window but I am unable to do so. Here is the code that i think should work (but isnt):

$('.mceEditor').blur(function(){
    // I would expect this to fire when the user leaves the
    // tinyMCE editor, but it never seems to fire
});

I've also tried:

$('*')
    .not('.mceEditor, .mceEditor *')
    .click(function(){
        // I would expect this to fire when anything but the tinyMCE editor
        // has been clicked, but it seems to fire at every click
    });

Neither methods are working and ive been at this for hours. Any help would be greatly apreciated.

Thanks, Simon

PS: I am using the jquery plugin version, found here: http://tinymce.moxiecode.com/examples/example%5F23.php

A: 

Looks like tinymce is being plugged in with an iframe. In that case you would have to access the iframe's DOM, something like this might work.

$("#content_ifr").contents().find('#tinymce');

Where content_ifr is the ID of the iframe and #tinymce seems to be the tag that encloses the content. Use firebug and poke around to see.

Calvin L
Thanks for the response. Actually, i did to some 'poking' with firebug and couldn't find any <textarea> elements inside that iframe but i could still type in there. This is driving me crazy!
I think it's converting the textarea that you put in your markup into an iframe with html/css. I would still try binding an onblur event to the iframe though. Worth a try.
Calvin L
A: 

TinyMCE creates editor as an iframe inside a wrapper SPAN element. you can use SPAN element 'onfocusout' event.

Ex: if textarea element id is 'content', TinyMCE creates a SPAN with element id 'content_parent'.

$("#content_parent")[0].onfocusout =function(){alert('mouse out');};
+1  A: 

I guess this should work

tinyMCE.dom.Event.add(tinyMCE.getInstanceById("editor-id").getWin(), "blur", function(){
    // Blur operations
});
Serkan Yersen