6

我在 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因为已删除元素的代码依赖关系。我用谷歌搜索了很多,似乎有两种方法可以解决这个问题 - 手动编辑那里写的插件的源代码(

我想唯一的解决方案是从 image/dialogs/image.js 中删除所有引用这些 html 对象的 javascript 函数,这些 html 对象已被删除。

我尝试遵循此建议,但无法在没有后续错误的情况下编辑源文件)或编写我自己的。当然,我可以简单地添加一些 css 规则并隐藏元素,但我想这不是一个好主意。这个问题已经够老了,我确信有一个很好的解决方案,但我没能找到它。希望你能帮助我。先感谢您。

PS 我有最新版本的 CKEditor - 3.6.4。

4

2 回答 2

9

由于图像对话框的编写方式,如果不进一步调整文件的其余部分以删除其所有引用,您将无法轻松删除预览。

我建议您使用我的配置插件(或编写类似的代码),如下所述: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

于 2013-04-16T18:44:03.050 回答
0

你可以试试infoTab.remove( 'htmlPreview' );

于 2012-09-18T17:59:43.500 回答