Ticket #7984: 7984_4.patch

File 7984_4.patch, 2.5 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/autogrow/plugin.js

     
    88 */
    99(function(){
    1010
     11        var parts = [ "margin-top","margin-bottom","border-top-width", "border-bottom-width", "padding-top",  "padding-bottom" ];
     12
     13        function nonContentHeight( element )
     14        {
     15                var adjustment = 0;
     16                for ( var i = 0, len = parts.length; i < len; i++ )
     17                        adjustment += parseInt( element.getComputedStyle( parts[ i ] ) || 0, 10 ) || 0;
     18                return adjustment;
     19        }
     20
     21        // Spaces outside of  the actual content.
     22        function extra( element )
     23        {
     24                var margin = 0;
     25                margin += nonContentHeight( element);
     26                if ( element.is( 'html' ) )
     27                        margin += nonContentHeight( element.getDocument().getBody() );
     28                return margin;
     29        }
     30
     31        // Height of the actual content size within body,
     32        // figured out by simply check the last element.
     33        function docContentHeight( doc )
     34        {
     35                var lastElement = doc.getBody().getLast( function( node )
     36                         {
     37                                 return node.type == CKEDITOR.NODE_ELEMENT;
     38                         });
     39
     40                return lastElement.getDocumentPosition( doc ).y + lastElement.$.offsetHeight
     41        }
     42
    1143        CKEDITOR.plugins.add( 'autogrow',
    1244        {
    1345                init : function( editor )
     
    2052
    2153                                var doc = editor.document,
    2254                                        resizeable = editor.getResizable( 1 ),
    23                                         body = doc.getBody().$,
    24                                         htmlElement = doc.getDocumentElement().$,
     55                                        body = doc.getBody(),
     56                                        htmlElement = doc.getDocumentElement(),
    2557                                        currentHeight = resizeable.$.offsetHeight,
    2658                                        newHeight;
    2759
    28                                 // Quirks mode overflows body, standards oveflows document element.
    29                                 var delta,
    30                                         scrollable = doc.$.compatMode == 'BackCompat' ? body : htmlElement,
    31                                         increase = scrollable.scrollHeight - scrollable.clientHeight,
    32                                         decrease = body.offsetHeight - scrollable.scrollHeight + contentMargin;
     60                                // Quirks mode overflows body except for IE9, standards overflows document element.
     61                                var scrollable = !CKEDITOR.env.ie9Compat && doc.$.compatMode == 'BackCompat' ? body : htmlElement,
     62                                        contentHeight = docContentHeight( doc ),
     63                                        delta = contentHeight - scrollable.$.clientHeight + extra( scrollable );
    3364
    3465                                // Delta height from either increasing or decreasing.
    35                                 if ( delta  =  increase ||decrease || 0 )
     66                                if ( delta )
    3667                                {
    3768                                        newHeight = currentHeight + delta;
    3869                                        var min = editor.config.autoGrow_minHeight,
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy