george.antoniadis
28 Nov 2007, 7:58 AM
Ext.ux.plugins.HtmlEditorImageInsert v.0.1
This is a very first draft of a plugin I needed for the HtmlEditor.
Allows the user to add images in the editor by specifying their URL.
Example:
http://noodles.gr/resources/javascript/extjs/2.0-rc1-lab/Ext.ux.plugins.HtmlEditorImageInsert.html
Usage:
<script type="text/javascript">
Ext.onReady(function(){
Ext.QuickTips.init();
new Ext.FormPanel({
renderTo: 'form',
defaultType: 'textfield',
items: [{
xtype:'htmleditor',
fieldLabel:'some label',
width: 650,
height: 350,
plugins: new Ext.ux.plugins.HtmlEditorImageInsert({
popTitle: 'Image url?',
popMsg: 'Please insert an image URL...',
popWidth: 400,
popValue: 'http://www.google.gr/intl/en_com/images/logo_plain.png'
})
}
]
});
});
</script>
Ext.ux.plugins.HtmlEditorImageInsert.js:
Ext.namespace('Ext.ux', 'Ext.ux.plugins');
Ext.ux.plugins.HtmlEditorImageInsert = function(config) {
config = config || {};
Ext.apply(this, config);
this.init = function(htmlEditor) {
this.editor = htmlEditor;
this.editor.on('render', onRender, this);
};
this.imageInsertConfig = {
popTitle: config.popTitle || 'Image URL',
popMsg: config.popMsg || 'Please select the URL of the image you want to insert:',
popWidth: config.popWidth || 350,
popValue: config.popValue || ''
}
this.imageInsert = function(){
Ext.MessageBox.show({
title: this.imageInsertConfig.popTitle,
msg: this.imageInsertConfig.popMsg,
width: this.imageInsertConfig.popWidth,
buttons: Ext.MessageBox.OKCANCEL,
prompt: true,
value: this.imageInsertConfig.popValue,
scope: this,
fn: function(btn, text){ if ( btn == 'ok' ) this.editor.relayCmd('insertimage', text); }
});
}
function onRender() {
if (!Ext.isSafari) {
this.editor.tb.add({
itemId : 'htmlEditorImage',
cls : 'x-btn-icon x-edit-insertimage',
enableToggle: false,
scope: this,
handler:function(){ this.imageInsert(); },
clickEvent:'mousedown',
tabIndex:-1
});
}
}
}
All plugin params are optional and for now are only used for the prompt message box.
This is very basic but should work ok...
I'm trying to make this play nice with something like JSakalos' fileTree thingie...
If anyone has any suggestions on the structure of the plugin please let me know cause it's my first attempt at one and I ain't sure it's the right way to go...
based on cmendez21's post (http://extjs.com/forum/showthread.php?t=15104)...
This is a very first draft of a plugin I needed for the HtmlEditor.
Allows the user to add images in the editor by specifying their URL.
Example:
http://noodles.gr/resources/javascript/extjs/2.0-rc1-lab/Ext.ux.plugins.HtmlEditorImageInsert.html
Usage:
<script type="text/javascript">
Ext.onReady(function(){
Ext.QuickTips.init();
new Ext.FormPanel({
renderTo: 'form',
defaultType: 'textfield',
items: [{
xtype:'htmleditor',
fieldLabel:'some label',
width: 650,
height: 350,
plugins: new Ext.ux.plugins.HtmlEditorImageInsert({
popTitle: 'Image url?',
popMsg: 'Please insert an image URL...',
popWidth: 400,
popValue: 'http://www.google.gr/intl/en_com/images/logo_plain.png'
})
}
]
});
});
</script>
Ext.ux.plugins.HtmlEditorImageInsert.js:
Ext.namespace('Ext.ux', 'Ext.ux.plugins');
Ext.ux.plugins.HtmlEditorImageInsert = function(config) {
config = config || {};
Ext.apply(this, config);
this.init = function(htmlEditor) {
this.editor = htmlEditor;
this.editor.on('render', onRender, this);
};
this.imageInsertConfig = {
popTitle: config.popTitle || 'Image URL',
popMsg: config.popMsg || 'Please select the URL of the image you want to insert:',
popWidth: config.popWidth || 350,
popValue: config.popValue || ''
}
this.imageInsert = function(){
Ext.MessageBox.show({
title: this.imageInsertConfig.popTitle,
msg: this.imageInsertConfig.popMsg,
width: this.imageInsertConfig.popWidth,
buttons: Ext.MessageBox.OKCANCEL,
prompt: true,
value: this.imageInsertConfig.popValue,
scope: this,
fn: function(btn, text){ if ( btn == 'ok' ) this.editor.relayCmd('insertimage', text); }
});
}
function onRender() {
if (!Ext.isSafari) {
this.editor.tb.add({
itemId : 'htmlEditorImage',
cls : 'x-btn-icon x-edit-insertimage',
enableToggle: false,
scope: this,
handler:function(){ this.imageInsert(); },
clickEvent:'mousedown',
tabIndex:-1
});
}
}
}
All plugin params are optional and for now are only used for the prompt message box.
This is very basic but should work ok...
I'm trying to make this play nice with something like JSakalos' fileTree thingie...
If anyone has any suggestions on the structure of the plugin please let me know cause it's my first attempt at one and I ain't sure it's the right way to go...
based on cmendez21's post (http://extjs.com/forum/showthread.php?t=15104)...