9 * @class Roo.bootstrap.HtmlEditor
10 * @extends Roo.bootstrap.TextArea
11 * Bootstrap HtmlEditor class
14 * Create a new HtmlEditor
15 * @param {Object} config The config object
18 Roo.bootstrap.HtmlEditor = function(config){
19 Roo.bootstrap.HtmlEditor.superclass.constructor.call(this, config);
23 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
27 * Fires when the editor is fully initialized (including the iframe)
28 * @param {HtmlEditor} this
33 * Fires when the editor is first receives the focus. Any insertion must wait
34 * until after this event.
35 * @param {HtmlEditor} this
40 * Fires before the textarea is updated with content from the editor iframe. Return false
42 * @param {HtmlEditor} this
43 * @param {String} html
48 * Fires before the iframe editor is updated with content from the textarea. Return false
50 * @param {HtmlEditor} this
51 * @param {String} html
56 * Fires when the textarea is updated with content from the editor iframe.
57 * @param {HtmlEditor} this
58 * @param {String} html
63 * Fires when the iframe editor is updated with content from the textarea.
64 * @param {HtmlEditor} this
65 * @param {String} html
69 * @event editmodechange
70 * Fires when the editor switches edit modes
71 * @param {HtmlEditor} this
72 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
77 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
78 * @param {HtmlEditor} this
83 * Fires when on first focus - needed by toolbars..
84 * @param {HtmlEditor} this
89 * Auto save the htmlEditor value as a file into Events
90 * @param {HtmlEditor} this
95 * preview the saved version of htmlEditor
96 * @param {HtmlEditor} this
103 Roo.extend(Roo.bootstrap.HtmlEditor, Roo.bootstrap.TextArea, {
107 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
112 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
117 * @cfg {Number} height (in pixels)
121 * @cfg {Number} width (in pixels)
126 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
134 // private properties
135 validationEvent : false,
140 onFocus : Roo.emptyFn,
147 toolbarContainer :function() {
148 return this.wrap.select('.x-html-editor-tb',true).first();
152 * Protected method that will not generally be called directly. It
153 * is called when the editor creates its toolbar. Override this method if you need to
154 * add custom toolbar buttons.
155 * @param {HtmlEditor} editor
157 createToolbar : function(){
159 Roo.log("create toolbars");
161 this.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard({editor: this} ) ];
162 this.toolbars[0].render(this.toolbarContainer());
166 // if (!editor.toolbars || !editor.toolbars.length) {
167 // editor.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard() ]; // can be empty?
170 // for (var i =0 ; i < editor.toolbars.length;i++) {
171 // editor.toolbars[i] = Roo.factory(
172 // typeof(editor.toolbars[i]) == 'string' ?
173 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
174 // Roo.bootstrap.HtmlEditor);
175 // editor.toolbars[i].init(editor);
181 onRender : function(ct, position)
183 // Roo.log("Call onRender: " + this.xtype);
185 Roo.bootstrap.HtmlEditor.superclass.onRender.call(this, ct, position);
187 this.wrap = this.inputEl().wrap({
188 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
191 this.editorcore.onRender(ct, position);
193 if (this.resizable) {
194 this.resizeEl = new Roo.Resizable(this.wrap, {
198 minHeight : this.height,
200 handles : this.resizable,
203 resize : function(r, w, h) {
204 _t.onResize(w,h); // -something
210 this.createToolbar(this);
214 this.setSize(this.wrap.getSize());
217 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
218 // should trigger onReize..
221 // if(this.autosave && this.w){
222 // this.autoSaveFn = setInterval(this.autosave, 1000);
227 onResize : function(w, h)
229 Roo.log('run resize 1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
230 Roo.log('resize: ' +w + ',' + h );
231 Roo.bootstrap.HtmlEditor.superclass.onResize.apply(this, arguments);
236 if(typeof w == 'number'){
237 var aw = w - this.wrap.getFrameWidth('lr');
238 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
241 if(typeof h == 'number'){
242 var tbh = -11; // fixme it needs to tool bar size!
243 for (var i =0; i < this.toolbars.length;i++) {
244 // fixme - ask toolbars for heights?
245 tbh += this.toolbars[i].el.getHeight();
246 //if (this.toolbars[i].footer) {
247 // tbh += this.toolbars[i].footer.el.getHeight();
255 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
256 ah -= 5; // knock a few pixes off for look..
257 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
261 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
262 this.editorcore.onResize(ew,eh);
267 * Toggles the editor between standard and source edit mode.
268 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
270 toggleSourceEdit : function(sourceEditMode)
272 this.editorcore.toggleSourceEdit(sourceEditMode);
274 if(this.editorcore.sourceEditMode){
275 Roo.log('editor - showing textarea');
278 // Roo.log(this.syncValue());
279 this.editorcore.syncValue();
280 this.inputEl().removeClass('hide');
281 this.inputEl().dom.removeAttribute('tabIndex');
282 this.inputEl().focus();
284 Roo.log('editor - hiding textarea');
286 // Roo.log(this.pushValue());
287 this.editorcore.pushValue();
289 this.inputEl().addClass('hide');
290 this.inputEl().dom.setAttribute('tabIndex', -1);
294 this.setSize(this.wrap.getSize());
295 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
298 // private (for BoxComponent)
299 adjustSize : Roo.BoxComponent.prototype.adjustSize,
301 // private (for BoxComponent)
302 getResizeEl : function(){
306 // private (for BoxComponent)
307 getPositionEl : function(){
312 initEvents : function(){
313 this.originalValue = this.getValue();
317 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
320 markInvalid : Roo.emptyFn,
322 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
325 clearInvalid : Roo.emptyFn,
327 setValue : function(v){
328 Roo.bootstrap.HtmlEditor.superclass.setValue.call(this, v);
329 this.editorcore.pushValue();
334 deferFocus : function(){
335 this.focus.defer(10, this);
340 this.editorcore.focus();
346 onDestroy : function(){
352 for (var i =0; i < this.toolbars.length;i++) {
353 // fixme - ask toolbars for heights?
354 this.toolbars[i].onDestroy();
357 this.wrap.dom.innerHTML = '';
363 onFirstFocus : function(){
364 //Roo.log("onFirstFocus");
365 this.editorcore.onFirstFocus();
366 for (var i =0; i < this.toolbars.length;i++) {
367 this.toolbars[i].onFirstFocus();
373 syncValue : function()
375 this.editorcore.syncValue();
378 pushValue : function()
380 this.editorcore.pushValue();
384 // hide stuff that is not compatible
402 * @cfg {String} fieldClass @hide
405 * @cfg {String} focusClass @hide
408 * @cfg {String} autoCreate @hide
411 * @cfg {String} inputType @hide
414 * @cfg {String} invalidClass @hide
417 * @cfg {String} invalidText @hide
420 * @cfg {String} msgFx @hide
423 * @cfg {String} validateOnBlur @hide