1 | /*
|
---|
2 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net
|
---|
3 | * Copyright (C) 2003-2009 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 | * Stretch the editor to full window size and back.
|
---|
22 | */
|
---|
23 |
|
---|
24 | var FCKFitWindow = function()
|
---|
25 | {
|
---|
26 | this.Name = 'FitWindow' ;
|
---|
27 | }
|
---|
28 |
|
---|
29 | FCKFitWindow.prototype.Execute = function()
|
---|
30 | {
|
---|
31 | var eEditorFrame = window.frameElement ;
|
---|
32 | var eEditorFrameStyle = eEditorFrame.style ;
|
---|
33 |
|
---|
34 | var eMainWindow = parent ;
|
---|
35 | var eDocEl = eMainWindow.document.documentElement ;
|
---|
36 | var eBody = eMainWindow.document.body ;
|
---|
37 | var eBodyStyle = eBody.style ;
|
---|
38 | var eParent ;
|
---|
39 |
|
---|
40 | // Save the current selection and scroll position.
|
---|
41 | var oRange, oEditorScrollPos ;
|
---|
42 | if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
|
---|
43 | {
|
---|
44 | oRange = new FCKDomRange( FCK.EditorWindow ) ;
|
---|
45 | oRange.MoveToSelection() ;
|
---|
46 | oEditorScrollPos = FCKTools.GetScrollPosition( FCK.EditorWindow ) ;
|
---|
47 | }
|
---|
48 | else
|
---|
49 | {
|
---|
50 | var eTextarea = FCK.EditingArea.Textarea ;
|
---|
51 | oRange = !FCKBrowserInfo.IsIE && [ eTextarea.selectionStart, eTextarea.selectionEnd ] ;
|
---|
52 | oEditorScrollPos = [ eTextarea.scrollLeft, eTextarea.scrollTop ] ;
|
---|
53 | }
|
---|
54 |
|
---|
55 | // No original style properties known? Go fullscreen.
|
---|
56 | if ( !this.IsMaximized )
|
---|
57 | {
|
---|
58 | // Registering an event handler when the window gets resized.
|
---|
59 | if( FCKBrowserInfo.IsIE )
|
---|
60 | eMainWindow.attachEvent( 'onresize', FCKFitWindow_Resize ) ;
|
---|
61 | else
|
---|
62 | eMainWindow.addEventListener( 'resize', FCKFitWindow_Resize, true ) ;
|
---|
63 |
|
---|
64 | // Save the scrollbars position.
|
---|
65 | this._ScrollPos = FCKTools.GetScrollPosition( eMainWindow ) ;
|
---|
66 |
|
---|
67 | // Save and reset the styles for the entire node tree. They could interfere in the result.
|
---|
68 | eParent = eEditorFrame ;
|
---|
69 | // The extra () is to avoid a warning with strict error checking. This is ok.
|
---|
70 | while( (eParent = eParent.parentNode) )
|
---|
71 | {
|
---|
72 | if ( eParent.nodeType == 1 )
|
---|
73 | {
|
---|
74 | eParent._fckSavedStyles = FCKTools.SaveStyles( eParent ) ;
|
---|
75 | eParent.style.zIndex = FCKConfig.FloatingPanelsZIndex - 1 ;
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | // Hide IE scrollbars (in strict mode).
|
---|
80 | if ( FCKBrowserInfo.IsIE )
|
---|
81 | {
|
---|
82 | this.documentElementOverflow = eDocEl.style.overflow ;
|
---|
83 | eDocEl.style.overflow = 'hidden' ;
|
---|
84 | eBodyStyle.overflow = 'hidden' ;
|
---|
85 | }
|
---|
86 | else
|
---|
87 | {
|
---|
88 | // Hide the scroolbars in Firefox.
|
---|
89 | eBodyStyle.overflow = 'hidden' ;
|
---|
90 | eBodyStyle.width = '0px' ;
|
---|
91 | eBodyStyle.height = '0px' ;
|
---|
92 | }
|
---|
93 |
|
---|
94 | // Save the IFRAME styles.
|
---|
95 | this._EditorFrameStyles = FCKTools.SaveStyles( eEditorFrame ) ;
|
---|
96 |
|
---|
97 | // Resize.
|
---|
98 | var oViewPaneSize = FCKTools.GetViewPaneSize( eMainWindow ) ;
|
---|
99 |
|
---|
100 | eEditorFrameStyle.position = "absolute";
|
---|
101 | eEditorFrame.offsetLeft ; // Kludge for Safari 3.1 browser bug, do not remove. See #2066.
|
---|
102 | eEditorFrameStyle.zIndex = FCKConfig.FloatingPanelsZIndex - 1;
|
---|
103 | eEditorFrameStyle.left = "0px";
|
---|
104 | eEditorFrameStyle.top = "0px";
|
---|
105 | eEditorFrameStyle.width = oViewPaneSize.Width + "px";
|
---|
106 | eEditorFrameStyle.height = oViewPaneSize.Height + "px";
|
---|
107 |
|
---|
108 | // Giving the frame some (huge) borders on his right and bottom
|
---|
109 | // side to hide the background that would otherwise show when the
|
---|
110 | // editor is in fullsize mode and the window is increased in size
|
---|
111 | // not for IE, because IE immediately adapts the editor on resize,
|
---|
112 | // without showing any of the background oddly in firefox, the
|
---|
113 | // editor seems not to fill the whole frame, so just setting the
|
---|
114 | // background of it to white to cover the page laying behind it anyway.
|
---|
115 | if ( !FCKBrowserInfo.IsIE )
|
---|
116 | {
|
---|
117 | eEditorFrameStyle.borderRight = eEditorFrameStyle.borderBottom = "9999px solid white" ;
|
---|
118 | eEditorFrameStyle.backgroundColor = "white";
|
---|
119 | }
|
---|
120 |
|
---|
121 | // Scroll to top left.
|
---|
122 | eMainWindow.scrollTo(0, 0);
|
---|
123 |
|
---|
124 | // Is the editor still not on the top left? Let's find out and fix that as well. (Bug #174)
|
---|
125 | var editorPos = FCKTools.GetWindowPosition( eMainWindow, eEditorFrame ) ;
|
---|
126 | if ( editorPos.x != 0 )
|
---|
127 | eEditorFrameStyle.left = ( -1 * editorPos.x ) + "px" ;
|
---|
128 | if ( editorPos.y != 0 )
|
---|
129 | eEditorFrameStyle.top = ( -1 * editorPos.y ) + "px" ;
|
---|
130 |
|
---|
131 | this.IsMaximized = true ;
|
---|
132 | }
|
---|
133 | else // Resize to original size.
|
---|
134 | {
|
---|
135 | // Remove the event handler of window resizing.
|
---|
136 | if( FCKBrowserInfo.IsIE )
|
---|
137 | eMainWindow.detachEvent( "onresize", FCKFitWindow_Resize ) ;
|
---|
138 | else
|
---|
139 | eMainWindow.removeEventListener( "resize", FCKFitWindow_Resize, true ) ;
|
---|
140 |
|
---|
141 | // Restore the CSS position for the entire node tree.
|
---|
142 | eParent = eEditorFrame ;
|
---|
143 | // The extra () is to avoid a warning with strict error checking. This is ok.
|
---|
144 | while( (eParent = eParent.parentNode) )
|
---|
145 | {
|
---|
146 | if ( eParent._fckSavedStyles )
|
---|
147 | {
|
---|
148 | FCKTools.RestoreStyles( eParent, eParent._fckSavedStyles ) ;
|
---|
149 | eParent._fckSavedStyles = null ;
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 | // Restore IE scrollbars
|
---|
154 | if ( FCKBrowserInfo.IsIE )
|
---|
155 | eDocEl.style.overflow = this.documentElementOverflow ;
|
---|
156 |
|
---|
157 | // Restore original size
|
---|
158 | FCKTools.RestoreStyles( eEditorFrame, this._EditorFrameStyles ) ;
|
---|
159 |
|
---|
160 | // Restore the window scroll position.
|
---|
161 | eMainWindow.scrollTo( this._ScrollPos.X, this._ScrollPos.Y ) ;
|
---|
162 |
|
---|
163 | this.IsMaximized = false ;
|
---|
164 | }
|
---|
165 |
|
---|
166 | FCKToolbarItems.GetItem('FitWindow').RefreshState() ;
|
---|
167 |
|
---|
168 | // It seams that Firefox restarts the editing area when making this changes.
|
---|
169 | // On FF 1.0.x, the area is not anymore editable. On FF 1.5+, the special
|
---|
170 | //configuration, like DisableFFTableHandles and DisableObjectResizing get
|
---|
171 | //lost, so we must reset it. Also, the cursor position and selection are
|
---|
172 | //also lost, even if you comment the following line (MakeEditable).
|
---|
173 | // if ( FCKBrowserInfo.IsGecko10 ) // Initially I thought it was a FF 1.0 only problem.
|
---|
174 | if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
|
---|
175 | FCK.EditingArea.MakeEditable() ;
|
---|
176 |
|
---|
177 | FCK.Focus() ;
|
---|
178 |
|
---|
179 | // Restore the selection and scroll position of inside the document.
|
---|
180 | if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
|
---|
181 | {
|
---|
182 | oRange.Select() ;
|
---|
183 | FCK.EditorWindow.scrollTo( oEditorScrollPos.X, oEditorScrollPos.Y ) ;
|
---|
184 | }
|
---|
185 | else
|
---|
186 | {
|
---|
187 | if ( !FCKBrowserInfo.IsIE )
|
---|
188 | {
|
---|
189 | eTextarea.selectionStart = oRange[0] ;
|
---|
190 | eTextarea.selectionEnd = oRange[1] ;
|
---|
191 | }
|
---|
192 | eTextarea.scrollLeft = oEditorScrollPos[0] ;
|
---|
193 | eTextarea.scrollTop = oEditorScrollPos[1] ;
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | FCKFitWindow.prototype.GetState = function()
|
---|
198 | {
|
---|
199 | if ( FCKConfig.ToolbarLocation != 'In' )
|
---|
200 | return FCK_TRISTATE_DISABLED ;
|
---|
201 | else
|
---|
202 | return ( this.IsMaximized ? FCK_TRISTATE_ON : FCK_TRISTATE_OFF );
|
---|
203 | }
|
---|
204 |
|
---|
205 | function FCKFitWindow_Resize()
|
---|
206 | {
|
---|
207 | var oViewPaneSize = FCKTools.GetViewPaneSize( parent ) ;
|
---|
208 |
|
---|
209 | var eEditorFrameStyle = window.frameElement.style ;
|
---|
210 |
|
---|
211 | eEditorFrameStyle.width = oViewPaneSize.Width + 'px' ;
|
---|
212 | eEditorFrameStyle.height = oViewPaneSize.Height + 'px' ;
|
---|
213 | }
|
---|