X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/2e847cf21b8ab9d15fa167b315ca5b2fa92638fc..6b044c28b5f26fb99c86c237ffad19741c0f7f3d:/src/widgets/form/HtmlEditor.js diff --git a/src/widgets/form/HtmlEditor.js b/src/widgets/form/HtmlEditor.js index 3c2965d0..20e1f91a 100644 --- a/src/widgets/form/HtmlEditor.js +++ b/src/widgets/form/HtmlEditor.js @@ -1,8 +1,8 @@ /*! - * Ext JS Library 3.1.1 - * Copyright(c) 2006-2010 Ext JS, LLC - * licensing@extjs.com - * http://www.extjs.com/license + * Ext JS Library 3.3.1 + * Copyright(c) 2006-2010 Sencha Inc. + * licensing@sencha.com + * http://www.sencha.com/license */ /** * @class Ext.form.HtmlEditor @@ -173,7 +173,8 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { * @param {Boolean} sourceEdit True if source edit, false if standard editing. */ 'editmodechange' - ) + ); + Ext.form.HtmlEditor.superclass.initComponent.call(this); }, // private @@ -200,7 +201,7 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { */ createToolbar : function(editor){ var items = []; - var tipsEnabled = Ext.QuickTips && Ext.QuickTips.isEnabled(); + var tipsEnabled = Ext.QuickTips && Ext.QuickTips.isEnabled(); function btn(id, toggle, handler){ @@ -219,13 +220,13 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { } - if(this.enableFont && !Ext.isSafari2){ - var fontSelectItem = new Ext.Toolbar.Item({ - autoEl: { - tag:'select', - cls:'x-font-select', - html: this.createFontOptions() - } + if(this.enableFont && !Ext.isSafari2){ + var fontSelectItem = new Ext.Toolbar.Item({ + autoEl: { + tag:'select', + cls:'x-font-select', + html: this.createFontOptions() + } }); items.push( @@ -337,31 +338,31 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { }) ); } - } - - // build the toolbar - var tb = new Ext.Toolbar({ - renderTo: this.wrap.dom.firstChild, - items: items - }); - - if (fontSelectItem) { - this.fontSelect = fontSelectItem.el; - - this.mon(this.fontSelect, 'change', function(){ - var font = this.fontSelect.dom.value; - this.relayCmd('fontname', font); - this.deferFocus(); - }, this); - } - - - // stop form submits - this.mon(tb.el, 'click', function(e){ - e.preventDefault(); - }); + } + + // build the toolbar + var tb = new Ext.Toolbar({ + renderTo: this.wrap.dom.firstChild, + items: items + }); + + if (fontSelectItem) { + this.fontSelect = fontSelectItem.el; + + this.mon(this.fontSelect, 'change', function(){ + var font = this.fontSelect.dom.value; + this.relayCmd('fontname', font); + this.deferFocus(); + }, this); + } + + // stop form submits + this.mon(tb.el, 'click', function(e){ + e.preventDefault(); + }); this.tb = tb; + this.tb.doLayout(); }, onDisable: function(){ @@ -377,25 +378,30 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { setReadOnly: function(readOnly){ Ext.form.HtmlEditor.superclass.setReadOnly.call(this, readOnly); - if(this.initialized){ - this.setDesignMode(!readOnly); - var bd = this.getEditorBody(); - if(bd){ - bd.style.cursor = this.readOnly ? 'default' : 'text'; - } - this.disableItems(readOnly); - } + if(this.initialized){ + if(Ext.isIE){ + this.getEditorBody().contentEditable = !readOnly; + }else{ + this.setDesignMode(!readOnly); + } + var bd = this.getEditorBody(); + if(bd){ + bd.style.cursor = this.readOnly ? 'default' : 'text'; + } + this.disableItems(readOnly); + } }, /** * Protected method that will not generally be called directly. It * is called when the editor initializes the iframe with HTML contents. Override this method if you * want to change the initialization markup of the iframe (e.g. to add stylesheets). - * - * Note: IE8-Standards has unwanted scroller behavior, so the default meta tag forces IE7 compatibility + * + * Note: IE8-Standards has unwanted scroller behavior, so the default meta tag forces IE7 compatibility */ getDocMarkup : function(){ - return '
'; + var h = Ext.fly(this.iframe).getHeight() - this.iframePad * 2; + return String.format('', this.iframePad, h); }, // private @@ -421,7 +427,7 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { this.el.dom.setAttribute('tabIndex', -1); this.el.addClass('x-hidden'); if(Ext.isIE){ // fix IE 1px bogus margin - this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;') + this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;'); } this.wrap = this.el.wrap({ cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'} @@ -446,7 +452,8 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { var iframe = document.createElement('iframe'); iframe.name = Ext.id(); iframe.frameBorder = '0'; - iframe.style.overflow = 'auto'; + iframe.style.overflow = 'auto'; + iframe.src = Ext.SSL_SECURE_URL; this.wrap.dom.appendChild(iframe); this.iframe = iframe; @@ -495,29 +502,29 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { } } }, - - /* private - * set current design mode. To enable, mode can be true or 'on', off otherwise - */ - setDesignMode : function(mode){ - var doc ; - if(doc = this.getDoc()){ - if(this.readOnly){ - mode = false; - } - doc.designMode = (/on|true/i).test(String(mode).toLowerCase()) ?'on':'off'; - } - - }, - - // private + + /* private + * set current design mode. To enable, mode can be true or 'on', off otherwise + */ + setDesignMode : function(mode){ + var doc = this.getDoc(); + if (doc) { + if(this.readOnly){ + mode = false; + } + doc.designMode = (/on|true/i).test(String(mode).toLowerCase()) ?'on':'off'; + } + + }, + + // private getDesignMode : function(){ - var doc = this.getDoc(); - if(!doc){ return ''; } - return String(doc.designMode).toLowerCase(); - - }, - + var doc = this.getDoc(); + if(!doc){ return ''; } + return String(doc.designMode).toLowerCase(); + + }, + disableItems: function(disabled){ if(this.fontSelect){ this.fontSelect.dom.disabled = disabled; @@ -556,27 +563,38 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { * @param {Boolean} sourceEdit (optional) True for source edit, false for standard */ toggleSourceEdit : function(sourceEditMode){ - if(sourceEditMode === undefined){ + var iframeHeight, + elHeight; + + if (sourceEditMode === undefined) { sourceEditMode = !this.sourceEditMode; } this.sourceEditMode = sourceEditMode === true; var btn = this.tb.getComponent('sourceedit'); - if(btn.pressed !== this.sourceEditMode){ + if (btn.pressed !== this.sourceEditMode) { btn.toggle(this.sourceEditMode); - if(!btn.xtbHidden){ + if (!btn.xtbHidden) { return; } } - if(this.sourceEditMode){ + if (this.sourceEditMode) { + // grab the height of the containing panel before we hide the iframe + this.previousSize = this.getSize(); + + iframeHeight = Ext.get(this.iframe).getHeight(); + this.disableItems(true); this.syncValue(); this.iframe.className = 'x-hidden'; this.el.removeClass('x-hidden'); this.el.dom.removeAttribute('tabIndex'); this.el.focus(); - }else{ - if(this.initialized){ + this.el.dom.style.height = iframeHeight + 'px'; + } + else { + elHeight = parseInt(this.el.dom.style.height, 10); + if (this.initialized) { this.disableItems(this.readOnly); } this.pushValue(); @@ -584,17 +602,16 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { this.el.addClass('x-hidden'); this.el.dom.setAttribute('tabIndex', -1); this.deferFocus(); - } - var lastSize = this.lastSize; - if(lastSize){ - delete this.lastSize; - this.setSize(lastSize); + + this.setSize(this.previousSize); + delete this.previousSize; + this.iframe.style.height = elHeight + 'px'; } this.fireEvent('editmodechange', this, this.sourceEditMode); }, // private used internally - createLink : function(){ + createLink : function() { var url = prompt(this.createLinkText, this.defaultLinkValue); if(url && url != 'http:/'+'/'){ this.relayCmd('createlink', url); @@ -691,13 +708,12 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { this.getEditorBody().innerHTML = v; if(Ext.isGecko){ // Gecko hack, see: https://bugzilla.mozilla.org/show_bug.cgi?id=232791#c8 - this.setDesignMode(false); //toggle off first - + this.setDesignMode(false); //toggle off first + this.setDesignMode(true); } - this.setDesignMode(true); this.fireEvent('push', this, v); } - + } }, @@ -720,7 +736,7 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { //Destroying the component during/before initEditor can cause issues. try{ var dbody = this.getEditorBody(), - ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat'), + ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat', 'background-color', 'color'), doc, fn; @@ -767,7 +783,7 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { }, // private - onDestroy : function(){ + beforeDestroy : function(){ if(this.monitorTask){ Ext.TaskMgr.stop(this.monitorTask); } @@ -787,12 +803,7 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { this.wrap.remove(); } } - - if(this.el){ - this.el.removeAllListeners(); - this.el.remove(); - } - this.purgeListeners(); + Ext.form.HtmlEditor.superclass.beforeDestroy.call(this); }, // private @@ -1249,4 +1260,4 @@ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { * @hide */ }); -Ext.reg('htmleditor', Ext.form.HtmlEditor); \ No newline at end of file +Ext.reg('htmleditor', Ext.form.HtmlEditor);