Ticket #8050: 8050_12.patch

File 8050_12.patch, 4.2 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                doc[ CKEDITOR.env.ie? 'getBody' : 'getDocumentElement']().append( marker );
     20
     21                var height = marker.getDocumentPosition( doc ).y + marker.$.offsetHeight;
     22                marker.remove();
     23                scrollable.setStyle( 'overflow-y', overflowY );
     24                return height;
     25        }
     26
    1027        var resizeEditor = function( editor )
    1128        {
    1229                if ( !editor.window )
    1330                        return;
     31
    1432                var doc = editor.document,
     33                        iframe = new CKEDITOR.dom.element( doc.getWindow().$.frameElement ),
     34                        body = doc.getBody(),
     35                        htmlElement = doc.getDocumentElement(),
    1536                        currentHeight = editor.window.getViewPaneSize().height,
    16                         newHeight;
     37                        // Quirks mode overflows body, standards overflows document element
     38                        scrollable = doc.$.compatMode == 'BackCompat' ? body : htmlElement,
     39                        newHeight = contentHeight( scrollable );
    1740
    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;
     41                var scrollbar = scrollable.$.scrollWidth > scrollable.$.clientWidth ? scrollable.$.scrollHeight - scrollable.$.clientHeight : 0;
     42                newHeight += scrollbar;
    2543
    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 );
     44                // Additional space specified by user.
     45                newHeight += ( editor.config.autoGrow_bottomSpace || 0 );
     46
     47                var min = editor.config.autoGrow_minHeight || 200,
     48                        max = editor.config.autoGrow_maxHeight || Infinity;
     49
     50                newHeight = Math.max( newHeight, min );
     51                newHeight = Math.min( newHeight, max );
    3352
    3453                if ( newHeight != currentHeight )
    3554                {
    3655                        newHeight = editor.fire( 'autoGrow', { currentHeight : currentHeight, newHeight : newHeight } ).newHeight;
    3756                        editor.resize( editor.container.getStyle( 'width' ), newHeight, true );
    3857                }
     58
     59                if ( scrollable.$.scrollHeight > scrollable.$.clientHeight && newHeight < max )
     60                        scrollable.setStyle( 'overflow-y', 'hidden' );
     61                else
     62                        scrollable.removeStyle( 'overflow-y' );
     63
     64
    3965        };
     66
    4067        CKEDITOR.plugins.add( 'autogrow',
    4168        {
    4269                init : function( editor )
     
    5178                                                // Disable autogrow when the editor is maximized .(#6339)
    5279                                                ( !maximize || maximize.state != CKEDITOR.TRISTATE_ON ) )
    5380                                        {
    54                                                 setTimeout( function(){ resizeEditor( evt.editor ); }, 100 );
     81                                                setTimeout( function()
     82                                                {
     83                                                        resizeEditor( evt.editor );
     84                                                        // Second pass to make correction upon
     85                                                        // the first resize, e.g. scrollbar.
     86                                                        resizeEditor( evt.editor );
     87                                                }, 100 );
    5588                                        }
    5689                                });
    5790                        }
     
    86119 * @param {Number} data.newHeight The new height of the editor (after resizing). It can be changed
    87120 *                              to determine a different height value to be used instead.
    88121 */
     122
     123
     124/**
     125 *  Extra height in pixel to leave between the bottom boundary of content with document size when auto resizing.
     126 * @name CKEDITOR.config.autoGrow_bottomSpace
     127 * @type Number
     128 * @default 0
     129 * @since 3.6.2
     130 */
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy