So this is how I achieved what I was after –
The filter 'tiny_mce_before_init'
is used to update the settings of the editor, so you can add your own JS to the 'setup'
key.
add_filter('tiny_mce_before_init', 'initiate_tinyMCE_wordcount');
function initiate_tinyMCE_wordcount($initArray){
$initArray['setup'] = <<<JS
[function(ed){
ed.onLoad.add(function(ed, e){
var tb_name = tinyMCE.activeEditor.id; // The ID of the active editor
/** Check to see if the text editor (not the TinyMCE iframe) has the class 'error' */
if($('#'+tb_name).hasClass('error')){
tinyMCE.activeEditor // Thanks fot @Kaiser for this bit
.getWin()
.document.body.style.backgroundColor="#FFEBE8";
}
});
return $initArray;
}