ontho
6 Jul 2011, 11:56 PM
Hello,
I know there are some solutions around for using a tinyMce-Editor with ExtJs 4, but I needed a class which is able to handle several different tinyMce-configs on one form. So here is my approach, any feedback is welcome.
Ext.define('Ext.ux.form.TinyMCE',
{ extend:'Ext.form.TextArea',
alias: 'widget.xtinymce',
tinyMceConfig: {}, // Config for this tinyMce-Instance
saveFunc: null, // Function called when pressing the save-button of tis tinyMce. If not set and this tinyMce-field is inside a form, the form is submitted.
onRender: function (ct, position)
{ if (this.id === undefined) this.id = this.name;
this.callParent(arguments);
this.initTinyMce();
},
getSubmitValue: function()
{ return this.getValue();
},
getValue : function()
{ if (this.inputEl && tinymce && tinymce.EditorManager && tinymce.EditorManager.get(this.inputEl.id))
{ this.value = tinymce.EditorManager.get(this.inputEl.id).getContent();
}
return this.value;
},
setValue : function(value)
{ if (value === null || value === undefined) value = "";
if (this.inputEl && tinymce && tinymce.EditorManager && tinymce.EditorManager.get(this.inputEl.id))
{ tinymce.EditorManager.get(this.inputEl.id).setContent(value);
}
this.value = value;
if (this.inputEl) this.inputEl.dom.value = value;
},
initTinyMce: function()
{ var standardConfig = {
mode : 'exact',
elements: this.inputEl.id,
theme : "advanced",
plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
theme_advanced_buttons1 :
"save,newdocument,separator,undo,redo,separator,"+ // cancel
"cut,copy,paste,pastetext,pasteword,separator,"+
"bold,italic,underline,blockquote,strikethrough,sub,sup,separator,help",
theme_advanced_buttons2 :
"justifyleft,justifycenter,justifyright,justifyfull,separator,"+
"bullist,numlist,outdent,indent,separator,"+
"link,unlink,image,media,advhr,separator,charmap,separator,pagebreak,separator,code",
theme_advanced_buttons3 :
"tablecontrols,separator,fullscreen,separator,styleprops,forecolor,backcolor", // preview,
theme_advanced_buttons4 :
"styleselect,formatselect,separator,fontselect,fontsizeselect,removeformat,cleanup",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_path_location : "bottom",
plugin_insertdate_dateFormat : "%Y-%m-%d",
plugin_insertdate_timeFormat : "%H:%M:%S",
theme_advanced_resize_horizontal : false,
theme_advanced_resizing : false,
width : "100%",
theme_advanced_source_editor_width : "600",
height: "100%",
class_filter : Ext.bind(this.onFilterClass, this),
save_onsavecallback : Ext.bind(this.onSave, this)
}
var config = this.tinyMceConfig;
Ext.apply(config, standardConfig);
tinyMCE.init(config);
},
// Called when the user presses the save-button in tinyMce
onSave: function()
{ if (this.saveFunc)
{ this.saveFunc();
}
else
{ var form = this.up('form');
if (form)
{ form.submit();
}
}
},
// Called when the css-classes are shown
onFilterClass: function(cls, rule)
{ // return false or otherClassName
return cls;
}
});
I know there are some solutions around for using a tinyMce-Editor with ExtJs 4, but I needed a class which is able to handle several different tinyMce-configs on one form. So here is my approach, any feedback is welcome.
Ext.define('Ext.ux.form.TinyMCE',
{ extend:'Ext.form.TextArea',
alias: 'widget.xtinymce',
tinyMceConfig: {}, // Config for this tinyMce-Instance
saveFunc: null, // Function called when pressing the save-button of tis tinyMce. If not set and this tinyMce-field is inside a form, the form is submitted.
onRender: function (ct, position)
{ if (this.id === undefined) this.id = this.name;
this.callParent(arguments);
this.initTinyMce();
},
getSubmitValue: function()
{ return this.getValue();
},
getValue : function()
{ if (this.inputEl && tinymce && tinymce.EditorManager && tinymce.EditorManager.get(this.inputEl.id))
{ this.value = tinymce.EditorManager.get(this.inputEl.id).getContent();
}
return this.value;
},
setValue : function(value)
{ if (value === null || value === undefined) value = "";
if (this.inputEl && tinymce && tinymce.EditorManager && tinymce.EditorManager.get(this.inputEl.id))
{ tinymce.EditorManager.get(this.inputEl.id).setContent(value);
}
this.value = value;
if (this.inputEl) this.inputEl.dom.value = value;
},
initTinyMce: function()
{ var standardConfig = {
mode : 'exact',
elements: this.inputEl.id,
theme : "advanced",
plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
theme_advanced_buttons1 :
"save,newdocument,separator,undo,redo,separator,"+ // cancel
"cut,copy,paste,pastetext,pasteword,separator,"+
"bold,italic,underline,blockquote,strikethrough,sub,sup,separator,help",
theme_advanced_buttons2 :
"justifyleft,justifycenter,justifyright,justifyfull,separator,"+
"bullist,numlist,outdent,indent,separator,"+
"link,unlink,image,media,advhr,separator,charmap,separator,pagebreak,separator,code",
theme_advanced_buttons3 :
"tablecontrols,separator,fullscreen,separator,styleprops,forecolor,backcolor", // preview,
theme_advanced_buttons4 :
"styleselect,formatselect,separator,fontselect,fontsizeselect,removeformat,cleanup",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_path_location : "bottom",
plugin_insertdate_dateFormat : "%Y-%m-%d",
plugin_insertdate_timeFormat : "%H:%M:%S",
theme_advanced_resize_horizontal : false,
theme_advanced_resizing : false,
width : "100%",
theme_advanced_source_editor_width : "600",
height: "100%",
class_filter : Ext.bind(this.onFilterClass, this),
save_onsavecallback : Ext.bind(this.onSave, this)
}
var config = this.tinyMceConfig;
Ext.apply(config, standardConfig);
tinyMCE.init(config);
},
// Called when the user presses the save-button in tinyMce
onSave: function()
{ if (this.saveFunc)
{ this.saveFunc();
}
else
{ var form = this.up('form');
if (form)
{ form.submit();
}
}
},
// Called when the css-classes are shown
onFilterClass: function(cls, rule)
{ // return false or otherClassName
return cls;
}
});