比较不错的修改FCKEditor的修改方法

所属分类: 网络编程 / 网页编辑器 阅读数: 633
收藏 0 赞 0 分享

修改后的代码下载http://www.cnblogs.com/Files/Truly/FCKeditor_Truly.rar
本地下载地址
由于项目需要,近期仔细研究了FCKEditor。发现一下bug,以及缺少的一些东西。

一、防止连续文本导致出现滚动条
        FCKEditor编辑器使用Iframe来处理编辑器内容,可惜不支持文本换行,假如你连续输入一段英文或数字等,将会出现滚动条,这时我们需要给其增加word-wrap样式为break-word;

添加方式有很多,我选择最便捷的修改方式:具体做法是修改fckeditor.html文件,给<iframe id="eEditorArea" 增加事件 onload="window.frames['eEditorArea'].document.body.style.wordWrap='break-word'"

二、增加Media以及Realplay按钮
      此项工作相对庞大,要修改很多js文件,以及一些图片和样式文件。
      a.准备图片:FCKeditor\editor\css\images下面,添加fck_medialogo.gif和fck_realplaylogo.gif,大小随意,作为背景居中显示的。
FCKeditor\editor\skins\default\toolbar\增加media.gif和realplay.gif,其他皮肤类推。
      b.修改css:给FCKeditor\editor\css\fck_internal.css增加

.FCK__Media
{
 border: darkgray 1px solid;
 background-position: center center;
 background-image: url(images/fck_medialogo.gif);
 background-repeat: no-repeat;
 width: 80px ;
 height: 80px ;
}

.FCK__Realplay
{
 border: darkgray 1px solid;
 background-position: center center;
 background-image: url(images/fck_realplaylogo.JPG);
 background-repeat: no-repeat;
 width: 80px ;
 height: 80px ;
}
c。修改js,主要以realplay做示例
FCKeditor\editor\js\fckeditorcode_ie_1.js,在FCKDocumentProcessors.addItem(FCKFlashProcessor);后面增加
// Realplay begin
var FCKRealplayProcessor=new Object();
FCKRealplayProcessor.ProcessDocument=function(A){
    var B=A.getElementsByTagName('EMBED');
    var C;
    var i=B.length-1;

while (i>=0&&(C=B[i--])){
if (C.src.endsWith('.rm',true) || C.src.endsWith('.ram',true) || C.src.endsWith('.ra',true))
{var D=FCKDocumentProcessors_CreateFakeImage('FCK__Realplay',C.cloneNode(true));
D.setAttribute('_fckRealplay','true',0);
FCKRealplayProcessor.RefreshView(D,C);
C.parentNode.insertBefore(D,C);
C.parentNode.removeChild(C);
};
};
};

FCKRealplayProcessor.RefreshView=function(A,B){
    if (B.width>0) A.style.width=FCKTools.ConvertHtmlSizeToStyle(B.width);
    if (B.height>0) A.style.height=FCKTools.ConvertHtmlSizeToStyle(B.height);
};
FCKDocumentProcessors.addItem(FCKRealplayProcessor);
// Realplay end
var FCKMediaProcessor=new Object();
FCKMediaProcessor.ProcessDocument=function(A)
{
    var B=A.getElementsByTagName('EMBED');
    var C;
    var i=B.length-1;
    while (i>=0&&(C=B[i--]))
    {
        if (C.src.endsWith('.avi',true) || C.src.endsWith('.mpg',true) || C.src.endsWith('.mpeg',true))
        {
            var D=FCKDocumentProcessors_CreateFakeImage('FCK__Media',C.cloneNode(true));
            D.setAttribute('_fckmedia','true',0);FCKMediaProcessor.RefreshView(D,C);
            C.parentNode.insertBefore(D,C);C.parentNode.removeChild(C);
        };
    };
};
FCKMediaProcessor.RefreshView=function(A,B)
{
    if (B.width>0) A.style.width=FCKTools.ConvertHtmlSizeToStyle(B.width);
    if (B.height>0) A.style.height=FCKTools.ConvertHtmlSizeToStyle(B.height);
};
FCKDocumentProcessors.addItem(FCKMediaProcessor);

然后修改FCK.GetRealElement方法为下面代码,该方法为处理编辑器中width和height的调整
FCK.GetRealElement=function(A){
var e=FCKTempBin.Elements[A.getAttribute('_fckrealelement')];

if (A.getAttribute('_fckflash')|| A.getAttribute('_fckrealplay') || A.getAttribute('_fckmedia')){
    if (A.style.width.length>0) e.width=FCKTools.ConvertStyleSizeToHtml(A.style.width);
    if (A.style.height.length>0) e.height=FCKTools.ConvertStyleSizeToHtml(A.style.height);
};
return e;};

----------
FCKeditor\editor\js\fckeditorcode_ie_2.js
FCKCommands.GetCommand方法增加
case 'Media':B=new FCKDialogCommand('Media',FCKLang.DlgMediaTitle,'dialog/fck_Media.html',450,400);
break;
case 'Realplay':B=new FCKDialogCommand('Realplay',FCKLang.DlgMediaTitle,'dialog/fck_Realplay.html',450,400);
break;

FCKToolbarItems.GetItem方法增加

case 'Media':B=new FCKToolbarButton('Media',FCKLang.InsertMediaLbl,FCKLang.InsertMedia);
break;
case 'Realplay':B=new FCKToolbarButton('Realplay',FCKLang.InsertRealplayLbl,FCKLang.InsertRealplay);
break;
FCKContextMenu._GetGroup方法增加
case 'Media':return new FCKContextMenuGroup(true,this,'Media',FCKLang.MediaProperties,true);
case 'Realplay':return new FCKContextMenuGroup(true,this,'Realplay',FCKLang.RealplayProperties,true);   // truly

FCKContextMenu.RefreshState方法增加
if (this.Groups['Media'])   this.Groups['Media'].SetVisible(B=='IMG'&&A.getAttribute('_fckmedia'));
if (this.Groups['Realplay'])  this.Groups['Realplay'].SetVisible(B=='IMG'&&A.getAttribute('_fckrealplay'));


然后要增加'dialog/fck_Media.html'和'dialog/fck_Realplay.html'页面,具体我懒得再写了,自己到我的源码下载里看,我是在2。1的基础上改的,2.2要做一些调整!

fckconfig.js也有较多调整,但是这个文件非常简单,自己去看我的源码吧。
然后就是lang目录中对常量的定义,搜索一下就很容易得到,没什么可讲。

在然后就可以了,:)。



三、添加删除按钮列,类似sina的blog中的编辑控件

四、修改上传路径
        默认是根目录/UserFiles,有多种方式进行修改,先看一下它的源码:
protected string UserFilesPath
{
 get
 {
  if ( sUserFilesPath == null )
  {
   // Try to get from the "Application".
   sUserFilesPath = (string)Application["FCKeditor:UserFilesPath"] ;

   // Try to get from the "Session".
   if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )
   {
    sUserFilesPath = (string)Session["FCKeditor:UserFilesPath"] ;

    // Try to get from the Web.config file.
    if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )
    {
     sUserFilesPath = System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:UserFilesPath"] ;

     // Otherwise use the default value.
     if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )
      sUserFilesPath = DEFAULT_USER_FILES_PATH ;

     // Try to get from the URL.
     if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )
     {
      sUserFilesPath = Request.QueryString["ServerPath"] ;
     }
    }
   }

   // Check that the user path ends with slash ("/")
   if ( ! sUserFilesPath.EndsWith("/") )
    sUserFilesPath += "/" ;
  }
  return sUserFilesPath ;
 }
}

由此,可以在Global里或者程序任意位置(加载fckeditor前可以运行到的位置)设置Application["FCKeditor:UserFilesPath"] ,或者Session,或者Webconfig,或者action中的请求参数等。


to be continued...


附:js版FCKEditor下载:http://prdownloads.sourceforge.net/fckeditor/FCKeditor_2.2.zip
.net版
http://prdownloads.sourceforge.net/fckeditor/FCKeditor.Net_2.2.zip
所有版本列表
http://prdownloads.sourceforge.net/fckeditor

更多精彩内容其他人还在看

FCKEditor常用Js代码,获取FCK内容,统计FCK字数,向FCK写入指定代码

FCKEditor常用Js代码,获取FCK内容,统计FCK字数,向FCK写入指定代码,使用FCKEditor的朋友可以参考下。增加编辑器的人性化功能。
收藏 0 赞 0 分享

CKEditor网页编辑器 中文使用说明

安装CKEditor是一件容易的工作,只需要按照下面的简单步骤就可以完成。多测试。
收藏 0 赞 0 分享

FCKeditor 和 SyntaxHighlighter 代码高亮插件的整合

FCKeditor 和 SyntaxHighlighter 代码高亮插件的整合方法,里面有下载,可以根据需要结合自己的fckeditor版本。
收藏 0 赞 0 分享

eWebEditor 请选择一个有效的文件的解决方法

解决eWebEditor上传图片提示 请选择一个有效的文件
收藏 0 赞 0 分享

Ewebeditor 不能粘贴或复制的解决方法

在调试网站后台时,遇见用EWEBEDITOR编辑内容时,不能从其他文件来源粘贴到里面.
收藏 0 赞 0 分享

javascript fckeditor编辑器取值与赋值实现代码

这篇文章对于使用fckeditor编辑器的朋友是个不错应用,主要介绍的是js对fckeditor的取值与赋值操作,fckeditor是个不错的比较方便的扩展功能的编辑器。
收藏 0 赞 0 分享

Html 编辑器粘贴内容过滤技术详解

最近在解决数据粘贴方面取得了不少进展,作为Html在线编辑器所必须具备的技术,在这里详细给大家介绍并提供实现参考。
收藏 0 赞 0 分享

Js FCKeditor的值获取和修改的代码小结

FCKeditor编辑器是比较流行的一款编辑器,很多cms系统都在使用,免费而功能强大。容易扩展等特性赢得了大家的喜爱。
收藏 0 赞 0 分享

22个国外的Web在线编辑器收集

本文搜集了 22 个 Web 在线编辑器,它们基本代表了当前 Web 编辑器的现状。
收藏 0 赞 0 分享

FCKeditor添加自定义按钮的方法

FCKLang是语言包对象,您只要打开FCK/editor/lang/下面的相应语言包添加相应的名称属性就可以了,比如:MyAlbum打开我的像册。注意大小写!至此我们的添加工作已完成。
收藏 0 赞 0 分享
查看更多