Suppression des images attachées fonctionnelle.
[ckeditor.git] / skins / ckeditor / _source / plugins / autogrow / plugin.js
1 /*
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
4 */
5
6 /**
7 * @file AutoGrow plugin
8 */
9 (function(){
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;
17
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;
25
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 );
33
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 {
44 for ( var eventName in { contentDom:1, key:1, selectionChange:1, insertElement:1 } )
45 {
46 editor.on( eventName, function( evt )
47 {
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 ) )
53 {
54 setTimeout( function(){ resizeEditor( evt.editor ); }, 100 );
55 }
56 });
57 }
58 }
59 });
60 })();
61 /**
62 * The minimum height to which the editor can reach using AutoGrow.
63 * @name CKEDITOR.config.autoGrow_minHeight
64 * @type Number
65 * @default 200
66 * @since 3.4
67 * @example
68 * config.autoGrow_minHeight = 300;
69 */
70
71 /**
72 * The maximum height to which the editor can reach using AutoGrow. Zero means unlimited.
73 * @name CKEDITOR.config.autoGrow_maxHeight
74 * @type Number
75 * @default 0
76 * @since 3.4
77 * @example
78 * config.autoGrow_maxHeight = 400;
79 */
80
81 /**
82 * Fired when the AutoGrow plugin is about to change the size of the editor.
83 * @name CKEDITOR.editor#autogrow
84 * @event
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.
88 */