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|boolean} toolbars Array of toolbars, or names of toolbars. - true for standard, and false for none.
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('renewing');
166 //Roo.log("create toolbars");
167 if (this.toolbars === false) {
170 if (this.toolbars === true) {
171 this.toolbars = [ 'Standard' ];
174 var ar = Array.from(this.toolbars);
176 ar.forEach(function(t,i) {
177 if (typeof(t) == 'string') {
182 if (typeof(t) == 'object' && typeof(t.xtype) == 'string') {
184 t.xns = t.xns || Roo.bootstrap.form.HtmlEditorToolbar;
187 this.toolbars[i] = t;
188 this.toolbars[i].render(this.toolbarContainer());
196 onRender : function(ct, position)
198 // Roo.log("Call onRender: " + this.xtype);
200 Roo.bootstrap.form.HtmlEditor.superclass.onRender.call(this, ct, position);
202 this.wrap = this.inputEl().wrap({
203 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
206 this.editorcore.onRender(ct, position);
209 this.createToolbar(this);
217 onResize : function(w, h)
219 Roo.log('resize: ' +w + ',' + h );
220 Roo.bootstrap.form.HtmlEditor.superclass.onResize.apply(this, arguments);
225 if(typeof w == 'number'){
226 var aw = w - this.wrap.getFrameWidth('lr');
227 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
230 if(typeof h == 'number'){
231 var tbh = -11; // fixme it needs to tool bar size!
232 for (var i =0; i < this.toolbars.length;i++) {
233 // fixme - ask toolbars for heights?
234 tbh += this.toolbars[i].el.getHeight();
235 //if (this.toolbars[i].footer) {
236 // tbh += this.toolbars[i].footer.el.getHeight();
244 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
245 ah -= 5; // knock a few pixes off for look..
246 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
250 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
251 this.editorcore.onResize(ew,eh);
256 * Toggles the editor between standard and source edit mode.
257 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
259 toggleSourceEdit : function(sourceEditMode)
261 this.editorcore.toggleSourceEdit(sourceEditMode);
263 if(this.editorcore.sourceEditMode){
264 Roo.log('editor - showing textarea');
267 // Roo.log(this.syncValue());
269 this.inputEl().removeClass(['hide', 'x-hidden']);
270 this.inputEl().dom.removeAttribute('tabIndex');
271 this.inputEl().focus();
273 Roo.log('editor - hiding textarea');
275 // Roo.log(this.pushValue());
278 this.inputEl().addClass(['hide', 'x-hidden']);
279 this.inputEl().dom.setAttribute('tabIndex', -1);
283 //if(this.resizable){
284 // this.setSize(this.wrap.getSize());
287 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
290 // private (for BoxComponent)
291 adjustSize : Roo.BoxComponent.prototype.adjustSize,
293 // private (for BoxComponent)
294 getResizeEl : function(){
298 // private (for BoxComponent)
299 getPositionEl : function(){
304 initEvents : function(){
305 this.originalValue = this.getValue();
309 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
312 // markInvalid : Roo.emptyFn,
314 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
317 // clearInvalid : Roo.emptyFn,
319 setValue : function(v){
320 Roo.bootstrap.form.HtmlEditor.superclass.setValue.call(this, v);
321 this.editorcore.pushValue();
326 deferFocus : function(){
327 this.focus.defer(10, this);
332 this.editorcore.focus();
338 onDestroy : function(){
344 for (var i =0; i < this.toolbars.length;i++) {
345 // fixme - ask toolbars for heights?
346 this.toolbars[i].onDestroy();
349 this.wrap.dom.innerHTML = '';
355 onFirstFocus : function(){
356 //Roo.log("onFirstFocus");
357 this.editorcore.onFirstFocus();
358 for (var i =0; i < this.toolbars.length;i++) {
359 this.toolbars[i].onFirstFocus();
365 syncValue : function()
367 this.editorcore.syncValue();
370 pushValue : function()
372 this.editorcore.pushValue();
376 // hide stuff that is not compatible
394 * @cfg {String} fieldClass @hide
397 * @cfg {String} focusClass @hide
400 * @cfg {String} autoCreate @hide
403 * @cfg {String} inputType @hide
407 * @cfg {String} invalidText @hide
410 * @cfg {String} msgFx @hide
413 * @cfg {String} validateOnBlur @hide