检查 TinyMCE 在 WordPress 中是否处于活动状态的方法 [英] Way to check whether TinyMCE is active in WordPress

查看:28
本文介绍了检查 TinyMCE 在 WordPress 中是否处于活动状态的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个插件,当 TinyMCE 用作可视化编辑器时,它使用 TinyMCE 命令将文本插入正文内容编辑区域.目前,它只需运行命令即可工作.如果有效,则 TinyMCE 处于活动状态,如果无效,则我将使用自定义 JS 来使用 HTML 编辑器.

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.

然而,我的问题是:有没有办法检查 TinyMCE 是否处于活动状态,而不是仅仅运行命令并在它不活动时让它失败?

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:

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.

这篇关于检查 TinyMCE 在 WordPress 中是否处于活动状态的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆