import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / commandclasses / fckfitwindow.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
4  *\r
5  * == BEGIN LICENSE ==\r
6  *\r
7  * Licensed under the terms of any of the following licenses at your\r
8  * choice:\r
9  *\r
10  *  - GNU General Public License Version 2 or later (the "GPL")\r
11  *    http://www.gnu.org/licenses/gpl.html\r
12  *\r
13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
14  *    http://www.gnu.org/licenses/lgpl.html\r
15  *\r
16  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
17  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
18  *\r
19  * == END LICENSE ==\r
20  *\r
21  * Stretch the editor to full window size and back.\r
22  */\r
23 \r
24 var FCKFitWindow = function()\r
25 {\r
26         this.Name = 'FitWindow' ;\r
27 }\r
28 \r
29 FCKFitWindow.prototype.Execute = function()\r
30 {\r
31         var eEditorFrame                = window.frameElement ;\r
32         var eEditorFrameStyle   = eEditorFrame.style ;\r
33 \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
38         var eParent ;\r
39 \r
40         // Save the current selection and scroll position.\r
41         var oRange, oEditorScrollPos ;\r
42         if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )\r
43         {\r
44                 oRange = new FCKDomRange( FCK.EditorWindow ) ;\r
45                 oRange.MoveToSelection() ;\r
46                 oEditorScrollPos = FCKTools.GetScrollPosition( FCK.EditorWindow ) ;\r
47         }\r
48         else\r
49         {\r
50                 var eTextarea = FCK.EditingArea.Textarea ;\r
51                 oRange = !FCKBrowserInfo.IsIE && [ eTextarea.selectionStart, eTextarea.selectionEnd ] ;\r
52                 oEditorScrollPos = [ eTextarea.scrollLeft, eTextarea.scrollTop ] ;\r
53         }\r
54 \r
55         // No original style properties known? Go fullscreen.\r
56         if ( !this.IsMaximized )\r
57         {\r
58                 // Registering an event handler when the window gets resized.\r
59                 if( FCKBrowserInfo.IsIE )\r
60                         eMainWindow.attachEvent( 'onresize', FCKFitWindow_Resize ) ;\r
61                 else\r
62                         eMainWindow.addEventListener( 'resize', FCKFitWindow_Resize, true ) ;\r
63 \r
64                 // Save the scrollbars position.\r
65                 this._ScrollPos = FCKTools.GetScrollPosition( eMainWindow ) ;\r
66 \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
71                 {\r
72                         if ( eParent.nodeType == 1 )\r
73                         {\r
74                                 eParent._fckSavedStyles = FCKTools.SaveStyles( eParent ) ;\r
75                                 eParent.style.zIndex = FCKConfig.FloatingPanelsZIndex - 1 ;\r
76                         }\r
77                 }\r
78 \r
79                 // Hide IE scrollbars (in strict mode).\r
80                 if ( FCKBrowserInfo.IsIE )\r
81                 {\r
82                         this.documentElementOverflow = eDocEl.style.overflow ;\r
83                         eDocEl.style.overflow   = 'hidden' ;\r
84                         eBodyStyle.overflow             = 'hidden' ;\r
85                 }\r
86                 else\r
87                 {\r
88                         // Hide the scroolbars in Firefox.\r
89                         eBodyStyle.overflow = 'hidden' ;\r
90                         eBodyStyle.width = '0px' ;\r
91                         eBodyStyle.height = '0px' ;\r
92                 }\r
93 \r
94                 // Save the IFRAME styles.\r
95                 this._EditorFrameStyles = FCKTools.SaveStyles( eEditorFrame ) ;\r
96 \r
97                 // Resize.\r
98                 var oViewPaneSize = FCKTools.GetViewPaneSize( eMainWindow ) ;\r
99 \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
107 \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
116                 {\r
117                         eEditorFrameStyle.borderRight = eEditorFrameStyle.borderBottom = "9999px solid white" ;\r
118                         eEditorFrameStyle.backgroundColor               = "white";\r
119                 }\r
120 \r
121                 // Scroll to top left.\r
122                 eMainWindow.scrollTo(0, 0);\r
123 \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
130 \r
131                 this.IsMaximized = true ;\r
132         }\r
133         else    // Resize to original size.\r
134         {\r
135                 // Remove the event handler of window resizing.\r
136                 if( FCKBrowserInfo.IsIE )\r
137                         eMainWindow.detachEvent( "onresize", FCKFitWindow_Resize ) ;\r
138                 else\r
139                         eMainWindow.removeEventListener( "resize", FCKFitWindow_Resize, true ) ;\r
140 \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
145                 {\r
146                         if ( eParent._fckSavedStyles )\r
147                         {\r
148                                 FCKTools.RestoreStyles( eParent, eParent._fckSavedStyles ) ;\r
149                                 eParent._fckSavedStyles = null ;\r
150                         }\r
151                 }\r
152 \r
153                 // Restore IE scrollbars\r
154                 if ( FCKBrowserInfo.IsIE )\r
155                         eDocEl.style.overflow = this.documentElementOverflow ;\r
156 \r
157                 // Restore original size\r
158                 FCKTools.RestoreStyles( eEditorFrame, this._EditorFrameStyles ) ;\r
159 \r
160                 // Restore the window scroll position.\r
161                 eMainWindow.scrollTo( this._ScrollPos.X, this._ScrollPos.Y ) ;\r
162 \r
163                 this.IsMaximized = false ;\r
164         }\r
165 \r
166         FCKToolbarItems.GetItem('FitWindow').RefreshState() ;\r
167 \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
176 \r
177         FCK.Focus() ;\r
178 \r
179         // Restore the selection and scroll position of inside the document.\r
180         if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )\r
181         {\r
182                 oRange.Select() ;\r
183                 FCK.EditorWindow.scrollTo( oEditorScrollPos.X, oEditorScrollPos.Y ) ;\r
184         }\r
185         else\r
186         {\r
187                 if ( !FCKBrowserInfo.IsIE )\r
188                 {\r
189                         eTextarea.selectionStart = oRange[0] ;\r
190                         eTextarea.selectionEnd = oRange[1] ;\r
191                 }\r
192                 eTextarea.scrollLeft = oEditorScrollPos[0] ;\r
193                 eTextarea.scrollTop = oEditorScrollPos[1] ;\r
194         }\r
195 }\r
196 \r
197 FCKFitWindow.prototype.GetState = function()\r
198 {\r
199         if ( FCKConfig.ToolbarLocation != 'In' )\r
200                 return FCK_TRISTATE_DISABLED ;\r
201         else\r
202                 return ( this.IsMaximized ? FCK_TRISTATE_ON : FCK_TRISTATE_OFF );\r
203 }\r
204 \r
205 function FCKFitWindow_Resize()\r
206 {\r
207         var oViewPaneSize = FCKTools.GetViewPaneSize( parent ) ;\r
208 \r
209         var eEditorFrameStyle = window.frameElement.style ;\r
210 \r
211         eEditorFrameStyle.width         = oViewPaneSize.Width + 'px' ;\r
212         eEditorFrameStyle.height        = oViewPaneSize.Height + 'px' ;\r
213 }\r