9 * @class Roo.bootstrap.HtmlEditor
10 * @extends Roo.bootstrap.TextArea
11 * Bootstrap HtmlEditor class
14 * Create a new HtmlEditor
15 * @param {Object} config The config object
18 Roo.bootstrap.HtmlEditor = function(config){
19 Roo.bootstrap.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.HtmlEditor, Roo.bootstrap.TextArea, {
108 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
113 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
118 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
123 * @cfg {Number} height (in pixels)
127 * @cfg {Number} width (in pixels)
132 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
140 // private properties
141 validationEvent : false,
146 onFocus : Roo.emptyFn,
154 toolbarContainer :function() {
155 return this.wrap.select('.x-html-editor-tb',true).first();
159 * Protected method that will not generally be called directly. It
160 * is called when the editor creates its toolbar. Override this method if you need to
161 * add custom toolbar buttons.
162 * @param {HtmlEditor} editor
164 createToolbar : function(){
166 Roo.log("create toolbars");
168 this.toolbars = [ new Roo.bootstrap.htmleditor.ToolbarStandard({editor: this} ) ];
169 this.toolbars[0].render(this.toolbarContainer());
173 // if (!editor.toolbars || !editor.toolbars.length) {
174 // editor.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard() ]; // can be empty?
177 // for (var i =0 ; i < editor.toolbars.length;i++) {
178 // editor.toolbars[i] = Roo.factory(
179 // typeof(editor.toolbars[i]) == 'string' ?
180 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
181 // Roo.bootstrap.HtmlEditor);
182 // editor.toolbars[i].init(editor);
188 onRender : function(ct, position)
190 // Roo.log("Call onRender: " + this.xtype);
192 Roo.bootstrap.HtmlEditor.superclass.onRender.call(this, ct, position);
194 this.wrap = this.inputEl().wrap({
195 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
198 this.editorcore.onRender(ct, position);
200 if (this.resizable) {
201 this.resizeEl = new Roo.Resizable(this.wrap, {
205 minHeight : this.height,
207 handles : this.resizable,
210 resize : function(r, w, h) {
211 _t.onResize(w,h); // -something
217 this.createToolbar(this);
220 if(!this.width && this.resizable){
221 this.setSize(this.wrap.getSize());
224 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
225 // should trigger onReize..
231 onResize : function(w, h)
233 Roo.log('resize: ' +w + ',' + h );
234 Roo.bootstrap.HtmlEditor.superclass.onResize.apply(this, arguments);
239 if(typeof w == 'number'){
240 var aw = w - this.wrap.getFrameWidth('lr');
241 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
244 if(typeof h == 'number'){
245 var tbh = -11; // fixme it needs to tool bar size!
246 for (var i =0; i < this.toolbars.length;i++) {
247 // fixme - ask toolbars for heights?
248 tbh += this.toolbars[i].el.getHeight();
249 //if (this.toolbars[i].footer) {
250 // tbh += this.toolbars[i].footer.el.getHeight();
258 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
259 ah -= 5; // knock a few pixes off for look..
260 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
264 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
265 this.editorcore.onResize(ew,eh);
270 * Toggles the editor between standard and source edit mode.
271 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
273 toggleSourceEdit : function(sourceEditMode)
275 this.editorcore.toggleSourceEdit(sourceEditMode);
277 if(this.editorcore.sourceEditMode){
278 Roo.log('editor - showing textarea');
281 // Roo.log(this.syncValue());
283 this.inputEl().removeClass(['hide', 'x-hidden']);
284 this.inputEl().dom.removeAttribute('tabIndex');
285 this.inputEl().focus();
287 Roo.log('editor - hiding textarea');
289 // Roo.log(this.pushValue());
292 this.inputEl().addClass(['hide', 'x-hidden']);
293 this.inputEl().dom.setAttribute('tabIndex', -1);
298 this.setSize(this.wrap.getSize());
301 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
304 // private (for BoxComponent)
305 adjustSize : Roo.BoxComponent.prototype.adjustSize,
307 // private (for BoxComponent)
308 getResizeEl : function(){
312 // private (for BoxComponent)
313 getPositionEl : function(){
318 initEvents : function(){
319 this.originalValue = this.getValue();
323 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
326 // markInvalid : Roo.emptyFn,
328 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
331 // clearInvalid : Roo.emptyFn,
333 setValue : function(v){
334 Roo.bootstrap.HtmlEditor.superclass.setValue.call(this, v);
335 this.editorcore.pushValue();
340 deferFocus : function(){
341 this.focus.defer(10, this);
346 this.editorcore.focus();
352 onDestroy : function(){
358 for (var i =0; i < this.toolbars.length;i++) {
359 // fixme - ask toolbars for heights?
360 this.toolbars[i].onDestroy();
363 this.wrap.dom.innerHTML = '';
369 onFirstFocus : function(){
370 //Roo.log("onFirstFocus");
371 this.editorcore.onFirstFocus();
372 for (var i =0; i < this.toolbars.length;i++) {
373 this.toolbars[i].onFirstFocus();
379 syncValue : function()
381 this.editorcore.syncValue();
384 pushValue : function()
386 this.editorcore.pushValue();
390 // hide stuff that is not compatible
408 * @cfg {String} fieldClass @hide
411 * @cfg {String} focusClass @hide
414 * @cfg {String} autoCreate @hide
417 * @cfg {String} inputType @hide
421 * @cfg {String} invalidText @hide
424 * @cfg {String} msgFx @hide
427 * @cfg {String} validateOnBlur @hide