日期:2014-05-17  浏览次数:20603 次

HTMLEditor 上传图片 组件


用Extjs做项目,用到htmleditor控件,唯一的缺陷是不可以上传图片,为了以后方便,在基于htmleditor控件上写了一个支持上传图片的。

控件StarHtmleditor

/**
* 重载EXTJS-HTML编辑器
*
* @class HTMLEditor
* @extends Ext.form.HtmlEditor
* @author wuliangbo
*/
HTMLEditor = Ext.extend(Ext.form.HtmlEditor, {
    addImage : function() {
        var editor = this;
        var imgform = new Ext.FormPanel({
            region : 'center',
            labelWidth : 55,
            frame : true,
            bodyStyle : 'padding:5px 5px 0',
            autoScroll : true,
            border : false,
            fileUpload : true,
            items : [{
                        xtype : 'textfield',
                        fieldLabel : '选择文件',
                        name : 'userfile',
                        inputType : 'file',
                        allowBlank : false,
                        blankText : '文件不能为空',
                        height : 25,
                        anchor : '90%'
                    }],
            buttons : [{
                text : '上传',
                type : 'submit',
                handler : function() {
                    if (!imgform.form.isValid()) {return;}
                    imgform.form.submit({
                        waitMsg : '正在上传',
                        url : 'Default.aspx',
                        success : function(form, action) {