`

ext学习之fckeditor的使用

    博客分类:
  • ext
阅读更多
1.下载fckeditor的包http://ckeditor.com 官网.
我就直接进入下载与java关联的一个项目.
https://sourceforge.net/projects/fckeditor/files/FCKeditor.Java/2.6/


直接将其一个demo下载下来..

2.打开fckeditor-java-demo-2.6.war.zip这个包.使用eclipse建立一个项目叫做fckeditordemo.然后将其文件夹下的所有数据都复制到WebContent下面


3.将项目部署入tomcat访问..http://localhost:8080/fckeditordemo/index.jsp
将会出现一个demo。你可以点击图片上传进行图片的管理..


4.确认了fckeditor可以使用了之后.我们就要使用到ext来调用了.首先在eclipse下面建立一个js文件.把ext2或者3存放到下面.然后建立KnowledgeManager文件夹.下面就是建立自己的js
KnowlegeForm.js。使用晚上的demo修改的.下面也是网上搜到最多的例子.个人觉得有点麻烦.
var KnowledgeForm = function(_title) {
	return this.setup();
};

KnowledgeForm.prototype.setup = function() {//内容初始化.
var fckeditorFormPanel = new Ext.FormPanel({
        labelWidth: 75, 
        url:'',
        frame:true,
        title: 'fckeditorForm',
        bodyStyle:'padding:5px 5px 0',
        width: 950,
        height:450,
          defaultType: 'textfield',
	        items:[
	            {
	            	fieldLabel:'知识标题',
	            	name:'knowledgeTitle',
	            	blankText: '知识标题为必填!',
	            	id:'knowledgeTitle'
	            },
	            {
	            	fieldLabel:'知识内容',
	            	xtype:'textarea',
	            	name:'knowledgeContent',
	            	blankText: '知识内容为必填!',
	            	id:'knowledgeContent'
	            }
	            ],
        buttons: [{
            text: 'Save',
			type:'submit',
            handler: function() {
                Ext.get('knowledgeContent').dom.value=editorInstance.GetXHTML( true );//获取fckeditor内容赋给textarea
                alert(Ext.get('knowledgeContent').dom.value);
                if(fckeditorFormPanel.form.isValid()){//验证通过
                    fckeditorFormPanel.form.doAction('submit',{
			              url:'submit.do',
			              method:'post',
						  waitMsg:'正在提交,请稍等...',
			              success:function(form,action){//成功返回	
	                          	
			              },
			              failure:function(form,action){//失败返回
	                          
			              }
	                });
                }
	        }
        },{
            text: 'Cancel'
        }]
    });  
    fckeditorFormPanel.render(document.body);
    /**
		 * 以下创建在线编辑器
		 */
  //knowledgeContent为你要取代的textarea的id名字
	var oFCKeditor = new FCKeditor( 'knowledgeContent',810,350 ) ; 
	oFCKeditor.BasePath = "/fckeditordemo/fckeditor/" ; //:项目的名字/fckeditor存放的路径
	oFCKeditor.ToolbarSet = 'Default';//使用默认的工具栏
	oFCKeditor.ReplaceTextarea() ;//取代textarea
}
var editorInstance;
/**
 * FCKEditor初始化完成将调用此方法
 * @param {Object} editorInstance
 */
function FCKeditor_OnComplete( instance ) {
	editorInstance=instance;
};

demo.jsp
    <link rel="stylesheet" type="text/css" href="js/ext2/resources/css/ext-all.css" />
	<script type="text/javascript" src="js/ext2/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="js/ext2/ext-all.js"></script> 
    <script type="text/javascript" src="js/ext2/build/locale/ext-lang-zh_CN.js"></script>
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript" src="fckeditor/fckeditor.js"></script><!-- 上线编辑工具 -->
    <script type="text/javascript" src="js/KnowledgeManager/KnowlegeForm.js"></script>
 	<script type="text/javascript">
 	Ext.onReady(function(){
 	 new KnowledgeForm("部门添加");
 	 });
 	</script>


下面是一个在ext官网的一个例子
http://www.extjs.com/forum/showthread.php?t=17423
他封装了一个ext.FCKeditor.js.
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:'content_1',
	id:'content_1',
	fieldLabel:'Content',
	height:270
}

KnowlegeForm2.js
var KnowledgeForm = function(_title) {
	return this.setup();
};

KnowledgeForm.prototype.setup = function() {//内容初始化.
var fckeditorFormPanel = new Ext.FormPanel({
        labelWidth: 75, 
        url:'',
        frame:true,
        title: 'fckeditorForm',
        bodyStyle:'padding:5px 5px 0',
        width: 950,
        height:450,
          defaultType: 'textfield',
	        reader: new Ext.data.JsonReader(
		        	{
		        	root:'data'
		        	},
		        	[
		        		 {name:'knowledgeId',mapping:'knowledgeId'}
		        		,{name:'knowledgeTitle',mapping:'knowledgeTitle'}
		        		,{name:'knowledgeContent',mapping:'knowledgeContent'}
		        	]
		        	),
	        
	        defaults: {
	            anchor: '95%,95%',
	            allowBlank: false,
	            selectOnFocus: true,
	            msgTarget: 'side',
	            width: 150
	        },
	        items:[{
		        	xtype:'hidden'
		        	,name:'knowledgeId'
		        	,id:'knowledgeId'
		        },
	            {
	            	fieldLabel:'知识标题',
	            	name:'knowledgeTitle',
	            	blankText: '知识标题为必填!',
	            	id:'knowledgeTitle'
	            },
	            {
	            	fieldLabel:'知识内容',
	            	xtype:'fckeditor',
	            	name:'knowledgeContent',
	            	blankText: '知识内容为必填!',
	            	id:'knowledgeContent'
	            }
	            ],
        buttons: [{
            text: 'Save',
			type:'submit',
            handler: function() {
                alert(Ext.get('knowledgeContent').dom.value);
                if(fckeditorFormPanel.form.isValid()){//验证通过
                    fckeditorFormPanel.form.doAction('submit',{
			              url:'submit.do',
			              method:'post',
						  waitMsg:'正在提交,请稍等...',
			              success:function(form,action){//成功返回	
	                          	
			              },
			              failure:function(form,action){//失败返回
	                          
			              }
	                });
                }
	        }
        },{
            text: 'Cancel'
        }]
    }); 
    return fckeditorFormPanel; 
}

demo2.jsp
    <link rel="stylesheet" type="text/css" href="js/ext2/resources/css/ext-all.css" />
	<script type="text/javascript" src="js/ext2/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="js/ext2/ext-all.js"></script> 
    <script type="text/javascript" src="js/ext2/build/locale/ext-lang-zh_CN.js"></script>
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript" src="fckeditor/fckeditor.js"></script><!-- 上线编辑工具 -->
    <script type="text/javascript" src="js/KnowledgeManager/ext.FCKeditor.js"></script>
    <script type="text/javascript" src="js/KnowledgeManager/KnowlegeForm2.js"></script>
 	<script type="text/javascript">
 	Ext.onReady(function(){
 	 new KnowledgeForm("部门添加");
 	 });
 	</script>

如果想使用的fckeditor比较符合ext风格.可以修改feckeditor里面的fckconfig.js.
将FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/default/' ;该我为FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/office2003/' ;.这里它显示将是office2003的风格
  • 大小: 40.9 KB
  • 大小: 24.8 KB
  • 大小: 109.2 KB
2
1
分享到:
评论

相关推荐

    ext-fckeditor整合

    5. **兼容性处理**:由于EXT和FCKeditor可能使用的JavaScript版本和API有所差异,可能需要进行一些兼容性处理,确保两者能够无缝协作。 压缩包中的“ext-fckeditor”可能包含了一个已经整合好的示例或者是一套整合...

    在EXT中使用FCKEditor编辑器例子

    通过学习EXT的组件体系和FCKEditor的API,你可以创建一个功能强大的文本编辑功能,提升用户体验。在实践中,你可能会遇到兼容性、性能优化或其他技术挑战,但通过查阅文档、社区问答和不断调试,这些问题都能得到...

    FCKEditor与ext结合使用

    **正文** 在Web开发中,富文本编辑器和前端框架...结合使用FCKEditor与EXT,可以创建出功能强大且用户体验优秀的Web应用。这种结合方式在内容管理系统、论坛、博客平台等场景下尤为常见,为用户提供了一流的编辑体验。

    fckeditor 与ext 集成使用

    **标题:“FCKeditor与EXT集成使用”** 在Web开发中,富文本编辑器和UI框架的集成是常见的需求,以便提供用户友好的界面和功能丰富的编辑体验。本主题主要探讨的是如何将FCKeditor(一个流行的开源JavaScript富文本...

    FCKEditor使用帮助文档

    **FCKEditor使用帮助文档** ...通过持续学习和实践,你可以根据项目需求定制FCKEditor,使其更好地服务于你的Web应用。在遇到问题时,查阅官方文档、社区资源和已有的解决方案,通常都能找到解答。

    ext-fckeditor

    从描述中我们可以推断,这个"ext-fckeditor"项目包含了完整的Java源代码,这意味着开发者可以直接查看和修改内部实现,学习如何将这两者结合使用,或者根据自己的需求进行定制。这对于那些希望在Java应用中集成富...

    FCKEDITOR 使用说明

    **FCKEditor 使用详解** FCKEditor是一款曾经非常流行的开源HTML文本编辑器,它使得在网页上创建富文本内容变得更加简单。尽管现在已经被CKEditor所取代,但FCKEditor在许多旧项目中仍然广泛使用,因此理解其工作...

    fckeditor和使用方法

    **FCKeditor简介** FCKeditor是一款开源的Web富文本编辑器,主要用于在网页上提供类似于桌面文字处理软件的编辑体验。它支持多种浏览器,包括Internet Explorer、Firefox、Chrome和Safari,使得用户可以在网页中...

    fckeditor使用手册

    **FCKeditor 使用手册** FCKeditor 是一款强大的开源富文本编辑器,广泛应用于网站内容管理系统,允许用户在网页上创建、编辑和格式化文本。本文档将详细介绍如何安装、配置、集成和优化 FCKeditor。 ### 安装 ...

    FCKeditor使用方法详解

    【FCKeditor 使用方法详解】 FCKeditor 是一个基于JavaScript的开源富文本编辑器,它在Web开发领域中被广泛使用,尤其适用于那些需要提供用户友好、可视化的文本编辑功能的网站。FCKeditor 具备强大的功能,包括...

    EXT中FCK的使用

    包含的"EXT中FCK使用"文件很可能是包含了一个完整的示例,展示如何在EXT应用中集成和使用FCKeditor。这个示例应该包括了创建FCKeditor组件的代码,以及如何在EXT布局中使用该组件的示例。通过阅读和运行这个示例,...

    asp.net文本编辑器FCKeditor使用方法详解

    ASP.NET 文本编辑器 FCKeditor 使用方法详解 FCKeditor 是一个功能强大且流行的 ASP.NET 文本编辑器,提供了许多实用的功能,如格式化文本、插入图片、上传文件、创建表格等。下面将详细介绍如何使用 FCKeditor 在 ...

    FCKeditor2.6.4使用说明

    **FCKeditor2.6.4使用说明** FCKeditor是一款功能强大的开源文本编辑器,广泛应用于网页内容编辑,尤其适合需要用户输入HTML内容的...通过不断的实践和学习,可以充分利用FCKeditor的各种功能,满足不同场景下的需求。

    FCKeditor中文使用手册

    **FCKeditor中文使用手册** FCKeditor是一款强大的开源在线文本编辑器,广泛应用于网站内容管理系统(CMS)、论坛和其他需要富文本编辑功能的Web应用中。这个中文使用手册由建站三人行站长(www.zengl.com)翻译,...

    FCKEditor使用方法

    **FCKEditor使用方法** FCKEditor是一款曾经非常流行的开源HTML文本编辑器,它允许用户在Web页面上创建和编辑富文本内容。FCKeditor以其强大的功能和易用性,被广泛应用于各种网站的后台管理系统中,使得非编程人员...

    FCKeditor 2.6.6 可直接使用

    开发者可能会选择FCKeditor因为其较低的学习曲线和更少的更新维护工作。 **在.NET环境中的应用** 标签提到了".net编辑器",这意味着FCKeditor在.NET Framework环境下也有良好的应用。.NET开发者可以利用ASP.NET...

    fckeditor php使用配置

    6. **安全性考虑**:使用FCKeditor时,需要注意XSS(跨站脚本攻击)的防范。在保存内容前,应进行HTML清理和过滤,去除可能的恶意代码。 7. **自定义图标**:`famfamfamAluminum`目录中的图标可以替换为自己的图标...

    文本编辑器FCKeditor使用方法详解--图文详解

    【FCKeditor使用方法详解】 FCKeditor是一款强大的开源文本编辑器,主要用于在网页中创建和编辑富文本内容。它的功能强大,支持多种语言,并且提供...FCKeditor的灵活性和易用性使其成为开发富文本编辑器的首选之一。

    FCKeditor使用方法技术详解.pdf

    ### FCKeditor使用方法技术详解 #### 一、概述 FCKeditor是一款杰出的富文本编辑器,以其直观的操作界面和强大的功能集受到广泛好评。它由JavaScript编写而成,能够轻松地集成到各种Web应用程序中,支持跨浏览器,...

Global site tag (gtag.js) - Google Analytics