1/* 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 * Copyright (C) 2003-2009 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 * 21 * Plugin: automatically resizes the editor until a configurable maximun 22 * height (FCKConfig.AutoGrowMax), based on its contents. 23 */ 24 25var FCKAutoGrow = { 26 MIN_HEIGHT : window.frameElement.offsetHeight, 27 28 Check : function() 29 { 30 var delta = FCKAutoGrow.GetHeightDelta() ; 31 if ( delta != 0 ) 32 { 33 var newHeight = window.frameElement.offsetHeight + delta ; 34 35 newHeight = FCKAutoGrow.GetEffectiveHeight( newHeight ) ; 36 37 if ( newHeight != window.frameElement.height ) 38 { 39 window.frameElement.style.height = newHeight + "px" ; 40 41 // Gecko browsers use an onresize handler to update the innermost 42 // IFRAME's height. If the document is modified before the onresize 43 // is triggered, the plugin will miscalculate the new height. Thus, 44 // forcibly trigger onresize. #1336 45 if ( typeof window.onresize == 'function' ) 46 { 47 window.onresize() ; 48 } 49 } 50 } 51 }, 52 53 CheckEditorStatus : function( sender, status ) 54 { 55 if ( status == FCK_STATUS_COMPLETE ) 56 FCKAutoGrow.Check() ; 57 }, 58 59 GetEffectiveHeight : function( height ) 60 { 61 if ( height < FCKAutoGrow.MIN_HEIGHT ) 62 height = FCKAutoGrow.MIN_HEIGHT; 63 else 64 { 65 var max = FCKConfig.AutoGrowMax; 66 if ( max && max > 0 && height > max ) 67 height = max; 68 } 69 70 return height; 71 }, 72 73 GetHeightDelta : function() 74 { 75 var oInnerDoc = FCK.EditorDocument ; 76 77 var iFrameHeight ; 78 var iInnerHeight ; 79 80 if ( FCKBrowserInfo.IsIE ) 81 { 82 iFrameHeight = FCK.EditorWindow.frameElement.offsetHeight ; 83 iInnerHeight = oInnerDoc.body.scrollHeight ; 84 } 85 else 86 { 87 iFrameHeight = FCK.EditorWindow.innerHeight ; 88 iInnerHeight = oInnerDoc.body.offsetHeight + 89 ( parseInt( FCKDomTools.GetCurrentElementStyle( oInnerDoc.body, 'margin-top' ), 10 ) || 0 ) + 90 ( parseInt( FCKDomTools.GetCurrentElementStyle( oInnerDoc.body, 'margin-bottom' ), 10 ) || 0 ) ; 91 } 92 93 return iInnerHeight - iFrameHeight ; 94 }, 95 96 SetListeners : function() 97 { 98 if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG ) 99 return ; 100 101 FCK.EditorWindow.attachEvent( 'onscroll', FCKAutoGrow.Check ) ; 102 FCK.EditorDocument.attachEvent( 'onkeyup', FCKAutoGrow.Check ) ; 103 } 104}; 105 106FCK.AttachToOnSelectionChange( FCKAutoGrow.Check ) ; 107 108if ( FCKBrowserInfo.IsIE ) 109 FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKAutoGrow.SetListeners ) ; 110 111FCK.Events.AttachEvent( 'OnStatusChange', FCKAutoGrow.CheckEditorStatus ) ; 112