3

I'm trying to add some custom JS functionality to the default "post" editing screen that depends upon TinyMCE being instantiated and ready to rock. If I try to make the changes before TinyMCE is set up, I (obviously) receive JS errors.

Without needing to modify any core files, and ideally using JS/jQuery events alone (i.e. not PHP/WP hooks/filters or polling with JS' setInterval()), is there a way to detect when TinyMCE is ready?

  • FYI, we're still on a version of WP that uses TinyMCE 3 (as opposed to the newer TinyMCE 4). – rinogo Oct 27 '15 at 21:31
5

Unless your WP version is truly ancient, you should be able to use the tinymce-editor-init event triggered on editor init by "wp-includes/js/tinymce/plugins/wordpress/plugin.js", eg (assuming your script is loading after jQuery):

jQuery( document ).on( 'tinymce-editor-init', function( event, editor ) {
    // Blah.
});
1

I have not tested this, but it should work:

is_tinyMCE_active = false;
if ( typeof( tinyMCE) != "undefined" ) {
    if ( tinyMCE.activeEditor == null || tinyMCE.activeEditor.isHidden() != false ) {
        is_tinyMCE_active = true;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.