ckeditor使用具有不同工具栏配置的类名替换textarea
我使用以下代码将ckeditor添加到我的页面中ckeditor使用具有不同工具栏配置的类名替换textarea,ckeditor,Ckeditor,我使用以下代码将ckeditor添加到我的页面中 <textarea class="ckeditor" name="editor1"></textarea> 我想定义一些工具栏配置,因为不是我的应用程序中的所有文本区域都需要完整的工具栏。 我已经根据自己的需要定制了默认的工具栏配置,但我想进一步细分,为我的一些文本区域提供一个更基本的工具栏 如果我使用class属性设置ckeditor,有没有办法做到这一点 对于按类名创建的编辑器,不可能有不同的配置。在这种情况下,
<textarea class="ckeditor" name="editor1"></textarea>
我想定义一些工具栏配置,因为不是我的应用程序中的所有文本区域都需要完整的工具栏。
我已经根据自己的需要定制了默认的工具栏配置,但我想进一步细分,为我的一些文本区域提供一个更基本的工具栏
如果我使用class属性设置ckeditor,有没有办法做到这一点 对于按类名创建的编辑器,不可能有不同的配置。在这种情况下,只考虑全局
CKEDITOR.config
对于这个问题仍然有简单的解决方法。首先,将此脚本放在文档顶部:
<script>
CKEDITOR.replaceClass = null; // Disable replacing by class
</script>
最后,使用以下代码以类名手动替换编辑器(假设您的类是ckeditor
)。此代码将使用由数据自定义配置
属性中定义的配置驱动的ckeditor实例替换类ckeditor
的所有文本区域:
var textareas = Array.prototype.slice.call( document.getElementsByClassName( 'ckeditor' ) ),
textarea, cfg, customCfg;
while ( ( textarea = textareas.pop() ) ) {
textarea = new CKEDITOR.dom.element( textarea );
cfg = {};
if ( ( customCfg = textarea.getAttribute( 'data-custom-config' ) ) )
cfg[ 'customConfig' ] = customCfg;
CKEDITOR.replace( textarea.getId(), cfg )
}
现在是顶部的樱桃。将自定义工具栏配置放入myCustomConfig.js
:
CKEDITOR.editorConfig = function( config ) {
config.toolbar = [
{ name: 'basicstyles', items: [ 'Bold', 'Italic' ] }
];
};
当然,您可以修改这段代码,使jQuery更容易选择元素,使用一些对象文字,而不是config.customConfig
等等。这只是一个如何解决问题的展示
CKEDITOR.editorConfig = function( config ) {
config.toolbar = [
{ name: 'basicstyles', items: [ 'Bold', 'Italic' ] }
];
};