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?
And… I’ve answered the question for myself. The conditional you want to test for is as follows:
The trick is that
tinyMCE.activeEditor
returns null when TinyMCE isn’t activated. You can use theisHidden()
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.
Yes, I saw that code on wordpress: ABSPATH/wp-includes/js/autosave.js file
As this questions ranked in search engines. I think I should extend Daniels answers a little bit to support when we have multiple instances of wordpress editor in a single page.
Uses
When you only need to check the active editor
If an editor with certain id needed to be checked
I hope this little function will be helpful to others 🙂
According to WordPress editor.js we can easily check that :