2 Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @file AutoGrow plugin
\r
11 // Actual content height, figured out by appending check the last element's document position.
\r
12 function contentHeight( scrollable )
\r
14 var overflowY = scrollable.getStyle( 'overflow-y' );
\r
16 var doc = scrollable.getDocument();
\r
17 // Create a temporary marker element.
\r
18 var marker = CKEDITOR.dom.element.createFromHtml( '<span style="margin:0;padding:0;border:0;clear:both;width:1px;height:1px;display:block;">' + ( CKEDITOR.env.webkit ? ' ' : '' ) + '</span>', doc );
\r
19 doc[ CKEDITOR.env.ie? 'getBody' : 'getDocumentElement']().append( marker );
\r
21 var height = marker.getDocumentPosition( doc ).y + marker.$.offsetHeight;
\r
23 scrollable.setStyle( 'overflow-y', overflowY );
\r
27 var resizeEditor = function( editor )
\r
29 if ( !editor.window )
\r
32 var doc = editor.document,
\r
33 iframe = new CKEDITOR.dom.element( doc.getWindow().$.frameElement ),
\r
34 body = doc.getBody(),
\r
35 htmlElement = doc.getDocumentElement(),
\r
36 currentHeight = editor.window.getViewPaneSize().height,
\r
37 // Quirks mode overflows body, standards overflows document element
\r
38 scrollable = doc.$.compatMode == 'BackCompat' ? body : htmlElement,
\r
39 newHeight = contentHeight( scrollable );
\r
41 // Additional space specified by user.
\r
42 newHeight += ( editor.config.autoGrow_bottomSpace || 0 );
\r
44 var min = editor.config.autoGrow_minHeight != undefined ? editor.config.autoGrow_minHeight : 200,
\r
45 max = editor.config.autoGrow_maxHeight || Infinity;
\r
47 newHeight = Math.max( newHeight, min );
\r
48 newHeight = Math.min( newHeight, max );
\r
50 if ( newHeight != currentHeight )
\r
52 newHeight = editor.fire( 'autoGrow', { currentHeight : currentHeight, newHeight : newHeight } ).newHeight;
\r
53 editor.resize( editor.container.getStyle( 'width' ), newHeight, true );
\r
56 if ( scrollable.$.scrollHeight > scrollable.$.clientHeight && newHeight < max )
\r
57 scrollable.setStyle( 'overflow-y', 'hidden' );
\r
59 scrollable.removeStyle( 'overflow-y' );
\r
64 CKEDITOR.plugins.add( 'autogrow',
\r
66 init : function( editor )
\r
68 editor.addCommand( 'autogrow', { exec : resizeEditor, modes : { wysiwyg:1 }, readOnly: 1, canUndo: false, editorFocus: false } );
\r
70 var eventsList = { contentDom:1, key:1, selectionChange:1, insertElement:1, mode:1 };
\r
71 editor.config.autoGrow_onStartup && ( eventsList[ 'instanceReady' ] = 1 );
\r
72 for ( var eventName in eventsList )
\r
74 editor.on( eventName, function( evt )
\r
76 var maximize = editor.getCommand( 'maximize' );
\r
77 // Some time is required for insertHtml, and it gives other events better performance as well.
\r
78 if ( evt.editor.mode == 'wysiwyg' &&
\r
79 // Disable autogrow when the editor is maximized .(#6339)
\r
80 ( !maximize || maximize.state != CKEDITOR.TRISTATE_ON ) )
\r
82 setTimeout( function()
\r
84 resizeEditor( evt.editor );
\r
85 // Second pass to make correction upon
\r
86 // the first resize, e.g. scrollbar.
\r
87 resizeEditor( evt.editor );
\r
96 * The minimum height that the editor can reach using the AutoGrow feature.
\r
97 * @name CKEDITOR.config.autoGrow_minHeight
\r
99 * @default <code>200</code>
\r
102 * config.autoGrow_minHeight = 300;
\r
106 * The maximum height that the editor can reach using the AutoGrow feature. Zero means unlimited.
\r
107 * @name CKEDITOR.config.autoGrow_maxHeight
\r
109 * @default <code>0</code>
\r
112 * config.autoGrow_maxHeight = 400;
\r
116 * Whether to have the auto grow happen on editor creation.
\r
117 * @name CKEDITOR.config.autoGrow_onStartup
\r
122 * config.autoGrow_onStartup = true;
\r
126 * Fired when the AutoGrow plugin is about to change the size of the editor.
\r
127 * @name CKEDITOR.editor#autogrow
\r
129 * @param {Number} data.currentHeight The current height of the editor (before resizing).
\r
130 * @param {Number} data.newHeight The new height of the editor (after resizing). It can be changed
\r
131 * to determine a different height value to be used instead.
\r
136 * Extra height in pixel to leave between the bottom boundary of content with document size when auto resizing.
\r
137 * @name CKEDITOR.config.autoGrow_bottomSpace
\r