Subversion Repositories Applications.papyrus

Rev

Rev 1925 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1925 jp_milcent 1
/*
2
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
2048 gduche 3
 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
1925 jp_milcent 4
 *
5
 * == BEGIN LICENSE ==
6
 *
7
 * Licensed under the terms of any of the following licenses at your
8
 * choice:
9
 *
10
 *  - GNU General Public License Version 2 or later (the "GPL")
11
 *    http://www.gnu.org/licenses/gpl.html
12
 *
13
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
 *    http://www.gnu.org/licenses/lgpl.html
15
 *
16
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
17
 *    http://www.mozilla.org/MPL/MPL-1.1.html
18
 *
19
 * == END LICENSE ==
20
 *
21
 * Plugin: automatically resizes the editor until a configurable maximun
22
 * height (FCKConfig.AutoGrowMax), based on its contents.
23
 */
24
 
2048 gduche 25
var FCKAutoGrow = {
26
	MIN_HEIGHT : window.frameElement.offsetHeight,
1925 jp_milcent 27
 
2048 gduche 28
	Check : function()
29
	{
30
		var delta = FCKAutoGrow.GetHeightDelta() ;
31
		if ( delta != 0 )
32
		{
33
			var newHeight = window.frameElement.offsetHeight + delta ;
1925 jp_milcent 34
 
2048 gduche 35
			newHeight = FCKAutoGrow.GetEffectiveHeight( newHeight ) ;
1925 jp_milcent 36
 
2048 gduche 37
			if ( newHeight != window.frameElement.height )
38
			{
39
				window.frameElement.style.height = newHeight + "px" ;
40
 
41
				// Gecko browsers use an onresize handler to update the innermost
42
				// IFRAME's height. If the document is modified before the onresize
43
				// is triggered, the plugin will miscalculate the new height. Thus,
44
				// forcibly trigger onresize. #1336
45
				if ( typeof window.onresize == 'function' )
46
				{
47
					window.onresize() ;
48
				}
49
			}
50
		}
51
	},
52
 
53
	CheckEditorStatus : function( sender, status )
1925 jp_milcent 54
	{
2048 gduche 55
		if ( status == FCK_STATUS_COMPLETE )
56
			FCKAutoGrow.Check() ;
57
	},
58
 
59
	GetEffectiveHeight : function( height )
1925 jp_milcent 60
	{
2048 gduche 61
		if ( height < FCKAutoGrow.MIN_HEIGHT )
62
			height = FCKAutoGrow.MIN_HEIGHT;
63
		else
64
		{
65
			var max = FCKConfig.AutoGrowMax;
66
			if ( max && max > 0 && height > max )
67
				height = max;
68
		}
1925 jp_milcent 69
 
2048 gduche 70
		return height;
71
	},
1925 jp_milcent 72
 
2048 gduche 73
	GetHeightDelta : function()
1925 jp_milcent 74
	{
2048 gduche 75
		var oInnerDoc = FCK.EditorDocument ;
1925 jp_milcent 76
 
2048 gduche 77
		var iFrameHeight ;
78
		var iInnerHeight ;
79
 
80
		if ( FCKBrowserInfo.IsIE )
1925 jp_milcent 81
		{
2048 gduche 82
			iFrameHeight = FCK.EditorWindow.frameElement.offsetHeight ;
83
			iInnerHeight = oInnerDoc.body.scrollHeight ;
1925 jp_milcent 84
		}
2048 gduche 85
		else
1925 jp_milcent 86
		{
2048 gduche 87
			iFrameHeight = FCK.EditorWindow.innerHeight ;
88
			iInnerHeight = oInnerDoc.body.offsetHeight +
89
				( parseInt( FCKDomTools.GetCurrentElementStyle( oInnerDoc.body, 'margin-top' ), 10 ) || 0 ) +
90
				( parseInt( FCKDomTools.GetCurrentElementStyle( oInnerDoc.body, 'margin-bottom' ), 10 ) || 0 ) ;
1925 jp_milcent 91
		}
2048 gduche 92
 
93
		return iInnerHeight - iFrameHeight ;
94
	},
95
 
96
	SetListeners : function()
97
	{
98
		if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
1925 jp_milcent 99
			return ;
100
 
2048 gduche 101
		FCK.EditorWindow.attachEvent( 'onscroll', FCKAutoGrow.Check ) ;
102
		FCK.EditorDocument.attachEvent( 'onkeyup', FCKAutoGrow.Check ) ;
1925 jp_milcent 103
	}
2048 gduche 104
};
1925 jp_milcent 105
 
2048 gduche 106
FCK.AttachToOnSelectionChange( FCKAutoGrow.Check ) ;
1925 jp_milcent 107
 
108
if ( FCKBrowserInfo.IsIE )
2048 gduche 109
	FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKAutoGrow.SetListeners ) ;
1925 jp_milcent 110
 
2048 gduche 111
FCK.Events.AttachEvent( 'OnStatusChange', FCKAutoGrow.CheckEditorStatus ) ;