2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2009 Frederico Caldeira Knabben
7
* Licensed under the terms of any of the following licenses at your
10
* - GNU General Public License Version 2 or later (the "GPL")
11
* http://www.gnu.org/licenses/gpl.html
13
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
* http://www.gnu.org/licenses/lgpl.html
16
* - Mozilla Public License Version 1.1 or later (the "MPL")
17
* http://www.mozilla.org/MPL/MPL-1.1.html
21
* Dialog windows operations.
24
var FCKDialog = ( function()
30
// The document that holds the dialog.
31
var topWindow = window.parent ;
33
while ( topWindow.parent && topWindow.parent != topWindow )
37
if ( topWindow.parent.document.domain != document.domain )
39
if ( topWindow.parent.document.getElementsByTagName( 'frameset' ).length > 0 )
46
topWindow = topWindow.parent ;
49
var topDocument = topWindow.document ;
51
var getZIndex = function()
54
baseZIndex = FCKConfig.FloatingPanelsZIndex + 999 ;
58
// TODO : This logic is not actually working when reducing the window, only
60
var resizeHandler = function()
65
var relElement = FCKTools.IsStrictMode( topDocument ) ? topDocument.documentElement : topDocument.body ;
67
FCKDomTools.SetElementStyles( cover,
69
'width' : Math.max( relElement.scrollWidth,
70
relElement.clientWidth,
71
topDocument.scrollWidth || 0 ) - 1 + 'px',
72
'height' : Math.max( relElement.scrollHeight,
73
relElement.clientHeight,
74
topDocument.scrollHeight || 0 ) - 1 + 'px'
80
* Opens a dialog window using the standard dialog template.
82
OpenDialog : function( dialogName, dialogTitle, dialogPage, width, height, customValue, parentWindow, resizable )
85
this.DisplayMainCover() ;
87
// Setup the dialog info to be passed to the dialog.
93
CustomValue : customValue, // Optional
97
FCK.ToolbarSet.CurrentInstance.Selection.Save( true ) ;
99
// Calculate the dialog position, centering it on the screen.
100
var viewSize = FCKTools.GetViewPaneSize( topWindow ) ;
101
var scrollPosition = { 'X' : 0, 'Y' : 0 } ;
102
var useAbsolutePosition = FCKBrowserInfo.IsIE && ( !FCKBrowserInfo.IsIE7 || !FCKTools.IsStrictMode( topWindow.document ) ) ;
103
if ( useAbsolutePosition )
104
scrollPosition = FCKTools.GetScrollPosition( topWindow ) ;
105
var iTop = Math.max( scrollPosition.Y + ( viewSize.Height - height - 20 ) / 2, 0 ) ;
106
var iLeft = Math.max( scrollPosition.X + ( viewSize.Width - width - 20 ) / 2, 0 ) ;
108
// Setup the IFRAME that will hold the dialog.
109
var dialog = topDocument.createElement( 'iframe' ) ;
110
FCKTools.ResetStyles( dialog ) ;
111
dialog.src = FCKConfig.BasePath + 'fckdialog.html' ;
113
// Dummy URL for testing whether the code in fckdialog.js alone leaks memory.
114
// dialog.src = 'about:blank';
116
dialog.frameBorder = 0 ;
117
dialog.allowTransparency = true ;
118
FCKDomTools.SetElementStyles( dialog,
120
'position' : ( useAbsolutePosition ) ? 'absolute' : 'fixed',
122
'left' : iLeft + 'px',
123
'width' : width + 'px',
124
'height' : height + 'px',
125
'zIndex' : getZIndex()
128
// Save the dialog info to be used by the dialog page once loaded.
129
dialog._DialogArguments = dialogInfo ;
131
// Append the IFRAME to the target document.
132
topDocument.body.appendChild( dialog ) ;
134
// Keep record of the dialog's parent/child relationships.
135
dialog._ParentDialog = topDialog ;
141
* Called when the top dialog is closed.
143
OnDialogClose : function( dialogWindow )
145
var dialog = dialogWindow.frameElement ;
146
FCKDomTools.RemoveNode( dialog ) ;
148
if ( dialog._ParentDialog ) // Nested Dialog.
150
topDialog = dialog._ParentDialog ;
151
dialog._ParentDialog.contentWindow.SetEnabled( true ) ;
153
else // First Dialog.
155
// Set the Focus in the browser, so the "OnBlur" event is not
156
// fired. In IE, there is no need to do that because the dialog
157
// already moved the selection to the editing area before
158
// closing (EnsureSelection). Also, the Focus() call here
159
// causes memory leak on IE7 (weird).
160
if ( !FCKBrowserInfo.IsIE )
163
this.HideMainCover() ;
164
// Bug #1918: Assigning topDialog = null directly causes IE6 to crash.
165
setTimeout( function(){ topDialog = null ; }, 0 ) ;
167
// Release the previously saved selection.
168
FCK.ToolbarSet.CurrentInstance.Selection.Release() ;
172
DisplayMainCover : function()
174
// Setup the DIV that will be used to cover.
175
cover = topDocument.createElement( 'div' ) ;
176
FCKTools.ResetStyles( cover ) ;
177
FCKDomTools.SetElementStyles( cover,
179
'position' : 'absolute',
180
'zIndex' : getZIndex(),
183
'backgroundColor' : FCKConfig.BackgroundBlockerColor
185
FCKDomTools.SetOpacity( cover, FCKConfig.BackgroundBlockerOpacity ) ;
187
// For IE6-, we need to fill the cover with a transparent IFRAME,
188
// to properly block <select> fields.
189
if ( FCKBrowserInfo.IsIE && !FCKBrowserInfo.IsIE7 )
191
var iframe = topDocument.createElement( 'iframe' ) ;
192
FCKTools.ResetStyles( iframe ) ;
193
iframe.hideFocus = true ;
194
iframe.frameBorder = 0 ;
195
iframe.src = FCKTools.GetVoidUrl() ;
196
FCKDomTools.SetElementStyles( iframe,
200
'position' : 'absolute',
203
'filter' : 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'
205
cover.appendChild( iframe ) ;
208
// We need to manually adjust the cover size on resize.
209
FCKTools.AddEventListener( topWindow, 'resize', resizeHandler ) ;
212
topDocument.body.appendChild( cover ) ;
214
FCKFocusManager.Lock() ;
216
// Prevent the user from refocusing the disabled
217
// editing window by pressing Tab. (Bug #2065)
218
var el = FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'frameElement' ) ;
219
el._fck_originalTabIndex = el.tabIndex ;
223
HideMainCover : function()
225
FCKDomTools.RemoveNode( cover ) ;
226
FCKFocusManager.Unlock() ;
228
// Revert the tab index hack. (Bug #2065)
229
var el = FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'frameElement' ) ;
230
el.tabIndex = el._fck_originalTabIndex ;
231
FCKDomTools.ClearElementJSProperty( el, '_fck_originalTabIndex' ) ;
234
GetCover : function()