安裝:javascript
下載CKEDITOR的文件,解壓後複製到工程的WEBROOT目錄下就OK!css
引用CKEDITOR的JS文件:html
新建JSP頁面,添加其JS文件<script type="text/javascript" src="ckeditor/ckeditor.js"></script>java
注意:1.src的路徑。web
2.不要寫成<script type="text/javascript" src="ckeditor/ckeditor.js />樣式,在現有的3.0.1版本中會出現CKEDITOR未定義的腳本錯誤提示,導致不能生成編輯器。api
替換TEXTAREA標籤:數組
注意:要在textarea後面加入javascript.若是要在HEAD區寫javasript,那麼採用以下代碼:app
好了到此一個默認的CKEDITOR就配置完畢了,能夠去頁面看看它的模樣了。dom
固然還有一個方法CKEDITOR.appendTo(elementOrId, config) 它能夠在特定的dom對象中建立CKEDITOR編輯器
屬性配置:
全部的配置,均可以查閱官方的API:http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html
IN-PAGE配置方式:
The best way to set your configurations is in-page, when creating editor instances. In this way you avoid touching the original distribution files in the CKEditor installation folder, making the upgrade task easier.
最好在建立編輯器的頁面中配置你的編輯器屬性,使用這種方式,你無需理會在CKEDITOR安裝目錄中的配置文件(ps:in-page的優先級最高).
注意:合法的屬性是以「{」開始,「}」"結束,屬性名和屬性值用「:」隔離.
默認屬性文件配置方式:
You can also place your settings inside the config.js file also. You will note that the file is mostly empty by default. You simply need to add the configurations that you want to change. For example:
你也能夠在config.js 中加入配置信息,當你打開該文件時你會發覺它幾乎爲空(默認)。你要作的是把配置信息加入其中。
自定義屬性文件配置方式:
Suppose you have copied config,js inside a folder named "custom" in the root of your web site. You have also renamed the file to "ckeditor_config.js". At that point, you must only set the customConfig setting when creating the editor instances. For example:
假設你在custom目錄中有一自定義的配置文件ckeditor_config.js,那麼就必須在建立ckeditor實例時制定它的路徑(用customConfig屬性)。
Configurations Overload Order 配置的優先級
You're not required to use only one of the above configuration options. You can mix all of them, and the configurations will be overloaded properly. The following is configurations loading order when creating an editor instance:
你沒必要僅使用上面的一種方式進行配置,而是能夠混合使用它們,這些配置會以特定的優先級順序進行復寫。
Avoiding Loading External Settings Files
It is also possible to completely avoid loading an external configuration file, reducing the number of files loaded. To do that, it's enough to set the customConfig setting to an empty string. For example:
This setting is definitely recommended if you are not setting configurations in the config.js file nor a custom configuration file.
這段就不翻譯了,so,easy!
配置個性化工具欄:
A toolbar definition is a JavaScript array that contains the elements to be displayed in all "toolbar rows" available in the editor. There are two ways to set the desired toolbar definition in the editor. It can be set directly into the "toolbar" setting, or it can instead be set to a configuration named "toolbar_<name>", where "<name>" is a name that can be used to identify the toolbar in the "toolbar" setting. The following is the default setting we have in the editor.
上面的英文太羅嗦了說重點算了:工具欄是經過數組來設定的,工具欄的名字以toolbar_<name>的方式命名,其中的<name>是用來賦值給config.toolbar這一變量的。
那麼如下代碼定義了toolbar_Full和toolbar_Basic的兩種工具欄配置,並使用了config.toolbar = 'Full';定義當前的編輯器的工具欄爲Full。
其中("-") 爲空間欄的水平分割,("/") 爲換行。
Note that two toolbar definitions have been defined, one named "Full" and the other "Basic". The "Full" definition has been set to be used in the toolbar setting.
You can create as many toolbar definitions as you want inside the configuration file. Later, based on some criteria, you can decide the toolbar to use for each editor instance. For example, with the following code, two editors are created in the page, each one using a different toolbar:
你也能夠根據您的須要在配置文件中創建多個工具欄的定義,而後,能夠根據特定條件,決定使用哪一個定義。
It's also possible to set the toolbar definition in-page, when creating the editor instance directly. In that case, just assign it to the toolbar setting directly, for example:
也能夠經過IN-PAGE的方式定義工具欄參數。
The Styles Definition
The styles definition is a JavaScript array which is registered by calling the CKEDITOR.addStylesSet() function. A unique name must be assigned to your style definition, so you can later set each editor instance to load it. It means that you can have a single style definition which is shared by several editor instances present on the page.
The following is a sample style definition registration:
經過CKEDITOR.addStylesSet() 函數,咱們能夠定義一個樣式,結合如下的例子,my_styles爲樣式的名稱,具體的樣式爲一個JAVASCRIPT數組。經過樣式的名稱我可讓頁面的多個編輯器應用該樣式。
The above definition registration can be placed inline in the page using the editor, or can even live in an external file, which is loaded "on demand", when needed only (see below).
樣式能夠經過IN-PAGE或配置文件中進行註冊。
After that, you must instruct the editor to use your newly registered style definition by using the stylesCombo_stylesSet setting. This may be set into the config.js file, for example:
你能夠經過在config.js 加入如下代碼使編輯器應用該樣式:
You can include the above styles definition registration call into an external JavaScript file. This is the preferred way for it because it will be loaded only when opening the Styles selection box, enhancing the page loading performance. Users may feel a small loading gap because of it though.
By default, the editor uses the "plugins/stylescombo/styles/default.js" file, which is a "minified" JavaScript file. You can find the uncompressed version of it at "_source/plugins/stylescombo/styles/default.js". You can see it online at our SVN also: http://svn.fckeditor.net/CKEditor/trunk/_source/plugins/stylescombo/styles/default.js. It can be used as a template for your custom file.
Your style definition file can be saved anywhere at your web site (or the web). You must just know the URL to reach it. For example, you can save at it at the root of your web site, so you can reach it with "/styles.js", or even place it in a central web site, so you can locate it with "http://www.example.com/styles.js". At that point, simply change the stylesCombo_stylesSet setting to point the editor to your file:
默認的樣式文件在"_source/plugins/stylescombo/styles/default.js"目錄中,咱們也能夠本身定義一個樣式文件,如在站點的跟目錄中有styles.js這一個樣式文件,這個文件經過如下代碼指定其路徑:
Style Rules
The entries inside a style definition are called "style rules". Each rule defines the display name for a single style as well as the element, attributes and css styles to be used for it. The following is the generic representation for it:
The "name" and "element" values are required, while other values are optional.
There are three types of style types, each one related to the element used in the style rule:
Output Formatting
The HTML Writer
這個是用來對各類標籤的排版進行設定的
Technically speaking, writing the final output is a task executed by the CKEDITOR.htmlWriter class ("writer"), used by the CKEDITOR.htmlDataProcessor class. Therefore, the current writer instance for a specific editor instance can be retrieved by the <editorInstance>.dataProcessor.writer property.
By setting the writer properties, it's possible to configure several output formatting options. The following example is the best way to summarize the most used of them, with their default values:
Because the writer is a property of each editor instance, and also because it's dependency on the writer plugin to be loaded, the best way to make changes to it is by listening to the "instanceReady" event, so it's safe to assume that the dataProcessor property will be loaded and ready to changes. The following is an example of it, when creating an editor instance:
能夠爲單一得編輯器指定標籤的格式。
Another way for it is by using the CKEDITOR object, so all editor instances will be changed:
也能夠對全部的編輯器進行設定。