如何解决有没有办法在没有手动按钮点击的情况下打开 Tinymce 评论侧栏
我们已经在我们的配置中实现了 Tinymce 评论插件,我们对它的工作方式感到满意。但是,我们的用户希望点击“showcomments”按钮并在页面加载时显示包含评论的侧边栏。
我们可以看到命令 'tc-open-comments' 是单击按钮时触发的命令,但我们无法自己触发该命令。
任何帮助将不胜感激。
配置
tinymce.init({
selector: '.tinymce',plugins: [
'paste tinycomments'
],toolbar: 'addcomment showcomments',tinycomments_mode: 'embedded',tinycomments_author: 'user1',tinycomments_author_name: 'username',content_css: '/css/app.css',setup: function (editor: any) {
editor.on('ExecCommand',function (e) {
console.log('The ' + e.command + ' command was fired.');
});
editor.on('init',function () {
// These are the two commands fired by a click of the 'showcomments' button
editor.execCommand('tc-open-comment'); // This does not work
editor.execCommand('ToggleSidebar'); // This works
let commentsPresent = false;
let textareaContent = editor.startContent;
if (textareaContent.includes('tox-comment')) {
commentsPresent = true;
console.log(commentsPresent);
} else {
console.log(commentsPresent);
}
});
}
});
解决方法
您调用命令打开评论侧边栏的代码缺少一些参数。正确的代码应该是:
editor.execCommand("ToggleSidebar",false,"showcomments");
来自文档:
https://www.tiny.cloud/docs/api/tinymce/tinymce.editor/#execcommand
execCommand(cmd:String,ui:Boolean,value:mixed,args:Object)
在这种情况下,要正确触发此特定命令,需要 ui:Boolean
和 value:mixed
参数。
行:
editor.execCommand('tc-open-comment');
...没有必要。
这是一个展示这一点的小小提琴:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。