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 | * Component that creates floating panels. It is used by many
|
---|
22 | * other components, like the toolbar items, context menu, etc...
|
---|
23 | */
|
---|
24 |
|
---|
25 | var FCKPanel = function( parentWindow )
|
---|
26 | {
|
---|
27 | this.IsRTL = ( FCKLang.Dir == 'rtl' ) ;
|
---|
28 | this.IsContextMenu = false ;
|
---|
29 | this._LockCounter = 0 ;
|
---|
30 |
|
---|
31 | this._Window = parentWindow || window ;
|
---|
32 |
|
---|
33 | var oDocument ;
|
---|
34 |
|
---|
35 | if ( FCKBrowserInfo.IsIE )
|
---|
36 | {
|
---|
37 | // Create the Popup that will hold the panel.
|
---|
38 | // The popup has to be created before playing with domain hacks, see #1666.
|
---|
39 | this._Popup = this._Window.createPopup() ;
|
---|
40 |
|
---|
41 | // this._Window cannot be accessed while playing with domain hacks, but local variable is ok.
|
---|
42 | // See #1666.
|
---|
43 | var pDoc = this._Window.document ;
|
---|
44 |
|
---|
45 | // This is a trick to IE6 (not IE7). The original domain must be set
|
---|
46 | // before creating the popup, so we are able to take a refence to the
|
---|
47 | // document inside of it, and the set the proper domain for it. (#123)
|
---|
48 | if ( FCK_IS_CUSTOM_DOMAIN && !FCKBrowserInfo.IsIE7 )
|
---|
49 | {
|
---|
50 | pDoc.domain = FCK_ORIGINAL_DOMAIN ;
|
---|
51 | document.domain = FCK_ORIGINAL_DOMAIN ;
|
---|
52 | }
|
---|
53 |
|
---|
54 | oDocument = this.Document = this._Popup.document ;
|
---|
55 |
|
---|
56 | // Set the proper domain inside the popup.
|
---|
57 | if ( FCK_IS_CUSTOM_DOMAIN )
|
---|
58 | {
|
---|
59 | oDocument.domain = FCK_RUNTIME_DOMAIN ;
|
---|
60 | pDoc.domain = FCK_RUNTIME_DOMAIN ;
|
---|
61 | document.domain = FCK_RUNTIME_DOMAIN ;
|
---|
62 | }
|
---|
63 |
|
---|
64 | FCK.IECleanup.AddItem( this, FCKPanel_Cleanup ) ;
|
---|
65 | }
|
---|
66 | else
|
---|
67 | {
|
---|
68 | var oIFrame = this._IFrame = this._Window.document.createElement('iframe') ;
|
---|
69 | FCKTools.ResetStyles( oIFrame );
|
---|
70 | oIFrame.src = 'javascript:void(0)' ;
|
---|
71 | oIFrame.allowTransparency = true ;
|
---|
72 | oIFrame.frameBorder = '0' ;
|
---|
73 | oIFrame.scrolling = 'no' ;
|
---|
74 | oIFrame.style.width = oIFrame.style.height = '0px' ;
|
---|
75 | FCKDomTools.SetElementStyles( oIFrame,
|
---|
76 | {
|
---|
77 | position : 'absolute',
|
---|
78 | zIndex : FCKConfig.FloatingPanelsZIndex
|
---|
79 | } ) ;
|
---|
80 |
|
---|
81 | this._Window.document.body.appendChild( oIFrame ) ;
|
---|
82 |
|
---|
83 | var oIFrameWindow = oIFrame.contentWindow ;
|
---|
84 |
|
---|
85 | oDocument = this.Document = oIFrameWindow.document ;
|
---|
86 |
|
---|
87 | // Workaround for Safari 12256. Ticket #63
|
---|
88 | var sBase = '' ;
|
---|
89 | if ( FCKBrowserInfo.IsSafari )
|
---|
90 | sBase = '<base href="' + window.document.location + '">' ;
|
---|
91 |
|
---|
92 | // Initialize the IFRAME document body.
|
---|
93 | oDocument.open() ;
|
---|
94 | oDocument.write( '<html><head>' + sBase + '<\/head><body style="margin:0px;padding:0px;"><\/body><\/html>' ) ;
|
---|
95 | oDocument.close() ;
|
---|
96 |
|
---|
97 | if( FCKBrowserInfo.IsAIR )
|
---|
98 | FCKAdobeAIR.Panel_Contructor( oDocument, window.document.location ) ;
|
---|
99 |
|
---|
100 | FCKTools.AddEventListenerEx( oIFrameWindow, 'focus', FCKPanel_Window_OnFocus, this ) ;
|
---|
101 | FCKTools.AddEventListenerEx( oIFrameWindow, 'blur', FCKPanel_Window_OnBlur, this ) ;
|
---|
102 | }
|
---|
103 |
|
---|
104 | oDocument.dir = FCKLang.Dir ;
|
---|
105 |
|
---|
106 | FCKTools.AddEventListener( oDocument, 'contextmenu', FCKTools.CancelEvent ) ;
|
---|
107 |
|
---|
108 |
|
---|
109 | // Create the main DIV that is used as the panel base.
|
---|
110 | this.MainNode = oDocument.body.appendChild( oDocument.createElement('DIV') ) ;
|
---|
111 |
|
---|
112 | // The "float" property must be set so Firefox calculates the size correctly.
|
---|
113 | this.MainNode.style.cssFloat = this.IsRTL ? 'right' : 'left' ;
|
---|
114 | }
|
---|
115 |
|
---|
116 |
|
---|
117 | FCKPanel.prototype.AppendStyleSheet = function( styleSheet )
|
---|
118 | {
|
---|
119 | FCKTools.AppendStyleSheet( this.Document, styleSheet ) ;
|
---|
120 | }
|
---|
121 |
|
---|
122 | FCKPanel.prototype.Preload = function( x, y, relElement )
|
---|
123 | {
|
---|
124 | // The offsetWidth and offsetHeight properties are not available if the
|
---|
125 | // element is not visible. So we must "show" the popup with no size to
|
---|
126 | // be able to use that values in the second call (IE only).
|
---|
127 | if ( this._Popup )
|
---|
128 | this._Popup.show( x, y, 0, 0, relElement ) ;
|
---|
129 | }
|
---|
130 |
|
---|
131 | // Workaround for IE7 problem. See #1982
|
---|
132 | // Submenus are restricted to the size of its parent, so we increase it as needed.
|
---|
133 | // Returns true if the panel has been repositioned
|
---|
134 | FCKPanel.prototype.ResizeForSubpanel = function( panel, width, height )
|
---|
135 | {
|
---|
136 | if ( !FCKBrowserInfo.IsIE7 )
|
---|
137 | return false ;
|
---|
138 |
|
---|
139 | if ( !this._Popup.isOpen )
|
---|
140 | {
|
---|
141 | this.Subpanel = null ;
|
---|
142 | return false ;
|
---|
143 | }
|
---|
144 |
|
---|
145 | // If we are resetting the extra space
|
---|
146 | if ( width == 0 && height == 0 )
|
---|
147 | {
|
---|
148 | // Another subpanel is being shown, so we must not shrink back
|
---|
149 | if (this.Subpanel !== panel)
|
---|
150 | return false ;
|
---|
151 |
|
---|
152 | // Reset values.
|
---|
153 | // We leave the IncreasedY untouched to avoid vertical movement of the
|
---|
154 | // menu if the submenu is higher than the main menu.
|
---|
155 | this.Subpanel = null ;
|
---|
156 | this.IncreasedX = 0 ;
|
---|
157 | }
|
---|
158 | else
|
---|
159 | {
|
---|
160 | this.Subpanel = panel ;
|
---|
161 | // If the panel has already been increased enough, get out
|
---|
162 | if ( ( this.IncreasedX >= width ) && ( this.IncreasedY >= height ) )
|
---|
163 | return false ;
|
---|
164 |
|
---|
165 | this.IncreasedX = Math.max( this.IncreasedX, width ) ;
|
---|
166 | this.IncreasedY = Math.max( this.IncreasedY, height ) ;
|
---|
167 | }
|
---|
168 |
|
---|
169 | var x = this.ShowRect.x ;
|
---|
170 | var w = this.IncreasedX ;
|
---|
171 | if ( this.IsRTL )
|
---|
172 | x = x - w ;
|
---|
173 |
|
---|
174 | // Horizontally increase as needed (sum of widths).
|
---|
175 | // Vertically, use only the maximum of this menu or the submenu
|
---|
176 | var finalWidth = this.ShowRect.w + w ;
|
---|
177 | var finalHeight = Math.max( this.ShowRect.h, this.IncreasedY ) ;
|
---|
178 | if ( this.ParentPanel )
|
---|
179 | this.ParentPanel.ResizeForSubpanel( this, finalWidth, finalHeight ) ;
|
---|
180 | this._Popup.show( x, this.ShowRect.y, finalWidth, finalHeight, this.RelativeElement ) ;
|
---|
181 |
|
---|
182 | return this.IsRTL ;
|
---|
183 | }
|
---|
184 |
|
---|
185 | FCKPanel.prototype.Show = function( x, y, relElement, width, height )
|
---|
186 | {
|
---|
187 | var iMainWidth ;
|
---|
188 | var eMainNode = this.MainNode ;
|
---|
189 |
|
---|
190 | if ( this._Popup )
|
---|
191 | {
|
---|
192 | // The offsetWidth and offsetHeight properties are not available if the
|
---|
193 | // element is not visible. So we must "show" the popup with no size to
|
---|
194 | // be able to use that values in the second call.
|
---|
195 | this._Popup.show( x, y, 0, 0, relElement ) ;
|
---|
196 |
|
---|
197 | // The following lines must be place after the above "show", otherwise it
|
---|
198 | // doesn't has the desired effect.
|
---|
199 | FCKDomTools.SetElementStyles( eMainNode,
|
---|
200 | {
|
---|
201 | width : width ? width + 'px' : '',
|
---|
202 | height : height ? height + 'px' : ''
|
---|
203 | } ) ;
|
---|
204 |
|
---|
205 | iMainWidth = eMainNode.offsetWidth ;
|
---|
206 |
|
---|
207 | if ( FCKBrowserInfo.IsIE7 )
|
---|
208 | {
|
---|
209 | if (this.ParentPanel && this.ParentPanel.ResizeForSubpanel(this, iMainWidth, eMainNode.offsetHeight) )
|
---|
210 | {
|
---|
211 | // As the parent has moved, allow the browser to update its internal data, so the new position is correct.
|
---|
212 | FCKTools.RunFunction( this.Show, this, [x, y, relElement] ) ;
|
---|
213 | return ;
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | if ( this.IsRTL )
|
---|
218 | {
|
---|
219 | if ( this.IsContextMenu )
|
---|
220 | x = x - iMainWidth + 1 ;
|
---|
221 | else if ( relElement )
|
---|
222 | x = ( x * -1 ) + relElement.offsetWidth - iMainWidth ;
|
---|
223 | }
|
---|
224 |
|
---|
225 | if ( FCKBrowserInfo.IsIE7 )
|
---|
226 | {
|
---|
227 | // Store the values that will be used by the ResizeForSubpanel function
|
---|
228 | this.ShowRect = {x:x, y:y, w:iMainWidth, h:eMainNode.offsetHeight} ;
|
---|
229 | this.IncreasedX = 0 ;
|
---|
230 | this.IncreasedY = 0 ;
|
---|
231 | this.RelativeElement = relElement ;
|
---|
232 | }
|
---|
233 |
|
---|
234 | // Save the popup related arguments so they can be used by others (e.g. SCAYT).
|
---|
235 | this._PopupArgs = [x, y, iMainWidth, eMainNode.offsetHeight, relElement];
|
---|
236 |
|
---|
237 | // Second call: Show the Popup at the specified location, with the correct size.
|
---|
238 | this._Popup.show( x, y, iMainWidth, eMainNode.offsetHeight, relElement ) ;
|
---|
239 |
|
---|
240 | if ( this.OnHide )
|
---|
241 | {
|
---|
242 | if ( this._Timer )
|
---|
243 | CheckPopupOnHide.call( this, true ) ;
|
---|
244 |
|
---|
245 | this._Timer = FCKTools.SetInterval( CheckPopupOnHide, 100, this ) ;
|
---|
246 | }
|
---|
247 | }
|
---|
248 | else
|
---|
249 | {
|
---|
250 | // Do not fire OnBlur while the panel is opened.
|
---|
251 | if ( typeof( FCK.ToolbarSet.CurrentInstance.FocusManager ) != 'undefined' )
|
---|
252 | FCK.ToolbarSet.CurrentInstance.FocusManager.Lock() ;
|
---|
253 |
|
---|
254 | if ( this.ParentPanel )
|
---|
255 | {
|
---|
256 | this.ParentPanel.Lock() ;
|
---|
257 |
|
---|
258 | // Due to a bug on FF3, we must ensure that the parent panel will
|
---|
259 | // blur (#1584).
|
---|
260 | FCKPanel_Window_OnBlur( null, this.ParentPanel ) ;
|
---|
261 | }
|
---|
262 |
|
---|
263 | // Toggle the iframe scrolling attribute to prevent the panel
|
---|
264 | // scrollbars from disappearing in FF Mac. (#191)
|
---|
265 | if ( FCKBrowserInfo.IsGecko && FCKBrowserInfo.IsMac )
|
---|
266 | {
|
---|
267 | this._IFrame.scrolling = '' ;
|
---|
268 | FCKTools.RunFunction( function(){ this._IFrame.scrolling = 'no'; }, this ) ;
|
---|
269 | }
|
---|
270 |
|
---|
271 | // Be sure we'll not have more than one Panel opened at the same time.
|
---|
272 | // Do not unlock focus manager here because we're displaying another floating panel
|
---|
273 | // instead of returning the editor to a "no panel" state (Bug #1514).
|
---|
274 | if ( FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'FCKPanel' )._OpenedPanel &&
|
---|
275 | FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'FCKPanel' )._OpenedPanel != this )
|
---|
276 | FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'FCKPanel' )._OpenedPanel.Hide( false, true ) ;
|
---|
277 |
|
---|
278 | FCKDomTools.SetElementStyles( eMainNode,
|
---|
279 | {
|
---|
280 | width : width ? width + 'px' : '',
|
---|
281 | height : height ? height + 'px' : ''
|
---|
282 | } ) ;
|
---|
283 |
|
---|
284 | iMainWidth = eMainNode.offsetWidth ;
|
---|
285 |
|
---|
286 | if ( !width ) this._IFrame.width = 1 ;
|
---|
287 | if ( !height ) this._IFrame.height = 1 ;
|
---|
288 |
|
---|
289 | // This is weird... but with Firefox, we must get the offsetWidth before
|
---|
290 | // setting the _IFrame size (which returns "0"), and then after that,
|
---|
291 | // to return the correct width. Remove the first step and it will not
|
---|
292 | // work when the editor is in RTL.
|
---|
293 | //
|
---|
294 | // The "|| eMainNode.firstChild.offsetWidth" part has been added
|
---|
295 | // for Opera compatibility (see #570).
|
---|
296 | iMainWidth = eMainNode.offsetWidth || eMainNode.firstChild.offsetWidth ;
|
---|
297 |
|
---|
298 | // Base the popup coordinates upon the coordinates of relElement.
|
---|
299 | var oPos = FCKTools.GetDocumentPosition( this._Window,
|
---|
300 | relElement.nodeType == 9 ?
|
---|
301 | ( FCKTools.IsStrictMode( relElement ) ? relElement.documentElement : relElement.body ) :
|
---|
302 | relElement ) ;
|
---|
303 |
|
---|
304 | // Minus the offsets provided by any positioned parent element of the panel iframe.
|
---|
305 | var positionedAncestor = FCKDomTools.GetPositionedAncestor( this._IFrame.parentNode ) ;
|
---|
306 | if ( positionedAncestor )
|
---|
307 | {
|
---|
308 | var nPos = FCKTools.GetDocumentPosition( FCKTools.GetElementWindow( positionedAncestor ), positionedAncestor ) ;
|
---|
309 | oPos.x -= nPos.x ;
|
---|
310 | oPos.y -= nPos.y ;
|
---|
311 | }
|
---|
312 |
|
---|
313 | if ( this.IsRTL && !this.IsContextMenu )
|
---|
314 | x = ( x * -1 ) ;
|
---|
315 |
|
---|
316 | x += oPos.x ;
|
---|
317 | y += oPos.y ;
|
---|
318 |
|
---|
319 | if ( this.IsRTL )
|
---|
320 | {
|
---|
321 | if ( this.IsContextMenu )
|
---|
322 | x = x - iMainWidth + 1 ;
|
---|
323 | else if ( relElement )
|
---|
324 | x = x + relElement.offsetWidth - iMainWidth ;
|
---|
325 | }
|
---|
326 | else
|
---|
327 | {
|
---|
328 | var oViewPaneSize = FCKTools.GetViewPaneSize( this._Window ) ;
|
---|
329 | var oScrollPosition = FCKTools.GetScrollPosition( this._Window ) ;
|
---|
330 |
|
---|
331 | var iViewPaneHeight = oViewPaneSize.Height + oScrollPosition.Y ;
|
---|
332 | var iViewPaneWidth = oViewPaneSize.Width + oScrollPosition.X ;
|
---|
333 |
|
---|
334 | if ( ( x + iMainWidth ) > iViewPaneWidth )
|
---|
335 | x -= x + iMainWidth - iViewPaneWidth ;
|
---|
336 |
|
---|
337 | if ( ( y + eMainNode.offsetHeight ) > iViewPaneHeight )
|
---|
338 | y -= y + eMainNode.offsetHeight - iViewPaneHeight ;
|
---|
339 | }
|
---|
340 |
|
---|
341 | // Set the context menu DIV in the specified location.
|
---|
342 | FCKDomTools.SetElementStyles( this._IFrame,
|
---|
343 | {
|
---|
344 | left : x + 'px',
|
---|
345 | top : y + 'px'
|
---|
346 | } ) ;
|
---|
347 |
|
---|
348 | // Move the focus to the IFRAME so we catch the "onblur".
|
---|
349 | this._IFrame.contentWindow.focus() ;
|
---|
350 | this._IsOpened = true ;
|
---|
351 |
|
---|
352 | var me = this ;
|
---|
353 | this._resizeTimer = setTimeout( function()
|
---|
354 | {
|
---|
355 | var iWidth = eMainNode.offsetWidth || eMainNode.firstChild.offsetWidth ;
|
---|
356 | var iHeight = eMainNode.offsetHeight ;
|
---|
357 | me._IFrame.style.width = iWidth + 'px' ;
|
---|
358 | me._IFrame.style.height = iHeight + 'px' ;
|
---|
359 |
|
---|
360 | }, 0 ) ;
|
---|
361 |
|
---|
362 | FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'FCKPanel' )._OpenedPanel = this ;
|
---|
363 | }
|
---|
364 |
|
---|
365 | FCKTools.RunFunction( this.OnShow, this ) ;
|
---|
366 | }
|
---|
367 |
|
---|
368 | FCKPanel.prototype.Hide = function( ignoreOnHide, ignoreFocusManagerUnlock )
|
---|
369 | {
|
---|
370 | if ( this._Popup )
|
---|
371 | this._Popup.hide() ;
|
---|
372 | else
|
---|
373 | {
|
---|
374 | if ( !this._IsOpened || this._LockCounter > 0 )
|
---|
375 | return ;
|
---|
376 |
|
---|
377 | // Enable the editor to fire the "OnBlur".
|
---|
378 | if ( typeof( FCKFocusManager ) != 'undefined' && !ignoreFocusManagerUnlock )
|
---|
379 | FCKFocusManager.Unlock() ;
|
---|
380 |
|
---|
381 | // It is better to set the sizes to 0, otherwise Firefox would have
|
---|
382 | // rendering problems.
|
---|
383 | this._IFrame.style.width = this._IFrame.style.height = '0px' ;
|
---|
384 |
|
---|
385 | this._IsOpened = false ;
|
---|
386 |
|
---|
387 | if ( this._resizeTimer )
|
---|
388 | {
|
---|
389 | clearTimeout( this._resizeTimer ) ;
|
---|
390 | this._resizeTimer = null ;
|
---|
391 | }
|
---|
392 |
|
---|
393 | if ( this.ParentPanel )
|
---|
394 | this.ParentPanel.Unlock() ;
|
---|
395 |
|
---|
396 | if ( !ignoreOnHide )
|
---|
397 | FCKTools.RunFunction( this.OnHide, this ) ;
|
---|
398 | }
|
---|
399 | }
|
---|
400 |
|
---|
401 | FCKPanel.prototype.CheckIsOpened = function()
|
---|
402 | {
|
---|
403 | if ( this._Popup )
|
---|
404 | return this._Popup.isOpen ;
|
---|
405 | else
|
---|
406 | return this._IsOpened ;
|
---|
407 | }
|
---|
408 |
|
---|
409 | FCKPanel.prototype.CreateChildPanel = function()
|
---|
410 | {
|
---|
411 | var oWindow = this._Popup ? FCKTools.GetDocumentWindow( this.Document ) : this._Window ;
|
---|
412 |
|
---|
413 | var oChildPanel = new FCKPanel( oWindow ) ;
|
---|
414 | oChildPanel.ParentPanel = this ;
|
---|
415 |
|
---|
416 | return oChildPanel ;
|
---|
417 | }
|
---|
418 |
|
---|
419 | FCKPanel.prototype.Lock = function()
|
---|
420 | {
|
---|
421 | this._LockCounter++ ;
|
---|
422 | }
|
---|
423 |
|
---|
424 | FCKPanel.prototype.Unlock = function()
|
---|
425 | {
|
---|
426 | if ( --this._LockCounter == 0 && !this.HasFocus )
|
---|
427 | this.Hide() ;
|
---|
428 | }
|
---|
429 |
|
---|
430 | /* Events */
|
---|
431 |
|
---|
432 | function FCKPanel_Window_OnFocus( e, panel )
|
---|
433 | {
|
---|
434 | panel.HasFocus = true ;
|
---|
435 | }
|
---|
436 |
|
---|
437 | function FCKPanel_Window_OnBlur( e, panel )
|
---|
438 | {
|
---|
439 | panel.HasFocus = false ;
|
---|
440 |
|
---|
441 | if ( panel._LockCounter == 0 )
|
---|
442 | FCKTools.RunFunction( panel.Hide, panel ) ;
|
---|
443 | }
|
---|
444 |
|
---|
445 | function CheckPopupOnHide( forceHide )
|
---|
446 | {
|
---|
447 | if ( forceHide || !this._Popup.isOpen )
|
---|
448 | {
|
---|
449 | window.clearInterval( this._Timer ) ;
|
---|
450 | this._Timer = null ;
|
---|
451 |
|
---|
452 | if (this._Popup && this.ParentPanel && !forceHide)
|
---|
453 | this.ParentPanel.ResizeForSubpanel(this, 0, 0) ;
|
---|
454 |
|
---|
455 | FCKTools.RunFunction( this.OnHide, this ) ;
|
---|
456 | }
|
---|
457 | }
|
---|
458 |
|
---|
459 | function FCKPanel_Cleanup()
|
---|
460 | {
|
---|
461 | this._Popup = null ;
|
---|
462 | this._Window = null ;
|
---|
463 | this.Document = null ;
|
---|
464 | this.MainNode = null ;
|
---|
465 | this.RelativeElement = null ;
|
---|
466 | }
|
---|