EXTJS htmleditor 삽입 이미지 개선

4072 단어
// .
var imgform;
var range;
var HTMLEditor = Ext.extend(Ext.form.HtmlEditor, {
addImage : function() {
	if (Ext.isIE) {
	if (this.iframe.contentWindow.document.selection.type.toLowerCase() != "none"){
		this.iframe.contentWindow.document.selection.clear() ;
		}
	this.iframe.contentWindow.focus();
	
	range = this.iframe.contentWindow.document.selection.createRange();
	range.collapse(false);
	range.select();
	}
	var editor = this;
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 : ' ',
			id : 'UserFile',
			name : 'UserFile',
			inputType : 'file',
			anchor : '90%'
		} ],
		buttons : [{
					text : ' ',
					handler : function() {
						if(Ext.getDom("UserFile").value == ""){
							Ext.Msg.alert(" "," , ");
							return;
						}
						if (!imgform.form.isValid()) {return;}
						imgform.form.submit({
							waitMsg : ' ......',
							url : '/DTAC/declareProject/uploadPic.do?t='+new Date().getTime(),
							success : function(form,action) {
								var element = document.createElement("img");
								element.src = action.result.fileURL;
								element.height = 200;
								element.wigth= 200;
								if (Ext.isIE) {
									/*var value = editor.getValue();
									editor.reset() ;
									editor.insertAtCursor(value);*/
									range.moveEnd("character",0);
									
									
									range.collapse(false);
									range.select();
									editor.iframe.contentWindow.focus();
									editor.insertAtCursor(element.outerHTML);
								} else {
									var selection = editor.win.getSelection();
									if (!selection.isCollapsed) {
										selection.deleteFromDocument();
									}
									selection.getRangeAt(0).insertNode(element);
								}
								// win.hide();// , 
								//  
								form.reset();
								win.close();
							},
							failure : function(form,action) {
							/* */
								form.reset();
								Ext.MessageBox.alert(' ',action.result.msg);
							}
						});
					}
				}, {
					text : ' ',
					handler : function() {
						win.close(this);
					}
				} ]
				});

		var win = new Ext.Window({
			title : " ",
			width : 300,
			height:150,
			modal : true,
			border : false,
			iconCls : "content/images/image.png",
			layout : "fit",
			items : imgform

		});
		win.show();
	},
	createToolbar : function(editor) {
		HTMLEditor.superclass.createToolbar.call(this, editor);
		this.tb.addButton({
			cls : "x-btn-icon",
			icon : "/DTAC/content/images/image.png",
			handler : this.addImage,
			scope : this,
			 tooltip :      
             {    
                 title : ' ',    
                 text : ' ',    
                 cls : 'x-html-editor-tip'    
             }
		});
	},
	addHelp :function(){
		var win = new Ext.Window({
			title : " ",
			width : 300,
			height : 120,
			modal : true,
			border : false,
			iconCls : "/DTAC/content/images/help.png",
			layout : "fit",
			html:' '
		});
		win.show();
	}
});
Ext.reg('StarHtmleditor', HTMLEditor);

좋은 웹페이지 즐겨찾기