如何在GWT中集成CKEditor [英] How to integrate CKEditor in GWT

查看:183
本文介绍了如何在GWT中集成CKEditor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来整合CKEditor在我的GWT项目。

I'm looking for a way to integrate CKEditor in my GWT project.

我做了一些搜索,发现这个项目: https://code.google.com/p/gwt-ckeditor/
,已被放弃多年。所以CKEditor完全过时。

I've made some googling and found this project: https://code.google.com/p/gwt-ckeditor/ which has been abandoned for years. So the CKEditor is completely outdated.

我也看到CKEditor在GWT之外加载到在GWT中创建的textarea。我不知道这是否是一个好方法。

I've also seen the CKEditor being loaded outside of GWT into a textarea created in GWT. I'm not sure if that's a good way.

如果有人可以给我一些建议,这将是非常感激。
感谢提前

If someone could give me some advises, it would be highly appreciated. Thanks by advance

推荐答案

您可以使用JSNI来激活CKEditor。
要加载javascript文件,您可以将其加载到html页面中,也可以使用 ScriptInjector

You can use JSNI for activate the CKEditor. For loadning the javascript file, either you load this in the html page, or by using ScriptInjector and StyleInjector.

在GWT中,创建一个组件:

In GWT, create a componant :

package com.google.editor;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.TakesValue;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TextArea;

public class CKeditor extends Composite implements TakesValue<String> {
  TextArea text = new TextArea();
  protected JavaScriptObject editor;

  public CKeditor() {
    initWidget(text);
  }

  @Override
  protected void onAttach() {
    super.onAttach();
    initCKEditor(text.getElement().getId());
  }

  private native void initCKEditor(String id) /*-{
    this.@com.google.editor.CKeditor::editor =  CKEDITOR.replace( id );
  }-*/;

  @Override
  public native void setValue(String value) /*-{
    this.@com.google.editor.CKeditor::editor.setData(value);
  }-*/;

  @Override
  public native String getValue() /*-{
    this.@com.google.editor.CKeditor::editor.setData(value);
  }-*/;
}

这是一个示例,添加所有要在CKEditor中设置的配置

It's a sample, add all config you want to set in CKEditor

这篇关于如何在GWT中集成CKEditor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆