import torrus 1.0.9
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / internals / fckdialog.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  * Dialog windows operations.\r
22  */\r
23 \r
24 var FCKDialog = ( function()\r
25 {\r
26         var topDialog ;\r
27         var baseZIndex ;\r
28         var cover ;\r
29 \r
30         // The document that holds the dialog.\r
31         var topWindow = window.parent ;\r
32 \r
33         while ( topWindow.parent && topWindow.parent != topWindow )\r
34         {\r
35                 try\r
36                 {\r
37                         if ( topWindow.parent.document.domain != document.domain )\r
38                                 break ;\r
39                         if ( topWindow.parent.document.getElementsByTagName( 'frameset' ).length > 0 )\r
40                                 break ;\r
41                 }\r
42                 catch ( e )\r
43                 {\r
44                         break ;\r
45                 }\r
46                 topWindow = topWindow.parent ;\r
47         }\r
48 \r
49         var topDocument = topWindow.document ;\r
50 \r
51         var getZIndex = function()\r
52         {\r
53                 if ( !baseZIndex )\r
54                         baseZIndex = FCKConfig.FloatingPanelsZIndex + 999 ;\r
55                 return ++baseZIndex ;\r
56         }\r
57 \r
58         // TODO : This logic is not actually working when reducing the window, only\r
59         // when enlarging it.\r
60         var resizeHandler = function()\r
61         {\r
62                 if ( !cover )\r
63                         return ;\r
64 \r
65                 var relElement = FCKTools.IsStrictMode( topDocument ) ? topDocument.documentElement : topDocument.body ;\r
66 \r
67                 FCKDomTools.SetElementStyles( cover,\r
68                         {\r
69                                 'width' : Math.max( relElement.scrollWidth,\r
70                                         relElement.clientWidth,\r
71                                         topDocument.scrollWidth || 0 ) - 1 + 'px',\r
72                                 'height' : Math.max( relElement.scrollHeight,\r
73                                         relElement.clientHeight,\r
74                                         topDocument.scrollHeight || 0 ) - 1 + 'px'\r
75                         } ) ;\r
76         }\r
77 \r
78         return {\r
79                 /**\r
80                  * Opens a dialog window using the standard dialog template.\r
81                  */\r
82                 OpenDialog : function( dialogName, dialogTitle, dialogPage, width, height, customValue, parentWindow, resizable )\r
83                 {\r
84                         if ( !topDialog )\r
85                                 this.DisplayMainCover() ;\r
86 \r
87                         // Setup the dialog info to be passed to the dialog.\r
88                         var dialogInfo =\r
89                         {\r
90                                 Title : dialogTitle,\r
91                                 Page : dialogPage,\r
92                                 Editor : window,\r
93                                 CustomValue : customValue,              // Optional\r
94                                 TopWindow : topWindow\r
95                         }\r
96 \r
97                         FCK.ToolbarSet.CurrentInstance.Selection.Save( true ) ;\r
98 \r
99                         // Calculate the dialog position, centering it on the screen.\r
100                         var viewSize = FCKTools.GetViewPaneSize( topWindow ) ;\r
101                         var scrollPosition = { 'X' : 0, 'Y' : 0 } ;\r
102                         var useAbsolutePosition = FCKBrowserInfo.IsIE && ( !FCKBrowserInfo.IsIE7 || !FCKTools.IsStrictMode( topWindow.document ) ) ;\r
103                         if ( useAbsolutePosition )\r
104                                 scrollPosition = FCKTools.GetScrollPosition( topWindow ) ;\r
105                         var iTop  = Math.max( scrollPosition.Y + ( viewSize.Height - height - 20 ) / 2, 0 ) ;\r
106                         var iLeft = Math.max( scrollPosition.X + ( viewSize.Width - width - 20 )  / 2, 0 ) ;\r
107 \r
108                         // Setup the IFRAME that will hold the dialog.\r
109                         var dialog = topDocument.createElement( 'iframe' ) ;\r
110                         FCKTools.ResetStyles( dialog ) ;\r
111                         dialog.src = FCKConfig.BasePath + 'fckdialog.html' ;\r
112 \r
113                         // Dummy URL for testing whether the code in fckdialog.js alone leaks memory.\r
114                         // dialog.src = 'about:blank';\r
115 \r
116                         dialog.frameBorder = 0 ;\r
117                         dialog.allowTransparency = true ;\r
118                         FCKDomTools.SetElementStyles( dialog,\r
119                                         {\r
120                                                 'position'      : ( useAbsolutePosition ) ? 'absolute' : 'fixed',\r
121                                                 'top'           : iTop + 'px',\r
122                                                 'left'          : iLeft + 'px',\r
123                                                 'width'         : width + 'px',\r
124                                                 'height'        : height + 'px',\r
125                                                 'zIndex'        : getZIndex()\r
126                                         } ) ;\r
127 \r
128                         // Save the dialog info to be used by the dialog page once loaded.\r
129                         dialog._DialogArguments = dialogInfo ;\r
130 \r
131                         // Append the IFRAME to the target document.\r
132                         topDocument.body.appendChild( dialog ) ;\r
133 \r
134                         // Keep record of the dialog's parent/child relationships.\r
135                         dialog._ParentDialog = topDialog ;\r
136                         topDialog = dialog ;\r
137                 },\r
138 \r
139                 /**\r
140                  * (For internal use)\r
141                  * Called when the top dialog is closed.\r
142                  */\r
143                 OnDialogClose : function( dialogWindow )\r
144                 {\r
145                         var dialog = dialogWindow.frameElement ;\r
146                         FCKDomTools.RemoveNode( dialog ) ;\r
147 \r
148                         if ( dialog._ParentDialog )             // Nested Dialog.\r
149                         {\r
150                                 topDialog = dialog._ParentDialog ;\r
151                                 dialog._ParentDialog.contentWindow.SetEnabled( true ) ;\r
152                         }\r
153                         else                                                    // First Dialog.\r
154                         {\r
155                                 // Set the Focus in the browser, so the "OnBlur" event is not\r
156                                 // fired. In IE, there is no need to do that because the dialog\r
157                                 // already moved the selection to the editing area before\r
158                                 // closing (EnsureSelection). Also, the Focus() call here\r
159                                 // causes memory leak on IE7 (weird).\r
160                                 if ( !FCKBrowserInfo.IsIE )\r
161                                         FCK.Focus() ;\r
162 \r
163                                 this.HideMainCover() ;\r
164                                 // Bug #1918: Assigning topDialog = null directly causes IE6 to crash.\r
165                                 setTimeout( function(){ topDialog = null ; }, 0 ) ;\r
166 \r
167                                 // Release the previously saved selection.\r
168                                 FCK.ToolbarSet.CurrentInstance.Selection.Release() ;\r
169                         }\r
170                 },\r
171 \r
172                 DisplayMainCover : function()\r
173                 {\r
174                         // Setup the DIV that will be used to cover.\r
175                         cover = topDocument.createElement( 'div' ) ;\r
176                         FCKTools.ResetStyles( cover ) ;\r
177                         FCKDomTools.SetElementStyles( cover,\r
178                                 {\r
179                                         'position' : 'absolute',\r
180                                         'zIndex' : getZIndex(),\r
181                                         'top' : '0px',\r
182                                         'left' : '0px',\r
183                                         'backgroundColor' : FCKConfig.BackgroundBlockerColor\r
184                                 } ) ;\r
185                         FCKDomTools.SetOpacity( cover, FCKConfig.BackgroundBlockerOpacity ) ;\r
186 \r
187                         // For IE6-, we need to fill the cover with a transparent IFRAME,\r
188                         // to properly block <select> fields.\r
189                         if ( FCKBrowserInfo.IsIE && !FCKBrowserInfo.IsIE7 )\r
190                         {\r
191                                 var iframe = topDocument.createElement( 'iframe' ) ;\r
192                                 FCKTools.ResetStyles( iframe ) ;\r
193                                 iframe.hideFocus = true ;\r
194                                 iframe.frameBorder = 0 ;\r
195                                 iframe.src = FCKTools.GetVoidUrl() ;\r
196                                 FCKDomTools.SetElementStyles( iframe,\r
197                                         {\r
198                                                 'width' : '100%',\r
199                                                 'height' : '100%',\r
200                                                 'position' : 'absolute',\r
201                                                 'left' : '0px',\r
202                                                 'top' : '0px',\r
203                                                 'filter' : 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'\r
204                                         } ) ;\r
205                                 cover.appendChild( iframe ) ;\r
206                         }\r
207 \r
208                         // We need to manually adjust the cover size on resize.\r
209                         FCKTools.AddEventListener( topWindow, 'resize', resizeHandler ) ;\r
210                         resizeHandler() ;\r
211 \r
212                         topDocument.body.appendChild( cover ) ;\r
213 \r
214                         FCKFocusManager.Lock() ;\r
215 \r
216                         // Prevent the user from refocusing the disabled\r
217                         // editing window by pressing Tab. (Bug #2065)\r
218                         var el = FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'frameElement' ) ;\r
219                         el._fck_originalTabIndex = el.tabIndex ;\r
220                         el.tabIndex = -1 ;\r
221                 },\r
222 \r
223                 HideMainCover : function()\r
224                 {\r
225                         FCKDomTools.RemoveNode( cover ) ;\r
226                         FCKFocusManager.Unlock() ;\r
227 \r
228                         // Revert the tab index hack. (Bug #2065)\r
229                         var el = FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'frameElement' ) ;\r
230                         el.tabIndex = el._fck_originalTabIndex ;\r
231                         FCKDomTools.ClearElementJSProperty( el, '_fck_originalTabIndex' ) ;\r
232                 },\r
233 \r
234                 GetCover : function()\r
235                 {\r
236                         return cover ;\r
237                 }\r
238         } ;\r
239 } )() ;\r