gwt + ckeditor config.js定制化问题

来源:互联网 发布:psp值得玩的游戏知乎 编辑:程序博客网 时间:2024/05/05 20:29

此问题出现在本地测试的时候:


1. 定制化config.js应该放的位置

放到gwt/server 端的src/main/webapp/ckeditor_local/config.js下,这样会被打包到apache-tomee/webapps/ROOT下, 然后

$wnd.CKEDITOR
                .replace(id, {
                    customConfig : '/ckeditor_local/config.js'
                });

就可以使定制化生效了。


2. 使用独立服务器(CDN)放置ckeditor的包时, 需要在index.html中配置如下:

<script type="text/javascript">
  var CKEDITOR_BASEPATH = '//www-static.***.com/libs/ckeditor-4.4.5/';
</script>
<script src="//www-static.***.com/libs/ckeditor-4.4.5/ckeditor.js"></script>


但是customConfig : '/ckeditor/config.js'就不work了。这个是误解。 这个是因为www-static上的ckeditor package plugins里没有autosave, 而我的ckeditor_local/config.js里有autosave的配置,所以导致出错,实际上可以在firebug中看到这个错误的原因。 而且和CKEDITOR_BASEPATH也没有关系。 我发现CKEDITOR_BASEPATH根本没必要配置。


3. 一直想把定制的ckeditor/config.js放到gwt/client一侧,但是一直不生效。【这个是错误做法,肯定不行。 只能放到gwt server, webapp下,也就是web server的root path下

无论放到src/main/resources还是src/main/resources/com/.../client/ckeditor/config.js 都不行。


4. 添加ckeditor autogrow插件

        editor.config.extraPlugins = 'autogrow';
        editor.config.autoGrow_minHeight = 100;
        editor.config.autoGrow_maxHeight = 1000;
        editor.config.removePlugins = 'resize';


5. ckeditor 在使用CDN情况下的配置

refer to: https://cdn.ckeditor.com/


6. 从server本地添加autosave插件的方法:

$wnd.CKEDITOR.plugins.addExternal('autosave',
                '/ckeditor_local/plugins/autosave/', 'plugin.js');

$wnd.CKEDITOR
                .replace(id, {
                    customConfig : '/ckeditor_local/config.js'
                });


7. 如果Toolbar 上没有出现想要的button, 比如TextColor, BGColor, 可能是因为缺少插件(那些插件不是默认添加的)

可以这样一次添加多个插件,主要如果写多次  config.extraPlugins =xxx, 后面的会覆盖前面的。

  config.extraPlugins = 'autosave,colorbutton,showblocks';


8. 获取CKEditor Toolbar命令Button的状态

public native int getCommandState(String command) /*-{
        return this.@com.xyz.gwt.client.entries.CKEditor::editor
                .getCommand(command).state;
  }-*/;


0 0