gpt4 book ai didi

javascript - 只读模式下的 TinyMCE 启用按钮

转载 作者:搜寻专家 更新时间:2023-11-01 04:24:58 28 4
gpt4 key购买 nike

我有一个 TinyMCE 4.x 实例,其中的文本应该处于只读模式。但是我仍然有一些我想启用的按钮。例如,一个按钮可以为我选择的文本部分提供字符数。但是当我为 TinyMCE 打开只读模式时,所有按钮都被禁用。我可以只启用我的按钮,同时仍保留只读模式吗?

最佳答案

这对你来说可能已经太晚了,但其他人可能会路过这里。

我是通过写这个函数想出来的

function enableTinyMceEditorPlugin(editorId, pluginName, commandName) {
var htmlEditorDiv = document.getElementById(editorId).previousSibling;
var editor = tinymce.get(editorId);
var buttonDiv = htmlEditorDiv.querySelectorAll('.mce-i-' + pluginName.toLowerCase())[0].parentElement.parentElement;
buttonDiv.className = buttonDiv.className.replace(' mce-disabled', '');
buttonDiv.removeAttribute('aria-disabled');
buttonDiv.firstChild.onclick = function () {
editor.execCommand(commandName);
};
}

它分两步完成:

  • 使按钮可点击(删除 mce-disabled CSS 类并删除 aria-disabled 属性)
  • 将好的命令分配给点击事件

然后在我的编辑器 init 事件中调用该函数。

editor.on('init', function () {
if (readOnly) {
editor.setMode('readonly');
enableTinyMceEditorPlugin(htmlEditorId, 'preview', 'mcePreview');
enableTinyMceEditorPlugin(htmlEditorId, 'code', 'mceCodeEditor');
}
});

我为其编写此代码的 TinyMCE 的当前版本是 4.4.3。它可能会在未来的版本中中断,特别是关于获取和修改好的 HTML 元素的选择器。

命令标识符可以在 this page 找到否则你也可以在 tinymce\plugins\PluginName\plugin(.min).js

下找到它们

关于javascript - 只读模式下的 TinyMCE 启用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26888276/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com