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){
23 * Fires when the editor is fully initialized (including the iframe)
24 * @param {Roo.bootstrap.form.HtmlEditor} this
29 * Fires when the editor is first receives the focus. Any insertion must wait
30 * until after this event.
31 * @param {Roo.bootstrap.form.HtmlEditor} this
36 * Fires before the textarea is updated with content from the editor iframe. Return false
38 * @param {Roo.bootstrap.form.HtmlEditor} this
39 * @param {String} html
44 * Fires before the iframe editor is updated with content from the textarea. Return false
46 * @param {Roo.bootstrap.form.HtmlEditor} this
47 * @param {String} html
52 * Fires when the textarea is updated with content from the editor iframe.
53 * @param {Roo.bootstrap.form.HtmlEditor} this
54 * @param {String} html
59 * Fires when the iframe editor is updated with content from the textarea.
60 * @param {Roo.bootstrap.form.HtmlEditor} this
61 * @param {String} html
65 * @event editmodechange
66 * Fires when the editor switches edit modes
67 * @param {Roo.bootstrap.form.HtmlEditor} this
68 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
73 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
74 * @param {Roo.bootstrap.form.HtmlEditor} this
79 * Fires when on first focus - needed by toolbars..
80 * @param {Roo.bootstrap.form.HtmlEditor} this
85 * Auto save the htmlEditor value as a file into Events
86 * @param {Roo.bootstrap.form.HtmlEditor} this
91 * preview the saved version of htmlEditor
92 * @param {Roo.bootstrap.form.HtmlEditor} this
96 * @event stylesheetsclick
97 * Fires when press the Sytlesheets button
98 * @param {Roo.HtmlEditorCore} this
100 stylesheetsclick: true,
103 * Fires when press user pastes into the editor
104 * @param {Roo.HtmlEditorCore} this
109 * Fires when on any editor when an image is added (excluding paste)
110 * @param {Roo.bootstrap.form.HtmlEditor} this
114 * @event imageupdated
115 * Fires when on any editor when an image is changed (excluding paste)
116 * @param {Roo.bootstrap.form.HtmlEditor} this
117 * @param {HTMLElement} img could also be a figure if blocks are enabled
122 * Fires when on any editor when an image is deleted
123 * @param {Roo.bootstrap.form.HtmlEditor} this
124 * @param {HTMLElement} img could also be a figure if blocks are enabled
125 * @param {HTMLElement} oldSrc source of image being replaced
129 Roo.bootstrap.form.HtmlEditor.superclass.constructor.call(this, config);
130 if (!this.toolbars) {
134 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
139 Roo.extend(Roo.bootstrap.form.HtmlEditor, Roo.bootstrap.form.TextArea, {
143 * @cfg {Array|boolean} toolbars Array of toolbars, or names of toolbars. - true for standard, and false for none.
148 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
153 * @cfg {String} resize (none|both|horizontal|vertical) - css resize of element
157 * @cfg {Number} height (in pixels)
161 * @cfg {Number} width (in pixels)
166 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
174 // private properties
175 validationEvent : false,
180 onFocus : Roo.emptyFn,
190 toolbarContainer :function() {
191 return this.wrap.select('.x-html-editor-tb',true).first();
195 * Protected method that will not generally be called directly. It
196 * is called when the editor creates its toolbar. Override this method if you need to
197 * add custom toolbar buttons.
198 * @param {HtmlEditor} editor
200 createToolbar : function()
202 //Roo.log('renewing');
203 //Roo.log("create toolbars");
204 if (this.toolbars === false) {
207 if (this.toolbars === true) {
208 this.toolbars = [ 'Standard' ];
211 var ar = Array.from(this.toolbars);
213 ar.forEach(function(t,i) {
214 if (typeof(t) == 'string') {
219 if (typeof(t) == 'object' && typeof(t.xtype) == 'string') {
221 t.xns = t.xns || Roo.bootstrap.form.HtmlEditorToolbar;
224 this.toolbars[i] = t;
225 this.toolbars[i].render(this.toolbarContainer());
233 onRender : function(ct, position)
235 // Roo.log("Call onRender: " + this.xtype);
237 Roo.bootstrap.form.HtmlEditor.superclass.onRender.call(this, ct, position);
239 this.wrap = this.inputEl().wrap({
240 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
243 this.editorcore.onRender(ct, position);
246 this.createToolbar(this);
254 onResize : function(w, h)
256 Roo.log('resize: ' +w + ',' + h );
257 Roo.bootstrap.form.HtmlEditor.superclass.onResize.apply(this, arguments);
262 if(typeof w == 'number'){
263 var aw = w - this.wrap.getFrameWidth('lr');
264 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
267 if(typeof h == 'number'){
268 var tbh = -11; // fixme it needs to tool bar size!
269 for (var i =0; i < this.toolbars.length;i++) {
270 // fixme - ask toolbars for heights?
271 tbh += this.toolbars[i].el.getHeight();
272 //if (this.toolbars[i].footer) {
273 // tbh += this.toolbars[i].footer.el.getHeight();
281 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
282 ah -= 5; // knock a few pixes off for look..
283 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
287 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
288 this.editorcore.onResize(ew,eh);
293 * Toggles the editor between standard and source edit mode.
294 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
296 toggleSourceEdit : function(sourceEditMode)
298 this.editorcore.toggleSourceEdit(sourceEditMode);
300 if(this.editorcore.sourceEditMode){
301 Roo.log('editor - showing textarea');
304 // Roo.log(this.syncValue());
306 this.inputEl().removeClass(['hide', 'x-hidden']);
307 this.inputEl().dom.removeAttribute('tabIndex');
308 this.inputEl().focus();
310 Roo.log('editor - hiding textarea');
312 // Roo.log(this.pushValue());
315 this.inputEl().addClass(['hide', 'x-hidden']);
316 this.inputEl().dom.setAttribute('tabIndex', -1);
320 //if(this.resizable){
321 // this.setSize(this.wrap.getSize());
324 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
327 // private (for BoxComponent)
328 adjustSize : Roo.BoxComponent.prototype.adjustSize,
330 // private (for BoxComponent)
331 getResizeEl : function(){
335 // private (for BoxComponent)
336 getPositionEl : function(){
341 initEvents : function(){
342 this.originalValue = this.getValue();
346 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
349 // markInvalid : Roo.emptyFn,
351 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
354 // clearInvalid : Roo.emptyFn,
356 setValue : function(v){
357 Roo.bootstrap.form.HtmlEditor.superclass.setValue.call(this, v);
358 this.editorcore.pushValue();
363 deferFocus : function(){
364 this.focus.defer(10, this);
369 this.editorcore.focus();
375 onDestroy : function(){
381 for (var i =0; i < this.toolbars.length;i++) {
382 // fixme - ask toolbars for heights?
383 this.toolbars[i].onDestroy();
386 this.wrap.dom.innerHTML = '';
392 onFirstFocus : function(){
393 //Roo.log("onFirstFocus");
394 this.editorcore.onFirstFocus();
395 for (var i =0; i < this.toolbars.length;i++) {
396 this.toolbars[i].onFirstFocus();
402 syncValue : function()
404 this.editorcore.syncValue();
407 pushValue : function()
409 this.editorcore.pushValue();
413 // hide stuff that is not compatible
431 * @cfg {String} fieldClass @hide
434 * @cfg {String} focusClass @hide
437 * @cfg {String} autoCreate @hide
440 * @cfg {String} inputType @hide
444 * @cfg {String} invalidText @hide
447 * @cfg {String} msgFx @hide
450 * @cfg {String} validateOnBlur @hide