且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查 TinyMCE 在 WordPress 中是否处于活动状态的方法

更新时间:2023-11-27 23:52:46

而且...我已经为自己回答了这个问题.您要测试的条件如下:

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;
  }
}

诀窍是 tinyMCE.activeEditor 在 TinyMCE 未激活时返回 null.您可以使用 isHidden() 方法来确保它在您切换回 HTML 编辑器模式时不会执行.

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.

这在 TinyMCE 网站和论坛上的记录很差.

This is poorly documented on the TinyMCE website and forums.