Way to check whether TinyMCE is active in WordPress
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.
Yes, I saw that code on wordpress: ABSPATH/wp-includes/js/autosave.js file
// (bool) is rich editor enabled and active
var rich = (typeof tinyMCE != "undefined") && tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden();