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
128 Roo.bootstrap.form.HtmlEditor.superclass.constructor.call(this, config);
129 if (!this.toolbars) {
133 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
138 Roo.extend(Roo.bootstrap.form.HtmlEditor, Roo.bootstrap.form.TextArea, {
142 * @cfg {Array|boolean} toolbars Array of toolbars, or names of toolbars. - true for standard, and false for none.
147 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
152 * @cfg {String} resize (none|both|horizontal|vertical) - css resize of element
156 * @cfg {Number} height (in pixels)
160 * @cfg {Number} width (in pixels)
165 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
173 // private properties
174 validationEvent : false,
179 onFocus : Roo.emptyFn,
187 toolbarContainer :function() {
188 return this.wrap.select('.x-html-editor-tb',true).first();
192 * Protected method that will not generally be called directly. It
193 * is called when the editor creates its toolbar. Override this method if you need to
194 * add custom toolbar buttons.
195 * @param {HtmlEditor} editor
197 createToolbar : function()
199 //Roo.log('renewing');
200 //Roo.log("create toolbars");
201 if (this.toolbars === false) {
204 if (this.toolbars === true) {
205 this.toolbars = [ 'Standard' ];
208 var ar = Array.from(this.toolbars);
210 ar.forEach(function(t,i) {
211 if (typeof(t) == 'string') {
216 if (typeof(t) == 'object' && typeof(t.xtype) == 'string') {
218 t.xns = t.xns || Roo.bootstrap.form.HtmlEditorToolbar;
221 this.toolbars[i] = t;
222 this.toolbars[i].render(this.toolbarContainer());
230 onRender : function(ct, position)
232 // Roo.log("Call onRender: " + this.xtype);
234 Roo.bootstrap.form.HtmlEditor.superclass.onRender.call(this, ct, position);
236 this.wrap = this.inputEl().wrap({
237 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
240 this.editorcore.onRender(ct, position);
243 this.createToolbar(this);
251 onResize : function(w, h)
253 Roo.log('resize: ' +w + ',' + h );
254 Roo.bootstrap.form.HtmlEditor.superclass.onResize.apply(this, arguments);
259 if(typeof w == 'number'){
260 var aw = w - this.wrap.getFrameWidth('lr');
261 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
264 if(typeof h == 'number'){
265 var tbh = -11; // fixme it needs to tool bar size!
266 for (var i =0; i < this.toolbars.length;i++) {
267 // fixme - ask toolbars for heights?
268 tbh += this.toolbars[i].el.getHeight();
269 //if (this.toolbars[i].footer) {
270 // tbh += this.toolbars[i].footer.el.getHeight();
278 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
279 ah -= 5; // knock a few pixes off for look..
280 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
284 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
285 this.editorcore.onResize(ew,eh);
290 * Toggles the editor between standard and source edit mode.
291 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
293 toggleSourceEdit : function(sourceEditMode)
295 this.editorcore.toggleSourceEdit(sourceEditMode);
297 if(this.editorcore.sourceEditMode){
298 Roo.log('editor - showing textarea');
301 // Roo.log(this.syncValue());
303 this.inputEl().removeClass(['hide', 'x-hidden']);
304 this.inputEl().dom.removeAttribute('tabIndex');
305 this.inputEl().focus();
307 Roo.log('editor - hiding textarea');
309 // Roo.log(this.pushValue());
312 this.inputEl().addClass(['hide', 'x-hidden']);
313 this.inputEl().dom.setAttribute('tabIndex', -1);
317 //if(this.resizable){
318 // this.setSize(this.wrap.getSize());
321 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
324 // private (for BoxComponent)
325 adjustSize : Roo.BoxComponent.prototype.adjustSize,
327 // private (for BoxComponent)
328 getResizeEl : function(){
332 // private (for BoxComponent)
333 getPositionEl : function(){
338 initEvents : function(){
339 this.originalValue = this.getValue();
343 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
346 // markInvalid : Roo.emptyFn,
348 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
351 // clearInvalid : Roo.emptyFn,
353 setValue : function(v){
356 Roo.bootstrap.form.HtmlEditor.superclass.setValue.call(this, v);
357 this.editorcore.pushValue();
362 deferFocus : function(){
363 this.focus.defer(10, this);
368 this.editorcore.focus();
374 onDestroy : function(){
380 for (var i =0; i < this.toolbars.length;i++) {
381 // fixme - ask toolbars for heights?
382 this.toolbars[i].onDestroy();
385 this.wrap.dom.innerHTML = '';
391 onFirstFocus : function(){
392 //Roo.log("onFirstFocus");
393 this.editorcore.onFirstFocus();
394 for (var i =0; i < this.toolbars.length;i++) {
395 this.toolbars[i].onFirstFocus();
401 syncValue : function()
403 this.editorcore.syncValue();
406 pushValue : function()
408 this.editorcore.pushValue();
412 // hide stuff that is not compatible
430 * @cfg {String} fieldClass @hide
433 * @cfg {String} focusClass @hide
436 * @cfg {String} autoCreate @hide
439 * @cfg {String} inputType @hide
443 * @cfg {String} invalidText @hide
446 * @cfg {String} msgFx @hide
449 * @cfg {String} validateOnBlur @hide