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.
64 * @cfg {Boolean} autosave Auto save the field as a file (default false)
73 validationEvent : false,
78 onFocus : Roo.emptyFn,
82 defaultAutoCreate : { // modified by initCompnoent..
84 style:"width:500px;height:300px;",
89 initComponent : function(){
93 * Fires when the editor is fully initialized (including the iframe)
94 * @param {HtmlEditor} this
99 * Fires when the editor is first receives the focus. Any insertion must wait
100 * until after this event.
101 * @param {HtmlEditor} this
106 * Fires before the textarea is updated with content from the editor iframe. Return false
107 * to cancel the sync.
108 * @param {HtmlEditor} this
109 * @param {String} html
114 * Fires before the iframe editor is updated with content from the textarea. Return false
115 * to cancel the push.
116 * @param {HtmlEditor} this
117 * @param {String} html
122 * Fires when the textarea is updated with content from the editor iframe.
123 * @param {HtmlEditor} this
124 * @param {String} html
129 * Fires when the iframe editor is updated with content from the textarea.
130 * @param {HtmlEditor} this
131 * @param {String} html
135 * @event editmodechange
136 * Fires when the editor switches edit modes
137 * @param {HtmlEditor} this
138 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
140 editmodechange: true,
143 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
144 * @param {HtmlEditor} this
149 * Fires when on first focus - needed by toolbars..
150 * @param {HtmlEditor} this
154 this.defaultAutoCreate = {
156 style:'width: ' + this.width + 'px;height: ' + this.height + 'px;',
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..
227 _this.autoSaveFn = setInterval(function(){
229 if(!_this.isDirty()){
230 Roo.log('not dirty');
233 Roo.log('dirty, auto save!');
235 // _this.form.findField('body').originalValue = _this.form.findField('body').getValue();
241 onResize : function(w, h)
243 //Roo.log('resize: ' +w + ',' + h );
244 Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
249 if(typeof w == 'number'){
250 var aw = w - this.wrap.getFrameWidth('lr');
251 this.el.setWidth(this.adjustWidth('textarea', aw));
254 if(typeof h == 'number'){
256 for (var i =0; i < this.toolbars.length;i++) {
257 // fixme - ask toolbars for heights?
258 tbh += this.toolbars[i].tb.el.getHeight();
259 if (this.toolbars[i].footer) {
260 tbh += this.toolbars[i].footer.el.getHeight();
267 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
268 ah -= 5; // knock a few pixes off for look..
269 this.el.setHeight(this.adjustWidth('textarea', ah));
273 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
274 this.editorcore.onResize(ew,eh);
279 * Toggles the editor between standard and source edit mode.
280 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
282 toggleSourceEdit : function(sourceEditMode)
284 this.editorcore.toggleSourceEdit(sourceEditMode);
286 if(this.editorcore.sourceEditMode){
287 Roo.log('editor - showing textarea');
290 // Roo.log(this.syncValue());
291 this.editorcore.syncValue();
292 this.el.removeClass('x-hidden');
293 this.el.dom.removeAttribute('tabIndex');
296 Roo.log('editor - hiding textarea');
298 // Roo.log(this.pushValue());
299 this.editorcore.pushValue();
301 this.el.addClass('x-hidden');
302 this.el.dom.setAttribute('tabIndex', -1);
306 this.setSize(this.wrap.getSize());
307 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
310 // private (for BoxComponent)
311 adjustSize : Roo.BoxComponent.prototype.adjustSize,
313 // private (for BoxComponent)
314 getResizeEl : function(){
318 // private (for BoxComponent)
319 getPositionEl : function(){
324 initEvents : function(){
325 this.originalValue = this.getValue();
329 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
332 markInvalid : Roo.emptyFn,
334 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
337 clearInvalid : Roo.emptyFn,
339 setValue : function(v){
340 Roo.form.HtmlEditor.superclass.setValue.call(this, v);
341 this.editorcore.pushValue();
346 deferFocus : function(){
347 this.focus.defer(10, this);
352 this.editorcore.focus();
358 onDestroy : function(){
364 for (var i =0; i < this.toolbars.length;i++) {
365 // fixme - ask toolbars for heights?
366 this.toolbars[i].onDestroy();
369 this.wrap.dom.innerHTML = '';
375 onFirstFocus : function(){
376 //Roo.log("onFirstFocus");
377 this.editorcore.onFirstFocus();
378 for (var i =0; i < this.toolbars.length;i++) {
379 this.toolbars[i].onFirstFocus();
385 syncValue : function()
387 this.editorcore.syncValue();
391 // hide stuff that is not compatible
409 * @cfg {String} fieldClass @hide
412 * @cfg {String} focusClass @hide
415 * @cfg {String} autoCreate @hide
418 * @cfg {String} inputType @hide
421 * @cfg {String} invalidClass @hide
424 * @cfg {String} invalidText @hide
427 * @cfg {String} msgFx @hide
430 * @cfg {String} validateOnBlur @hide