点集贵州电脑网
 
 
 梦想之源 ›› 灌水专区 ›› FCKeditor JavaScript API 版主:
灌水专区
新建论坛
申请免费TS
1 / 1 页
<< 1 >>
跳转
 主题:FCKeditor JavaScript API
 
 干煸四季豆
发表时间:[2007-08-06 17:28:21] [向作者发站内短信] [复制链接告诉朋友]
等 级:下士
经 验:1683
性 别:帅哥
文 章:496
精 华:2

FCKeditor是比较有名的开源页面编辑器,我们论坛和网站用的就是这个编辑器。功能非常强大,所以嘛,解读源代码也比较费力。下面是FCKeditor API的简介,比较简单,就不翻译了。

FCKeditor offers a complete JavaScript API so you can interact with it once the editor is loaded and running.

Once loaded, the editor registers a global object called FCKeditorAPI. This object offers the entry point to interact with any editor instance placed in a page (you can have more than one).

/!\ The FCKeditorAPI object will not be available during the page load. You need to wait for the editor to be loaded to use it. If you need to interact with the editor right after is has been loaded, use the "FCKeditor_OnComplete" function (see "Events").

 

Retrieving an Editor Instance

 

From out of an external script:

When placing the editor in the page, you give it an "instance name". To retrieve it, you must simply call the FCKeditorAPI.GetInstance method. For example:

 

var oEditor = FCKeditorAPI.GetInstance('InstanceName') ;

 

From out of a dialog of the editor:

Call the InnerDialogLoaded to get the FCK Object. Read more in this HOWTO

var oEditor = window.parent.InnerDialogLoaded().FCK ;

 

Both methods return the main FCKeditor object that gives the necessary bridge to interact with it. These are the most useful properties and methods of this object:

 

Properties:
 * Name = (string) The instance name.
 * Status = (integer) The editor status (loading status).
 * EditorDocument = (object) The DOM Document object for the editing area.
 * EditorWindow = (object) The DOM Window object for the editing area.
Methods:
 * AttachToOnSelectionChange( functionPointer )
 * Focus()
 * GetXHTML( formatted )
 * InsertElement(element)
 * InsertElementAndGetIt(e)
 * InsertHtml(html)  // Inserts HTML in the current cursor position
 * IsDirty()  // Checks if the content in the editor has been changed
 * MakeEditable()
 * ResetIsDirty()  // Resets the dirty state
 * SetHTML( html, forceWYSIWYG )  // Sets the contents of the editor
     // Note that when using this method, you will loose any listener that you
     // may have previously registered on the editor.EditorDocument. A workaround is
     // to use instead: editor.EditorDocument.body.innerHTML.
 * SwitchEditMode()
 * UpdateLinkedField()
 
var oEditor = window.parent.InnerDialogLoaded().FCK;
oEditor.EditorDocument.body.innerHTML = thisFCK.GetXHTML();

 

 

Events

 

Once the editor loading phase is complete and it is ready to use (and interact with JavaScript), a standard function is called in the page that contains the editor, if the function is defined. This function must be named "FCKeditor_OnComplete" and receives the related editor instance as the parameter. Using it, you can execute any initial code that may interact with the editor. This is a declaration example:

 

function FCKeditor_OnComplete( editorInstance )
{
    alert( editorInstance.Name ) ;
}

 

Other than the above standard function, every FCKeditor instance has an "Event" object that can be used to listen for events to be fired. For example, the following code listens for the "OnSelectionChange" to execute custom code:

 

var counter = 0 ;
function DoSomething( editorInstance )
{
        window.document.title = editorInstance.Name + ' : ' + ( ++counter ) ;
}
function FCKeditor_OnComplete( editorInstance )
{
    editorInstance.Events.AttachEvent( 'OnSelectionChange', DoSomething ) ;
}

 

Note that every callback function receives the editor instance as a parameter.

The following is the list of events available:

  • OnSelectionChange: fired when the actual selection in the editor area changes (by selection I mean the cursor position too... it changes on key strokes). Note: In IE6, this event does not fire on every keystroke, but only on some random keystrokes. Handy!

  • OnAfterSetHTML: fired once the HTML is loaded in the editor (including when changing views).

  • OnStatusChange: fired when the editor status changes. The following constants are also available globally in the page: FCK_STATUS_NOTLOADED, FCK_STATUS_ACTIVE and FCK_STATUS_COMPLETE.

  • OnPaste: fired when something is pasted in the editor.

  • OnAfterLinkedFieldUpdate: fired right after the hidden linked field attached to the editor has its contents updated. It happens usually when the form is being posted.

 

Misc commands

 

Through this API, many things can be controlled:


 楼主更多新贴 :  
灌水专区美女深夜遇劫该怎么办?
IT科技出售二手电脑
主题活动团购一期:三星R458-DS0G+高端游戏
IT科技上有政策下有对策:盗版系统避免10
  楼1  
等 级:上士
经 验:4246
性 别:美女
文 章:476
精 华:40
 烂笔头
发表时间:[2007-08-06 22:20:54] [向作者发站内短信] [复制链接告诉朋友]

你这家伙,抢我的地方,哼!~

  楼2  
等 级:小兵
经 验:0
性 别:美女
文 章:0
精 华:0
 游客
发表时间:[2009-01-05 15:23:46] [向作者发站内短信] [复制链接告诉朋友]
  楼3  
等 级:小兵
经 验:0
性 别:美女
文 章:0
精 华:0
 游客
发表时间:[2009-01-05 15:29:15] [向作者发站内短信] [复制链接告诉朋友]
1 / 1 页
<< 1 >>
跳转
  快速回复
  帐号: 密码: 匿名不登陆
回复内容:  
验 证 码:
 
 
·VIP收费TS,您明智的选择!
·9800GT+19'液晶DIY仅售3500元
·双核特惠:1999、2999、3999
·什么是点金积分,如何查看自
·团购一期:三星R458-DS0G+高
  
贵州点集科技发展有限责任公司·点集贵州电脑网 版权所有©2006-2008
中华人民共和国增值电信业务经营许可证 黔B-20070010号
客服QQ: 93804809818866281927205370
电子邮件: deangi@vip.sina.com
技术支持: 0851-5109268