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