我想创建一个没有工具栏的CKEditor实例。我尝试在实例的配置中定义一个空工具栏。
(可能是重复问题:CKEditor - 没有工具栏)
oConfigName.toolbar = 'Custom';
oConfigName.toolbar_Custom = [];
但是在我的实例中,我得到了一个小的空工具栏,而不是没有工具栏。
我正在使用 CKEditor4 的内联编辑。
我想创建一个没有工具栏的CKEditor实例。我尝试在实例的配置中定义一个空工具栏。
(可能是重复问题:CKEditor - 没有工具栏)
oConfigName.toolbar = 'Custom';
oConfigName.toolbar_Custom = [];
但是在我的实例中,我得到了一个小的空工具栏,而不是没有工具栏。
我正在使用 CKEditor4 的内联编辑。
哇 :) 在实现工具栏时我们没有想到过这一点。但我刚刚检查了一下,您可以删除工具栏插件,因为没有其他插件需要它。
所以构建您自己的CKEditor包不包含工具栏,或使用removePlugins
配置 - 例如:
var editor = CKEDITOR.inline( 'editable', {
removePlugins: 'toolbar'
} );
更新:在 CKEditor 4.1 版本中引入了高级内容过滤器。在其自动模式中,通过加载到工具栏的按钮来配置它。没有 toolbar
插件,就无法配置 ACF,因此需要自己手动完成:
var editor = CKEDITOR.inline( 'editable', {
removePlugins: 'toolbar',
allowedContent: 'p h1 h2 strong em; a[!href]; img[!src,width,height];'
} );
CKEDITOR.replace( 'editor1', {
...
toolbar: []
});
我在 ckeditor5 中这样做:
ClassicEditor
.create( document.querySelector( '.editor' ), {
licenseKey: '',
toolbar: [],
} )
.then( editor => {
window.editor = editor;
editor.isReadOnly = true;
} )
.catch( error => {
console.error( 'Oops, something went wrong!' );
console.error( 'Please, report the following error on https://github.com/ckeditor/ckeditor5/issues with the build id and the error stack trace:' );
console.warn( 'Build id: efxy8wt6qchd-qhxgzg9ulnyo' );
console.error( error );
} );
<style>
.ck{
border:0px !important;
}
</style>
我见过两种方法:
1)使用removePlugins
选项并仅删除工具栏:
CKEDITOR.inline( 'textarea', {
removePlugins: 'toolbar',
allowedContent: 'p h1 h2 strong em; a[!href]; img[!src,width,height];'
} );
2) 使用CSS - 非标准方法: (有点棘手)
只需使用CSS将工具栏显示为none,如下所示:
.cke_inner {
display: none;
}
.cke_inner .cke_top {
display: none;
}
.cke_inner .cke_top .cke_toolbox {
display: none;
}
我使用以下配置关闭了除斜体、粗体和下划线之外的所有内容:
CKEDITOR.editorConfig = function( config ) {
config.autoParagraph = false;
config.toolbarGroups = [
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
];
config.removeButtons = 'Strike,Subscript,Superscript,RemoveFormat';
};
ClassicEditor
.create( document.querySelector( '#editor' ), {
// ...
} )
.then( editor => {
const toolbarElement = editor.ui.view.toolbar.element;
editor.on( 'change:isReadOnly', ( evt, propertyName, isReadOnly ) => {
if ( isReadOnly ) {
toolbarElement.style.display = 'none';
} else {
toolbarElement.style.display = 'flex';
}
} );
} )
.catch( error => {
console.log( error );
} );
在CKEditor 5中更正确的方式:
editor.ui.view.panel.element.setAttribute('style', 'display:none');
config.removePlugins= 'toolbar'
我已经在我的项目中添加了新的功能,用于隐藏/显示工具栏。
function onClickToolbarButton() {
var bar = document.getElementById("cke_1_top");
if(bar.style.display == "none"){
bar.style.display = "block";
}else{
bar.style.display = "none";
}
//resize web page
//onresize();
}
如果您想要隐藏/显示工具栏,请每次调用此函数。
.ck.ck-editor__top {
display: none;
}
config.allowedContent
设置为true
***。 - bendmanremovePlugins: 'toolbar, pastefromword, tableselection, uploadwidget, clipboard, pastetext, widget, uploadimage',
- HoseinGhanbariextraAllowedContent: 'style;*[id,rel](*){*}'
。 - undefined