- function abc()
- {
- var checkContent =FCKeditorAPI.GetInstance("editor");
- alert(checkContent.GetXHTML());
- var newelement = document.createElement("a");
- newelement.href="#";
- newelement.innerHTML="df";
- checkContent.InsertElement(newelement);
- var a=checkContent.InsertElementAndGetIt(newelement);
- checkContent.InsertHtml("")
- checkContent.SetHTML("",true);
-
- }
- function aaa()
- {
- var checkContent =FCKeditorAPI.GetInstance("editor");
- checkContent.SwitchEditMode();
- checkContent.UpdateLinkedField();
- }
- function FCKeditor_OnComplete( checkContent )
- {
- alert( checkContent.Name ) ;
- }
-
-
- function FCKeditor_OnComplete(editorInstance)
- {
- editorInstance.EditorDocument.body.disabled = true;
- editorInstance.EditorWindow.parent.document.getElementById ('xExpanded').style.display = 'none';
- editorInstance.EditorWindow.parent.document.getElementById('xCollapsed').style.display = 'none';
- editorInstance.EditorWindow.blur();
- }
-
-
- function insertHTMLToEditor(codeStr){
- var oEditor = FCKeditorAPI.GetInstance("content");
- if (oEditor.EditMode==FCK_EDITMODE_WYSIWYG){
- oEditor.InsertHtml(codeStr);
- }else{
- return false;
- }
- }
-
- function getLength(){
- var oEditor = FCKeditorAPI.GetInstance("content");
- var oDOM = oEditor.EditorDocument;
- var iLength ;
- if(document.all){
- iLength = oDOM.body.innerText.length;
- }else{
- var r = oDOM.createRange();
- r.selectNodeContents(oDOM.body);
- iLength = r.toString().length;
- }
- alert(iLength);
- }
-
- function ExecuteCommand(commandName){
- var oEditor = FCKeditorAPI.GetInstance("content") ;
- oEditor.Commands.GetCommand(commandName).Execute() ;
- }
-
- function SetContents(codeStr){
- var oEditor = FCKeditorAPI.GetInstance("content") ;
- oEditor.SetHTML(codeStr) ;
- }
-
-
- function InsertHTML(e,inStr)
- {
- var oEditor = FCKeditorAPI.GetInstance(e) ;
- if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
- {
- oEditor.InsertHtml( inStr ) ;
- }
- else
- alert("You must be on WYSIWYG mode!" ) ;
- }
-
- function ExecuteCommand( commandName,e )
- {
- var oEditor = FCKeditorAPI.GetInstance(e) ;
- oEditor.Commands.GetCommand(commandName ).Execute() ;
- }
Commands 的定义:
\fckeditor\editor\js\fckeditorcode_ie.js
自定义 Commands 实战: 自定义我们的打开图片选择对话框的命令!!!
step1 : 注册我们自己定义的 Commands "JSCallbackCommand"
查找 “|InsertHorizontalRule” 然后再后面插入 "|JSCallbackCommand"
step2:定义我们的 JSCallbackCommand 【直接 copy 现有的 FCKDialogCommand 再做修改即可】
var FCKJSCallbackCommand=function(A,B,C,D,E,F,G,H){
this.Name=A;
this.Title=B;
this.Url=C;
this.Width=D;
this.Height=E;
this.CustomValue=H;
this.GetStateFunction=F;
this.GetStateParam=G;
this.Resizable=false;
};FCKJSCallbackCommand.prototype.Execute=function(fileUrl){
try
{
FCKDialog.OpenDialog('FCKDialog_'+this.Name,this.Title,this.Url + '?preview=' + encodeURIComponent(fileUrl),this.Width,this.Height,this.CustomValue,null,this.Resizable);
} catch(e){
alert(e);
}
};FCKJSCallbackCommand.prototype.GetState=function(){if (this.GetStateFunction)
return this.GetStateFunction(this.GetStateParam);
else return FCK.EditMode==0?0:-1;};
step3 : 注册进事件处理
查找 ";break;default:if (FCKRegexLib.NamedCommands.test(A)) B=new FCKNamedCommand(A);" 然后在 break; 前面插入:
case 'JSCallback':B=new FCKJSCallbackCommand('JSCallback',FCKLang.DlgImgTitle,'dialog/fck_image.html',450,390);
这样,我们自定义的 JSCallbackCommand 就注册完了!!!
到时候可以通过 FCKEditorAPI 直接执行该命令, 并且还可以传递参数。
调用示例:
var inst = FCKeditorAPI.GetInstance('HTMLeditor1');"
inst.Commands.GetCommand('JSCallback').Execute('http://a3.att.hudong.com/68/93/01300000556189125362932760553_140.jpg');"
结果就是,浏览器打开一个弹出图片dialog, 并且默认选中了这张图片