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
101 * @event stylesheetsclick
102 * Fires when press the Sytlesheets button
103 * @param {Roo.HtmlEditorCore} this
105 stylesheetsclick: true,
108 * Fires when press user pastes into the editor
109 * @param {Roo.HtmlEditorCore} this
114 * Fires when on any editor when an image is added (excluding paste)
115 * @param {Roo.HtmlEditorCore} this
120 * Fires when on any editor when an image is deleted
121 * @param {Roo.HtmlEditorCore} this
128 Roo.extend(Roo.bootstrap.form.HtmlEditor, Roo.bootstrap.form.TextArea, {
132 * @cfg {Array|boolean} toolbars Array of toolbars, or names of toolbars. - true for standard, and false for none.
137 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
142 * @cfg {String} resize (none|both|horizontal|vertical) - css resize of element
146 * @cfg {Number} height (in pixels)
150 * @cfg {Number} width (in pixels)
155 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
163 // private properties
164 validationEvent : false,
169 onFocus : Roo.emptyFn,
177 toolbarContainer :function() {
178 return this.wrap.select('.x-html-editor-tb',true).first();
182 * Protected method that will not generally be called directly. It
183 * is called when the editor creates its toolbar. Override this method if you need to
184 * add custom toolbar buttons.
185 * @param {HtmlEditor} editor
187 createToolbar : function()
189 //Roo.log('renewing');
190 //Roo.log("create toolbars");
191 if (this.toolbars === false) {
194 if (this.toolbars === true) {
195 this.toolbars = [ 'Standard' ];
198 var ar = Array.from(this.toolbars);
200 ar.forEach(function(t,i) {
201 if (typeof(t) == 'string') {
206 if (typeof(t) == 'object' && typeof(t.xtype) == 'string') {
208 t.xns = t.xns || Roo.bootstrap.form.HtmlEditorToolbar;
211 this.toolbars[i] = t;
212 this.toolbars[i].render(this.toolbarContainer());
220 onRender : function(ct, position)
222 // Roo.log("Call onRender: " + this.xtype);
224 Roo.bootstrap.form.HtmlEditor.superclass.onRender.call(this, ct, position);
226 this.wrap = this.inputEl().wrap({
227 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
230 this.editorcore.onRender(ct, position);
233 this.createToolbar(this);
241 onResize : function(w, h)
243 Roo.log('resize: ' +w + ',' + h );
244 Roo.bootstrap.form.HtmlEditor.superclass.onResize.apply(this, arguments);
249 if(typeof w == 'number'){
250 var aw = w - this.wrap.getFrameWidth('lr');
251 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
254 if(typeof h == 'number'){
255 var tbh = -11; // fixme it needs to tool bar size!
256 for (var i =0; i < this.toolbars.length;i++) {
257 // fixme - ask toolbars for heights?
258 tbh += this.toolbars[i].el.getHeight();
259 //if (this.toolbars[i].footer) {
260 // tbh += this.toolbars[i].footer.el.getHeight();
268 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
269 ah -= 5; // knock a few pixes off for look..
270 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
274 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
275 this.editorcore.onResize(ew,eh);
280 * Toggles the editor between standard and source edit mode.
281 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
283 toggleSourceEdit : function(sourceEditMode)
285 this.editorcore.toggleSourceEdit(sourceEditMode);
287 if(this.editorcore.sourceEditMode){
288 Roo.log('editor - showing textarea');
291 // Roo.log(this.syncValue());
293 this.inputEl().removeClass(['hide', 'x-hidden']);
294 this.inputEl().dom.removeAttribute('tabIndex');
295 this.inputEl().focus();
297 Roo.log('editor - hiding textarea');
299 // Roo.log(this.pushValue());
302 this.inputEl().addClass(['hide', 'x-hidden']);
303 this.inputEl().dom.setAttribute('tabIndex', -1);
307 //if(this.resizable){
308 // 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.form.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();
394 pushValue : function()
396 this.editorcore.pushValue();
400 // hide stuff that is not compatible
418 * @cfg {String} fieldClass @hide
421 * @cfg {String} focusClass @hide
424 * @cfg {String} autoCreate @hide
427 * @cfg {String} inputType @hide
431 * @cfg {String} invalidText @hide
434 * @cfg {String} msgFx @hide
437 * @cfg {String} validateOnBlur @hide