2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
\r
3 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
\r
5 * == BEGIN LICENSE ==
\r
7 * Licensed under the terms of any of the following licenses at your
\r
10 * - GNU General Public License Version 2 or later (the "GPL")
\r
11 * http://www.gnu.org/licenses/gpl.html
\r
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
\r
14 * http://www.gnu.org/licenses/lgpl.html
\r
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
\r
17 * http://www.mozilla.org/MPL/MPL-1.1.html
\r
21 * Stretch the editor to full window size and back.
\r
24 var FCKFitWindow = function()
\r
26 this.Name = 'FitWindow' ;
\r
29 FCKFitWindow.prototype.Execute = function()
\r
31 var eEditorFrame = window.frameElement ;
\r
32 var eEditorFrameStyle = eEditorFrame.style ;
\r
34 var eMainWindow = parent ;
\r
35 var eDocEl = eMainWindow.document.documentElement ;
\r
36 var eBody = eMainWindow.document.body ;
\r
37 var eBodyStyle = eBody.style ;
\r
40 // Save the current selection and scroll position.
\r
41 var oRange, oEditorScrollPos ;
\r
42 if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
\r
44 oRange = new FCKDomRange( FCK.EditorWindow ) ;
\r
45 oRange.MoveToSelection() ;
\r
46 oEditorScrollPos = FCKTools.GetScrollPosition( FCK.EditorWindow ) ;
\r
50 var eTextarea = FCK.EditingArea.Textarea ;
\r
51 oRange = !FCKBrowserInfo.IsIE && [ eTextarea.selectionStart, eTextarea.selectionEnd ] ;
\r
52 oEditorScrollPos = [ eTextarea.scrollLeft, eTextarea.scrollTop ] ;
\r
55 // No original style properties known? Go fullscreen.
\r
56 if ( !this.IsMaximized )
\r
58 // Registering an event handler when the window gets resized.
\r
59 if( FCKBrowserInfo.IsIE )
\r
60 eMainWindow.attachEvent( 'onresize', FCKFitWindow_Resize ) ;
\r
62 eMainWindow.addEventListener( 'resize', FCKFitWindow_Resize, true ) ;
\r
64 // Save the scrollbars position.
\r
65 this._ScrollPos = FCKTools.GetScrollPosition( eMainWindow ) ;
\r
67 // Save and reset the styles for the entire node tree. They could interfere in the result.
\r
68 eParent = eEditorFrame ;
\r
69 // The extra () is to avoid a warning with strict error checking. This is ok.
\r
70 while( (eParent = eParent.parentNode) )
\r
72 if ( eParent.nodeType == 1 )
\r
74 eParent._fckSavedStyles = FCKTools.SaveStyles( eParent ) ;
\r
75 eParent.style.zIndex = FCKConfig.FloatingPanelsZIndex - 1 ;
\r
79 // Hide IE scrollbars (in strict mode).
\r
80 if ( FCKBrowserInfo.IsIE )
\r
82 this.documentElementOverflow = eDocEl.style.overflow ;
\r
83 eDocEl.style.overflow = 'hidden' ;
\r
84 eBodyStyle.overflow = 'hidden' ;
\r
88 // Hide the scroolbars in Firefox.
\r
89 eBodyStyle.overflow = 'hidden' ;
\r
90 eBodyStyle.width = '0px' ;
\r
91 eBodyStyle.height = '0px' ;
\r
94 // Save the IFRAME styles.
\r
95 this._EditorFrameStyles = FCKTools.SaveStyles( eEditorFrame ) ;
\r
98 var oViewPaneSize = FCKTools.GetViewPaneSize( eMainWindow ) ;
\r
100 eEditorFrameStyle.position = "absolute";
\r
101 eEditorFrame.offsetLeft ; // Kludge for Safari 3.1 browser bug, do not remove. See #2066.
\r
102 eEditorFrameStyle.zIndex = FCKConfig.FloatingPanelsZIndex - 1;
\r
103 eEditorFrameStyle.left = "0px";
\r
104 eEditorFrameStyle.top = "0px";
\r
105 eEditorFrameStyle.width = oViewPaneSize.Width + "px";
\r
106 eEditorFrameStyle.height = oViewPaneSize.Height + "px";
\r
108 // Giving the frame some (huge) borders on his right and bottom
\r
109 // side to hide the background that would otherwise show when the
\r
110 // editor is in fullsize mode and the window is increased in size
\r
111 // not for IE, because IE immediately adapts the editor on resize,
\r
112 // without showing any of the background oddly in firefox, the
\r
113 // editor seems not to fill the whole frame, so just setting the
\r
114 // background of it to white to cover the page laying behind it anyway.
\r
115 if ( !FCKBrowserInfo.IsIE )
\r
117 eEditorFrameStyle.borderRight = eEditorFrameStyle.borderBottom = "9999px solid white" ;
\r
118 eEditorFrameStyle.backgroundColor = "white";
\r
121 // Scroll to top left.
\r
122 eMainWindow.scrollTo(0, 0);
\r
124 // Is the editor still not on the top left? Let's find out and fix that as well. (Bug #174)
\r
125 var editorPos = FCKTools.GetWindowPosition( eMainWindow, eEditorFrame ) ;
\r
126 if ( editorPos.x != 0 )
\r
127 eEditorFrameStyle.left = ( -1 * editorPos.x ) + "px" ;
\r
128 if ( editorPos.y != 0 )
\r
129 eEditorFrameStyle.top = ( -1 * editorPos.y ) + "px" ;
\r
131 this.IsMaximized = true ;
\r
133 else // Resize to original size.
\r
135 // Remove the event handler of window resizing.
\r
136 if( FCKBrowserInfo.IsIE )
\r
137 eMainWindow.detachEvent( "onresize", FCKFitWindow_Resize ) ;
\r
139 eMainWindow.removeEventListener( "resize", FCKFitWindow_Resize, true ) ;
\r
141 // Restore the CSS position for the entire node tree.
\r
142 eParent = eEditorFrame ;
\r
143 // The extra () is to avoid a warning with strict error checking. This is ok.
\r
144 while( (eParent = eParent.parentNode) )
\r
146 if ( eParent._fckSavedStyles )
\r
148 FCKTools.RestoreStyles( eParent, eParent._fckSavedStyles ) ;
\r
149 eParent._fckSavedStyles = null ;
\r
153 // Restore IE scrollbars
\r
154 if ( FCKBrowserInfo.IsIE )
\r
155 eDocEl.style.overflow = this.documentElementOverflow ;
\r
157 // Restore original size
\r
158 FCKTools.RestoreStyles( eEditorFrame, this._EditorFrameStyles ) ;
\r
160 // Restore the window scroll position.
\r
161 eMainWindow.scrollTo( this._ScrollPos.X, this._ScrollPos.Y ) ;
\r
163 this.IsMaximized = false ;
\r
166 FCKToolbarItems.GetItem('FitWindow').RefreshState() ;
\r
168 // It seams that Firefox restarts the editing area when making this changes.
\r
169 // On FF 1.0.x, the area is not anymore editable. On FF 1.5+, the special
\r
170 //configuration, like DisableFFTableHandles and DisableObjectResizing get
\r
171 //lost, so we must reset it. Also, the cursor position and selection are
\r
172 //also lost, even if you comment the following line (MakeEditable).
\r
173 // if ( FCKBrowserInfo.IsGecko10 ) // Initially I thought it was a FF 1.0 only problem.
\r
174 if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
\r
175 FCK.EditingArea.MakeEditable() ;
\r
179 // Restore the selection and scroll position of inside the document.
\r
180 if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
\r
183 FCK.EditorWindow.scrollTo( oEditorScrollPos.X, oEditorScrollPos.Y ) ;
\r
187 if ( !FCKBrowserInfo.IsIE )
\r
189 eTextarea.selectionStart = oRange[0] ;
\r
190 eTextarea.selectionEnd = oRange[1] ;
\r
192 eTextarea.scrollLeft = oEditorScrollPos[0] ;
\r
193 eTextarea.scrollTop = oEditorScrollPos[1] ;
\r
197 FCKFitWindow.prototype.GetState = function()
\r
199 if ( FCKConfig.ToolbarLocation != 'In' )
\r
200 return FCK_TRISTATE_DISABLED ;
\r
202 return ( this.IsMaximized ? FCK_TRISTATE_ON : FCK_TRISTATE_OFF );
\r
205 function FCKFitWindow_Resize()
\r
207 var oViewPaneSize = FCKTools.GetViewPaneSize( parent ) ;
\r
209 var eEditorFrameStyle = window.frameElement.style ;
\r
211 eEditorFrameStyle.width = oViewPaneSize.Width + 'px' ;
\r
212 eEditorFrameStyle.height = oViewPaneSize.Height + 'px' ;
\r