Ticket #2696: autogrow-firefox.patch

File autogrow-firefox.patch, 4.6 KB (added by slessard, 11 years ago)

Patch

  • editor/plugins/autogrow/fckplugin.js

     
    1 /*
     1/*
    22 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
    33 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
    44 *
     
    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    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
     56FCKAutoGrow.CheckEditorStatus = function( sender, status )
     57{
     58        if ( status == FCK_STATUS_COMPLETE )
     59        {
     60                FCKAutoGrow.Check() ;
     61        }
     62}
     63
     64FCKAutoGrow.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
     82FCKAutoGrow.GetHeightDelta = function()
     83{
    2984        var oInnerDoc = FCK.EditorDocument ;
    3085
    31         var iFrameHeight, iInnerHeight ;
     86        var iFrameHeight ;
     87        var iInnerHeight ;
    3288
    3389        if ( FCKBrowserInfo.IsIE )
    3490        {
     
    3894        else
    3995        {
    4096                iFrameHeight = FCK.EditorWindow.innerHeight ;
    41                 iInnerHeight = oInnerDoc.body.offsetHeight ;
     97                iInnerHeight = oInnerDoc.body.offsetHeight + 16;
    4298        }
    4399
    44         var iDiff = iInnerHeight - iFrameHeight ;
     100        return iInnerHeight - iFrameHeight ;
     101}
    45102
    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         }
     103FCKAutoGrow.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    }
    74114}
    75115
    76 FCK.AttachToOnSelectionChange( FCKAutoGrow_Check ) ;
    77 
    78 function FCKAutoGrow_SetListeners()
     116FCKAutoGrow.SetListeners = function()
    79117{
    80118        if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
     119        {
    81120                return ;
     121        }
    82122
    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 ) ;
    85125}
    86126
     127FCK.AttachToOnSelectionChange( FCKAutoGrow.Check ) ;
     128
    87129if ( FCKBrowserInfo.IsIE )
    88130{
    89 //      FCKAutoGrow_SetListeners() ;
    90         FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKAutoGrow_SetListeners ) ;
     131        FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKAutoGrow.SetListeners ) ;
    91132}
    92133
    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 ) ;
     134FCK.Events.AttachEvent( 'OnStatusChange', FCKAutoGrow.CheckEditorStatus ) ;
     135 No newline at end of file
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy