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)
80 * @cfg {Array} blacklist of html tags - in addition to standard blacklist.
85 * @cfg {Array} whitelist of html tags - in addition to statndard whitelist
94 validationEvent : false,
99 onFocus : Roo.emptyFn,
103 defaultAutoCreate : { // modified by initCompnoent..
105 style:"width:500px;height:300px;",
110 initComponent : function(){
114 * Fires when the editor is fully initialized (including the iframe)
115 * @param {HtmlEditor} this
120 * Fires when the editor is first receives the focus. Any insertion must wait
121 * until after this event.
122 * @param {HtmlEditor} this
127 * Fires before the textarea is updated with content from the editor iframe. Return false
128 * to cancel the sync.
129 * @param {HtmlEditor} this
130 * @param {String} html
135 * Fires before the iframe editor is updated with content from the textarea. Return false
136 * to cancel the push.
137 * @param {HtmlEditor} this
138 * @param {String} html
143 * Fires when the textarea is updated with content from the editor iframe.
144 * @param {HtmlEditor} this
145 * @param {String} html
150 * Fires when the iframe editor is updated with content from the textarea.
151 * @param {HtmlEditor} this
152 * @param {String} html
156 * @event editmodechange
157 * Fires when the editor switches edit modes
158 * @param {HtmlEditor} this
159 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
161 editmodechange: true,
164 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
165 * @param {HtmlEditor} this
170 * Fires when on first focus - needed by toolbars..
171 * @param {HtmlEditor} this
176 * Auto save the htmlEditor value as a file into Events
177 * @param {HtmlEditor} this
181 * @event savedpreview
182 * preview the saved version of htmlEditor
183 * @param {HtmlEditor} this
187 this.defaultAutoCreate = {
189 style:'width: ' + this.width + 'px;height: ' + this.height + 'px;',
195 * Protected method that will not generally be called directly. It
196 * is called when the editor creates its toolbar. Override this method if you need to
197 * add custom toolbar buttons.
198 * @param {HtmlEditor} editor
200 createToolbar : function(editor){
201 Roo.log("create toolbars");
202 if (!editor.toolbars || !editor.toolbars.length) {
203 editor.toolbars = [ new Roo.form.HtmlEditor.ToolbarStandard() ]; // can be empty?
206 for (var i =0 ; i < editor.toolbars.length;i++) {
207 editor.toolbars[i] = Roo.factory(
208 typeof(editor.toolbars[i]) == 'string' ?
209 { xtype: editor.toolbars[i]} : editor.toolbars[i],
210 Roo.form.HtmlEditor);
211 editor.toolbars[i].init(editor);
219 onRender : function(ct, position)
222 Roo.form.HtmlEditor.superclass.onRender.call(this, ct, position);
224 this.wrap = this.el.wrap({
225 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
228 this.editorcore.onRender(ct, position);
230 if (this.resizable) {
231 this.resizeEl = new Roo.Resizable(this.wrap, {
235 minHeight : this.height,
237 handles : this.resizable,
240 resize : function(r, w, h) {
241 _t.onResize(w,h); // -something
247 this.createToolbar(this);
251 this.setSize(this.wrap.getSize());
254 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
255 // should trigger onReize..
258 // if(this.autosave && this.w){
259 // this.autoSaveFn = setInterval(this.autosave, 1000);
264 onResize : function(w, h)
266 //Roo.log('resize: ' +w + ',' + h );
267 Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
272 if(typeof w == 'number'){
273 var aw = w - this.wrap.getFrameWidth('lr');
274 this.el.setWidth(this.adjustWidth('textarea', aw));
277 if(typeof h == 'number'){
279 for (var i =0; i < this.toolbars.length;i++) {
280 // fixme - ask toolbars for heights?
281 tbh += this.toolbars[i].tb.el.getHeight();
282 if (this.toolbars[i].footer) {
283 tbh += this.toolbars[i].footer.el.getHeight();
290 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
291 ah -= 5; // knock a few pixes off for look..
292 this.el.setHeight(this.adjustWidth('textarea', ah));
296 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
297 this.editorcore.onResize(ew,eh);
302 * Toggles the editor between standard and source edit mode.
303 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
305 toggleSourceEdit : function(sourceEditMode)
307 this.editorcore.toggleSourceEdit(sourceEditMode);
309 if(this.editorcore.sourceEditMode){
310 Roo.log('editor - showing textarea');
313 // Roo.log(this.syncValue());
314 this.editorcore.syncValue();
315 this.el.removeClass('x-hidden');
316 this.el.dom.removeAttribute('tabIndex');
319 Roo.log('editor - hiding textarea');
321 // Roo.log(this.pushValue());
322 this.editorcore.pushValue();
324 this.el.addClass('x-hidden');
325 this.el.dom.setAttribute('tabIndex', -1);
329 this.setSize(this.wrap.getSize());
330 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
333 // private (for BoxComponent)
334 adjustSize : Roo.BoxComponent.prototype.adjustSize,
336 // private (for BoxComponent)
337 getResizeEl : function(){
341 // private (for BoxComponent)
342 getPositionEl : function(){
347 initEvents : function(){
348 this.originalValue = this.getValue();
352 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
355 markInvalid : Roo.emptyFn,
357 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
360 clearInvalid : Roo.emptyFn,
362 setValue : function(v){
363 Roo.form.HtmlEditor.superclass.setValue.call(this, v);
364 this.editorcore.pushValue();
369 deferFocus : function(){
370 this.focus.defer(10, this);
375 this.editorcore.focus();
381 onDestroy : function(){
387 for (var i =0; i < this.toolbars.length;i++) {
388 // fixme - ask toolbars for heights?
389 this.toolbars[i].onDestroy();
392 this.wrap.dom.innerHTML = '';
398 onFirstFocus : function(){
399 //Roo.log("onFirstFocus");
400 this.editorcore.onFirstFocus();
401 for (var i =0; i < this.toolbars.length;i++) {
402 this.toolbars[i].onFirstFocus();
408 syncValue : function()
410 this.editorcore.syncValue();
413 pushValue : function()
415 this.editorcore.pushValue();
419 // hide stuff that is not compatible
437 * @cfg {String} fieldClass @hide
440 * @cfg {String} focusClass @hide
443 * @cfg {String} autoCreate @hide
446 * @cfg {String} inputType @hide
449 * @cfg {String} invalidClass @hide
452 * @cfg {String} invalidText @hide
455 * @cfg {String} msgFx @hide
458 * @cfg {String} validateOnBlur @hide