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 * Dialog windows operations.
\r
24 var FCKDialog = ( function()
\r
30 // The document that holds the dialog.
\r
31 var topWindow = window.parent ;
\r
33 while ( topWindow.parent && topWindow.parent != topWindow )
\r
37 if ( topWindow.parent.document.domain != document.domain )
\r
39 if ( topWindow.parent.document.getElementsByTagName( 'frameset' ).length > 0 )
\r
46 topWindow = topWindow.parent ;
\r
49 var topDocument = topWindow.document ;
\r
51 var getZIndex = function()
\r
54 baseZIndex = FCKConfig.FloatingPanelsZIndex + 999 ;
\r
55 return ++baseZIndex ;
\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
65 var relElement = FCKTools.IsStrictMode( topDocument ) ? topDocument.documentElement : topDocument.body ;
\r
67 FCKDomTools.SetElementStyles( cover,
\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
80 * Opens a dialog window using the standard dialog template.
\r
82 OpenDialog : function( dialogName, dialogTitle, dialogPage, width, height, customValue, parentWindow, resizable )
\r
85 this.DisplayMainCover() ;
\r
87 // Setup the dialog info to be passed to the dialog.
\r
90 Title : dialogTitle,
\r
93 CustomValue : customValue, // Optional
\r
94 TopWindow : topWindow
\r
97 FCK.ToolbarSet.CurrentInstance.Selection.Save( true ) ;
\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
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
113 // Dummy URL for testing whether the code in fckdialog.js alone leaks memory.
\r
114 // dialog.src = 'about:blank';
\r
116 dialog.frameBorder = 0 ;
\r
117 dialog.allowTransparency = true ;
\r
118 FCKDomTools.SetElementStyles( dialog,
\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
128 // Save the dialog info to be used by the dialog page once loaded.
\r
129 dialog._DialogArguments = dialogInfo ;
\r
131 // Append the IFRAME to the target document.
\r
132 topDocument.body.appendChild( dialog ) ;
\r
134 // Keep record of the dialog's parent/child relationships.
\r
135 dialog._ParentDialog = topDialog ;
\r
136 topDialog = dialog ;
\r
140 * (For internal use)
\r
141 * Called when the top dialog is closed.
\r
143 OnDialogClose : function( dialogWindow )
\r
145 var dialog = dialogWindow.frameElement ;
\r
146 FCKDomTools.RemoveNode( dialog ) ;
\r
148 if ( dialog._ParentDialog ) // Nested Dialog.
\r
150 topDialog = dialog._ParentDialog ;
\r
151 dialog._ParentDialog.contentWindow.SetEnabled( true ) ;
\r
153 else // First Dialog.
\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
163 this.HideMainCover() ;
\r
164 // Bug #1918: Assigning topDialog = null directly causes IE6 to crash.
\r
165 setTimeout( function(){ topDialog = null ; }, 0 ) ;
\r
167 // Release the previously saved selection.
\r
168 FCK.ToolbarSet.CurrentInstance.Selection.Release() ;
\r
172 DisplayMainCover : function()
\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
179 'position' : 'absolute',
\r
180 'zIndex' : getZIndex(),
\r
183 'backgroundColor' : FCKConfig.BackgroundBlockerColor
\r
185 FCKDomTools.SetOpacity( cover, FCKConfig.BackgroundBlockerOpacity ) ;
\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
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
200 'position' : 'absolute',
\r
203 'filter' : 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'
\r
205 cover.appendChild( iframe ) ;
\r
208 // We need to manually adjust the cover size on resize.
\r
209 FCKTools.AddEventListener( topWindow, 'resize', resizeHandler ) ;
\r
212 topDocument.body.appendChild( cover ) ;
\r
214 FCKFocusManager.Lock() ;
\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
223 HideMainCover : function()
\r
225 FCKDomTools.RemoveNode( cover ) ;
\r
226 FCKFocusManager.Unlock() ;
\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
234 GetCover : function()
\r