Ticket #8050: 8050_10.patch

File 8050_10.patch, 3.8 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/autogrow/plugin.js

     
    66/**
    77 * @file AutoGrow plugin
    88 */
    9 (function(){
    10         var resizeEditor = function( editor )
    11         {
    12                 if ( !editor.window )
    13                         return;
    14                 var doc = editor.document,
    15                         currentHeight = editor.window.getViewPaneSize().height,
    16                         newHeight;
     9(function()
     10{
     11        CKEDITOR.plugins.add( 'autogrow',
     12        {
     13                init : function( editor )
     14                {
     15                        function resizeEditor()
     16                        {
     17                                if ( !editor.window )
     18                                        return;
     19
     20                                var doc = editor.document,
     21                                                iframe = new CKEDITOR.dom.element( doc.getWindow().$.frameElement ),
     22                                                resizeable = editor.getResizable( 1 ),
     23                                                body = doc.getBody(),
     24                                                htmlElement = doc.getDocumentElement(),
     25                                                currentHeight = resizeable.$.offsetHeight,
     26                                                newHeight;
    1727
    18                 // We can not use documentElement to calculate the height for IE (#6061).
    19                 // It is not good for IE Quirks, yet using offsetHeight would also not work as expected (#6408).
    20                 // We do the same for FF because of the html height workaround (#6341).
    21                 if ( CKEDITOR.env.ie || CKEDITOR.env.gecko )
    22                         newHeight = doc.getBody().$.scrollHeight + ( CKEDITOR.env.ie && CKEDITOR.env.quirks ? 0 : 24 );
    23                 else
    24                         newHeight = doc.getDocumentElement().$.offsetHeight;
     28                                // Quirks mode overflows body except for IE9, standards overflows document element.
     29                                var scrollable = !CKEDITOR.env.ie9Compat && doc.$.compatMode == 'BackCompat' ? body : htmlElement;
    2530
    26                 var min = editor.config.autoGrow_minHeight,
    27                         max = editor.config.autoGrow_maxHeight;
    28                 ( min == undefined ) && ( editor.config.autoGrow_minHeight = min = 200 );
    29                 if ( min )
    30                         newHeight = Math.max( newHeight, min );
    31                 if ( max )
    32                         newHeight = Math.min( newHeight, max );
     31                                // Content height
     32                                iframe.setStyle( 'height', '1px' );
     33                                newHeight = scrollable.$.scrollHeight;
     34
     35                                // Count for the height of h-scrollbar.
     36                                iframe.setStyle( 'height', newHeight + 'px' );
     37                                newHeight += scrollable.$.scrollWidth > scrollable.$.clientWidth ? scrollable.$.scrollHeight - scrollable.$.clientHeight : 0;
     38
     39                                // Now restore iframe height.
     40                                iframe.setStyle( 'height', '100%' );
     41
     42                                var min = editor.config.autoGrow_minHeight || 0,
     43                                                max = editor.config.autoGrow_maxHeight || Infinity;
     44
     45                                newHeight = Math.max( newHeight, min );
     46                                newHeight = Math.min( newHeight, max );
    3347
    34                 if ( newHeight != currentHeight )
    35                 {
    36                         newHeight = editor.fire( 'autoGrow', { currentHeight : currentHeight, newHeight : newHeight } ).newHeight;
    37                         editor.resize( editor.container.getStyle( 'width' ), newHeight, true );
    38                 }
    39         };
    40         CKEDITOR.plugins.add( 'autogrow',
    41         {
    42                 init : function( editor )
    43                 {
     48                                if ( newHeight != currentHeight )
     49                                {
     50                                        newHeight = editor.fire( 'autoGrow', { currentHeight : currentHeight, newHeight : newHeight } ).newHeight;
     51                                        resizeable.setStyle( 'height', newHeight + 'px' );
     52                                        editor.fire( 'resize' );
     53
     54                                        // Make sure v-scrollbar isn't invisible after all.
     55                                        newHeight < max ?
     56                                                scrollable.setStyle( 'overflow-y', 'hidden' )
     57                                                : scrollable.removeStyle( 'overflow-y' );
     58                                }
     59                        }
     60
    4461                        for ( var eventName in { contentDom:1, key:1, selectionChange:1, insertElement:1 } )
    4562                        {
    4663                                editor.on( eventName, function( evt )
     
    5168                                                // Disable autogrow when the editor is maximized .(#6339)
    5269                                                ( !maximize || maximize.state != CKEDITOR.TRISTATE_ON ) )
    5370                                        {
    54                                                 setTimeout( function(){ resizeEditor( evt.editor ); }, 100 );
     71                                                setTimeout( function(){ resizeEditor(); }, 0 );
    5572                                        }
    56                                 });
    57                         }
     73                        });
     74                }
    5875                }
    5976        });
    6077})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy