Ticket #2696: autogrow-firefox.patch
File autogrow-firefox.patch, 4.6 KB (added by , 15 years ago) |
---|
-
editor/plugins/autogrow/fckplugin.js
1 /*1 /* 2 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 3 * Copyright (C) 2003-2008 Frederico Caldeira Knabben 4 4 * … … 22 22 * height (FCKConfig.AutoGrowMax), based on its contents. 23 23 */ 24 24 25 var FCKAutoGrow_Min = window.frameElement.offsetHeight;25 FCKAutoGrow = new Object(); 26 26 27 function FCKAutoGrow_Check() 27 FCKAutoGrow.MIN_HEIGHT = window.frameElement.offsetHeight ; 28 29 FCKAutoGrow.Check = function() 28 30 { 31 FCKAutoGrow.RemoveOverflow(); 32 33 var delta = FCKAutoGrow.GetHeightDelta() ; 34 if ( delta != 0 ) 35 { 36 var newHeight = window.frameElement.offsetHeight + delta ; 37 38 newHeight = FCKAutoGrow.GetEffectiveHeight( newHeight ) ; 39 40 if ( newHeight != window.frameElement.height ) 41 { 42 window.frameElement.style.height = newHeight + "px" ; 43 44 // Gecko browsers use an onresize handler to update the innermost 45 // IFRAME's height. If the document is modified before the onresize 46 // is triggered, the plugin will miscalculate the new height. Thus, 47 // forcibly trigger onresize. #1336 48 if ( typeof window.onresize == 'function' ) 49 { 50 window.onresize() ; 51 } 52 } 53 } 54 } 55 56 FCKAutoGrow.CheckEditorStatus = function( sender, status ) 57 { 58 if ( status == FCK_STATUS_COMPLETE ) 59 { 60 FCKAutoGrow.Check() ; 61 } 62 } 63 64 FCKAutoGrow.GetEffectiveHeight = function( height ) 65 { 66 if ( height < FCKAutoGrow.MIN_HEIGHT ) 67 { 68 height = FCKAutoGrow.MIN_HEIGHT; 69 } 70 else 71 { 72 var max = FCKConfig.AutoGrowMax; 73 if ( max && max > 0 && height > max ) 74 { 75 height = max; 76 } 77 } 78 79 return height; 80 } 81 82 FCKAutoGrow.GetHeightDelta = function() 83 { 29 84 var oInnerDoc = FCK.EditorDocument ; 30 85 31 var iFrameHeight, iInnerHeight ; 86 var iFrameHeight ; 87 var iInnerHeight ; 32 88 33 89 if ( FCKBrowserInfo.IsIE ) 34 90 { … … 38 94 else 39 95 { 40 96 iFrameHeight = FCK.EditorWindow.innerHeight ; 41 iInnerHeight = oInnerDoc.body.offsetHeight ;97 iInnerHeight = oInnerDoc.body.offsetHeight + 16; 42 98 } 43 99 44 var iDiff = iInnerHeight - iFrameHeight ; 100 return iInnerHeight - iFrameHeight ; 101 } 45 102 46 if ( iDiff != 0 ) 47 { 48 var iMainFrameSize = window.frameElement.offsetHeight ; 49 50 if ( iDiff > 0 && iMainFrameSize < FCKConfig.AutoGrowMax ) 51 { 52 iMainFrameSize += iDiff ; 53 if ( iMainFrameSize > FCKConfig.AutoGrowMax ) 54 iMainFrameSize = FCKConfig.AutoGrowMax ; 55 } 56 else if ( iDiff < 0 && iMainFrameSize > FCKAutoGrow_Min ) 57 { 58 iMainFrameSize += iDiff ; 59 if ( iMainFrameSize < FCKAutoGrow_Min ) 60 iMainFrameSize = FCKAutoGrow_Min ; 61 } 62 else 63 return ; 64 65 window.frameElement.height = iMainFrameSize ; 66 67 // Gecko browsers use an onresize handler to update the innermost 68 // IFRAME's height. If the document is modified before the onresize 69 // is triggered, the plugin will miscalculate the new height. Thus, 70 // forcibly trigger onresize. #1336 71 if ( typeof window.onresize == 'function' ) 72 window.onresize() ; 73 } 103 FCKAutoGrow.RemoveOverflow = function() 104 { 105 var area = FCK.EditingArea; 106 if (area) 107 { 108 var iframe = area.IFrame; 109 if (iframe) 110 { 111 iframe.style.overflowY = "hidden"; 112 } 113 } 74 114 } 75 115 76 FCK.AttachToOnSelectionChange( FCKAutoGrow_Check ) ; 77 78 function FCKAutoGrow_SetListeners() 116 FCKAutoGrow.SetListeners = function() 79 117 { 80 118 if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG ) 119 { 81 120 return ; 121 } 82 122 83 FCK.EditorWindow.attachEvent( 'onscroll', FCKAutoGrow _Check ) ;84 FCK.EditorDocument.attachEvent( 'onkeyup', FCKAutoGrow _Check ) ;123 FCK.EditorWindow.attachEvent( 'onscroll', FCKAutoGrow.Check ) ; 124 FCK.EditorDocument.attachEvent( 'onkeyup', FCKAutoGrow.Check ) ; 85 125 } 86 126 127 FCK.AttachToOnSelectionChange( FCKAutoGrow.Check ) ; 128 87 129 if ( FCKBrowserInfo.IsIE ) 88 130 { 89 // FCKAutoGrow_SetListeners() ; 90 FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKAutoGrow_SetListeners ) ; 131 FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKAutoGrow.SetListeners ) ; 91 132 } 92 133 93 function FCKAutoGrow_CheckEditorStatus( sender, status ) 94 { 95 if ( status == FCK_STATUS_COMPLETE ) 96 FCKAutoGrow_Check() ; 97 } 98 99 FCK.Events.AttachEvent( 'OnStatusChange', FCKAutoGrow_CheckEditorStatus ) ; 134 FCK.Events.AttachEvent( 'OnStatusChange', FCKAutoGrow.CheckEditorStatus ) ; 135 No newline at end of file