neni
13 Jan 2008, 8:55 PM
This a very simple plugin for use TinyMce (Version 3) on a textarea.
TinyMce.plugin.js:
Ext.namespace('Ext.ux.plugins');
Ext.ux.plugins.TinyMceEditor = function(config){
Ext.apply(this, {config:config});
};
Ext.extend(Ext.ux.plugins.TinyMceEditor, Ext.util.Observable, {
config:{mode : "textareas",editor_selector : "mceEditor",theme : "simple"}
,onRender:function(o){
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);
tinyMCE.getInstanceById( textarea.id ).setContent( 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 );
}
})
});
}
});
In HTML file:
<head>
...
<!-- Editeur HTML : Tiny Mce (V3) -->
<script type="text/javascript" src="ux/HtmlEditor/tinymce3/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="ux/HtmlEditor/TinyMce.plugin.js"></script>
...
</head>
And in JS code:
...
// TinyMce configs
var tinyMCEConf1={
mode : "textareas",
theme : "advanced",
editor_selector : "mceEditor",
theme_advanced_buttons3_add : "fullpage",
plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom"
//theme_advanced_resizing : true
};
var tinyMCEConf2={
mode : "textareas"
,editor_selector : "mceEditor"
,theme : "simple"
};
...
var localForm = new Ext.form.FormPanel({
....
,items: [
{
xtype:'textfield'
,fieldLabel: 'Titre'
,name: 'titre'
,anchor:'100%'
},{
xtype:'textarea'
,fieldLabel:'Entete'
,name:'entete'
,anchor:'100%'
,height:100
,plugins:new Ext.ux.plugins.TinyMceEditor(tinyMCEConf2)
},{
xtype:'textarea'
,fieldLabel:'Contenu'
,name:'contenu'
,anchor:'100%'
,height:300
,plugins:new Ext.ux.plugins.TinyMceEditor(tinyMCEConf1)
}
]
...
});
The beforeDestroy method seems to be call after that the textarea was destroyed (that is why TinyMce's remove method make an error if it is not commented). Sorry for my English!
That's my first plugin, so I don't know if this is the best way to do.
TinyMce.plugin.js:
Ext.namespace('Ext.ux.plugins');
Ext.ux.plugins.TinyMceEditor = function(config){
Ext.apply(this, {config:config});
};
Ext.extend(Ext.ux.plugins.TinyMceEditor, Ext.util.Observable, {
config:{mode : "textareas",editor_selector : "mceEditor",theme : "simple"}
,onRender:function(o){
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);
tinyMCE.getInstanceById( textarea.id ).setContent( 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 );
}
})
});
}
});
In HTML file:
<head>
...
<!-- Editeur HTML : Tiny Mce (V3) -->
<script type="text/javascript" src="ux/HtmlEditor/tinymce3/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="ux/HtmlEditor/TinyMce.plugin.js"></script>
...
</head>
And in JS code:
...
// TinyMce configs
var tinyMCEConf1={
mode : "textareas",
theme : "advanced",
editor_selector : "mceEditor",
theme_advanced_buttons3_add : "fullpage",
plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom"
//theme_advanced_resizing : true
};
var tinyMCEConf2={
mode : "textareas"
,editor_selector : "mceEditor"
,theme : "simple"
};
...
var localForm = new Ext.form.FormPanel({
....
,items: [
{
xtype:'textfield'
,fieldLabel: 'Titre'
,name: 'titre'
,anchor:'100%'
},{
xtype:'textarea'
,fieldLabel:'Entete'
,name:'entete'
,anchor:'100%'
,height:100
,plugins:new Ext.ux.plugins.TinyMceEditor(tinyMCEConf2)
},{
xtype:'textarea'
,fieldLabel:'Contenu'
,name:'contenu'
,anchor:'100%'
,height:300
,plugins:new Ext.ux.plugins.TinyMceEditor(tinyMCEConf1)
}
]
...
});
The beforeDestroy method seems to be call after that the textarea was destroyed (that is why TinyMce's remove method make an error if it is not commented). Sorry for my English!
That's my first plugin, so I don't know if this is the best way to do.