Ticket #2696: 2696_2.patch

File 2696_2.patch, 5.2 KB (added by Martin Kou, 15 years ago)
  • _whatsnew.html

     
    116116                <li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/2649">#2649</a>] Fixed a JavaScript error
    117117                        in IE when user tries to search with the "Match whole word" option enabled and the matched word is
    118118                        at exactly the end of document.</li>
     119                <li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/2696">#2696</a>] Fixed non-working
     120                        autogrow plugin.</li>
    119121        </ul>
    120122        <p>
    121123                <a href="_whatsnew_history.html">See previous versions history</a></p>
  • editor/plugins/autogrow/fckplugin.js

     
    2222 * height (FCKConfig.AutoGrowMax), based on its contents.
    2323 */
    2424
    25 var FCKAutoGrow_Min = window.frameElement.offsetHeight ;
     25var FCKAutoGrow = {
     26        MIN_HEIGHT : window.frameElement.offsetHeight,
    2627
    27 function FCKAutoGrow_Check()
    28 {
    29         var oInnerDoc = FCK.EditorDocument ;
     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" ;
    3040
    31         var iFrameHeight, iInnerHeight ;
     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        },
    3252
    33         if ( FCKBrowserInfo.IsIE )
     53        CheckEditorStatus : function( sender, status )
    3454        {
    35                 iFrameHeight = FCK.EditorWindow.frameElement.offsetHeight ;
    36                 iInnerHeight = oInnerDoc.body.scrollHeight ;
    37         }
    38         else
     55                if ( status == FCK_STATUS_COMPLETE )
     56                        FCKAutoGrow.Check() ;
     57        },
     58
     59        GetEffectiveHeight : function( height )
    3960        {
    40                 iFrameHeight = FCK.EditorWindow.innerHeight ;
    41                 iInnerHeight = oInnerDoc.body.offsetHeight ;
    42         }
     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        },
    4372
    44         var iDiff = iInnerHeight - iFrameHeight ;
    45 
    46         if ( iDiff != 0 )
     73        GetHeightDelta : function()
    4774        {
    48                 var iMainFrameSize = window.frameElement.offsetHeight ;
     75                var oInnerDoc = FCK.EditorDocument ;
    4976
    50                 if ( iDiff > 0 && iMainFrameSize < FCKConfig.AutoGrowMax )
     77                var iFrameHeight ;
     78                var iInnerHeight ;
     79
     80                if ( FCKBrowserInfo.IsIE )
    5181                {
    52                         iMainFrameSize += iDiff ;
    53                         if ( iMainFrameSize > FCKConfig.AutoGrowMax )
    54                                 iMainFrameSize = FCKConfig.AutoGrowMax ;
     82                        iFrameHeight = FCK.EditorWindow.frameElement.offsetHeight ;
     83                        iInnerHeight = oInnerDoc.body.scrollHeight ;
    5584                }
    56                 else if ( iDiff < 0 && iMainFrameSize > FCKAutoGrow_Min )
     85                else
    5786                {
    58                         iMainFrameSize += iDiff ;
    59                         if ( iMainFrameSize < FCKAutoGrow_Min )
    60                                 iMainFrameSize = FCKAutoGrow_Min ;
     87                        iFrameHeight = FCK.EditorWindow.innerHeight ;
     88                        iInnerHeight = oInnerDoc.body.offsetHeight +
     89                                ( parseInt( FCKDomTools.GetCurrentElementStyle( oInnerDoc.body, 'margin-top' ) ) || 0 ) +
     90                                ( parseInt( FCKDomTools.GetCurrentElementStyle( oInnerDoc.body, 'margin-bottom' ) ) || 0 ) ;
    6191                }
    62                 else
     92
     93                return iInnerHeight - iFrameHeight ;
     94        },
     95
     96        SetListeners : function()
     97        {
     98                if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
    6399                        return ;
    64100
    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() ;
     101                FCK.EditorWindow.attachEvent( 'onscroll', FCKAutoGrow.Check ) ;
     102                FCK.EditorDocument.attachEvent( 'onkeyup', FCKAutoGrow.Check ) ;
    73103        }
    74 }
     104};
    75105
    76 FCK.AttachToOnSelectionChange( FCKAutoGrow_Check ) ;
     106FCK.AttachToOnSelectionChange( FCKAutoGrow.Check ) ;
    77107
    78 function FCKAutoGrow_SetListeners()
    79 {
    80         if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
    81                 return ;
    82 
    83         FCK.EditorWindow.attachEvent( 'onscroll', FCKAutoGrow_Check ) ;
    84         FCK.EditorDocument.attachEvent( 'onkeyup', FCKAutoGrow_Check ) ;
    85 }
    86 
    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 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy