9 * @class Roo.bootstrap.HtmlEditor
10 * @extends Roo.bootstrap.Component
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);
23 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
27 * Fires when the editor is fully initialized (including the iframe)
28 * @param {HtmlEditor} this
33 * Fires when the editor is first receives the focus. Any insertion must wait
34 * until after this event.
35 * @param {HtmlEditor} this
40 * Fires before the textarea is updated with content from the editor iframe. Return false
42 * @param {HtmlEditor} this
43 * @param {String} html
48 * Fires before the iframe editor is updated with content from the textarea. Return false
50 * @param {HtmlEditor} this
51 * @param {String} html
56 * Fires when the textarea is updated with content from the editor iframe.
57 * @param {HtmlEditor} this
58 * @param {String} html
63 * Fires when the iframe editor is updated with content from the textarea.
64 * @param {HtmlEditor} this
65 * @param {String} html
69 * @event editmodechange
70 * Fires when the editor switches edit modes
71 * @param {HtmlEditor} this
72 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
77 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
78 * @param {HtmlEditor} this
83 * Fires when on first focus - needed by toolbars..
84 * @param {HtmlEditor} this
89 * Auto save the htmlEditor value as a file into Events
90 * @param {HtmlEditor} this
95 * preview the saved version of htmlEditor
96 * @param {HtmlEditor} this
103 Roo.extend(Roo.bootstrap.HtmlEditor, Roo.bootstrap.TextArea, {
107 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
112 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
117 * @cfg {Number} height (in pixels)
121 * @cfg {Number} width (in pixels)
126 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
134 // private properties
135 validationEvent : false,
140 onFocus : Roo.emptyFn,
147 toolbarContainer :function() {
148 return this.wrap.select('.x-html-editor-tb',true).first();
152 * Protected method that will not generally be called directly. It
153 * is called when the editor creates its toolbar. Override this method if you need to
154 * add custom toolbar buttons.
155 * @param {HtmlEditor} editor
157 createToolbar : function(editor){
173 xns: Roo.bootstrap.Navbar,
175 href : 'http://roojs.com',
185 href : 'http://roojs.com'
188 xtype: 'MenuSeparator',
195 href: 'http://roojs.com'
216 }, 'toolbarContainer')
218 Roo.log("create toolbars");
220 if (!editor.toolbars || !editor.toolbars.length) {
221 editor.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard() ]; // can be empty?
224 for (var i =0 ; i < editor.toolbars.length;i++) {
225 editor.toolbars[i] = Roo.factory(
226 typeof(editor.toolbars[i]) == 'string' ?
227 { xtype: editor.toolbars[i]} : editor.toolbars[i],
228 Roo.bootstrap.HtmlEditor);
229 editor.toolbars[i].init(editor);
237 onRender : function(ct, position)
239 // Roo.log("Call onRender: " + this.xtype);
241 Roo.bootstrap.HtmlEditor.superclass.onRender.call(this, ct, position);
243 this.wrap = this.inputEl().wrap({
244 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
247 this.editorcore.onRender(ct, position);
249 if (this.resizable) {
250 this.resizeEl = new Roo.Resizable(this.wrap, {
254 minHeight : this.height,
256 handles : this.resizable,
259 resize : function(r, w, h) {
260 _t.onResize(w,h); // -something
266 this.createToolbar(this);
270 this.setSize(this.wrap.getSize());
273 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
274 // should trigger onReize..
277 // if(this.autosave && this.w){
278 // this.autoSaveFn = setInterval(this.autosave, 1000);
283 onResize : function(w, h)
285 //Roo.log('resize: ' +w + ',' + h );
286 Roo.bootstrap.HtmlEditor.superclass.onResize.apply(this, arguments);
291 if(typeof w == 'number'){
292 var aw = w - this.wrap.getFrameWidth('lr');
293 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
296 if(typeof h == 'number'){
298 for (var i =0; i < this.toolbars.length;i++) {
299 // fixme - ask toolbars for heights?
300 tbh += this.toolbars[i].tb.el.getHeight();
301 if (this.toolbars[i].footer) {
302 tbh += this.toolbars[i].footer.el.getHeight();
309 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
310 ah -= 5; // knock a few pixes off for look..
311 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
315 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
316 this.editorcore.onResize(ew,eh);
321 * Toggles the editor between standard and source edit mode.
322 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
324 toggleSourceEdit : function(sourceEditMode)
326 this.editorcore.toggleSourceEdit(sourceEditMode);
328 if(this.editorcore.sourceEditMode){
329 Roo.log('editor - showing textarea');
332 // Roo.log(this.syncValue());
333 this.editorcore.syncValue();
334 this.inputEl().removeClass('hide');
335 this.inputEl().dom.removeAttribute('tabIndex');
336 this.inputEl().focus();
338 Roo.log('editor - hiding textarea');
340 // Roo.log(this.pushValue());
341 this.editorcore.pushValue();
343 this.inputEl().addClass('hide');
344 this.inputEl().dom.setAttribute('tabIndex', -1);
348 this.setSize(this.wrap.getSize());
349 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
352 // private (for BoxComponent)
353 adjustSize : Roo.BoxComponent.prototype.adjustSize,
355 // private (for BoxComponent)
356 getResizeEl : function(){
360 // private (for BoxComponent)
361 getPositionEl : function(){
366 initEvents : function(){
367 this.originalValue = this.getValue();
371 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
374 markInvalid : Roo.emptyFn,
376 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
379 clearInvalid : Roo.emptyFn,
381 setValue : function(v){
382 Roo.bootstrap.HtmlEditor.superclass.setValue.call(this, v);
383 this.editorcore.pushValue();
388 deferFocus : function(){
389 this.focus.defer(10, this);
394 this.editorcore.focus();
400 onDestroy : function(){
406 for (var i =0; i < this.toolbars.length;i++) {
407 // fixme - ask toolbars for heights?
408 this.toolbars[i].onDestroy();
411 this.wrap.dom.innerHTML = '';
417 onFirstFocus : function(){
418 //Roo.log("onFirstFocus");
419 this.editorcore.onFirstFocus();
420 for (var i =0; i < this.toolbars.length;i++) {
421 this.toolbars[i].onFirstFocus();
427 syncValue : function()
429 this.editorcore.syncValue();
433 // hide stuff that is not compatible
451 * @cfg {String} fieldClass @hide
454 * @cfg {String} focusClass @hide
457 * @cfg {String} autoCreate @hide
460 * @cfg {String} inputType @hide
463 * @cfg {String} invalidClass @hide
466 * @cfg {String} invalidText @hide
469 * @cfg {String} msgFx @hide
472 * @cfg {String} validateOnBlur @hide