2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @file AutoGrow plugin
10 var resizeEditor = function( editor
)
14 var doc
= editor
.document
,
15 currentHeight
= editor
.window
.getViewPaneSize().height
,
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 );
24 newHeight
= doc
.getDocumentElement().$.offsetHeight
;
26 var min
= editor
.config
.autoGrow_minHeight
,
27 max
= editor
.config
.autoGrow_maxHeight
;
28 ( min
== undefined ) && ( editor
.config
.autoGrow_minHeight
= min
= 200 );
30 newHeight
= Math
.max( newHeight
, min
);
32 newHeight
= Math
.min( newHeight
, max
);
34 if ( newHeight
!= currentHeight
)
36 newHeight
= editor
.fire( 'autoGrow', { currentHeight
: currentHeight
, newHeight
: newHeight
} ).newHeight
;
37 editor
.resize( editor
.container
.getStyle( 'width' ), newHeight
, true );
40 CKEDITOR
.plugins
.add( 'autogrow',
42 init : function( editor
)
44 for ( var eventName
in { contentDom
:1, key
:1, selectionChange
:1, insertElement
:1 } )
46 editor
.on( eventName
, function( evt
)
48 var maximize
= editor
.getCommand( 'maximize' );
49 // Some time is required for insertHtml, and it gives other events better performance as well.
50 if ( evt
.editor
.mode
== 'wysiwyg' &&
51 // Disable autogrow when the editor is maximized .(#6339)
52 ( !maximize
|| maximize
.state
!= CKEDITOR
.TRISTATE_ON
) )
54 setTimeout( function(){ resizeEditor( evt
.editor
); }, 100 );
62 * The minimum height to which the editor can reach using AutoGrow.
63 * @name CKEDITOR.config.autoGrow_minHeight
68 * config.autoGrow_minHeight = 300;
72 * The maximum height to which the editor can reach using AutoGrow. Zero means unlimited.
73 * @name CKEDITOR.config.autoGrow_maxHeight
78 * config.autoGrow_maxHeight = 400;
82 * Fired when the AutoGrow plugin is about to change the size of the editor.
83 * @name CKEDITOR.editor#autogrow
85 * @param {Number} data.currentHeight The current height of the editor (before the resizing).
86 * @param {Number} data.newHeight The new height of the editor (after the resizing). It can be changed
87 * to determine another height to be used instead.