Code:
/*
* EditArea Plugin
* HTML sample :
<!-- Editeur HTML : EditArea (v0.7) -->
<script type="text/javascript" src="ux/HtmlEditor/editarea/edit_area/edit_area_full.js"></script>
<script type="text/javascript" src="ux/HtmlEditor/Ext.ux.EditArea.js"></script>
*
* JS Sample :
// EditArea configs
editAreaConf1={
start_highlight: true // if start with highlight
,allow_resize: "both"
,allow_toggle: true
,language: "en"
,syntax: "php"
};
editAreaConf2={
start_highlight: true
,allow_toggle: false
,language: "en"
,syntax: "html"
,toolbar: "search, go_to_line, |, undo, redo, |, select_font, |, syntax_selection, |, change_smooth_selection, highlight, reset_highlight, |, help"
,syntax_selection_allow: "css,html,js,php,python,vb,xml,c,cpp,basic,pas,brain"
,is_multi_files: true
,EA_load_callback: "editAreaLoaded"
};
editAreaConf3={
start_highlight: true
,font_size: "8"
,font_family: "verdana, monospace"
,allow_resize: "y"
,allow_toggle: false
,language: "fr"
,syntax: "css"
,toolbar: "new_document, save, load, |, charmap, |, search, go_to_line, |, undo, redo, |, select_font, |, change_smooth_selection, highlight, reset_highlight, |, help"
,load_callback: "my_load"
,save_callback: "my_save"
,plugins: "charmap"
,charmap_default: "arrows"
};
editAreaConf4={
//start_highlight: true // if start with highlight
//,font_size: "10"
,allow_resize: "no"
,allow_toggle: true
,language: "de"
,syntax: "python"
,load_callback: "my_load"
,save_callback: "my_save"
,display: "later"
,replace_tab_by_spaces: 4
,min_height: 350
};
// callback functions
function my_save(id, content){
alert("Here is the content of the EditArea '"+ id +"' as received by the save callback function:\n"+content);
}
function my_load(id){
editAreaLoader.setValue(id, "The content is loaded from the load_callback function into EditArea");
}
var localForm = new Ext.form.FormPanel({
....
,items: [{
xtype:'textarea'
,fieldLabel:'Entete'
,name:'entete'
,anchor:'100%'
,height:100
,plugins:new Ext.ux.plugins.EditAreaEditor(editAreaConf1)
}]});
*/
Ext.namespace('Ext.ux.plugins');
Ext.ux.plugins.EditAreaEditor = function(config){
Ext.apply(this, {config:config});
};
Ext.extend(Ext.ux.plugins.EditAreaEditor, Ext.util.Observable, {
config:{start_highlight: true,allow_toggle: false,language: "en",syntax: "php"}
,onRender:function(o){
Ext.apply(this.config, { id: o.id});
editAreaLoader.init(this.config);
//tinyMCE.init(this.config);
//tinyMCE.execCommand('mceAddControl', false, o.id);
}
,init:function(textarea) {
textarea.on('render', this.onRender, this);
Ext.apply(textarea, {
setValue:textarea.setValue.createSequence(function(ct, position) {
//alert('update:'+textarea.id);
editAreaLoader.setValue(textarea.id, textarea.getValue())
})
,beforeDestroy:textarea.beforeDestroy.createSequence(function(ct, position) {
//if (tinyMCE.getInstanceById(textarea.id) != null){
//alert('destroy: '+textarea.id);
// TO DO: fond the problem
//tinyMCE.execCommand( 'mceRemoveControl', false, textarea.id );
}
//}
)
});
}
});
// register xtype
Ext.reg('editarea', Ext.ux.plugins.EditAreaEditor);
HTML sample :
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>EditArea plugin</title>
<link rel="stylesheet" type="text/css" href= "../ext-2.0/resources/css/ext-all.css">
<!-- extjs: -->
<script type="text/javascript" src="../ext-2.0/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../ext-2.0/ext-all.js"></script>
<!-- editarea-plugin: -->
<script type="text/javascript" src="../../editors/editarea_0_7/edit_area/edit_area_full.js"></script>
<script type="text/javascript" src="Ext.ux.EditArea.js"></script>
<script type="text/javascript">
// EditArea configs
var editAreaConf1={
start_highlight: true // if start with highlight
,allow_resize: "both"
,allow_toggle: false
,language: "en"
,syntax: "php"
//,debug: true
};
Ext.onReady(function(){
var win;
var button = Ext.get('show-btn');
button.on('click', function(){
// create the window on the first click and reuse on subsequent clicks
if(!win){
win = new Ext.Window({
id:'hello-win',
layout:'fit',
width:600,
height:300,
closeAction:'hide',
plain: true,
items: new Ext.form.FormPanel({
id : 'myForm'
,items: [{
xtype:'textarea'
,fieldLabel:'MyText'
,name:'my text'
,anchor:'100%'
,height:200
,plugins:new Ext.ux.plugins.EditAreaEditor(editAreaConf1)
}]}),
buttons: [{
text:'Submit',
disabled:true
},{
text: 'Close',
handler: function(){
win.hide();
}
}]
});
}
win.show(this);
});
});
</script>
</head>
<body>
<input type="button" id="show-btn" value="Show Window"/>
</body>
</html>