9 * @class Roo.bootstrap.HtmlEditor
10 * @extends Roo.bootstrap.Component
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(editor){
178 }, 'toolbarContainer')
180 Roo.log("create toolbars");
182 if (!editor.toolbars || !editor.toolbars.length) {
183 editor.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard() ]; // can be empty?
186 for (var i =0 ; i < editor.toolbars.length;i++) {
187 editor.toolbars[i] = Roo.factory(
188 typeof(editor.toolbars[i]) == 'string' ?
189 { xtype: editor.toolbars[i]} : editor.toolbars[i],
190 Roo.bootstrap.HtmlEditor);
191 editor.toolbars[i].init(editor);
199 onRender : function(ct, position)
201 // Roo.log("Call onRender: " + this.xtype);
203 Roo.bootstrap.HtmlEditor.superclass.onRender.call(this, ct, position);
205 this.wrap = this.inputEl().wrap({
206 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
209 this.editorcore.onRender(ct, position);
211 if (this.resizable) {
212 this.resizeEl = new Roo.Resizable(this.wrap, {
216 minHeight : this.height,
218 handles : this.resizable,
221 resize : function(r, w, h) {
222 _t.onResize(w,h); // -something
228 this.createToolbar(this);
232 this.setSize(this.wrap.getSize());
235 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
236 // should trigger onReize..
239 // if(this.autosave && this.w){
240 // this.autoSaveFn = setInterval(this.autosave, 1000);
245 onResize : function(w, h)
247 //Roo.log('resize: ' +w + ',' + h );
248 Roo.bootstrap.HtmlEditor.superclass.onResize.apply(this, arguments);
253 if(typeof w == 'number'){
254 var aw = w - this.wrap.getFrameWidth('lr');
255 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
258 if(typeof h == 'number'){
260 for (var i =0; i < this.toolbars.length;i++) {
261 // fixme - ask toolbars for heights?
262 tbh += this.toolbars[i].tb.el.getHeight();
263 if (this.toolbars[i].footer) {
264 tbh += this.toolbars[i].footer.el.getHeight();
271 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
272 ah -= 5; // knock a few pixes off for look..
273 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
277 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
278 this.editorcore.onResize(ew,eh);
283 * Toggles the editor between standard and source edit mode.
284 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
286 toggleSourceEdit : function(sourceEditMode)
288 this.editorcore.toggleSourceEdit(sourceEditMode);
290 if(this.editorcore.sourceEditMode){
291 Roo.log('editor - showing textarea');
294 // Roo.log(this.syncValue());
295 this.editorcore.syncValue();
296 this.inputEl().removeClass('hide');
297 this.inputEl().dom.removeAttribute('tabIndex');
298 this.inputEl().focus();
300 Roo.log('editor - hiding textarea');
302 // Roo.log(this.pushValue());
303 this.editorcore.pushValue();
305 this.inputEl().addClass('hide');
306 this.inputEl().dom.setAttribute('tabIndex', -1);
310 this.setSize(this.wrap.getSize());
311 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
314 // private (for BoxComponent)
315 adjustSize : Roo.BoxComponent.prototype.adjustSize,
317 // private (for BoxComponent)
318 getResizeEl : function(){
322 // private (for BoxComponent)
323 getPositionEl : function(){
328 initEvents : function(){
329 this.originalValue = this.getValue();
333 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
336 markInvalid : Roo.emptyFn,
338 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
341 clearInvalid : Roo.emptyFn,
343 setValue : function(v){
344 Roo.bootstrap.HtmlEditor.superclass.setValue.call(this, v);
345 this.editorcore.pushValue();
350 deferFocus : function(){
351 this.focus.defer(10, this);
356 this.editorcore.focus();
362 onDestroy : function(){
368 for (var i =0; i < this.toolbars.length;i++) {
369 // fixme - ask toolbars for heights?
370 this.toolbars[i].onDestroy();
373 this.wrap.dom.innerHTML = '';
379 onFirstFocus : function(){
380 //Roo.log("onFirstFocus");
381 this.editorcore.onFirstFocus();
382 for (var i =0; i < this.toolbars.length;i++) {
383 this.toolbars[i].onFirstFocus();
389 syncValue : function()
391 this.editorcore.syncValue();
395 // hide stuff that is not compatible
413 * @cfg {String} fieldClass @hide
416 * @cfg {String} focusClass @hide
419 * @cfg {String} autoCreate @hide
422 * @cfg {String} inputType @hide
425 * @cfg {String} invalidClass @hide
428 * @cfg {String} invalidText @hide
431 * @cfg {String} msgFx @hide
434 * @cfg {String} validateOnBlur @hide