Ticket #8050: 8050_11.patch
File 8050_11.patch, 4.1 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 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 10 28 var resizeEditor = function( editor ) 11 29 { 12 30 if ( !editor.window ) 13 31 return; 32 14 33 var doc = editor.document, 34 iframe = new CKEDITOR.dom.element( doc.getWindow().$.frameElement ), 35 body = doc.getBody(), 36 htmlElement = doc.getDocumentElement(), 15 37 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 ); 17 41 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; 25 44 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 ); 33 53 34 54 if ( newHeight != currentHeight ) 35 55 { 36 56 newHeight = editor.fire( 'autoGrow', { currentHeight : currentHeight, newHeight : newHeight } ).newHeight; 37 57 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' ); 38 63 } 39 64 }; 65 40 66 CKEDITOR.plugins.add( 'autogrow', 41 67 { 42 68 init : function( editor ) … … 51 77 // Disable autogrow when the editor is maximized .(#6339) 52 78 ( !maximize || maximize.state != CKEDITOR.TRISTATE_ON ) ) 53 79 { 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 ); 55 87 } 56 88 }); 57 89 } … … 86 118 * @param {Number} data.newHeight The new height of the editor (after resizing). It can be changed 87 119 * to determine a different height value to be used instead. 88 120 */ 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 */