我有一个对话框,其内容通过解析当前页面的DOM来填充。我尝试了两件事,两件都不完全正确:
CKEDITOR.on('dialogDefinition', ...
:此方法适用于第一次打开对话框,但后续开头使用缓存的对话框定义,因此对DOM的任何更改都不会显示在对话框内容中。
dialog.on('show', ...
:每次显示对话框时都会触发此方法,但似乎在对话框的内容已经计算之后它会被触发。
所以我的问题是:是否有我可以使用的钩子或其他方法,每次打开对话框时都会填写内容?谢谢!
修改
这是我现在所拥有的一个基本示例,它不起作用 - 对话框中没有显示“No embeds”消息。
CKEDITOR.plugins.add('embeds', {
init: function(editor) {
editor.on('dialogShow', function(event) {
var dialog = event.data,
dialogDefinition = dialog.definition;
if(dialog.getName() != "EmbedsDialog") return;
var main = dialogDefinition.getContents('main');
main.add({
type : 'html',
html : "<strong>There are no embeds yet! Add them below.</strong>"
});
});
CKEDITOR.dialog.add('EmbedsDialog', function (instance) {
return {
title : 'Embeds',
minWidth : 550,
minHeight : 200,
contents: [{
id: "main",
elements: []
}],
}; // return
});
editor.addCommand('Embeds',
new CKEDITOR.dialogCommand('EmbedsDialog', {
allowedContent: 'a[*](*)'
})
);
editor.ui.addButton('Embeds', {
label : 'Embeds',
command : 'Embeds',
toolbar : 'embeds'
});
} // init
}); // add