注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

phperwuhan的博客

记载一个phper的历程!phperwuhan.blog.163.com

 
 
 

日志

 
 

FCKeditor的全局API   

2008-03-18 09:29:48|  分类: js |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

来源:http://www.cnblogs.com/xiaotaoliang/archive/2007/05/15/746851.html

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


Retrieving an editor instanceOnce 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). When placing the editor in the page, you give it an "instance name". So, to retrieve it, you must simply call the FCKeditorAPI.GetInstance method. For example:

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


The returned object
The GetInstance method returns the main FCKeditor object that gives the necessary bridge to interact with it. This is a list of properties and methods of this object:


* Description = string
* EditMode = Integer
* Name = string
* Status = Integer
* function AttachToOnSelectionChange(functionPointer)
* function CleanAndPaste(html)
* function CreateElement(tag)
* function CreateLink(url)
* function ExecOnSelectionChange() //Fires OnSelectionChange event in event manager
* function ExecOnSelectionChangeTimer()
* function ExecuteNamedCommand(commandName, commandParameter)
* function ExecuteRedirectedNamedCommand(commandName, commandParameter)
* function Focus()
* function GetHTML(format) // doesnt work. Use GetXHTML instead.
* function GetNamedCommandState(commandName)
* function GetNamedCommandValue(commandName)
* function GetXHTML(format)
* function InitializeBehaviors()
* function InsertElement(element)
* function InsertElementAndGetIt(e)
* function InsertHtml(html)
* function IsDirty();
* function MakeEditable()
* function OnDoubleClick(element)
* function Paste()
* function PasteAsPlainText()
* function PasteFromWord()
* function Preview()
* function RegisterDoubleClickHandler(handlerFunction, tag)
* function ResetIsDirty();
* function SetHTML(html, forceWYSIWYG)
* function SetStatus()
* function ShowContextMenu(x, y)
* function SwitchEditMode()
* function UpdateLinkedField()


EventsOnce the editor loading 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 makes the initial interaction with the editor. This is a declaration example:


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

Apart the above standard event, every FCKeditor instance has a "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

 

  评论这张
 
阅读(335)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017