Ticket #2696: 2696.patch

File 2696.patch, 4.3 KB (added by Martin Kou, 11 years ago)
  • editor/plugins/autogrow/fckplugin.js

     
    2222 * height (FCKConfig.AutoGrowMax), based on its contents.
    2323 */
    2424
    25 var FCKAutoGrow_Min = window.frameElement.offsetHeight ;
     25FCKAutoGrow = new Object();
    2626
    27 function FCKAutoGrow_Check()
     27FCKAutoGrow.MIN_HEIGHT = window.frameElement.offsetHeight ;
     28
     29FCKAutoGrow.Check = function()
    2830{
     31    var delta = FCKAutoGrow.GetHeightDelta() ;
     32        if ( delta != 0 )
     33        {
     34                var newHeight = window.frameElement.offsetHeight + delta ;
     35               
     36                newHeight = FCKAutoGrow.GetEffectiveHeight( newHeight ) ;
     37               
     38        if ( newHeight != window.frameElement.height )
     39        {
     40            window.frameElement.style.height = newHeight + "px" ;
     41
     42                // Gecko browsers use an onresize handler to update the innermost
     43                // IFRAME's height. If the document is modified before the onresize
     44                // is triggered, the plugin will miscalculate the new height. Thus,
     45                // forcibly trigger onresize. #1336
     46                if ( typeof window.onresize == 'function' )
     47                {
     48                        window.onresize() ;
     49                }
     50        }
     51        }
     52}
     53
     54FCKAutoGrow.CheckEditorStatus = function( sender, status )
     55{
     56        if ( status == FCK_STATUS_COMPLETE )
     57                FCKAutoGrow.Check() ;
     58}
     59
     60FCKAutoGrow.GetEffectiveHeight = function( height )
     61{
     62    if ( height < FCKAutoGrow.MIN_HEIGHT )
     63        height = FCKAutoGrow.MIN_HEIGHT;
     64    else
     65    {
     66        var max = FCKConfig.AutoGrowMax;
     67        if ( max && max > 0 && height > max )
     68            height = max;
     69    }
     70   
     71    return height;
     72}
     73
     74FCKAutoGrow.GetHeightDelta = function()
     75{
    2976        var oInnerDoc = FCK.EditorDocument ;
    3077
    31         var iFrameHeight, iInnerHeight ;
     78        var iFrameHeight ;
     79        var iInnerHeight ;
    3280
    3381        if ( FCKBrowserInfo.IsIE )
    3482        {
     
    3886        else
    3987        {
    4088                iFrameHeight = FCK.EditorWindow.innerHeight ;
    41                 iInnerHeight = oInnerDoc.body.offsetHeight ;
     89                iInnerHeight = oInnerDoc.body.offsetHeight +
     90                        ( parseInt( FCKDomTools.GetCurrentElementStyle( oInnerDoc.body, 'margin-top' ) ) || 0 ) +
     91                        ( parseInt( FCKDomTools.GetCurrentElementStyle( oInnerDoc.body, 'margin-bottom' ) ) || 0 ) ;
    4292        }
    4393
    44         var iDiff = iInnerHeight - iFrameHeight ;
    45 
    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         }
     94        return iInnerHeight - iFrameHeight ;
    7495}
    7596
    76 FCK.AttachToOnSelectionChange( FCKAutoGrow_Check ) ;
    77 
    78 function FCKAutoGrow_SetListeners()
     97FCKAutoGrow.SetListeners = function()
    7998{
    8099        if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
    81100                return ;
    82101
    83         FCK.EditorWindow.attachEvent( 'onscroll', FCKAutoGrow_Check ) ;
    84         FCK.EditorDocument.attachEvent( 'onkeyup', FCKAutoGrow_Check ) ;
     102        FCK.EditorWindow.attachEvent( 'onscroll', FCKAutoGrow.Check ) ;
     103        FCK.EditorDocument.attachEvent( 'onkeyup', FCKAutoGrow.Check ) ;
    85104}
    86105
     106FCK.AttachToOnSelectionChange( FCKAutoGrow.Check ) ;
     107
    87108if ( FCKBrowserInfo.IsIE )
    88 {
    89 //      FCKAutoGrow_SetListeners() ;
    90         FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKAutoGrow_SetListeners ) ;
    91 }
     109        FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKAutoGrow.SetListeners ) ;
    92110
    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 ) ;
     111FCK.Events.AttachEvent( 'OnStatusChange', FCKAutoGrow.CheckEditorStatus ) ;
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy