~ubuntu-branches/ubuntu/jaunty/moin/jaunty-security

« back to all changes in this revision

Viewing changes to wiki/htdocs/applets/FCKeditor/editor/_source/classes/fckpanel.js

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2008-11-13 16:45:52 UTC
  • mfrom: (0.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20081113164552-49t6zf2t2o5bqigh
Tags: 1.8.0-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Drop recommendation of python-xml, the packages isn't anymore in
    sys.path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 
3
 * Copyright (C) 2003-2008 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
FCKPanel.prototype.Show = function( x, y, relElement, width, height )
 
132
{
 
133
        var iMainWidth ;
 
134
        var eMainNode = this.MainNode ;
 
135
 
 
136
        if ( this._Popup )
 
137
        {
 
138
                // The offsetWidth and offsetHeight properties are not available if the
 
139
                // element is not visible. So we must "show" the popup with no size to
 
140
                // be able to use that values in the second call.
 
141
                this._Popup.show( x, y, 0, 0, relElement ) ;
 
142
 
 
143
                // The following lines must be place after the above "show", otherwise it
 
144
                // doesn't has the desired effect.
 
145
                FCKDomTools.SetElementStyles( eMainNode,
 
146
                        {
 
147
                                width   : width ? width + 'px' : '',
 
148
                                height  : height ? height + 'px' : ''
 
149
                        } ) ;
 
150
 
 
151
                iMainWidth = eMainNode.offsetWidth ;
 
152
 
 
153
                if ( this.IsRTL )
 
154
                {
 
155
                        if ( this.IsContextMenu )
 
156
                                x  = x - iMainWidth + 1 ;
 
157
                        else if ( relElement )
 
158
                                x  = ( x * -1 ) + relElement.offsetWidth - iMainWidth ;
 
159
                }
 
160
 
 
161
                // Second call: Show the Popup at the specified location, with the correct size.
 
162
                this._Popup.show( x, y, iMainWidth, eMainNode.offsetHeight, relElement ) ;
 
163
 
 
164
                if ( this.OnHide )
 
165
                {
 
166
                        if ( this._Timer )
 
167
                                CheckPopupOnHide.call( this, true ) ;
 
168
 
 
169
                        this._Timer = FCKTools.SetInterval( CheckPopupOnHide, 100, this ) ;
 
170
                }
 
171
        }
 
172
        else
 
173
        {
 
174
                // Do not fire OnBlur while the panel is opened.
 
175
                if ( typeof( FCK.ToolbarSet.CurrentInstance.FocusManager ) != 'undefined' )
 
176
                        FCK.ToolbarSet.CurrentInstance.FocusManager.Lock() ;
 
177
 
 
178
                if ( this.ParentPanel )
 
179
                {
 
180
                        this.ParentPanel.Lock() ;
 
181
 
 
182
                        // Due to a bug on FF3, we must ensure that the parent panel will
 
183
                        // blur (#1584).
 
184
                        FCKPanel_Window_OnBlur( null, this.ParentPanel ) ;
 
185
                }
 
186
 
 
187
                // Toggle the iframe scrolling attribute to prevent the panel
 
188
                // scrollbars from disappearing in FF Mac. (#191)
 
189
                if ( FCKBrowserInfo.IsGecko && FCKBrowserInfo.IsMac )
 
190
                {
 
191
                        this._IFrame.scrolling = '' ;
 
192
                        FCKTools.RunFunction( function(){ this._IFrame.scrolling = 'no'; }, this ) ;
 
193
                }
 
194
 
 
195
                // Be sure we'll not have more than one Panel opened at the same time.
 
196
                // Do not unlock focus manager here because we're displaying another floating panel
 
197
                // instead of returning the editor to a "no panel" state (Bug #1514).
 
198
                if ( FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'FCKPanel' )._OpenedPanel &&
 
199
                                FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'FCKPanel' )._OpenedPanel != this )
 
200
                        FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'FCKPanel' )._OpenedPanel.Hide( false, true ) ;
 
201
 
 
202
                FCKDomTools.SetElementStyles( eMainNode,
 
203
                        {
 
204
                                width   : width ? width + 'px' : '',
 
205
                                height  : height ? height + 'px' : ''
 
206
                        } ) ;
 
207
 
 
208
                iMainWidth = eMainNode.offsetWidth ;
 
209
 
 
210
                if ( !width )   this._IFrame.width      = 1 ;
 
211
                if ( !height )  this._IFrame.height     = 1 ;
 
212
 
 
213
                // This is weird... but with Firefox, we must get the offsetWidth before
 
214
                // setting the _IFrame size (which returns "0"), and then after that,
 
215
                // to return the correct width. Remove the first step and it will not
 
216
                // work when the editor is in RTL.
 
217
                //
 
218
                // The "|| eMainNode.firstChild.offsetWidth" part has been added
 
219
                // for Opera compatibility (see #570).
 
220
                iMainWidth = eMainNode.offsetWidth || eMainNode.firstChild.offsetWidth ;
 
221
 
 
222
                // Base the popup coordinates upon the coordinates of relElement.
 
223
                var oPos = FCKTools.GetDocumentPosition( this._Window,
 
224
                        relElement.nodeType == 9 ?
 
225
                                ( FCKTools.IsStrictMode( relElement ) ? relElement.documentElement : relElement.body ) :
 
226
                                relElement ) ;
 
227
 
 
228
                // Minus the offsets provided by any positioned parent element of the panel iframe.
 
229
                var positionedAncestor = FCKDomTools.GetPositionedAncestor( this._IFrame.parentNode ) ;
 
230
                if ( positionedAncestor )
 
231
                {
 
232
                        var nPos = FCKTools.GetDocumentPosition( FCKTools.GetElementWindow( positionedAncestor ), positionedAncestor ) ;
 
233
                        oPos.x -= nPos.x ;
 
234
                        oPos.y -= nPos.y ;
 
235
                }
 
236
 
 
237
                if ( this.IsRTL && !this.IsContextMenu )
 
238
                        x = ( x * -1 ) ;
 
239
 
 
240
                x += oPos.x ;
 
241
                y += oPos.y ;
 
242
 
 
243
                if ( this.IsRTL )
 
244
                {
 
245
                        if ( this.IsContextMenu )
 
246
                                x  = x - iMainWidth + 1 ;
 
247
                        else if ( relElement )
 
248
                                x  = x + relElement.offsetWidth - iMainWidth ;
 
249
                }
 
250
                else
 
251
                {
 
252
                        var oViewPaneSize = FCKTools.GetViewPaneSize( this._Window ) ;
 
253
                        var oScrollPosition = FCKTools.GetScrollPosition( this._Window ) ;
 
254
 
 
255
                        var iViewPaneHeight     = oViewPaneSize.Height + oScrollPosition.Y ;
 
256
                        var iViewPaneWidth      = oViewPaneSize.Width + oScrollPosition.X ;
 
257
 
 
258
                        if ( ( x + iMainWidth ) > iViewPaneWidth )
 
259
                                x -= x + iMainWidth - iViewPaneWidth ;
 
260
 
 
261
                        if ( ( y + eMainNode.offsetHeight ) > iViewPaneHeight )
 
262
                                y -= y + eMainNode.offsetHeight - iViewPaneHeight ;
 
263
                }
 
264
 
 
265
                // Set the context menu DIV in the specified location.
 
266
                FCKDomTools.SetElementStyles( this._IFrame,
 
267
                        {
 
268
                                left    : x + 'px',
 
269
                                top             : y + 'px'
 
270
                        } ) ;
 
271
 
 
272
                // Move the focus to the IFRAME so we catch the "onblur".
 
273
                this._IFrame.contentWindow.focus() ;
 
274
                this._IsOpened = true ;
 
275
 
 
276
                var me = this ;
 
277
                this._resizeTimer = setTimeout( function()
 
278
                        {
 
279
                                var iWidth = eMainNode.offsetWidth || eMainNode.firstChild.offsetWidth ;
 
280
                                var iHeight = eMainNode.offsetHeight ;
 
281
                                me._IFrame.style.width = iWidth + 'px' ;
 
282
                                me._IFrame.style.height = iHeight + 'px' ;
 
283
 
 
284
                        }, 0 ) ;
 
285
 
 
286
                FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'FCKPanel' )._OpenedPanel = this ;
 
287
        }
 
288
 
 
289
        FCKTools.RunFunction( this.OnShow, this ) ;
 
290
}
 
291
 
 
292
FCKPanel.prototype.Hide = function( ignoreOnHide, ignoreFocusManagerUnlock )
 
293
{
 
294
        if ( this._Popup )
 
295
                this._Popup.hide() ;
 
296
        else
 
297
        {
 
298
                if ( !this._IsOpened || this._LockCounter > 0 )
 
299
                        return ;
 
300
 
 
301
                // Enable the editor to fire the "OnBlur".
 
302
                if ( typeof( FCKFocusManager ) != 'undefined' && !ignoreFocusManagerUnlock )
 
303
                        FCKFocusManager.Unlock() ;
 
304
 
 
305
                // It is better to set the sizes to 0, otherwise Firefox would have
 
306
                // rendering problems.
 
307
                this._IFrame.style.width = this._IFrame.style.height = '0px' ;
 
308
 
 
309
                this._IsOpened = false ;
 
310
 
 
311
                if ( this._resizeTimer )
 
312
                {
 
313
                        clearTimeout( this._resizeTimer ) ;
 
314
                        this._resizeTimer = null ;
 
315
                }
 
316
 
 
317
                if ( this.ParentPanel )
 
318
                        this.ParentPanel.Unlock() ;
 
319
 
 
320
                if ( !ignoreOnHide )
 
321
                        FCKTools.RunFunction( this.OnHide, this ) ;
 
322
        }
 
323
}
 
324
 
 
325
FCKPanel.prototype.CheckIsOpened = function()
 
326
{
 
327
        if ( this._Popup )
 
328
                return this._Popup.isOpen ;
 
329
        else
 
330
                return this._IsOpened ;
 
331
}
 
332
 
 
333
FCKPanel.prototype.CreateChildPanel = function()
 
334
{
 
335
        var oWindow = this._Popup ? FCKTools.GetDocumentWindow( this.Document ) : this._Window ;
 
336
 
 
337
        var oChildPanel = new FCKPanel( oWindow ) ;
 
338
        oChildPanel.ParentPanel = this ;
 
339
 
 
340
        return oChildPanel ;
 
341
}
 
342
 
 
343
FCKPanel.prototype.Lock = function()
 
344
{
 
345
        this._LockCounter++ ;
 
346
}
 
347
 
 
348
FCKPanel.prototype.Unlock = function()
 
349
{
 
350
        if ( --this._LockCounter == 0 && !this.HasFocus )
 
351
                this.Hide() ;
 
352
}
 
353
 
 
354
/* Events */
 
355
 
 
356
function FCKPanel_Window_OnFocus( e, panel )
 
357
{
 
358
        panel.HasFocus = true ;
 
359
}
 
360
 
 
361
function FCKPanel_Window_OnBlur( e, panel )
 
362
{
 
363
        panel.HasFocus = false ;
 
364
 
 
365
        if ( panel._LockCounter == 0 )
 
366
                FCKTools.RunFunction( panel.Hide, panel ) ;
 
367
}
 
368
 
 
369
function CheckPopupOnHide( forceHide )
 
370
{
 
371
        if ( forceHide || !this._Popup.isOpen )
 
372
        {
 
373
                window.clearInterval( this._Timer ) ;
 
374
                this._Timer = null ;
 
375
 
 
376
                FCKTools.RunFunction( this.OnHide, this ) ;
 
377
        }
 
378
}
 
379
 
 
380
function FCKPanel_Cleanup()
 
381
{
 
382
        this._Popup = null ;
 
383
        this._Window = null ;
 
384
        this.Document = null ;
 
385
        this.MainNode = null ;
 
386
}