I'm working on a plugin that, when TinyMCE is in use as the Visual editor, uses TinyMCE commands to insert text into body content editing area. Currently, it works by just running the command. If it works, then TinyMCE is active and if not, then I have custom JS for working with the HTML editor.
My question, however: is there any way to check whether TinyMCE is active or not instead of just running the command and having it fail when it isn't?
If you check on the source code of TinyMCE in the official repository at Github, specifically on this file, you will find 2 properties on the definition of the TinyMCE object: majorVersion : contains the Major version of TinyMCE build. minorVersion : contains the Minor version of TinyMCE build.
The TinyMCE getContent and setContent methods 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.
And... I've answered the question for myself. The conditional you want to test for is as follows:
is_tinyMCE_active = false;
if (typeof(tinyMCE) != "undefined") {
if (tinyMCE.activeEditor == null || tinyMCE.activeEditor.isHidden() != false) {
is_tinyMCE_active = true;
}
}
The trick is that tinyMCE.activeEditor
returns null when TinyMCE isn't activated. You can use the isHidden()
method to make sure it isn't executing when you've switched back to HTML editor mode.
This is poorly documented on the TinyMCE website and forums.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With