Ticket #8050: 8050_12_broken_ie7.patch

File 8050_12_broken_ie7.patch, 4.8 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                                // Dinu 02.08.11: Webkit also scrolls body, overflows both
     30                                var scrollable = !CKEDITOR.env.ie9Compat && doc.$.compatMode == 'BackCompat' || CKEDITOR.env.webkit ? body : htmlElement,
     31                                // Dinu 02.08.11: This is broken in IE7
     32                                        currentScroll = body.$.scrollTop + htmlElement.$.scrollTop;
    3333
    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                 {
     34                                iframe.setStyle('height','1px');
     35
     36                                // Get maximum possible height
     37                                newHeight = scrollable.$.scrollHeight;
     38                                // And resize to it
     39                                iframe.setStyle( 'height', newHeight + 'px' );
     40                                // If vertical scrollbar disappeared
     41                                if ( scrollable.$.clientWidth >= scrollable.$.scrollWidth ) {
     42                                        // Resize down to size gained by removal of vertical and horizontal scrollbar
     43                                        newHeight = scrollable.$.scrollHeight;
     44                                } else
     45                                        // Otherwise add height of scrollbar
     46                                        newHeight += scrollable.$.scrollHeight - scrollable.$.clientHeight;
     47
     48                var min = editor.config.autoGrow_minHeight || 0,
     49                                        max = editor.config.autoGrow_maxHeight || Infinity;
     50
     51                                newHeight = Math.max( newHeight, min );
     52                                newHeight = Math.min( newHeight, max );
     53                               
     54                                if ( newHeight != currentHeight ) {
     55                                        newHeight = editor.fire( 'autoGrow', { currentHeight : currentHeight, newHeight : newHeight } ).newHeight;
     56                                        // Dinu 02.08.11: WebKit hack: outcome is different if iframe is sized 100% before or after the container
     57                                        if ( newHeight < currentHeight )
     58                                                iframe.setStyle( 'height', '100%' );
     59                                        // Dinu 02.08.11: Using editor.resize causes top document to scroll in Webkit; needs more investigation
     60                                        resizeable.setStyle( 'height', newHeight + 'px' );
     61                                        // Dinu 02.08.11: WebKit hack: outcome is different if iframe is sized 100% before or after the container
     62                                        if ( newHeight >= currentHeight )
     63                                                iframe.setStyle( 'height', '100%' );
     64                                        editor.fire( 'resize' );
     65                                        if ( newHeight < max )
     66                                                scrollable.setStyle( 'overflow-y', 'hidden' );
     67                                        else
     68                                                scrollable.removeStyle( 'overflow-y' );
     69                                } else
     70                                        iframe.setStyle( 'height', '100%' );
     71                                scrollable.$.scrollTop = currentScroll;
     72                        };
     73                        editor.addCommand( 'autogrow', { exec : resizeEditor, modes : { wysiwyg:1 }, readOnly: 1, canUndo: false, editorFocus: false } );
    4474                        for ( var eventName in { contentDom:1, key:1, selectionChange:1, insertElement:1 } )
    4575                        {
    4676                                editor.on( eventName, function( evt )
     
    5181                                                // Disable autogrow when the editor is maximized .(#6339)
    5282                                                ( !maximize || maximize.state != CKEDITOR.TRISTATE_ON ) )
    5383                                        {
    54                                                 setTimeout( function(){ resizeEditor( evt.editor ); }, 100 );
     84                                                setTimeout( function(){ resizeEditor( evt.editor ); }, 0 );
    5585                                        }
    56                                 });
    57                         }
     86                        });
    5887                }
     88                }
    5989        });
    6090})();
    6191/**
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy