1 //<script type="text/javascript">
5 * Copyright(c) 2006-2007, Ext JS, LLC.
11 Roo.form.HtmlEditor = function(config){
15 Roo.form.HtmlEditor.superclass.constructor.call(this, config);
20 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
26 * @class Ext.form.HtmlEditor
27 * @extends Ext.form.Field
28 * Provides a lightweight HTML Editor component.
30 * This has been tested on Fireforx / Chrome.. IE may not be so great..
32 * <br><br><b>Note: The focus/blur and validation marking functionality inherited from Ext.form.Field is NOT
33 * supported by this editor.</b><br/><br/>
34 * An Editor is a sensitive component that can't be used in all spots standard fields can be used. Putting an Editor within
35 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
37 Roo.extend(Roo.form.HtmlEditor, Roo.form.Field, {
39 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
44 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
49 * @cfg {Number} height (in pixels)
53 * @cfg {Number} width (in pixels)
58 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
67 validationEvent : false,
72 onFocus : Roo.emptyFn,
76 defaultAutoCreate : { // modified by initCompnoent..
78 style:"width:500px;height:300px;",
83 initComponent : function(){
87 * Fires when the editor is fully initialized (including the iframe)
88 * @param {HtmlEditor} this
93 * Fires when the editor is first receives the focus. Any insertion must wait
94 * until after this event.
95 * @param {HtmlEditor} this
100 * Fires before the textarea is updated with content from the editor iframe. Return false
101 * to cancel the sync.
102 * @param {HtmlEditor} this
103 * @param {String} html
108 * Fires before the iframe editor is updated with content from the textarea. Return false
109 * to cancel the push.
110 * @param {HtmlEditor} this
111 * @param {String} html
116 * Fires when the textarea is updated with content from the editor iframe.
117 * @param {HtmlEditor} this
118 * @param {String} html
123 * Fires when the iframe editor is updated with content from the textarea.
124 * @param {HtmlEditor} this
125 * @param {String} html
129 * @event editmodechange
130 * Fires when the editor switches edit modes
131 * @param {HtmlEditor} this
132 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
134 editmodechange: true,
137 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
138 * @param {HtmlEditor} this
143 * Fires when on first focus - needed by toolbars..
144 * @param {HtmlEditor} this
148 this.defaultAutoCreate = {
150 style:'width: ' + this.width + 'px;height: ' + this.height + 'px;',
156 * Protected method that will not generally be called directly. It
157 * is called when the editor creates its toolbar. Override this method if you need to
158 * add custom toolbar buttons.
159 * @param {HtmlEditor} editor
161 createToolbar : function(editor){
162 Roo.log("create toolbars");
163 if (!editor.toolbars || !editor.toolbars.length) {
164 editor.toolbars = [ new Roo.form.HtmlEditor.ToolbarStandard() ]; // can be empty?
167 for (var i =0 ; i < editor.toolbars.length;i++) {
168 editor.toolbars[i] = Roo.factory(
169 typeof(editor.toolbars[i]) == 'string' ?
170 { xtype: editor.toolbars[i]} : editor.toolbars[i],
171 Roo.form.HtmlEditor);
172 editor.toolbars[i].init(editor);
180 onRender : function(ct, position)
183 Roo.form.HtmlEditor.superclass.onRender.call(this, ct, position);
185 this.wrap = this.el.wrap({
186 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
189 this.editorcore.onRender(ct, position);
191 if (this.resizable) {
192 this.resizeEl = new Roo.Resizable(this.wrap, {
196 minHeight : this.height,
198 handles : this.resizable,
201 resize : function(r, w, h) {
202 _t.onResize(w,h); // -something
208 this.createToolbar(this);
212 this.setSize(this.wrap.getSize());
215 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
216 // should trigger onReize..
221 onResize : function(w, h)
223 //Roo.log('resize: ' +w + ',' + h );
224 Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
229 if(typeof w == 'number'){
230 var aw = w - this.wrap.getFrameWidth('lr');
231 this.el.setWidth(this.adjustWidth('textarea', aw));
234 if(typeof h == 'number'){
236 for (var i =0; i < this.toolbars.length;i++) {
237 // fixme - ask toolbars for heights?
238 tbh += this.toolbars[i].tb.el.getHeight();
239 if (this.toolbars[i].footer) {
240 tbh += this.toolbars[i].footer.el.getHeight();
247 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
248 ah -= 5; // knock a few pixes off for look..
249 this.el.setHeight(this.adjustWidth('textarea', ah));
253 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
254 this.editorcore.onResize(ew,eh);
259 * Toggles the editor between standard and source edit mode.
260 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
262 toggleSourceEdit : function(sourceEditMode)
264 this.editorcore.toggleSourceEdit(sourceEditMode);
266 if(this.editorcore.sourceEditMode){
267 Roo.log('editor - showing textarea');
270 // Roo.log(this.syncValue());
271 this.editorcore.syncValue();
272 this.el.removeClass('x-hidden');
273 this.el.dom.removeAttribute('tabIndex');
276 Roo.log('editor - hiding textarea');
278 // Roo.log(this.pushValue());
279 this.editorcore.pushValue();
281 this.el.addClass('x-hidden');
282 this.el.dom.setAttribute('tabIndex', -1);
286 this.setSize(this.wrap.getSize());
287 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
290 // private (for BoxComponent)
291 adjustSize : Roo.BoxComponent.prototype.adjustSize,
293 // private (for BoxComponent)
294 getResizeEl : function(){
298 // private (for BoxComponent)
299 getPositionEl : function(){
304 initEvents : function(){
305 this.originalValue = this.getValue();
309 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
312 markInvalid : Roo.emptyFn,
314 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
317 clearInvalid : Roo.emptyFn,
319 setValue : function(v){
320 Roo.form.HtmlEditor.superclass.setValue.call(this, v);
321 this.editorcore.pushValue();
326 deferFocus : function(){
327 this.focus.defer(10, this);
332 this.editorcore.focus();
338 onDestroy : function(){
344 for (var i =0; i < this.toolbars.length;i++) {
345 // fixme - ask toolbars for heights?
346 this.toolbars[i].onDestroy();
349 this.wrap.dom.innerHTML = '';
355 onFirstFocus : function(){
356 //Roo.log("onFirstFocus");
357 this.editorcore.onFirstFocus();
358 for (var i =0; i < this.toolbars.length;i++) {
359 this.toolbars[i].onFirstFocus();
365 // hide stuff that is not compatible
383 * @cfg {String} fieldClass @hide
386 * @cfg {String} focusClass @hide
389 * @cfg {String} autoCreate @hide
392 * @cfg {String} inputType @hide
395 * @cfg {String} invalidClass @hide
398 * @cfg {String} invalidText @hide
401 * @cfg {String} msgFx @hide
404 * @cfg {String} validateOnBlur @hide