10 | | var resizeEditor = function( editor ) |
11 | | { |
12 | | if ( !editor.window ) |
13 | | return; |
14 | | var doc = editor.document, |
15 | | currentHeight = editor.window.getViewPaneSize().height, |
16 | | newHeight; |
| 10 | |
| 11 | CKEDITOR.plugins.add( 'autogrow', |
| 12 | { |
| 13 | init : function( editor ) |
| 14 | { |
| 15 | var lastContentHeight; |
| 16 | var resizeEditor = function( editor ) |
| 17 | { |
| 18 | if ( !editor.window ) |
| 19 | return; |
| 20 | |
| 21 | var doc = editor.document, |
| 22 | resizeable = editor.getResizable( 1 ), |
| 23 | body = doc.getBody().$, |
| 24 | htmlElement = doc.getDocumentElement().$, |
| 25 | currentHeight = resizeable.$.offsetHeight, |
| 26 | newHeight; |
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; |
| 28 | var delta = |
| 29 | // Delta height by checking scrollHeight. |
| 30 | ( CKEDITOR.env.ie && CKEDITOR.env.quirks ? body.scrollHeight - body.clientHeight |
| 31 | : htmlElement.scrollHeight - ( htmlElement.clientHeight || htmlElement.offsetHeight ) ) |
| 32 | // Negative scrollHeight (content reduced) is not supported in some browsers, figure it out by watching over the content size. |
| 33 | || ( body.clientHeight < lastContentHeight ? body.clientHeight - lastContentHeight : 0 ); |
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 ); |
| 35 | if ( delta ) |
| 36 | { |
| 37 | newHeight = currentHeight + delta; |
| 38 | var min = editor.config.autoGrow_minHeight, |
| 39 | max = editor.config.autoGrow_maxHeight; |
| 40 | |
| 41 | ( min == undefined ) && ( editor.config.autoGrow_minHeight = min = 200 ); |
| 42 | if ( min ) |
| 43 | newHeight = Math.max( newHeight, min ); |
| 44 | if ( max ) |
| 45 | newHeight = Math.min( newHeight, max ); |
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 | | { |
| 47 | if ( newHeight != currentHeight ) |
| 48 | { |
| 49 | newHeight = editor.fire( 'autoGrow', { currentHeight : currentHeight, newHeight : newHeight } ).newHeight; |
| 50 | resizeable.setStyle( 'height', newHeight + 'px' ); |
| 51 | editor.fire( 'resize' ); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | lastContentHeight = body.clientHeight; |
| 56 | }; |
| 57 | |