我在CKEditor的图像插件中隐藏预览元素时遇到问题。我需要一个非常简单的图像对话框,其中只有用于图像源的输入字段,以及带有用于图像上传的按钮的表单。
因此,我使用以下自定义配置设置删除了不必要的元素:
CKEDITOR.on( 'dialogDefinition', function( ev )
{
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if ( dialogName == 'image' ){
dialogDefinition.removeContents( 'advanced' );
dialogDefinition.removeContents( 'Link' );
var infoTab = dialogDefinition.getContents( 'info' );
infoTab.remove( 'ratioLock' );
infoTab.remove( 'txtHeight' );
infoTab.remove( 'txtWidth' );
infoTab.remove( 'txtBorder');
infoTab.remove( 'txtHSpace');
infoTab.remove( 'txtVSpace');
infoTab.remove( 'cmbAlign' );
infoTab.remove( 'txtAlt' );
}
});
当我尝试隐藏htmlPreview元素时,问题开始了。如果仅添加
infoTab.remove( 'htmlPreview ' );
,则会发生错误:Uncaught TypeError: Cannot call method 'setStyle' of null
,因为所删除元素的代码依赖性。我在Google上搜索了很多,似乎有两种方法可以解决此问题-以there(手动编写形式编辑插件的源代码(我尝试遵循此建议,但没有后续错误就无法编辑源文件)
或写我自己的。当然,我可以简单地添加一些CSS规则并使元素隐藏,但是我认为这不是一个好主意。
这个问题已经足够老了,我敢肯定有一个好的解决方案,但是我找不到它。
希望你能帮助我。先感谢您。
P.S.我拥有CKEditor的最新版本-3.6.4。
最佳答案
由于图像对话框的编写方式,如果不进一步调整文件的其余部分以删除其所有引用,就无法轻松删除预览。
我建议您使用我的配置插件(或编写类似的代码),如下所述:http://alfonsoml.blogspot.com.es/2012/04/hide-dialog-fields-in-ckeditor.html
config.hideDialogFields="image:info:htmlPreview";
您可以从我的博客下载该插件,或者如果您已切换到CKEditor 4,则将其添加到您的构建中:http://ckeditor.com/addon/confighelper
关于javascript - 在CKEditor的图像插件中删除htmlPreview,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12307967/