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,
188 toolbarContainer :function() {
189 return this.wrap.select('.x-html-editor-tb',true).first();
193 * Protected method that will not generally be called directly. It
194 * is called when the editor creates its toolbar. Override this method if you need to
195 * add custom toolbar buttons.
196 * @param {HtmlEditor} editor
198 createToolbar : function()
200 //Roo.log('renewing');
201 //Roo.log("create toolbars");
202 if (this.toolbars === false) {
205 if (this.toolbars === true) {
206 this.toolbars = [ 'Standard' ];
209 var ar = Array.from(this.toolbars);
211 ar.forEach(function(t,i) {
212 if (typeof(t) == 'string') {
217 if (typeof(t) == 'object' && typeof(t.xtype) == 'string') {
219 t.xns = t.xns || Roo.bootstrap.form.HtmlEditorToolbar;
222 this.toolbars[i] = t;
223 this.toolbars[i].render(this.toolbarContainer());
231 onRender : function(ct, position)
233 // Roo.log("Call onRender: " + this.xtype);
235 Roo.bootstrap.form.HtmlEditor.superclass.onRender.call(this, ct, position);
237 this.wrap = this.inputEl().wrap({
238 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
241 this.editorcore.onRender(ct, position);
244 this.createToolbar(this);
252 onResize : function(w, h)
254 Roo.log('resize: ' +w + ',' + h );
255 Roo.bootstrap.form.HtmlEditor.superclass.onResize.apply(this, arguments);
260 if(typeof w == 'number'){
261 var aw = w - this.wrap.getFrameWidth('lr');
262 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
265 if(typeof h == 'number'){
266 var tbh = -11; // fixme it needs to tool bar size!
267 for (var i =0; i < this.toolbars.length;i++) {
268 // fixme - ask toolbars for heights?
269 tbh += this.toolbars[i].el.getHeight();
270 //if (this.toolbars[i].footer) {
271 // tbh += this.toolbars[i].footer.el.getHeight();
279 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
280 ah -= 5; // knock a few pixes off for look..
281 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
285 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
286 this.editorcore.onResize(ew,eh);
291 * Toggles the editor between standard and source edit mode.
292 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
294 toggleSourceEdit : function(sourceEditMode)
296 this.editorcore.toggleSourceEdit(sourceEditMode);
298 if(this.editorcore.sourceEditMode){
299 Roo.log('editor - showing textarea');
302 // Roo.log(this.syncValue());
304 this.inputEl().removeClass(['hide', 'x-hidden']);
305 this.inputEl().dom.removeAttribute('tabIndex');
306 this.inputEl().focus();
308 Roo.log('editor - hiding textarea');
310 // Roo.log(this.pushValue());
313 this.inputEl().addClass(['hide', 'x-hidden']);
314 this.inputEl().dom.setAttribute('tabIndex', -1);
318 //if(this.resizable){
319 // this.setSize(this.wrap.getSize());
322 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
325 // private (for BoxComponent)
326 adjustSize : Roo.BoxComponent.prototype.adjustSize,
328 // private (for BoxComponent)
329 getResizeEl : function(){
333 // private (for BoxComponent)
334 getPositionEl : function(){
339 initEvents : function(){
340 this.originalValue = this.getValue();
344 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
347 // markInvalid : Roo.emptyFn,
349 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
352 // clearInvalid : Roo.emptyFn,
354 setValue : function(v){
355 Roo.bootstrap.form.HtmlEditor.superclass.setValue.call(this, v);
356 this.editorcore.pushValue();
361 deferFocus : function(){
362 this.focus.defer(10, this);
367 this.editorcore.focus();
373 onDestroy : function(){
379 for (var i =0; i < this.toolbars.length;i++) {
380 // fixme - ask toolbars for heights?
381 this.toolbars[i].onDestroy();
384 this.wrap.dom.innerHTML = '';
390 onFirstFocus : function(){
391 //Roo.log("onFirstFocus");
392 this.editorcore.onFirstFocus();
393 for (var i =0; i < this.toolbars.length;i++) {
394 this.toolbars[i].onFirstFocus();
400 syncValue : function()
402 this.editorcore.syncValue();
405 pushValue : function()
407 this.editorcore.pushValue();
411 // hide stuff that is not compatible
429 * @cfg {String} fieldClass @hide
432 * @cfg {String} focusClass @hide
435 * @cfg {String} autoCreate @hide
438 * @cfg {String} inputType @hide
442 * @cfg {String} invalidText @hide
445 * @cfg {String} msgFx @hide
448 * @cfg {String} validateOnBlur @hide