太牛了,在ext里面用fckeditor~~~

softfire 2008-08-13
转自:http://www.17ext.com/showtopic-250.aspx

var oFCKeditorOptions = {
    BasePath : 'fckeditor/',   
    Config : {   
        ProcessHTMLEntities : true,   
        ProcessNumericEntities : false,   
        StartupShowBlocks : false,   
        ToolbarCanCollapse : false       
    },   
    ToolbarSet : 'Default' 
};
Ext.form.FCKeditor = function(config){
Ext.form.FCKeditor.superclass.constructor.call(this, config);
this.FCKid=0;
this.MyisLoaded=false;
this.MyValue='';
};
Ext.extend(Ext.form.FCKeditor, Ext.form.TextArea,  {
onRender : function(ct, position){
        if(!this.el){
            this.defaultAutoCreate = {
                tag: "textarea",
                style:"width:100px;height:60px;",
                autocomplete: "off"
            };
        }
        Ext.form.TextArea.superclass.onRender.call(this, ct, position);
        if(this.grow){
            this.textSizeEl = Ext.DomHelper.append(document.body, {
                tag: "pre", cls: "x-form-grow-sizer"
            });
            if(this.preventScrollbars){
                this.el.setStyle("overflow", "hidden");
            }
            this.el.setHeight(this.growMin);
        }
  if (this.FCKid==0) this.FCKid=get_FCKeditor_id_value()
  setTimeout("loadFCKeditor('"+this.name+"');",100);
    },
    setValue : function(value){
    this.MyValue=value;
    if (this.FCKid==0) this.FCKid=get_FCKeditor_id_value()
    FCKeditorSetValue(this.FCKid,this.name,value)
    Ext.form.TextArea.superclass.setValue.apply(this,[value]);
    },
   
 
   
    getValue : function(){
    if (this.MyisLoaded){
      value=FCKeditorGetValue(this.name);
      Ext.form.TextArea.superclass.setValue.apply(this,[value]);
  return Ext.form.TextArea.superclass.getValue(this);
    }else{
      return this.MyValue;
    }
    },
   
    getRawValue : function(){
    if (this.MyisLoaded){
      value=FCKeditorGetValue(this.name);
      Ext.form.TextArea.superclass.setRawValue.apply(this,[value]);
  return Ext.form.TextArea.superclass.getRawValue(this);
    }else{
      return this.MyValue;
    }
    }
});
Ext.reg('fckeditor', Ext.form.FCKeditor);

function loadFCKeditor(element){
oFCKeditor = new FCKeditor( element ) ;
oFCKeditor.ToolbarSet = sFCKeditorToolbar ;
oFCKeditor.Config['SkinPath'] = sFCKeditorSkinPath ;
oFCKeditor.Config['PreloadImages'] = sFCKeditorSkinPath + 'images/toolbar.start.gif' + ';' +
    sFCKeditorSkinPath + 'images/toolbar.end.gif' + ';' +
    sFCKeditorSkinPath + 'images/toolbar.bg.gif' + ';' +
    sFCKeditorSkinPath + 'images/toolbar.buttonarrow.gif' ;
oFCKeditor.BasePath = sFCKeditorBasePath ;
oFCKeditor.Config['BaseHref'] = sFCKeditorBaseHref ;
oFCKeditor.Height = 260 ;
oFCKeditor.ReplaceTextarea() ;
}
function FCKeditor_OnComplete(editorInstance){
    Ext.getCmp(editorInstance.Name).MyisLoaded=true;
    editorInstance.Events.AttachEvent('OnStatusChange', function(){
    Ext.getCmp(editorInstance.Name).setValue();
    })
}
var FCKeditor_value=new Array();
function FCKeditorSetValue(id,name,value){
if ((id!=undefined)&&(name!=undefined)){
  if (value!=undefined) FCKeditor_value[id]=value;
  else if (FCKeditor_value[id]==undefined) FCKeditor_value[id]='';
  var oEditor = FCKeditorAPI.GetInstance(name) ;
 
  if(oEditor!=undefined) oEditor.SetData(FCKeditor_value[id])
}
}
function FCKeditorGetValue(name){
if ((id!=undefined)&&(name!=undefined)){
  var oEditor = FCKeditorAPI.GetInstance(name) ;
  data='';
  if(oEditor!=undefined) data=oEditor.GetData()
  return data;
}
}
var FCKeditor_id_value;
function get_FCKeditor_id_value(){
if (!FCKeditor_id_value){
  FCKeditor_id_value=0;
}
FCKeditor_id_value=FCKeditor_id_value+1;
return FCKeditor_id_value;
}

{   
                xtype: 'fckeditor',   
                name: 'n_context',   
                id: 'n_context',   
                fieldLabel: '内容',   
                height: 550
}

rikugun 2008-08-14
页面打不开
用的是这个吧?
http://extjs.com/forum/showthread.php?t=17423
vb2005xu 2008-08-21
感觉这个太复杂了,可以参考我写的'EXT/FCKEditor 集成 -- AJAX UI -- 一种web开发的新的思维',没有多少行代码,
vb2005xu 2008-08-21
Ext.onReady(function() {
 var fckFormObj = new Ext.FormPanel({
  labelWidth:75,
  url:"",
  title:"EXT/FCKEditor 集成 -- vb2005xu | cdlinux.ys168.com",
  bodyStyle:"padding:5px 5px 0",
  defaultType:"form",
  buttons:[
   {
    text:"Save" ,
    type:'submit',
    handler: function(){
     //获取fckeditor内容赋给textarea
     Ext.get('fckInstance').dom.value = "jjj";//fckobj.GetXHTML(true) + '提交后';  
     Ext.MessageBox.alert('FCK内容',Ext.get('fckInstance').dom.value);
     if (fckFormObj.form.isValid())
     {
      //创建响应测试函数      
      var fckobj_temp = FCKeditorAPI.GetInstance('fckInstance');
      //fckobj_temp.UpdateLinkedField();//此方法被绑定到submit事件
      
      fckFormObj.form.doAction('submit',{
       url:'submit.php',
       method:'post',
       waitMsg:'正在提交,请稍等...',
        success:function(form,action){//成功
         showInfo('Success',fckobj_temp.GetXHTML(true));
        } ,
        failure:function(form,action){//失败
         showInfo('Failed','网络中断造成连接失败');
        }
      });
     }
    }
   },
   {
    text:"Cancel"
   }
  ],
  items:[{
      xtype:"textarea",
      fieldLabel:"编辑",
      labelSeparator:":",
      id:"fckInstance", //div节点,这里要挂接FCKeditor编辑器
      name:"fckInstance",
      width:736,
      height:371
  }]
 });
 fckFormObj.render(document.body);
 
 /*创建Fckeditor对象 -- 构造函数指出了Fckeditor要挂接的id,上文中的xtype : 'textarea'指定*/
 //在页面上要求挂载fckeditor/fckeditor.js文件
 var fckobj = new FCKeditor('fckInstance',810,350);
 fckobj.BasePath = "/ucren/fckeditor/" ;
 fckobj.ToolbarSet = 'Default' ;
 fckobj.ReplaceTextarea(); 
 
 //创建响应测试函数
 function msgBox()
 {
  var fckobj_temp = FCKeditorAPI.GetInstance('fckInstance');
  fckobj_temp.UpdateLinkedField();//此方法被绑定到submit事件
  Ext.MessageBox.alert('FCK内容',fckobj_temp.GetXHTML( true ));
  
 }
 
 function showInfo(tip,str){
  var win = new Ext.Window({
   title: '信息提交应答提示 -- ' + tip,
   width: 400 , height: 200 ,autoScroll: true ,
   html: '<h1>'+ str +'</h1>'    
  });
  win.show();
 }
});

Global site tag (gtag.js) - Google Analytics