PDA

View Full Version : htmledit image



Mycoding
9 Jul 2010, 9:20 AM
Please give advice.
I'm trying to add image insert in htmledit. But error occurs.
I use this plugin


/**
* @author Shea Frederick - http://www.vinylfox.com
* @class Ext.ux.form.HtmlEditor.Image (r20)
* @extends Ext.util.Observable
* <p>A plugin that creates an image button in the HtmlEditor toolbar for inserting an image. The method to select an image must be defined by overriding the selectImage method. Supports resizing of the image after insertion.</p>
* <p>The selectImage implementation must call insertImage after the user has selected an image, passing it a simple image object like the one below.</p>
* <pre>
* var img = {
* Width: 100,
* Height: 100,
* ID: 123,
* Title: 'My Image'
* };
* </pre>
*/
Ext.ux.form.HtmlEditor.Image = Ext.extend(Ext.util.Observable, {
urlSizeVars: ['width','height'],
basePath: 'image.php',
init: function(cmp){
this.cmp = cmp;
this.cmp.on('render', this.onRender, this);
this.cmp.on('initialize', this.onInit, this, {delay:100, single: true});
},
onEditorMouseUp : function(e){
Ext.get(e.getTarget()).select('img').each(function(el){
var w = el.getAttribute('width'), h = el.getAttribute('height'), src = el.getAttribute('src')+' ';
src = src.replace(new RegExp(this.urlSizeVars[0]+'=[0-9]{1,5}([&| ])'), this.urlSizeVars[0]+'='+w+'$1');
src = src.replace(new RegExp(this.urlSizeVars[1]+'=[0-9]{1,5}([&| ])'), this.urlSizeVars[1]+'='+h+'$1');
el.set({src:src.replace(/\s+$/,"")});
}, this);

},
onInit: function(){
Ext.EventManager.on(this.cmp.getDoc(), {
'mouseup': this.onEditorMouseUp,
buffer: 100,
scope: this
});
},
onRender: function() {
var btn = this.cmp.getToolbar().addButton({
iconCls: 'x-edit-pictures',
handler: this.selectImage,
scope: this,
tooltip: {
title: Image_ttTitle,
text: Image_ttText
}
});
},
selectImage: Ext.emptyFn,
insertImage: function(img) {
this.cmp.insertAtCursor('<img src="'+this.basePath+'?'+this.urlSizeVars[0]+'='+img.Width+'&'+this.urlSizeVars[1]+'='+img.Height+'&id='+img.ID+'" title="'+img.Name+'" alt="'+img.Name+'">');
}
});


And add it as plugin to form



var addReshenieForm = new Ext.FormPanel({
url:'/requests/add_reshenie.php',
frame:true,
bodyStyle:'padding:5px 5px 0',
defaults: {width: 230},
items:[{
xtype: 'combo',
fieldLabel: '????????',
name: 'zadachnik',
mode: 'local',
store: zadachniki,
displayField:'zadachnik',
emptyText:'???????? ????????',
triggerAction: 'all'
},{
fieldLabel: '????? ??????',
xtype:'textfield',
name:'numInZadachnike'
},{
xtype:'htmleditor',
name: 'reshenie',
title:'???????',
hideLabel: true,
width: 550,
autoHeight:true,
plugins:[new Ext.ux.form.HtmlEditor.Image]
}],
buttons:[{
text:'????????? ???????',
formBind: true
}]
});

13 Jul 2010, 2:41 PM
can you explain what "error occurs" means? It's hard to help you with such minimal data.

Maybe post in your native language?

apriza
1 Nov 2010, 4:10 PM
cann't insert image to htmleditor with this plugin, i have a some problem...
any one know, how to fix that?

Mycoding
1 Nov 2010, 8:54 PM
I still don't know, but I need it.

Condor
2 Nov 2010, 1:23 AM
You need to specify a selectImage function in the plugin that calls insertImage with the selected image, otherwise the plugin will do nothing.