使用 CKEditor 4 以编程方式调用按钮

Programmatically invoking a button with CKEditor 4

您好CKEditor专家,

我可以使用 javascript 代码(页内)调用 CKEditor 的按钮和对话框吗?

我正在尝试将 "anchor" 按钮的使用恢复到我们的 CryptPad 协作套件中。为此,我希望编写一个调用 "anchor" 按钮的集成测试,然后检查导出的内容是否确实包含预期的 <a name="..."> 元素。我们的测试实际上是页面内的脚本 运行(并由 selenium 调用)。作为 JS 页面的一部分,我可以调用什么函数来调用该按钮或调用与按钮调用完全相同的内容添加?

提前致谢。

通常按钮都有定义的命令。如果您不知道要调用的按钮绑定了什么命令,那么您可以找到它:

var editor = CKEDITOR.insances[ instanceName ];
console.log( editor.ui.get( 'Anchor' ).command ) // 'anchor'
editor.execCommand( 'anchor' ) // Dialog opens

一旦我们知道我们的命令,测试代码就像:

editor.on( 'dialogShow', function( evt ) {
  evt.data // Dialog instance
  // All code goes here
} );

editor.execCommand( 'anchor' );

访问文档以获取有关对话方法的更多详细信息,这可能有助于您进行适当的测试。 https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_dialog.html