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; |
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 | var scrollable = !CKEDITOR.env.ie9Compat && doc.$.compatMode == 'BackCompat' ? body : htmlElement; |
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 | | { |
| 31 | iframe.setStyle('height','1px'); |
| 32 | |
| 33 | // Get maximum possible height |
| 34 | newHeight = scrollable.$.scrollHeight; |
| 35 | // And resize to it |
| 36 | iframe.setStyle( 'height', newHeight + 'px' ); |
| 37 | // If vertical scrollbar disappeared |
| 38 | if ( scrollable.$.clientWidth >= scrollable.$.scrollWidth ) { |
| 39 | // Resize down to size gained by removal of vertical and horizontal scrollbar |
| 40 | newHeight = scrollable.$.scrollHeight; |
| 41 | if ( CKEDITOR.env.webkit ){ |
| 42 | // Force recomp |
| 43 | var last = CKEDITOR.dom.element.createFromHtml( '<span></span>', doc ); |
| 44 | doc.getBody().append( last ); |
| 45 | last.getDocumentPosition( doc ); |
| 46 | last.remove(); |
| 47 | } |
| 48 | } else |
| 49 | // Otherwise add height of scrollbar |
| 50 | newHeight += scrollable.$.scrollHeight - scrollable.$.clientHeight; |
| 51 | |
| 52 | var min = editor.config.autoGrow_minHeight || 0, |
| 53 | max = editor.config.autoGrow_maxHeight || Infinity; |
| 54 | |
| 55 | newHeight = Math.max( newHeight, min ); |
| 56 | newHeight = Math.min( newHeight, max ); |
| 57 | |
| 58 | if ( newHeight != currentHeight ) { |
| 59 | if ( newHeight < currentHeight ) |
| 60 | iframe.setStyle( 'height', '100%' ); |
| 61 | newHeight = editor.fire( 'autoGrow', { currentHeight : currentHeight, newHeight : newHeight } ).newHeight; |
| 62 | resizeable.setStyle( 'height', newHeight + 'px' ); |
| 63 | if ( newHeight >= currentHeight ) |
| 64 | iframe.setStyle( 'height', '100%' ); |
| 65 | editor.fire( 'resize' ); // ??? This is bound to be called before or after container resize 2 lines above? |
| 66 | if ( newHeight < max ) |
| 67 | scrollable.setStyle( 'overflow-y', 'hidden' ); |
| 68 | else |
| 69 | scrollable.removeStyle( 'overflow-y' ); |
| 70 | } else |
| 71 | iframe.setStyle( 'height', '100%' ); |
| 72 | }; |