1 | /* |
---|
2 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net |
---|
3 | * Copyright (C) 2003-2008 Frederico Caldeira Knabben |
---|
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 | |
---|
25 | var FCKAutoGrow_Min = window.frameElement.offsetHeight ; |
---|
26 | |
---|
27 | function FCKAutoGrow_Check() |
---|
28 | { |
---|
29 | var oInnerDoc = FCK.EditorDocument ; |
---|
30 | |
---|
31 | var iFrameHeight, iInnerHeight ; |
---|
32 | |
---|
33 | if ( FCKBrowserInfo.IsIE ) |
---|
34 | { |
---|
35 | iFrameHeight = FCK.EditorWindow.frameElement.offsetHeight ; |
---|
36 | iInnerHeight = oInnerDoc.body.scrollHeight ; |
---|
37 | } |
---|
38 | else |
---|
39 | { |
---|
40 | iFrameHeight = FCK.EditorWindow.innerHeight ; |
---|
41 | iInnerHeight = oInnerDoc.body.offsetHeight ; |
---|
42 | } |
---|
43 | |
---|
44 | var iDiff = iInnerHeight - iFrameHeight ; |
---|
45 | |
---|
46 | if ( iDiff != 0 ) |
---|
47 | { |
---|
48 | var iMainFrameSize = window.frameElement.offsetHeight ; |
---|
49 | var FrameMax = FCKAutoGrow_GetFrameMax() ; |
---|
50 | |
---|
51 | if ( iDiff > 0 && iMainFrameSize < FrameMax ) |
---|
52 | { |
---|
53 | iMainFrameSize += iDiff ; |
---|
54 | if ( iMainFrameSize > FrameMax ) |
---|
55 | iMainFrameSize = FrameMax ; |
---|
56 | } |
---|
57 | // resizing buggyness of the inner frame sometimes returns a possitive iDiff when it should be negative, handle it |
---|
58 | else if ( iDiff > 0 && iMainFrameSize > FrameMax ){ |
---|
59 | iMainFrameSize = FrameMax ; |
---|
60 | } |
---|
61 | else if ( iDiff < 0 && iMainFrameSize > FCKAutoGrow_Min ) |
---|
62 | { |
---|
63 | iMainFrameSize += iDiff ; |
---|
64 | if ( iMainFrameSize < FCKAutoGrow_Min ) |
---|
65 | iMainFrameSize = FCKAutoGrow_Min ; |
---|
66 | else if ( iMainFrameSize > FrameMax ) |
---|
67 | iMainFrameSize = FrameMax ; |
---|
68 | } |
---|
69 | else |
---|
70 | return ; |
---|
71 | |
---|
72 | window.frameElement.height = iMainFrameSize ; |
---|
73 | |
---|
74 | // Gecko browsers use an onresize handler to update the innermost |
---|
75 | // IFRAME's height. If the document is modified before the onresize |
---|
76 | // is triggered, the plugin will miscalculate the new height. Thus, |
---|
77 | // forcibly trigger onresize. #1336 |
---|
78 | if ( typeof window.onresize == 'function' ) |
---|
79 | window.onresize() ; |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | function FCKAutoGrow_GetFrameMax(){ |
---|
84 | if ( typeof( FCKConfig.AutoGrowMax ) == "number" ){ |
---|
85 | return FCKConfig.AutoGrowMax; |
---|
86 | }else{ |
---|
87 | return FCKTools.GetViewPaneSize( window.parent ).Height; |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | FCK.AttachToOnSelectionChange( FCKAutoGrow_Check ) ; |
---|
92 | |
---|
93 | function FCKAutoGrow_SetListeners() |
---|
94 | { |
---|
95 | if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG ) |
---|
96 | return ; |
---|
97 | |
---|
98 | FCK.EditorWindow.attachEvent( 'onscroll', FCKAutoGrow_Check ) ; |
---|
99 | FCK.EditorDocument.attachEvent( 'onkeyup', FCKAutoGrow_Check ) ; |
---|
100 | } |
---|
101 | |
---|
102 | if ( FCKBrowserInfo.IsIE ) |
---|
103 | { |
---|
104 | // FCKAutoGrow_SetListeners() ; |
---|
105 | FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKAutoGrow_SetListeners ) ; |
---|
106 | } |
---|
107 | |
---|
108 | function FCKAutoGrow_CheckEditorStatus( sender, status ) |
---|
109 | { |
---|
110 | if ( status == FCK_STATUS_COMPLETE ) |
---|
111 | FCKAutoGrow_Check() ; |
---|
112 | } |
---|
113 | |
---|
114 | FCK.Events.AttachEvent( 'OnStatusChange', FCKAutoGrow_CheckEditorStatus ) ; |
---|