Ticket #8050: 8050_11.patch

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

     
    77 * @file AutoGrow plugin
    88 */
    99(function(){
     10
     11        // Actual content height, figured out by appending check the last element's document position.
     12        function contentHeight( scrollable )
     13        {
     14                var overflowY = scrollable.getStyle( 'overflow-y' );
     15
     16                var doc = scrollable.getDocument();
     17                // Create a temporary marker element.
     18                var marker = CKEDITOR.dom.element.createFromHtml( '<span style="margin:0;padding:0;border:0;clear:both;width:1px;height:1px;display:block;">' + ( CKEDITOR.env.webkit ? '&nbsp;' : '' ) + '</span>', doc );
     19                var body = doc.getBody();
     20                body.append( marker );
     21
     22                var height = marker.getDocumentPosition( doc ).y + marker.$.offsetHeight;
     23                marker.remove();
     24                scrollable.setStyle( 'overflow-y', overflowY );
     25                return height;
     26        }
     27
    1028        var resizeEditor = function( editor )
    1129        {
    1230                if ( !editor.window )
    1331                        return;
     32
    1433                var doc = editor.document,
     34                        iframe = new CKEDITOR.dom.element( doc.getWindow().$.frameElement ),
     35                        body = doc.getBody(),
     36                        htmlElement = doc.getDocumentElement(),
    1537                        currentHeight = editor.window.getViewPaneSize().height,
    16                         newHeight;
     38                        // Quirks mode overflows body, standards overflows document element
     39                        scrollable = doc.$.compatMode == 'BackCompat' ? body : htmlElement,
     40                        newHeight = contentHeight( scrollable );
    1741
    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;
     42                var scrollbar = scrollable.$.scrollWidth > scrollable.$.clientWidth ? scrollable.$.scrollHeight - scrollable.$.clientHeight : 0;
     43                newHeight += scrollbar;
    2544
    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 );
     45                // Additional space specified by user.
     46                newHeight += ( editor.config.autoGrow_bottomSpace || 0 );
     47
     48                var min = editor.config.autoGrow_minHeight || 200,
     49                        max = editor.config.autoGrow_maxHeight || Infinity;
     50
     51                newHeight = Math.max( newHeight, min );
     52                newHeight = Math.min( newHeight, max );
    3353
    3454                if ( newHeight != currentHeight )
    3555                {
    3656                        newHeight = editor.fire( 'autoGrow', { currentHeight : currentHeight, newHeight : newHeight } ).newHeight;
    3757                        editor.resize( editor.container.getStyle( 'width' ), newHeight, true );
     58
     59                        if ( newHeight < max )
     60                                scrollable.setStyle( 'overflow-y', 'hidden' );
     61                        else
     62                                scrollable.removeStyle( 'overflow-y' );
    3863                }
    3964        };
     65
    4066        CKEDITOR.plugins.add( 'autogrow',
    4167        {
    4268                init : function( editor )
     
    5177                                                // Disable autogrow when the editor is maximized .(#6339)
    5278                                                ( !maximize || maximize.state != CKEDITOR.TRISTATE_ON ) )
    5379                                        {
    54                                                 setTimeout( function(){ resizeEditor( evt.editor ); }, 100 );
     80                                                setTimeout( function()
     81                                                {
     82                                                        resizeEditor( evt.editor );
     83                                                        // Second pass to make correction upon
     84                                                        // the first resize, e.g. scrollbar.
     85                                                        resizeEditor( evt.editor );
     86                                                }, 100 );
    5587                                        }
    5688                                });
    5789                        }
     
    86118 * @param {Number} data.newHeight The new height of the editor (after resizing). It can be changed
    87119 *                              to determine a different height value to be used instead.
    88120 */
     121
     122
     123/**
     124 *  Extra height in pixel to leave between the bottom boundary of content with document size when auto resizing.
     125 * @name CKEDITOR.config.autoGrow_bottomSpace
     126 * @type Number
     127 * @default 0
     128 * @since 3.6.2
     129 */
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy