PluginProbe
Wp-Insert / 1.7.2
Wp-Insert v1.7.2
trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.3.0 1.3.1 1.3.3 1.4 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 2.0 All 63 releases
wp-insert / fckeditor / editor / _source / internals / fckdialog.js

fckdialog.js in Wp-Insert 1.7.2, at fckeditor/editor/_source/internals/fckdialog.js

240 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /*
2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
4 *
5 * == BEGIN LICENSE ==
6 *
7 * Licensed under the terms of any of the following licenses at your
8 * choice:
9 *
10 * - GNU General Public License Version 2 or later (the "GPL")
11 * http://www.gnu.org/licenses/gpl.html
12 *
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14 * http://www.gnu.org/licenses/lgpl.html
15 *
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
17 * http://www.mozilla.org/MPL/MPL-1.1.html
18 *
19 * == END LICENSE ==
20 *
21 * Dialog windows operations.
22 */
23
24 var FCKDialog = ( function()
25 {
26 var topDialog ;
27 var baseZIndex ;
28 var cover ;
29
30 // The document that holds the dialog.
31 var topWindow = window.parent ;
32
33 while ( topWindow.parent && topWindow.parent != topWindow )
34 {
35 try
36 {
37 if ( topWindow.parent.document.domain != document.domain )
38 break ;
39 if ( topWindow.parent.document.getElementsByTagName( 'frameset' ).length > 0 )
40 break ;
41 }
42 catch ( e )
43 {
44 break ;
45 }
46 topWindow = topWindow.parent ;
47 }
48
49 var topDocument = topWindow.document ;
50
51 var getZIndex = function()
52 {
53 if ( !baseZIndex )
54 baseZIndex = FCKConfig.FloatingPanelsZIndex + 999 ;
55 return ++baseZIndex ;
56 }
57
58 // TODO : This logic is not actually working when reducing the window, only
59 // when enlarging it.
60 var resizeHandler = function()
61 {
62 if ( !cover )
63 return ;
64
65 var relElement = FCKTools.IsStrictMode( topDocument ) ? topDocument.documentElement : topDocument.body ;
66
67 FCKDomTools.SetElementStyles( cover,
68 {
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'
75 } ) ;
76 }
77
78 return {
79 /**
80 * Opens a dialog window using the standard dialog template.
81 */
82 OpenDialog : function( dialogName, dialogTitle, dialogPage, width, height, customValue, parentWindow, resizable )
83 {
84 if ( !topDialog )
85 this.DisplayMainCover() ;
86
87 // Setup the dialog info to be passed to the dialog.
88 var dialogInfo =
89 {
90 Title : dialogTitle,
91 Page : dialogPage,
92 Editor : window,
93 CustomValue : customValue, // Optional
94 TopWindow : topWindow
95 }
96
97 FCK.ToolbarSet.CurrentInstance.Selection.Save( true ) ;
98
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 ) ;
107
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' ;
112
113 // Dummy URL for testing whether the code in fckdialog.js alone leaks memory.
114 // dialog.src = 'about:blank';
115
116 dialog.frameBorder = 0 ;
117 dialog.allowTransparency = true ;
118 FCKDomTools.SetElementStyles( dialog,
119 {
120 'position' : ( useAbsolutePosition ) ? 'absolute' : 'fixed',
121 'top' : iTop + 'px',
122 'left' : iLeft + 'px',
123 'width' : width + 'px',
124 'height' : height + 'px',
125 'zIndex' : getZIndex()
126 } ) ;
127
128 // Save the dialog info to be used by the dialog page once loaded.
129 dialog._DialogArguments = dialogInfo ;
130
131 // Append the IFRAME to the target document.
132 topDocument.body.appendChild( dialog ) ;
133
134 // Keep record of the dialog's parent/child relationships.
135 dialog._ParentDialog = topDialog ;
136 topDialog = dialog ;
137 },
138
139 /**
140 * (For internal use)
141 * Called when the top dialog is closed.
142 */
143 OnDialogClose : function( dialogWindow )
144 {
145 var dialog = dialogWindow.frameElement ;
146 FCKDomTools.RemoveNode( dialog ) ;
147
148 if ( dialog._ParentDialog ) // Nested Dialog.
149 {
150 topDialog = dialog._ParentDialog ;
151 dialog._ParentDialog.contentWindow.SetEnabled( true ) ;
152 }
153 else // First Dialog.
154 {
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 )
161 FCK.Focus() ;
162
163 this.HideMainCover() ;
164 // Bug #1918: Assigning topDialog = null directly causes IE6 to crash.
165 setTimeout( function(){ topDialog = null ; }, 0 ) ;
166
167 // Release the previously saved selection.
168 FCK.ToolbarSet.CurrentInstance.Selection.Release() ;
169 }
170 },
171
172 DisplayMainCover : function()
173 {
174 // Setup the DIV that will be used to cover.
175 cover = topDocument.createElement( 'div' ) ;
176 FCKTools.ResetStyles( cover ) ;
177 FCKDomTools.SetElementStyles( cover,
178 {
179 'position' : 'absolute',
180 'zIndex' : getZIndex(),
181 'top' : '0px',
182 'left' : '0px',
183 'backgroundColor' : FCKConfig.BackgroundBlockerColor
184 } ) ;
185 FCKDomTools.SetOpacity( cover, FCKConfig.BackgroundBlockerOpacity ) ;
186
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 )
190 {
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,
197 {
198 'width' : '100%',
199 'height' : '100%',
200 'position' : 'absolute',
201 'left' : '0px',
202 'top' : '0px',
203 'filter' : 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'
204 } ) ;
205 cover.appendChild( iframe ) ;
206 }
207
208 // We need to manually adjust the cover size on resize.
209 FCKTools.AddEventListener( topWindow, 'resize', resizeHandler ) ;
210 resizeHandler() ;
211
212 topDocument.body.appendChild( cover ) ;
213
214 FCKFocusManager.Lock() ;
215
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 ;
220 el.tabIndex = -1 ;
221 },
222
223 HideMainCover : function()
224 {
225 FCKDomTools.RemoveNode( cover ) ;
226 FCKFocusManager.Unlock() ;
227
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' ) ;
232 },
233
234 GetCover : function()
235 {
236 return cover ;
237 }
238 } ;
239 } )() ;
240