将外部对话框与 CKEditor 小部件集成

Integrate external dialogs with CKEditor Widgets

在工作中,我们有一个弹出对话框系统,我想用它来编辑 CKEditor 中的小部件的内容。有什么办法可以解决这个问题吗?

CKEditor有没有办法在Widget上调用外部回调设置值?

我已经用谷歌搜索了很长时间,但没有成功:(

当正在编辑小部件时(在其初始化、双击、输入和调用 widget.edit() 方法时),则会触发 widget#edit 事件。 widget.edit 方法中代码的开头如下所示:

edit: function() {
    var evtData = { dialog: this.dialog };

    // Edit event was blocked or there's no dialog to be automatically opened.
    if ( this.fire( 'edit', evtData ) === false || !evtData.dialog )
        return false;

    ...
}

这意味着如果事件被取消或 widget.definition 中没有设置对话框名称(我猜是你的情况),那么在事件被触发后什么都不会发生。

因此,首先,监听 widget#edit 事件并显示您的对话。然后,当用户按下 "OK" 按钮时使用 widget.setData()。您还需要在进行任何更改之前和之后触发 editor#saveSnapshot 事件。

此外,请阅读 widget.repository#finalizeCreation 方法的文档,它可以让您处理小部件的创建。