CKeditor:如何构建自定义插件?
CKeditor: How to build a custom plugin?
我正在尝试为 CKeditor 创建自定义插件 this guide。我按照指示创建了文件 (myplugin.png、myplugin.js、plugin.js) 并添加了
CKEDITOR_CONFIGS = {
'default': {
'extraPlugins': ','.join( [ 'myplugin' ] ),
'allowedContent' : True,
}
}
进入设置。
这是我的 plugin.js 文件的内容:
CKEDITOR.plugins.add( 'myplugin', {
icons: 'myplugin',
init: function( editor ) {
// Plugin logic goes here...
editor.addCommand( 'myplugin', new CKEDITOR.dialogCommand( 'mypluginDialog' ) );
editor.ui.addButton( 'myplugin', {
label: 'My Plugin',
command: 'myplugin',
toolbar: 'insert'
});
}
});
然而,自定义插件的图标仍然没有显示。我可以在浏览器的工具中看到检索到 plugin.js 文件。我通过删除图标文件进行了测试,但没有产生任何差异(没有错误消息,没有 404)。我想那时候甚至没有调用或访问该文件。所以初始化甚至不会尝试渲染按钮。
谢谢你的帮助。
终于,我找到了问题的答案。它来自 CKEditor 显示工具栏的方式。在指南中,自定义插件被添加到工具栏的 "insert" 组中。但是,在明确设置为显示之前,这个将不可见。
将额外的插件添加到默认配置是不够的,必须正确指定工具栏设置(如果由于某种原因,您的平台没有默认为 null)。就我而言,使用 django-ckeditor,我必须添加
'toolbar': None,
到CKEDITOR_CONFIGS。
我正在尝试为 CKeditor 创建自定义插件 this guide。我按照指示创建了文件 (myplugin.png、myplugin.js、plugin.js) 并添加了
CKEDITOR_CONFIGS = {
'default': {
'extraPlugins': ','.join( [ 'myplugin' ] ),
'allowedContent' : True,
}
}
进入设置。
这是我的 plugin.js 文件的内容:
CKEDITOR.plugins.add( 'myplugin', {
icons: 'myplugin',
init: function( editor ) {
// Plugin logic goes here...
editor.addCommand( 'myplugin', new CKEDITOR.dialogCommand( 'mypluginDialog' ) );
editor.ui.addButton( 'myplugin', {
label: 'My Plugin',
command: 'myplugin',
toolbar: 'insert'
});
}
});
然而,自定义插件的图标仍然没有显示。我可以在浏览器的工具中看到检索到 plugin.js 文件。我通过删除图标文件进行了测试,但没有产生任何差异(没有错误消息,没有 404)。我想那时候甚至没有调用或访问该文件。所以初始化甚至不会尝试渲染按钮。 谢谢你的帮助。
终于,我找到了问题的答案。它来自 CKEditor 显示工具栏的方式。在指南中,自定义插件被添加到工具栏的 "insert" 组中。但是,在明确设置为显示之前,这个将不可见。 将额外的插件添加到默认配置是不够的,必须正确指定工具栏设置(如果由于某种原因,您的平台没有默认为 null)。就我而言,使用 django-ckeditor,我必须添加
'toolbar': None,
到CKEDITOR_CONFIGS。