GVKun编程网logo

Ckeditor在Java项目中与Extjs结合使用(javaeditorcr怎么用)

14

最近很多小伙伴都在问Ckeditor在Java项目中与Extjs结合使用和javaeditorcr怎么用这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展CKEditor/FCKEd

最近很多小伙伴都在问Ckeditor在Java项目中与Extjs结合使用javaeditorcr怎么用这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展CKEditor/FCKEditor 使用 CKeditor 3.0.1 快速使用教程(含插入图片)、CKEditor/FCKEditor 使用FCKeditor 2.6.5 快速使用教程(含插入图片)、CKEditor3.x 在Java项目中配置、包括图片上传(支持FTP、图片压缩)、CKEditor在jQuery UI重新排序时冻结等相关知识,下面开始了哦!

本文目录一览:

Ckeditor在Java项目中与Extjs结合使用(javaeditorcr怎么用)

Ckeditor在Java项目中与Extjs结合使用(javaeditorcr怎么用)

一、              配置所需文件及jar包

1、  ckeditor.zip,解压后放入web项目WebRoot目录中(可自定义子目录)

2、  ckeditor-java-core.jar,放入web项目WebRoot/WEB-INF/lib目录中

下载地址:http://ckeditor.com/download

3、  其他所需资源jar包已集成在struts2-core.jar中

二、              简单的使用

1、  导入ckeditor.js

<script type="text/javascript" src="ckeditor/ckeditor.js"></script>

2、  一般是使用一个”<textarea>”来显示内容,然后替换成CKEditor编辑器

<textarea cols="80" id="content" name="fileUpload"> </textarea>

<script type="text/javascript">

CKEDITOR.replace(''content''); //content为textarea的id

</script>

三、              项目中的使用

1、  在WebRoot/ckeditor/config.js中使用自定义的工具条,加上自定义的按钮"addpic"和插件定义:CKEDITOR.editorConfig = function( config )

{

config.toolbar = […,

[''addpic''],

…];

};

config.extraPlugins = ''addpic'';

2、  在WebRoot/ckeditor/plugins/下新建文件夹addpic,文件夹下有自定义图片(14px*13px)作为按钮的图标,和自定义的plugin.js文件:

(function () {

    //Section 1 : 按下自定义按钮时执行的代码

    var a = {

        exec: function (editor) {

            editor.show();

        }

    },

    b = ''addpic'';

    CKEDITOR.plugins.add(b, {

        init: function (editor) {

            editor.addCommand(b, a);

            editor.ui.addButton(''addpic'', {

                label: ''添加图片'',

                icon: this.path + ''addpic.png'',//自定义图片按钮路径名称

                command: b

            });

        }

    });

})();

3、  自定义的show方法:(WebRoot/scripts/comm/extCkeditorFun.js)

/*html编辑器图片上传*/

SMFshow=function(editorId){

    var _items=[{

        xtype:''panel'',

         width:270,

        border:false,

        bodyStyle:''font-size:12px;color:red;'',

        html:''文件名中含有特殊字符或文件名过长都会导致上传失败!''

    }];

    var ff=function(){

        var f=new Ext.form.TextField({

            inputType:''file'',

            width:210,

            hideLabel:true

        });

        var p=new Ext.Panel({

           layout:''form'',

           width:280,

           border:false,

           items:[f]

        });       

        return p;

    }

    _items.push(ff());

    //按钮

    var _buttons=[];

    _buttons.push({

        text:''确定插入'',

        handler:function(){

             if(uploadForm.form.isValid()){

                uploadForm.form.doAction(''submit'',{

                  waitTitle:''上传文件'',

                  waitMsg:''正在上传文件……'',

                  url:''../ckeditor/fileUploadAction.action'',//自定义后台处理上传文件Action(配置映射到com.fun.ExtCkeditorAction)

                  method:''post'',

                  success:function(form,action){

            //插入图片

            var result=action.result;

            if(result.error){  //Java程序中返回的json串中自定义的属性error,这个地方要根据自己的需要判断出错

                alert(''图片插入失败,请检查文件名!'');

                return;

            }

//SMF.base为预定义的根路径,result.filename也是返回的json串中自定义的属性。我把上传的文件都放到images/htmlEditor目录下了,所以只需要返回文件名就行。

var img=

''<img src="''+SMF.base+''/images/htmlEditor/''+result.filename+''"/>'';

                InsertHTML(img);

                win.close();

                  },failure:function(form,action){

                alert(''图片插入失败,请检查文件名!'');

                  }       

                });

             }

        }

    },{

        text:''取消'',

        handler:function(){

            win.close();

        }

    });

    var uploadForm=new Ext.form.FormPanel({

        fileUpload :true,

        items:_items,

        buttons:_buttons,

        bodyStyle:''padding:5px;'',

        autoScroll:true

    })

    var win=new Ext.Window({

        title:''插入图片'',

        width:330,

        height:300,

        layout:''fit'',

        modal:true,

        items:uploadForm

    });

    win.show();

    var InsertHTML=function(value){

        // Get the editor instance that we want to interact with.

        var oEditor = CKEDITOR.instances[editorId];

        // Check the active editing mode.

        if ( oEditor.mode == ''wysiwyg'' ){

            oEditor.insertHtml( value );

        }

    }       

}

4、  ExtCkeditorAction:

execute() {

           imagePath//服务器上物理地址

    pagePath//服务器上web地址(前端调用该地址供客户端访问)

}

copy(myFile, imageFile){

           //读入myFile写到imageFile

           //myFile为上传的文件

           //imageFile为服务器上物理文件

}

5、  使用ckeditor:(dc16.js)

(1)新建id为description(id名称自己取)的textarea,EXT中为Ext.form.TextArea

var dtl = new Ext.form.TextArea({

id : ''description'',

           name : ''DETAIL'',

           allowBlank : false,

           blankText : ''详细内容不能为空'',

           disabled : false,

           autoWidth : true

});

(2)然后在适当的地方执行

var editor=CKEDITOR.replace(''description'');

editor.show=function(){
  SMFshow(''description'');
}//注意:Ext组件的加载延迟

//ckeditor初始化时editor.setData('''');

//或加载数据时editor.setData(result.data[''description'']);//Ext里的result

6、  销毁当前组件时需移除editor,否则下次加载时会失败:

listeners : {

         ''beforedestroy'' : function(v) {

                    if(editor!=null) {

                             CKEDITOR.remove(editor);

                    }

                    editorPanel.destroy();

           }

}

 

CKEditor/FCKEditor 使用 CKeditor 3.0.1 快速使用教程(含插入图片)

CKEditor/FCKEditor 使用 CKeditor 3.0.1 快速使用教程(含插入图片)

因为直接把内容作为字符串给编辑器的 Value 属性赋值使用的是 JavaScript 代码,要让 JS 代码不受内容中双引号、换行等的干扰,只有先读入到 textarea 最方便。

使用 CKeditor 3.0.1
复制代码 代码如下:

<textarea cols="90" rows="10" id="content" name="content">cftea</textarea>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
<!--
CKEDITOR.replace("content");
//-->
</script>

可以看出,3.x 版本的使用非常方便,也不用担心会形成两个同名的 content。实际上 textarea 的 id 省略了也是可以的,因为 CKEditor 会先按 name 来查找,查找不到,再按 id 来查找。

并且编辑器会在 textarea 的位置替换原有的 textarea。

设置编辑器皮肤、宽高
复制代码 代码如下:

<textarea cols="90" rows="10" id="content" name="content">cftea</textarea>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
<!--
CKEDITOR.replace("content",
{
skin: "kama", width:700, height:300
});
//-->
</script>

skin 值应该是 ckeditor/skins 文件夹下的某个文件夹名称,如果指向不存在的皮肤,则不会显示编辑器。

设置值、取值

设置值

CKEDITOR.instances.content.setData(""); // content 就是前面 CKEDITOR.replace 的第一个参数值

复制代码 代码如下:

var editor = CKEDITOR.replace("content");
editor.setData("");

取值

alert(CKEDITOR.instances.content.getData()); // content 就是前面 CKEDITOR.replace 的第一个参数值


var editor = CKEDITOR.replace("content");
alert(editor.getData());
插入图片

若要演示此示例,最好是放在按钮的事件处理程序中,目的是有些延迟。

CKEDITOR.instances.content.insertHtml("<img src=...>");
您可能感兴趣的文章:

CKEditor/FCKEditor 使用FCKeditor 2.6.5 快速使用教程(含插入图片)

CKEditor/FCKEditor 使用FCKeditor 2.6.5 快速使用教程(含插入图片)

其开源协议是基于 GPL, LGPL 和 MPL 的。官方网站:http://ckeditor.com/

一般来说,我们在编辑内容时,先是读入到 textarea,再将 textarea 的内容赋给编辑器。因为直接把内容作为字符串给编辑器的 Value 属性赋值使用的是 JavaScript 代码,要让 JS 代码不受内容中双引号、换行等的干扰,只有先读入到 textarea 最方便。

使用 FCKeditor 2.6.5
复制代码 代码如下:

<div><textarea id="fckcontent" name="content">cftea</textarea></div>
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
<script type="text/javascript">
<!--
var oFCKeditor = new FCKeditor("fckcontent");
oFCKeditor.BasePath = "fckeditor/"; // fckeditor 文件夹位置。
oFCKeditor.Create();
//-->
</script>

本来应该用 display:none 将 textarea 隐藏起来,不过为了查看效果,这里不隐藏。

这样编辑器就自动与 fckcontent 关联起来了,打开网页时 FCKeditor 自动读取 textarea 的内容,提交时又自动将其内容(自动为 XHTML)赋给 textarea。

注意,我们 textarea 的 id 和 name 值不一样,为什么呢?

这里应该是这个版本不太完善的地方,如果我们把 textarea 的 id 和 name 值设置为一样,那么 FCKeditor 文本区的 name 值也是 content,在服务器端 Request.Form("content").Count 就会有两个,我们服务器端取值就稍稍有点不方便,得用 Request.Form("content")(0)。如果我们将 id 设为 fckcontent,那么 FCKeditor 文本区的 name 就是 fckcontent,与 textarea 不同名。

设置编辑器宽高

var oFCKeditor = new FCKeditor("fckcontent", 500, 300);

复制代码 代码如下:

var oFCKeditor = new FCKeditor("fckcontent");
oFCKeditor.Width = 500;
oFCKeditor.Height = 300;

设置工具条

var oFCKeditor = new FCKeditor("fckcontent", 500, 300, "Basic");
注意第四个参数,其可选值有 Basic、Default,注意大小写不可搞错,分别表示基本工具条、默认工具条(全部按钮)。

设置初始值、设置值、取值

设置初始值

实际上设置初始值很少用,因为一般都是与 textarea 关联的,故只是简单列出来一下,不深究。说明一下,如果关联的 textarea 存在,则赋初始值是没有用的。

var oFCKeditor = new FCKeditor("fckcontent2", 500, 300, "Default", "");

复制代码 代码如下:

var oFCKeditor = new FCKeditor("fckcontent2", 500, 300, "Default");
oFCKeditor.BasePath = "fckeditor/";
oFCKeditor.Value = "cftea"; // 必须在 Create 之前
oFCKeditor.Create();

设置值

若要演示此示例,最好是放在按钮的事件处理程序中,目的是有些延迟,否则会说 FCKeditorAPI 未定义。
复制代码 代码如下:

var oEditor = FCKeditorAPI.GetInstance("fckcontent");
oEditor.SetHTML("");

取值

若要演示此示例,最好是放在按钮的事件处理程序中,目的是有些延迟,否则会说 FCKeditorAPI 未定义。
复制代码 代码如下:

var oEditor = FCKeditorAPI.GetInstance("fckcontent");
alert(oEditor.GetXHTML()); // 还有个类似方法是 GetHTML,但不推荐用 GetHTML。

您这样做很危险:
复制代码 代码如下:

var oEditor = FCKeditorAPI.GetInstance("fckcontent");
oEditor.SetHTML("");
alert(oEditor.GetXHTML()); // 这里的值并不一定是上一句赋的值。因为他们太近了,值还没来得及赋,就已经 alert 了。

插入图片

若要演示此示例,最好是放在按钮的事件处理程序中,目的是有些延迟,否则会说 FCKeditorAPI 未定义。

FCKeditorAPI.GetInstance("fckcontent").InsertHtml("<img src...>");

CKEditor3.x 在Java项目中配置、包括图片上传(支持FTP、图片压缩)

CKEditor3.x 在Java项目中配置、包括图片上传(支持FTP、图片压缩)

CKEditor 3.x配置说明

一、基本使用:

 1、所需文件架包

A. Ckeditor基本文件包,比如:ckeditor_3.6.2.zip

  下载地址:http://ckeditor.com/download

 

 2、配置使用

A.将下载下来的CKEditor压缩解压,将解压后的文件夹(“ckeditor”)拷贝进项目里面,比如我是放在”WebContent”的”commons”文件夹下;

B.在需要使用CKEditor的页面引入CKEditor的支持javascript

<head>

<script type="text/javascript" src="/commons/ckeditor/ckeditor.js"></script>

</head>

 

C.一般我们的内容是使用一个”<textarea>”来显示内容,然后使用调用脚本替换

<textarea id="editor1"name="editor1">Initial value.</textarea>

<script type="text/javascript">CKEDITOR.replace(“editor1”);</script>

D.CKEDITOR.replace(“editor1”)中的”editor1”为id或者是name搜索方式默认是先按id来搜索,没找到再按name来搜索

E.具体的图例

 


二、Java项目中配置使用:

1、所需文件架包

A.Ckeditor基本文件包,比如:ckeditor_3.6.2.zip

  下载地址:http://ckeditor.com/download

B.CKEditor for Java 架包,比如:ckeditor-java-core-3.5.3.jar

      下载地址:http://ckeditor.com/download

 2、配置使用

A.将下载下来的CKEditor压缩解压,将解压后的文件夹(“ckeditor”)拷贝进项目里面,比如我是放在”WebContent”的”commons”文件夹下;

B.将下载下来的CKEditorfor Java 包(ckeditor-java-core-3.5.3.jar)复制进项目” /WEB-INF/lib”目录;

C.在需要使用CKEditor的jsp页面配置CKEditor的标签,以后使用通过标签使用

<%@ taglib uri="http://ckeditor.com" prefix="ckeditor"%>

D.一般我们的内容是使用一个”<textarea>”来显示内容,然后替换成CKEditor编辑器

<textareaid="id_1"name="id_1">Initial value.</textarea> 

<ckeditor:replacereplace="id_1"basePath="/commons/ckeditor/"/>

   * replace 只的是textarea name或者id
* basePath CKEditor的根目录

E.具体图例

            

三、Java项目中配置使用并支持简单的图片上传功能:

CKEditor在Java项目中配置使用,并支持图片的上传功能。原理是通过showModalDialog来实现的,弊端不支持Chrome浏览器,IE,FireFox支持;

1、所需文件架包

A.Ckeditor基本文件包,比如:ckeditor_3.6.2.zip

  下载地址:http://ckeditor.com/download

B.CKEditor for Java 架包,比如:ckeditor-java-core-3.5.3.jar

     下载地址:http://ckeditor.com/download

 2、配置使用

A.将下载下来的CKEditor压缩解压,将解压后的文件夹(“ckeditor”)拷贝进项目里面,比如我是放在”WebContent”的”commons”文件夹下;

B.将下载下来的CKEditorfor Java 包(ckeditor-java-core-3.5.3.jar)复制进项目” /WEB-INF/lib”目录;

C.在需要使用CKEditor的jsp页面配置CKEditor的标签,以后使用通过标签使用

<%@ taglib uri="http://ckeditor.com" prefix="ckeditor"%>

D.一般我们的内容是使用一个”<textarea>”来显示内容,然后替换成CKEditor编辑器

<textareaid="id_1"name="id_1">Initial value.</textarea> 

<ckeditor:replacereplace="id_1"basePath="/commons/ckeditor/"/>

   * replace 只的是textarea name或者id
   * basePath CKEditor的根目录
 

E简单快捷的给CKEditor加上图片上传功能

 

         CKEditor非常好用,但它的图片/文件上传使用了CKFinder,虽然功能非常强大,但集成起来还是比较麻烦,而且根据应用还需要改造。如果自己的应用已经有图片/文件上传模块,能否直接拿过来用呢?答案是肯定的,而且非常简单,就是在图片链接输入框的右边加个按钮,点击事件链接到已有的上传模块,上传后把图片的url传递给左边的输入框即可。步骤如下:

  打开ckeditor\plugins\image\dialogs\image.js,在链接输入框代码结尾也就是“m.lang.image.urlMissing)},后面加上这些代码:

{type:''button'',id:''myUpload'',align:''center'',label:''新上传'',onClick:function(){varretFile = showModalDialog("/common/uploadImage.jsp","", "dialogHeight:20;dialogWidth:29;"); if(retFile !=null){this.getDialog().setValueOf(''info'',''txtUrl'',retFile);}}},

  /common/uploadImage.jsp是应用已经有的上传模块链接,上传成功后通过模式对话框的returnValue返回图片链接,比如在上传成功页面加上如下js函数,点击确定时调用。

function Done() {

  window.returnValue = imgPath;//上传后的图片链接

  window.close();

}

F.具体图例

 

四、Java项目中配置使用并支持图片上传功能包括FTP上传,图片压缩:

CKEditor在Java项目中配置使用,并支持图片的上传功能。原理是通过commons-fileupload上传组件实现的,这里已经封装好上传处理Servlet只需要在配置文件ckeditor.properties 中配置相关FTP服务器信息,是否压缩图片,上传附件的大小格式限制等。

1、所需文件架包和配置文件

A.Ckeditor基本文件包,比如:ckeditor_3.6.2.zip

  下载地址:http://ckeditor.com/download

B.CKEditor for Java 架包,比如:ckeditor-java-core-3.5.3.jar

     下载地址:http://ckeditor.com/download

C.Apache的上传组包 commons-fileupload,比如:commons-fileupload-1.2.1.jar

   下载地址:http://commons.apache.org/

D.Apache的上传组包 commons-io,比如:commons-io-1.4.jar

   下载地址:http://commons.apache.org/

E.Apache的FTP组件包commons-net, 比如:commons-net-ftp-2.0.jar

   下载地址:http://commons.apache.org/

F.Apache的工具包 commons-lang,比如:commons-lang-2.5.jar

   下载地址:http://commons.apache.org/

G.上传处理组件包 ckeditor-upload-1.0.jar

         自己封装的基于Servlet的图片上传处理组件

H.CKEditor的图片上传配置属性文件:ckeditor.properties

I.CKEditor的配置文件 config.js


备注:点击下载以上资源包

 

 2、配置使用

A.将下载下来的CKEditor压缩解压,将解压后的文件夹(“ckeditor”)拷贝进项目里面,比如我是放在”WebContent”的”commons”文件夹下;

B.将下载下来的所需组件架包拷贝进项目” /WEB-INF/lib”目录;

         C.将图片上传配置文件ckeditor.properties拷贝到项目SRC(classes)根目录下

          属性文件内容如下:

# default allowed extensionssettings

ckeditor.resourceType.media.extensions.allowed=.aiff|.asf|.avi|.bmp|.fla|.flv|.gif|.jpeg|.jpg|.mid|.mov|.mp3|.mp4|.mpc|.mpeg|.mpg|.png|.qt|.ram|.rm|.rmi|.rmvb|.swf|.tif|.tiff|.wav|.wma|.wmv

# base directory for the userfiles relative to the context root

ckeditor.userFilesPath = /files/ckeditor/

# default encoding

ckeditor.encoding = UTF-8

# default file size threshold: 1*1024*1024 = 1048576

ckeditor.size.threshold = 1048576

# default one file size :5*1024*1024 = 52428800

ckeditor.file.size.max = 52428800

# default all files size :10*1024*1024 = 10485760

ckeditor.size.max = 10485760

# some messages

message.request.not.contain.images= Requestdoes not contain image or media file.

message.request.general.form = Request is thegeneral form.

message.request.file.max = One file is toolarge.

message.request.all.file.max = All files is toolarge.

# ftp configurations

# open ftp file upload istrue otherwise false

ftp.upload = true


ftp.server = 127.0.0.1

ftp.user_name = jjy

ftp.password = 123

ftp.port = 21

 

# image resize configurations

# open image resize is trueotherwise false

image.resize = true

#resizeByMaxSize:0,resizeByRatio:1,resizeByFixedWidth:2,resizeByFixedHeight:3

image.resize.type = 0

# resize size 100,120,240,400,640

image.resize.size = 120,240,400

 

D.CKEditor配置文件” /ckeditor/config.js”修改

 

CKEDITOR.editorConfig = function(config) {

    //获取项目的目录比如:http://www.mymyty.com

    var strFullPath = window.document.location.href;

    var strPath = window.document.location.pathname;

    var pos = strFullPath.indexOf(strPath);

    var prePath = strFullPath.substring(0,pos);

    var postPath =strPath.substring(0,strPath.substr(1).indexOf(''/'')+1);

    var path_url = prePath+postPath;

 

    //显示出图片上传模块 

    config.pasteFromWordRemoveStyles = true;

    config.filebrowserImageUploadUrl = path_url + "/commons/ckeditor/images/upload.html"; //为图片上传处理Servletweb.xml中配置

 

    // 去掉ckeditor保存按钮 

    config.removePlugins = ''save'';

};

 图片

 

E.在web.xml中配置Servlet

  <servlet>

    <servlet-name>ckeditor</servlet-name>

    <servlet-class>com.ebiz.ssi.ckeditor.CkeditorImagesUploadServlet</servlet-class>

       <load-on-startup>1</load-on-startup>

    </servlet>

<servlet-mapping>

     <servlet-name>ckeditor</servlet-name>

     <url-pattern>/commons/ckeditor/images/upload.html</url-pattern>

</servlet-mapping>

  图片:

 

 

F.在需要使用CKEditor的jsp页面配置CKEditor的标签,以后使用通过标签使用

<%@ taglib uri="http://ckeditor.com" prefix="ckeditor"%>

G.一般我们的内容是使用一个”<textarea>”来显示内容,然后替换成CKEditor编辑器

<textareaid="id_1"name="id_1">Initial value.</textarea> 

<ckeditor:replacereplace="id_1"basePath="/commons/ckeditor/"/>

   * replace 只的是textarea name或者id
* basePath CKEditor的根目录
 

H.具体图例

 

五、CKEditorconfig.js配置文件的说明即样式自定义调整:

Congfig.js是CKDitor的配置文件,在这个里面可以修改编辑器的样式和所需工具栏等等

 

config.language= ''zh-cn'';         // 编辑器语言
config.width =600;                  //初始化时的宽度

config.height = 400;           //初始化时的高度
config.skin=''kama'';        //编辑器样式,有三种:’kama’(默认)、’office2003′、’v2′
config.tabSpaces =4;               
config.resize_maxWidth =600;    //如果设置了编辑器可以拖拽 这是可以移动的最大宽度
config.toolbarCanCollapse =false;             //工具栏可以隐藏
//config.toolbarLocation =''bottom'';       //可选:设置工具栏在整个编辑器的底部bottom
config.resize_minWidth =600;    //如果设置了编辑器可以拖拽 这是可以移动的最小宽度
config.resize_enabled =false;            //如果设置了编辑器可以拖拽

//以下是后添加的验证非法数据
config.protectedSource.push(/<\s*iframe[\s\S]*?>/gi); //<iframe>tags.              
config.protectedSource.push(/<\s*frameset[\s\S]*?>/gi); // <frameset> tags.
config.protectedSource.push(/<\s*frame[\s\S]*?>/gi); // <frame> tags.
config.protectedSource.push(/<\s*script[\s\S]*?\/script\s*>/gi); // <SCRIPT> tags.

config.baseFloatZIndex = 10000;   // 编辑器的z-index值

config.baseHref = “”;    //设置是使用绝对目录还是相对目录,为空为相对目录

 

六、CKEditor精简说明:

下载了完整的程序之后,先要对程序中的不必要的东西进行删除。凡是文件名或文件夹名前面有"_"的文件或文件夹都可以删除,这些文件是一些说明文件或者实例文件。另外,./lang文件夹中,只保留:zh_cn.js,en.js文件即可,这个文件夹是程序的语言包,因为其它语言大家用不到,放在那里也占用空间,所以删掉。./skins文件夹是编辑器的界面,根据情况保留至少一个文件夹即可,其中kama是可自定颜色UI的文件,建议保留,当然如果不在乎空间大小的话,也可以全部上传。删除根目录下的changes.html(更新列表),install.html(安装指向),license.html(使用许可).

 

CKEditor在jQuery UI重新排序时冻结

CKEditor在jQuery UI重新排序时冻结

我试图使用jQuery UI框架重新排序动态创建的CKEditors列表,但我遇到了编辑器释放的问题.当我刚刚使用< textarea>时,它工作得很好,但现在,在拖动操作完成后,它不会让用户写任何文本.

这是Javascript代码:

$(function() {
    $("#list").sortable({
        placeholder: 'ui-state-highlight'
    });
    $("#list").disableSelection();

    for (i=0;i<10;i++)
    {
        addEditor();
    }
});

function addEditor()
{
    alert("Hello");
    var editor_fields = document.editors.elements["editor[]"];

    var editorAmount = 0;

    if (editor_fields.length)
    {
        editorAmount = editor_fields.length;
    }
    else
    {
        editorAmount = 1;
    }

    var newElem = $('#editor_container' + editorAmount).clone().attr('id','editor_container' + (editorAmount + 1));

    newElem.html("<textareaname='editor[]' id='editor" + (editorAmount + 1) + "' rows='4' cols='30'></textarea>");

    $("#editor_container" + editorAmount).after(newElem);

    $("#editor" + (editorAmount + 1)).ckeditor();
}

这是HTML代码:

<form name="editors">
    <ul id="list">
        <li name="editor_container1" id="editor_container1"><textarea name='editor[]' id='editor1' rows='4' cols='30'></textarea></li>
    </ul>
</form>

解决方法

虽然不理想,但我发现了一个潜在的解决方案:
$(function () {
        $("#list").sortable({
            placeholder: 'ui-state-highlight',start: function () {
                $('.editor').each(function () {
                    $(this).ckeditorGet().destroy();
                });
            },stop: createckeditor()
        });
        $("#list").disableSelection();

        for (i = 0; i < 10; i++) {
            createckeditor()
        }
    });

    function createckeditor() {
        $(".editor").ckeditor();
    }

这对我有用,因为当你拖动某些东西时,所有编辑器都可以被销毁并重新创建.它可能会被调整为仅删除被拖动的项目.

关于Ckeditor在Java项目中与Extjs结合使用javaeditorcr怎么用的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于CKEditor/FCKEditor 使用 CKeditor 3.0.1 快速使用教程(含插入图片)、CKEditor/FCKEditor 使用FCKeditor 2.6.5 快速使用教程(含插入图片)、CKEditor3.x 在Java项目中配置、包括图片上传(支持FTP、图片压缩)、CKEditor在jQuery UI重新排序时冻结等相关内容,可以在本站寻找。

本文标签: