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 | // 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; |
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 } ); |