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 Roo.form.HtmlEditor
27 * @extends Roo.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.
69 validationEvent : false,
74 onFocus : Roo.emptyFn,
78 defaultAutoCreate : { // modified by initCompnoent..
80 style:"width:500px;height:300px;",
85 initComponent : function(){
89 * Fires when the editor is fully initialized (including the iframe)
90 * @param {HtmlEditor} this
95 * Fires when the editor is first receives the focus. Any insertion must wait
96 * until after this event.
97 * @param {HtmlEditor} this
102 * Fires before the textarea is updated with content from the editor iframe. Return false
103 * to cancel the sync.
104 * @param {HtmlEditor} this
105 * @param {String} html
110 * Fires before the iframe editor is updated with content from the textarea. Return false
111 * to cancel the push.
112 * @param {HtmlEditor} this
113 * @param {String} html
118 * Fires when the textarea is updated with content from the editor iframe.
119 * @param {HtmlEditor} this
120 * @param {String} html
125 * Fires when the iframe editor is updated with content from the textarea.
126 * @param {HtmlEditor} this
127 * @param {String} html
131 * @event editmodechange
132 * Fires when the editor switches edit modes
133 * @param {HtmlEditor} this
134 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
136 editmodechange: true,
139 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
140 * @param {HtmlEditor} this
145 * Fires when on first focus - needed by toolbars..
146 * @param {HtmlEditor} this
151 * Fires when this field receives input focus.
152 * @param {HtmlEditor} this
156 this.defaultAutoCreate = {
158 style:'width: ' + this.width + 'px;height: ' + this.height + 'px;',
164 * Protected method that will not generally be called directly. It
165 * is called when the editor creates its toolbar. Override this method if you need to
166 * add custom toolbar buttons.
167 * @param {HtmlEditor} editor
169 createToolbar : function(editor){
170 Roo.log("create toolbars");
171 if (!editor.toolbars || !editor.toolbars.length) {
172 editor.toolbars = [ new Roo.form.HtmlEditor.ToolbarStandard() ]; // can be empty?
175 for (var i =0 ; i < editor.toolbars.length;i++) {
176 editor.toolbars[i] = Roo.factory(
177 typeof(editor.toolbars[i]) == 'string' ?
178 { xtype: editor.toolbars[i]} : editor.toolbars[i],
179 Roo.form.HtmlEditor);
180 editor.toolbars[i].init(editor);
188 onRender : function(ct, position)
191 Roo.form.HtmlEditor.superclass.onRender.call(this, ct, position);
193 this.wrap = this.el.wrap({
194 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
197 this.editorcore.onRender(ct, position);
199 if (this.resizable) {
200 this.resizeEl = new Roo.Resizable(this.wrap, {
204 minHeight : this.height,
206 handles : this.resizable,
209 resize : function(r, w, h) {
210 _t.onResize(w,h); // -something
216 this.createToolbar(this);
220 this.setSize(this.wrap.getSize());
223 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
224 // should trigger onReize..
227 // if(this.autosave){
228 // this.autoSaveFn = setInterval(this.autosave, 1000);
233 onResize : function(w, h)
235 //Roo.log('resize: ' +w + ',' + h );
236 Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
241 if(typeof w == 'number'){
242 var aw = w - this.wrap.getFrameWidth('lr');
243 this.el.setWidth(this.adjustWidth('textarea', aw));
246 if(typeof h == 'number'){
248 for (var i =0; i < this.toolbars.length;i++) {
249 // fixme - ask toolbars for heights?
250 tbh += this.toolbars[i].tb.el.getHeight();
251 if (this.toolbars[i].footer) {
252 tbh += this.toolbars[i].footer.el.getHeight();
259 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
260 ah -= 5; // knock a few pixes off for look..
261 this.el.setHeight(this.adjustWidth('textarea', ah));
265 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
266 this.editorcore.onResize(ew,eh);
271 * Toggles the editor between standard and source edit mode.
272 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
274 toggleSourceEdit : function(sourceEditMode)
276 this.editorcore.toggleSourceEdit(sourceEditMode);
278 if(this.editorcore.sourceEditMode){
279 Roo.log('editor - showing textarea');
282 // Roo.log(this.syncValue());
283 this.editorcore.syncValue();
284 this.el.removeClass('x-hidden');
285 this.el.dom.removeAttribute('tabIndex');
288 Roo.log('editor - hiding textarea');
290 // Roo.log(this.pushValue());
291 this.editorcore.pushValue();
293 this.el.addClass('x-hidden');
294 this.el.dom.setAttribute('tabIndex', -1);
298 this.setSize(this.wrap.getSize());
299 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
302 // private (for BoxComponent)
303 adjustSize : Roo.BoxComponent.prototype.adjustSize,
305 // private (for BoxComponent)
306 getResizeEl : function(){
310 // private (for BoxComponent)
311 getPositionEl : function(){
316 initEvents : function(){
317 this.originalValue = this.getValue();
321 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
324 markInvalid : Roo.emptyFn,
326 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
329 clearInvalid : Roo.emptyFn,
331 setValue : function(v){
332 Roo.form.HtmlEditor.superclass.setValue.call(this, v);
333 this.editorcore.pushValue();
338 deferFocus : function(){
339 this.focus.defer(10, this);
344 this.editorcore.focus();
350 onDestroy : function(){
356 for (var i =0; i < this.toolbars.length;i++) {
357 // fixme - ask toolbars for heights?
358 this.toolbars[i].onDestroy();
361 this.wrap.dom.innerHTML = '';
367 onFirstFocus : function(){
368 //Roo.log("onFirstFocus");
369 this.editorcore.onFirstFocus();
370 for (var i =0; i < this.toolbars.length;i++) {
371 this.toolbars[i].onFirstFocus();
377 syncValue : function()
379 this.editorcore.syncValue();
383 // hide stuff that is not compatible
401 * @cfg {String} fieldClass @hide
404 * @cfg {String} focusClass @hide
407 * @cfg {String} autoCreate @hide
410 * @cfg {String} inputType @hide
413 * @cfg {String} invalidClass @hide
416 * @cfg {String} invalidText @hide
419 * @cfg {String} msgFx @hide
422 * @cfg {String} validateOnBlur @hide