9 * @class Roo.bootstrap.form.HtmlEditor
10 * @extends Roo.bootstrap.form.TextArea
11 * Bootstrap HtmlEditor class
14 * Create a new HtmlEditor
15 * @param {Object} config The config object
18 Roo.bootstrap.form.HtmlEditor = function(config){
19 Roo.bootstrap.form.HtmlEditor.superclass.constructor.call(this, config);
24 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
28 * Fires when the editor is fully initialized (including the iframe)
29 * @param {HtmlEditor} this
34 * Fires when the editor is first receives the focus. Any insertion must wait
35 * until after this event.
36 * @param {HtmlEditor} this
41 * Fires before the textarea is updated with content from the editor iframe. Return false
43 * @param {HtmlEditor} this
44 * @param {String} html
49 * Fires before the iframe editor is updated with content from the textarea. Return false
51 * @param {HtmlEditor} this
52 * @param {String} html
57 * Fires when the textarea is updated with content from the editor iframe.
58 * @param {HtmlEditor} this
59 * @param {String} html
64 * Fires when the iframe editor is updated with content from the textarea.
65 * @param {HtmlEditor} this
66 * @param {String} html
70 * @event editmodechange
71 * Fires when the editor switches edit modes
72 * @param {HtmlEditor} this
73 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
78 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
79 * @param {HtmlEditor} this
84 * Fires when on first focus - needed by toolbars..
85 * @param {HtmlEditor} this
90 * Auto save the htmlEditor value as a file into Events
91 * @param {HtmlEditor} this
96 * preview the saved version of htmlEditor
97 * @param {HtmlEditor} this
104 Roo.extend(Roo.bootstrap.form.HtmlEditor, Roo.bootstrap.form.TextArea, {
108 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
113 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
118 * @cfg {String} resize (none|both|horizontal|vertical) - css resize of element
122 * @cfg {Number} height (in pixels)
126 * @cfg {Number} width (in pixels)
131 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
139 // private properties
140 validationEvent : false,
145 onFocus : Roo.emptyFn,
153 toolbarContainer :function() {
154 return this.wrap.select('.x-html-editor-tb',true).first();
158 * Protected method that will not generally be called directly. It
159 * is called when the editor creates its toolbar. Override this method if you need to
160 * add custom toolbar buttons.
161 * @param {HtmlEditor} editor
163 createToolbar : function(){
165 Roo.log("create toolbars");
167 this.toolbars = [ new Roo.bootstrap.form.HtmlEditorToolbarStandard({editor: this} ) ];
168 this.toolbars[0].render(this.toolbarContainer());
172 // if (!editor.toolbars || !editor.toolbars.length) {
173 // editor.toolbars = [ new Roo.bootstrap.form.HtmlEditorToolbarStandard() ]; // can be empty?
176 // for (var i =0 ; i < editor.toolbars.length;i++) {
177 // editor.toolbars[i] = Roo.factory(
178 // typeof(editor.toolbars[i]) == 'string' ?
179 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
180 // Roo.bootstrap.form.HtmlEditor);
181 // editor.toolbars[i].init(editor);
187 onRender : function(ct, position)
189 // Roo.log("Call onRender: " + this.xtype);
191 Roo.bootstrap.form.HtmlEditor.superclass.onRender.call(this, ct, position);
193 this.wrap = this.inputEl().wrap({
194 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
197 this.editorcore.onRender(ct, position);
200 this.createToolbar(this);
208 onResize : function(w, h)
210 Roo.log('resize: ' +w + ',' + h );
211 Roo.bootstrap.form.HtmlEditor.superclass.onResize.apply(this, arguments);
216 if(typeof w == 'number'){
217 var aw = w - this.wrap.getFrameWidth('lr');
218 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
221 if(typeof h == 'number'){
222 var tbh = -11; // fixme it needs to tool bar size!
223 for (var i =0; i < this.toolbars.length;i++) {
224 // fixme - ask toolbars for heights?
225 tbh += this.toolbars[i].el.getHeight();
226 //if (this.toolbars[i].footer) {
227 // tbh += this.toolbars[i].footer.el.getHeight();
235 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
236 ah -= 5; // knock a few pixes off for look..
237 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
241 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
242 this.editorcore.onResize(ew,eh);
247 * Toggles the editor between standard and source edit mode.
248 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
250 toggleSourceEdit : function(sourceEditMode)
252 this.editorcore.toggleSourceEdit(sourceEditMode);
254 if(this.editorcore.sourceEditMode){
255 Roo.log('editor - showing textarea');
258 // Roo.log(this.syncValue());
260 this.inputEl().removeClass(['hide', 'x-hidden']);
261 this.inputEl().dom.removeAttribute('tabIndex');
262 this.inputEl().focus();
264 Roo.log('editor - hiding textarea');
266 // Roo.log(this.pushValue());
269 this.inputEl().addClass(['hide', 'x-hidden']);
270 this.inputEl().dom.setAttribute('tabIndex', -1);
274 //if(this.resizable){
275 // this.setSize(this.wrap.getSize());
278 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
281 // private (for BoxComponent)
282 adjustSize : Roo.BoxComponent.prototype.adjustSize,
284 // private (for BoxComponent)
285 getResizeEl : function(){
289 // private (for BoxComponent)
290 getPositionEl : function(){
295 initEvents : function(){
296 this.originalValue = this.getValue();
300 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
303 // markInvalid : Roo.emptyFn,
305 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
308 // clearInvalid : Roo.emptyFn,
310 setValue : function(v){
311 Roo.bootstrap.form.HtmlEditor.superclass.setValue.call(this, v);
312 this.editorcore.pushValue();
317 deferFocus : function(){
318 this.focus.defer(10, this);
323 this.editorcore.focus();
329 onDestroy : function(){
335 for (var i =0; i < this.toolbars.length;i++) {
336 // fixme - ask toolbars for heights?
337 this.toolbars[i].onDestroy();
340 this.wrap.dom.innerHTML = '';
346 onFirstFocus : function(){
347 //Roo.log("onFirstFocus");
348 this.editorcore.onFirstFocus();
349 for (var i =0; i < this.toolbars.length;i++) {
350 this.toolbars[i].onFirstFocus();
356 syncValue : function()
358 this.editorcore.syncValue();
361 pushValue : function()
363 this.editorcore.pushValue();
367 // hide stuff that is not compatible
385 * @cfg {String} fieldClass @hide
388 * @cfg {String} focusClass @hide
391 * @cfg {String} autoCreate @hide
394 * @cfg {String} inputType @hide
398 * @cfg {String} invalidText @hide
401 * @cfg {String} msgFx @hide
404 * @cfg {String} validateOnBlur @hide