2013-09-23 49 views
5

我正在尋找一種將CKEditor集成到我的GWT項目中的方法。如何將CKEditor集成到GWT中

我做了一些Google搜索,發現這個項目:https://code.google.com/p/gwt-ckeditor/ 已經放棄了多年。所以CKEditor完全過時了。

我也看到CKEditor被加載到GWT之外的文本區域中。我不確定這是否是一個好方法。

如果有人能給我一些建議,將不勝感激。 提前致謝

+0

http://angulartutorial.blogspot.in/2014/03/integration-of-ck-editor-to-ui.html – Prashobh

回答

5

您可以使用JSNI來激活CKEditor。 要加載JavaScript文件,可以將其加載到html頁面中,也可以使用ScriptInjectorStyleInjector

在GWT,創建一個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) /*-{ 
    [email protected]::editor = CKEDITOR.replace(id); 
    }-*/; 

    @Override 
    public native void setValue(String value) /*-{ 
    [email protected]::editor.setData(value); 
    }-*/; 

    @Override 
    public native String getValue() /*-{ 
    [email protected]::editor.setData(value); 
    }-*/; 
} 

這是一個樣本,添加要在CKEditor的設置

+0

不錯!你的原生getValue()方法應該調用editor.getValue();我還需要使用$ wnd.CKEDITOR,如下面的@ArcTanH所示。 – Jamie

3

我也建議ScriptInjector因爲它給你一個回調腳本所有配置終於加載,一切都很好。

之後,你必須使用$ WND妥善解決CKEDITOR和本地代碼替換textarea的:

private native void initCKEditor(String id) /*-{ 
    [email protected]::editor = $wnd.CKEDITOR.replace(id); 
    }-*/; 
1

帕特里斯的回答是非常有益的,但它最初並沒有爲我工作,因爲文本區文本=新的TextArea ();正在創建一個沒有ID字段的TextArea。爲了解決這個問題,我只是手動添加了一個ID字段:

text.getElement().setId("make_up_an_id_name_here"); 

此外,請確保你把ckeditor文件夾放在你的戰爭目錄中。

如果您選擇鏈接到它在你的project_name.html文件中,添加插入你的主... nocache.js腳本線這條線之上。

<script type="text/javascript" src="ckeditor/ckeditor.js"></script> 
0

text.getElement()SETID (DOM.createUniqueId());