删除CKEditor图像插件中的htmlPreview

时间:2012-09-06 20:35:06

标签: javascript ckeditor wysiwyg

我在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

  

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

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

P.S。我有最新版本的CKEditor - 3.6.4。

2 个答案:

答案 0 :(得分:7)

由于图像对话框的编写方式,您无法轻松删除预览而无需进一步调整文件的其余部分以删除其所有参考文件。

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

答案 1 :(得分:0)

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

相关问题