Ticket #8050: 8050_9.patch

File 8050_9.patch, 4.4 KB (added by Dinu, 13 years ago)
  • _source/plugins/autogrow/plugin.js

     
    66/**
    77 * @file AutoGrow plugin
    88 */
     9
    910(function(){
    10         var resizeEditor = function( editor )
     11        CKEDITOR.plugins.add( 'autogrow',
    1112        {
    12                 if ( !editor.window )
    13                         return;
    14                 var doc = editor.document,
    15                         currentHeight = editor.window.getViewPaneSize().height,
    16                         newHeight;
     13                init : function( editor )
     14                {
     15                        function resizeEditor( editor )
     16                        {
     17                                if ( !editor.window )
     18                                        return;
    1719
    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;
     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;
    2527
    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 );
     28                                // Quirks mode overflows body except for IE9, standards overflows document element.
     29                                var scrollable = !CKEDITOR.env.ie9Compat && doc.$.compatMode == 'BackCompat' ? body : htmlElement;
    3330
    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                 {
     31                                iframe.setStyle('height','1px');
     32
     33                                // Get maximum possible height
     34                                newHeight = scrollable.$.scrollHeight;
     35                                // And resize to it
     36                                iframe.setStyle( 'height', newHeight + 'px' );
     37                                // If vertical scrollbar disappeared
     38                                if ( scrollable.$.clientWidth >= scrollable.$.scrollWidth ) {
     39                                        // Resize down to size gained by removal of vertical and horizontal scrollbar
     40                                        newHeight = scrollable.$.scrollHeight;
     41                                        if ( CKEDITOR.env.webkit ){
     42                                                // Force recomp
     43                                                var last = CKEDITOR.dom.element.createFromHtml( '<span></span>', doc );
     44                                                doc.getBody().append( last );
     45                                                last.getDocumentPosition( doc );
     46                                                last.remove();
     47                                        }
     48                                } else
     49                                        // Otherwise add height of scrollbar
     50                                        newHeight += scrollable.$.scrollHeight - scrollable.$.clientHeight;
     51
     52                var min = editor.config.autoGrow_minHeight || 0,
     53                                        max = editor.config.autoGrow_maxHeight || Infinity;
     54
     55                                newHeight = Math.max( newHeight, min );
     56                                newHeight = Math.min( newHeight, max );
     57                               
     58                                if ( newHeight != currentHeight ) {
     59                                        if ( newHeight < currentHeight )
     60                                                iframe.setStyle( 'height', '100%' );
     61                                        newHeight = editor.fire( 'autoGrow', { currentHeight : currentHeight, newHeight : newHeight } ).newHeight;
     62                                        resizeable.setStyle( 'height', newHeight + 'px' );
     63                                        if ( newHeight >= currentHeight )
     64                                                iframe.setStyle( 'height', '100%' );
     65                                        editor.fire( 'resize' );        // ??? This is bound to be called before or after container resize 2 lines above?
     66                                        if ( newHeight < max )
     67                                                scrollable.setStyle( 'overflow-y', 'hidden' );
     68                                        else
     69                                                scrollable.removeStyle( 'overflow-y' );
     70                                } else
     71                                        iframe.setStyle( 'height', '100%' );
     72                        };
    4473                        for ( var eventName in { contentDom:1, key:1, selectionChange:1, insertElement:1 } )
    4574                        {
    4675                                editor.on( eventName, function( evt )
     
    5180                                                // Disable autogrow when the editor is maximized .(#6339)
    5281                                                ( !maximize || maximize.state != CKEDITOR.TRISTATE_ON ) )
    5382                                        {
    54                                                 setTimeout( function(){ resizeEditor( evt.editor ); }, 100 );
     83                                                setTimeout( function(){ resizeEditor( evt.editor ); }, 0 );
    5584                                        }
    56                                 });
    57                         }
     85                        });
    5886                }
     87                }
    5988        });
    6089})();
    6190/**
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy