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 )
12 var doc = editor.document,
13 currentHeight = editor.window.getViewPaneSize().height,
16 // We can not use documentElement to calculate the height for IE (#6061).
17 // It is not good for IE Quirks, yet using offsetHeight would also not work as expected (#6408).
18 // We do the same for FF because of the html height workaround (#6341).
19 if ( CKEDITOR.env.ie || CKEDITOR.env.gecko )
20 newHeight = doc.getBody().$.scrollHeight + ( CKEDITOR.env.ie && CKEDITOR.env.quirks ? 0 : 24 );
22 newHeight = doc.getDocumentElement().$.offsetHeight;
24 var min = editor.config.autoGrow_minHeight,
25 max = editor.config.autoGrow_maxHeight;
26 ( min == undefined ) && ( editor.config.autoGrow_minHeight = min = 200 );
28 newHeight = Math.max( newHeight, min );
30 newHeight = Math.min( newHeight, max );
32 if ( newHeight != currentHeight )
34 newHeight = editor.fire( 'autoGrow', { currentHeight : currentHeight, newHeight : newHeight } ).newHeight;
35 editor.resize( editor.container.getStyle( 'width' ), newHeight, true );
38 CKEDITOR.plugins.add( 'autogrow',
40 init : function( editor )
42 for ( var eventName in { contentDom:1, key:1, selectionChange:1, insertElement:1 } )
44 editor.on( eventName, function( evt )
46 var maximize = editor.getCommand( 'maximize' );
47 // Some time is required for insertHtml, and it gives other events better performance as well.
48 if ( evt.editor.mode == 'wysiwyg' &&
49 // Disable autogrow when the editor is maximized .(#6339)
50 ( !maximize || maximize.state != CKEDITOR.TRISTATE_ON ) )
52 setTimeout( function(){ resizeEditor( evt.editor ); }, 100 );
60 * The minimum height to which the editor can reach using AutoGrow.
61 * @name CKEDITOR.config.autoGrow_minHeight
66 * config.autoGrow_minHeight = 300;
70 * The maximum height to which the editor can reach using AutoGrow. Zero means unlimited.
71 * @name CKEDITOR.config.autoGrow_maxHeight
76 * config.autoGrow_maxHeight = 400;
80 * Fired when the AutoGrow plugin is about to change the size of the editor.
81 * @name CKEDITOR.editor#autogrow
83 * @param {Number} data.currentHeight The current height of the editor (before the resizing).
84 * @param {Number} data.newHeight The new height of the editor (after the resizing). It can be changed
85 * to determine another height to be used instead.