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 {Boolean} clearUp
43 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
48 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
53 * @cfg {Number} height (in pixels)
57 * @cfg {Number} width (in pixels)
62 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
69 * @cfg {Array} blacklist of css styles style attributes (blacklist overrides whitelist)
74 * @cfg {Array} whitelist of css styles style attributes (blacklist overrides whitelist)
83 validationEvent : false,
88 onFocus : Roo.emptyFn,
92 defaultAutoCreate : { // modified by initCompnoent..
94 style:"width:500px;height:300px;",
99 initComponent : function(){
103 * Fires when the editor is fully initialized (including the iframe)
104 * @param {HtmlEditor} this
109 * Fires when the editor is first receives the focus. Any insertion must wait
110 * until after this event.
111 * @param {HtmlEditor} this
116 * Fires before the textarea is updated with content from the editor iframe. Return false
117 * to cancel the sync.
118 * @param {HtmlEditor} this
119 * @param {String} html
124 * Fires before the iframe editor is updated with content from the textarea. Return false
125 * to cancel the push.
126 * @param {HtmlEditor} this
127 * @param {String} html
132 * Fires when the textarea is updated with content from the editor iframe.
133 * @param {HtmlEditor} this
134 * @param {String} html
139 * Fires when the iframe editor is updated with content from the textarea.
140 * @param {HtmlEditor} this
141 * @param {String} html
145 * @event editmodechange
146 * Fires when the editor switches edit modes
147 * @param {HtmlEditor} this
148 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
150 editmodechange: true,
153 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
154 * @param {HtmlEditor} this
159 * Fires when on first focus - needed by toolbars..
160 * @param {HtmlEditor} this
165 * Auto save the htmlEditor value as a file into Events
166 * @param {HtmlEditor} this
170 * @event savedpreview
171 * preview the saved version of htmlEditor
172 * @param {HtmlEditor} this
176 this.defaultAutoCreate = {
178 style:'width: ' + this.width + 'px;height: ' + this.height + 'px;',
184 * Protected method that will not generally be called directly. It
185 * is called when the editor creates its toolbar. Override this method if you need to
186 * add custom toolbar buttons.
187 * @param {HtmlEditor} editor
189 createToolbar : function(editor){
190 Roo.log("create toolbars");
191 if (!editor.toolbars || !editor.toolbars.length) {
192 editor.toolbars = [ new Roo.form.HtmlEditor.ToolbarStandard() ]; // can be empty?
195 for (var i =0 ; i < editor.toolbars.length;i++) {
196 editor.toolbars[i] = Roo.factory(
197 typeof(editor.toolbars[i]) == 'string' ?
198 { xtype: editor.toolbars[i]} : editor.toolbars[i],
199 Roo.form.HtmlEditor);
200 editor.toolbars[i].init(editor);
208 onRender : function(ct, position)
211 Roo.form.HtmlEditor.superclass.onRender.call(this, ct, position);
213 this.wrap = this.el.wrap({
214 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
217 this.editorcore.onRender(ct, position);
219 if (this.resizable) {
220 this.resizeEl = new Roo.Resizable(this.wrap, {
224 minHeight : this.height,
226 handles : this.resizable,
229 resize : function(r, w, h) {
230 _t.onResize(w,h); // -something
236 this.createToolbar(this);
240 this.setSize(this.wrap.getSize());
243 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
244 // should trigger onReize..
247 // if(this.autosave && this.w){
248 // this.autoSaveFn = setInterval(this.autosave, 1000);
253 onResize : function(w, h)
255 //Roo.log('resize: ' +w + ',' + h );
256 Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
261 if(typeof w == 'number'){
262 var aw = w - this.wrap.getFrameWidth('lr');
263 this.el.setWidth(this.adjustWidth('textarea', aw));
266 if(typeof h == 'number'){
268 for (var i =0; i < this.toolbars.length;i++) {
269 // fixme - ask toolbars for heights?
270 tbh += this.toolbars[i].tb.el.getHeight();
271 if (this.toolbars[i].footer) {
272 tbh += this.toolbars[i].footer.el.getHeight();
279 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
280 ah -= 5; // knock a few pixes off for look..
281 this.el.setHeight(this.adjustWidth('textarea', ah));
285 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
286 this.editorcore.onResize(ew,eh);
291 * Toggles the editor between standard and source edit mode.
292 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
294 toggleSourceEdit : function(sourceEditMode)
296 this.editorcore.toggleSourceEdit(sourceEditMode);
298 if(this.editorcore.sourceEditMode){
299 Roo.log('editor - showing textarea');
302 // Roo.log(this.syncValue());
303 this.editorcore.syncValue();
304 this.el.removeClass('x-hidden');
305 this.el.dom.removeAttribute('tabIndex');
308 Roo.log('editor - hiding textarea');
310 // Roo.log(this.pushValue());
311 this.editorcore.pushValue();
313 this.el.addClass('x-hidden');
314 this.el.dom.setAttribute('tabIndex', -1);
318 this.setSize(this.wrap.getSize());
319 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
322 // private (for BoxComponent)
323 adjustSize : Roo.BoxComponent.prototype.adjustSize,
325 // private (for BoxComponent)
326 getResizeEl : function(){
330 // private (for BoxComponent)
331 getPositionEl : function(){
336 initEvents : function(){
337 this.originalValue = this.getValue();
341 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
344 markInvalid : Roo.emptyFn,
346 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
349 clearInvalid : Roo.emptyFn,
351 setValue : function(v){
352 Roo.form.HtmlEditor.superclass.setValue.call(this, v);
353 this.editorcore.pushValue();
358 deferFocus : function(){
359 this.focus.defer(10, this);
364 this.editorcore.focus();
370 onDestroy : function(){
376 for (var i =0; i < this.toolbars.length;i++) {
377 // fixme - ask toolbars for heights?
378 this.toolbars[i].onDestroy();
381 this.wrap.dom.innerHTML = '';
387 onFirstFocus : function(){
388 //Roo.log("onFirstFocus");
389 this.editorcore.onFirstFocus();
390 for (var i =0; i < this.toolbars.length;i++) {
391 this.toolbars[i].onFirstFocus();
397 syncValue : function()
399 this.editorcore.syncValue();
402 pushValue : function()
404 this.editorcore.pushValue();
408 // hide stuff that is not compatible
426 * @cfg {String} fieldClass @hide
429 * @cfg {String} focusClass @hide
432 * @cfg {String} autoCreate @hide
435 * @cfg {String} inputType @hide
438 * @cfg {String} invalidClass @hide
441 * @cfg {String} invalidText @hide
444 * @cfg {String} msgFx @hide
447 * @cfg {String} validateOnBlur @hide