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
150 this.defaultAutoCreate = {
152 style:'width: ' + this.width + 'px;height: ' + this.height + 'px;',
159 Roo.log('onFocus!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1');
162 * Protected method that will not generally be called directly. It
163 * is called when the editor creates its toolbar. Override this method if you need to
164 * add custom toolbar buttons.
165 * @param {HtmlEditor} editor
167 createToolbar : function(editor){
168 Roo.log("create toolbars");
169 if (!editor.toolbars || !editor.toolbars.length) {
170 editor.toolbars = [ new Roo.form.HtmlEditor.ToolbarStandard() ]; // can be empty?
173 for (var i =0 ; i < editor.toolbars.length;i++) {
174 editor.toolbars[i] = Roo.factory(
175 typeof(editor.toolbars[i]) == 'string' ?
176 { xtype: editor.toolbars[i]} : editor.toolbars[i],
177 Roo.form.HtmlEditor);
178 editor.toolbars[i].init(editor);
186 onRender : function(ct, position)
189 Roo.form.HtmlEditor.superclass.onRender.call(this, ct, position);
191 this.wrap = this.el.wrap({
192 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
195 this.editorcore.onRender(ct, position);
197 if (this.resizable) {
198 this.resizeEl = new Roo.Resizable(this.wrap, {
202 minHeight : this.height,
204 handles : this.resizable,
207 resize : function(r, w, h) {
208 _t.onResize(w,h); // -something
214 this.createToolbar(this);
218 this.setSize(this.wrap.getSize());
221 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
222 // should trigger onReize..
225 // if(this.autosave){
226 // this.autoSaveFn = setInterval(this.autosave, 1000);
231 onResize : function(w, h)
233 //Roo.log('resize: ' +w + ',' + h );
234 Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
239 if(typeof w == 'number'){
240 var aw = w - this.wrap.getFrameWidth('lr');
241 this.el.setWidth(this.adjustWidth('textarea', aw));
244 if(typeof h == 'number'){
246 for (var i =0; i < this.toolbars.length;i++) {
247 // fixme - ask toolbars for heights?
248 tbh += this.toolbars[i].tb.el.getHeight();
249 if (this.toolbars[i].footer) {
250 tbh += this.toolbars[i].footer.el.getHeight();
257 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
258 ah -= 5; // knock a few pixes off for look..
259 this.el.setHeight(this.adjustWidth('textarea', ah));
263 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
264 this.editorcore.onResize(ew,eh);
269 * Toggles the editor between standard and source edit mode.
270 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
272 toggleSourceEdit : function(sourceEditMode)
274 this.editorcore.toggleSourceEdit(sourceEditMode);
276 if(this.editorcore.sourceEditMode){
277 Roo.log('editor - showing textarea');
280 // Roo.log(this.syncValue());
281 this.editorcore.syncValue();
282 this.el.removeClass('x-hidden');
283 this.el.dom.removeAttribute('tabIndex');
286 Roo.log('editor - hiding textarea');
288 // Roo.log(this.pushValue());
289 this.editorcore.pushValue();
291 this.el.addClass('x-hidden');
292 this.el.dom.setAttribute('tabIndex', -1);
296 this.setSize(this.wrap.getSize());
297 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
300 // private (for BoxComponent)
301 adjustSize : Roo.BoxComponent.prototype.adjustSize,
303 // private (for BoxComponent)
304 getResizeEl : function(){
308 // private (for BoxComponent)
309 getPositionEl : function(){
314 initEvents : function(){
315 this.originalValue = this.getValue();
319 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
322 markInvalid : Roo.emptyFn,
324 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
327 clearInvalid : Roo.emptyFn,
329 setValue : function(v){
330 Roo.form.HtmlEditor.superclass.setValue.call(this, v);
331 this.editorcore.pushValue();
336 deferFocus : function(){
337 this.focus.defer(10, this);
342 this.editorcore.focus();
348 onDestroy : function(){
354 for (var i =0; i < this.toolbars.length;i++) {
355 // fixme - ask toolbars for heights?
356 this.toolbars[i].onDestroy();
359 this.wrap.dom.innerHTML = '';
365 onFirstFocus : function(){
366 //Roo.log("onFirstFocus");
367 this.editorcore.onFirstFocus();
368 for (var i =0; i < this.toolbars.length;i++) {
369 this.toolbars[i].onFirstFocus();
375 syncValue : function()
377 this.editorcore.syncValue();
381 // hide stuff that is not compatible
399 * @cfg {String} fieldClass @hide
402 * @cfg {String} focusClass @hide
405 * @cfg {String} autoCreate @hide
408 * @cfg {String} inputType @hide
411 * @cfg {String} invalidClass @hide
414 * @cfg {String} invalidText @hide
417 * @cfg {String} msgFx @hide
420 * @cfg {String} validateOnBlur @hide