Ticket #8050: 8050_12.patch
File 8050_12.patch, 4.2 KB (added by , 13 years ago) |
---|
-
_source/plugins/autogrow/plugin.js
7 7 * @file AutoGrow plugin 8 8 */ 9 9 (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 ? ' ' : '' ) + '</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 10 27 var resizeEditor = function( editor ) 11 28 { 12 29 if ( !editor.window ) 13 30 return; 31 14 32 var doc = editor.document, 33 iframe = new CKEDITOR.dom.element( doc.getWindow().$.frameElement ), 34 body = doc.getBody(), 35 htmlElement = doc.getDocumentElement(), 15 36 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 ); 17 40 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; 25 43 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 ); 33 52 34 53 if ( newHeight != currentHeight ) 35 54 { 36 55 newHeight = editor.fire( 'autoGrow', { currentHeight : currentHeight, newHeight : newHeight } ).newHeight; 37 56 editor.resize( editor.container.getStyle( 'width' ), newHeight, true ); 38 57 } 58 59 if ( scrollable.$.scrollHeight > scrollable.$.clientHeight && newHeight < max ) 60 scrollable.setStyle( 'overflow-y', 'hidden' ); 61 else 62 scrollable.removeStyle( 'overflow-y' ); 63 64 39 65 }; 66 40 67 CKEDITOR.plugins.add( 'autogrow', 41 68 { 42 69 init : function( editor ) … … 51 78 // Disable autogrow when the editor is maximized .(#6339) 52 79 ( !maximize || maximize.state != CKEDITOR.TRISTATE_ON ) ) 53 80 { 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 ); 55 88 } 56 89 }); 57 90 } … … 86 119 * @param {Number} data.newHeight The new height of the editor (after resizing). It can be changed 87 120 * to determine a different height value to be used instead. 88 121 */ 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 */