~ubuntu-branches/ubuntu/oneiric/moin/oneiric-security

« back to all changes in this revision

Viewing changes to wiki/htdocs/applets/FCKeditor/editor/_source/internals/fcktools_gecko.js

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-03-30 12:55:34 UTC
  • mfrom: (0.1.17 sid)
  • Revision ID: james.westby@ubuntu.com-20100330125534-4c2ufc1rok24447l
Tags: 1.9.2-2ubuntu1
* Merge from Debian testing (LP: #521834). Based on work by Stefan Ebner.
  Remaining changes:
 - Remove python-xml from Suggests field, the package isn't anymore in
   sys.path.
 - Demote fckeditor from Recommends to Suggests; the code was previously
   embedded in moin, but it was also disabled, so there's no reason for us
   to pull this in by default currently. Note: This isn't necessary anymore
   but needs a MIR for fckeditor, so postpone dropping this change until
   lucid+1
* debian/rules:
  - Replace hardcoded python2.5 with python* and hardcore python2.6 for ln
* debian/control.in: drop versioned depends on cdbs

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-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
 
 * Utility functions. (Gecko version).
22
 
 */
23
 
 
24
 
FCKTools.CancelEvent = function( e )
25
 
{
26
 
        if ( e )
27
 
                e.preventDefault() ;
28
 
}
29
 
 
30
 
FCKTools.DisableSelection = function( element )
31
 
{
32
 
        if ( FCKBrowserInfo.IsGecko )
33
 
                element.style.MozUserSelect             = 'none' ;      // Gecko only.
34
 
        else if ( FCKBrowserInfo.IsSafari )
35
 
                element.style.KhtmlUserSelect   = 'none' ;      // WebKit only.
36
 
        else
37
 
                element.style.userSelect                = 'none' ;      // CSS3 (not supported yet).
38
 
}
39
 
 
40
 
// Appends a CSS file to a document.
41
 
FCKTools._AppendStyleSheet = function( documentElement, cssFileUrl )
42
 
{
43
 
        var e = documentElement.createElement( 'LINK' ) ;
44
 
        e.rel   = 'stylesheet' ;
45
 
        e.type  = 'text/css' ;
46
 
        e.href  = cssFileUrl ;
47
 
        documentElement.getElementsByTagName("HEAD")[0].appendChild( e ) ;
48
 
        return e ;
49
 
}
50
 
 
51
 
// Appends a CSS style string to a document.
52
 
FCKTools.AppendStyleString = function( documentElement, cssStyles )
53
 
{
54
 
        if ( !cssStyles )
55
 
                return null ;
56
 
 
57
 
        var e = documentElement.createElement( "STYLE" ) ;
58
 
        e.appendChild( documentElement.createTextNode( cssStyles ) ) ;
59
 
        documentElement.getElementsByTagName( "HEAD" )[0].appendChild( e ) ;
60
 
        return e ;
61
 
}
62
 
 
63
 
// Removes all attributes and values from the element.
64
 
FCKTools.ClearElementAttributes = function( element )
65
 
{
66
 
        // Loop throw all attributes in the element
67
 
        for ( var i = 0 ; i < element.attributes.length ; i++ )
68
 
        {
69
 
                // Remove the element by name.
70
 
                element.removeAttribute( element.attributes[i].name, 0 ) ;      // 0 : Case Insensitive
71
 
        }
72
 
}
73
 
 
74
 
// Returns an Array of strings with all defined in the elements inside another element.
75
 
FCKTools.GetAllChildrenIds = function( parentElement )
76
 
{
77
 
        // Create the array that will hold all Ids.
78
 
        var aIds = new Array() ;
79
 
 
80
 
        // Define a recursive function that search for the Ids.
81
 
        var fGetIds = function( parent )
82
 
        {
83
 
                for ( var i = 0 ; i < parent.childNodes.length ; i++ )
84
 
                {
85
 
                        var sId = parent.childNodes[i].id ;
86
 
 
87
 
                        // Check if the Id is defined for the element.
88
 
                        if ( sId && sId.length > 0 ) aIds[ aIds.length ] = sId ;
89
 
 
90
 
                        // Recursive call.
91
 
                        fGetIds( parent.childNodes[i] ) ;
92
 
                }
93
 
        }
94
 
 
95
 
        // Start the recursive calls.
96
 
        fGetIds( parentElement ) ;
97
 
 
98
 
        return aIds ;
99
 
}
100
 
 
101
 
// Replaces a tag with its contents. For example "<span>My <b>tag</b></span>"
102
 
// will be replaced with "My <b>tag</b>".
103
 
FCKTools.RemoveOuterTags = function( e )
104
 
{
105
 
        var oFragment = e.ownerDocument.createDocumentFragment() ;
106
 
 
107
 
        for ( var i = 0 ; i < e.childNodes.length ; i++ )
108
 
                oFragment.appendChild( e.childNodes[i].cloneNode(true) ) ;
109
 
 
110
 
        e.parentNode.replaceChild( oFragment, e ) ;
111
 
}
112
 
 
113
 
FCKTools.CreateXmlObject = function( object )
114
 
{
115
 
        switch ( object )
116
 
        {
117
 
                case 'XmlHttp' :
118
 
                        return new XMLHttpRequest() ;
119
 
 
120
 
                case 'DOMDocument' :
121
 
                        // Originaly, we were had the following here:
122
 
                        // return document.implementation.createDocument( '', '', null ) ;
123
 
                        // But that doesn't work if we're running under domain relaxation mode, so we need a workaround.
124
 
                        // See http://ajaxian.com/archives/xml-messages-with-cross-domain-json about the trick we're using.
125
 
                        var doc = ( new DOMParser() ).parseFromString( '<tmp></tmp>', 'text/xml' ) ;
126
 
                        FCKDomTools.RemoveNode( doc.firstChild ) ;
127
 
                        return doc ;
128
 
        }
129
 
        return null ;
130
 
}
131
 
 
132
 
FCKTools.GetScrollPosition = function( relativeWindow )
133
 
{
134
 
        return { X : relativeWindow.pageXOffset, Y : relativeWindow.pageYOffset } ;
135
 
}
136
 
 
137
 
FCKTools.AddEventListener = function( sourceObject, eventName, listener )
138
 
{
139
 
        sourceObject.addEventListener( eventName, listener, false ) ;
140
 
}
141
 
 
142
 
FCKTools.RemoveEventListener = function( sourceObject, eventName, listener )
143
 
{
144
 
        sourceObject.removeEventListener( eventName, listener, false ) ;
145
 
}
146
 
 
147
 
// Listeners attached with this function cannot be detached.
148
 
FCKTools.AddEventListenerEx = function( sourceObject, eventName, listener, paramsArray )
149
 
{
150
 
        sourceObject.addEventListener(
151
 
                eventName,
152
 
                function( e )
153
 
                {
154
 
                        listener.apply( sourceObject, [ e ].concat( paramsArray || [] ) ) ;
155
 
                },
156
 
                false
157
 
        ) ;
158
 
}
159
 
 
160
 
// Returns and object with the "Width" and "Height" properties.
161
 
FCKTools.GetViewPaneSize = function( win )
162
 
{
163
 
        return { Width : win.innerWidth, Height : win.innerHeight } ;
164
 
}
165
 
 
166
 
FCKTools.SaveStyles = function( element )
167
 
{
168
 
        var data = FCKTools.ProtectFormStyles( element ) ;
169
 
 
170
 
        var oSavedStyles = new Object() ;
171
 
 
172
 
        if ( element.className.length > 0 )
173
 
        {
174
 
                oSavedStyles.Class = element.className ;
175
 
                element.className = '' ;
176
 
        }
177
 
 
178
 
        var sInlineStyle = element.getAttribute( 'style' ) ;
179
 
 
180
 
        if ( sInlineStyle && sInlineStyle.length > 0 )
181
 
        {
182
 
                oSavedStyles.Inline = sInlineStyle ;
183
 
                element.setAttribute( 'style', '', 0 ) ;        // 0 : Case Insensitive
184
 
        }
185
 
 
186
 
        FCKTools.RestoreFormStyles( element, data ) ;
187
 
        return oSavedStyles ;
188
 
}
189
 
 
190
 
FCKTools.RestoreStyles = function( element, savedStyles )
191
 
{
192
 
        var data = FCKTools.ProtectFormStyles( element ) ;
193
 
        element.className = savedStyles.Class || '' ;
194
 
 
195
 
        if ( savedStyles.Inline )
196
 
                element.setAttribute( 'style', savedStyles.Inline, 0 ) ;        // 0 : Case Insensitive
197
 
        else
198
 
                element.removeAttribute( 'style', 0 ) ;
199
 
        FCKTools.RestoreFormStyles( element, data ) ;
200
 
}
201
 
 
202
 
FCKTools.RegisterDollarFunction = function( targetWindow )
203
 
{
204
 
        targetWindow.$ = function( id )
205
 
        {
206
 
                return targetWindow.document.getElementById( id ) ;
207
 
        } ;
208
 
}
209
 
 
210
 
FCKTools.AppendElement = function( target, elementName )
211
 
{
212
 
        return target.appendChild( target.ownerDocument.createElement( elementName ) ) ;
213
 
}
214
 
 
215
 
// Get the coordinates of an element.
216
 
//              @el : The element to get the position.
217
 
//              @relativeWindow: The window to which we want the coordinates relative to.
218
 
FCKTools.GetElementPosition = function( el, relativeWindow )
219
 
{
220
 
        // Initializes the Coordinates object that will be returned by the function.
221
 
        var c = { X:0, Y:0 } ;
222
 
 
223
 
        var oWindow = relativeWindow || window ;
224
 
 
225
 
        var oOwnerWindow = FCKTools.GetElementWindow( el ) ;
226
 
 
227
 
        var previousElement = null ;
228
 
        // Loop throw the offset chain.
229
 
        while ( el )
230
 
        {
231
 
                var sPosition = oOwnerWindow.getComputedStyle(el, '').position ;
232
 
 
233
 
                // Check for non "static" elements.
234
 
                // 'FCKConfig.FloatingPanelsZIndex' -- Submenus are under a positioned IFRAME.
235
 
                if ( sPosition && sPosition != 'static' && el.style.zIndex != FCKConfig.FloatingPanelsZIndex )
236
 
                        break ;
237
 
 
238
 
                /*
239
 
                FCKDebug.Output( el.tagName + ":" + "offset=" + el.offsetLeft + "," + el.offsetTop + "  "
240
 
                                + "scroll=" + el.scrollLeft + "," + el.scrollTop ) ;
241
 
                */
242
 
 
243
 
                c.X += el.offsetLeft - el.scrollLeft ;
244
 
                c.Y += el.offsetTop - el.scrollTop  ;
245
 
 
246
 
                // Backtrack due to offsetParent's calculation by the browser ignores scrollLeft and scrollTop.
247
 
                // Backtracking is not needed for Opera
248
 
                if ( ! FCKBrowserInfo.IsOpera )
249
 
                {
250
 
                        var scrollElement = previousElement ;
251
 
                        while ( scrollElement && scrollElement != el )
252
 
                        {
253
 
                                c.X -= scrollElement.scrollLeft ;
254
 
                                c.Y -= scrollElement.scrollTop ;
255
 
                                scrollElement = scrollElement.parentNode ;
256
 
                        }
257
 
                }
258
 
 
259
 
                previousElement = el ;
260
 
                if ( el.offsetParent )
261
 
                        el = el.offsetParent ;
262
 
                else
263
 
                {
264
 
                        if ( oOwnerWindow != oWindow )
265
 
                        {
266
 
                                el = oOwnerWindow.frameElement ;
267
 
                                previousElement = null ;
268
 
                                if ( el )
269
 
                                        oOwnerWindow = FCKTools.GetElementWindow( el ) ;
270
 
                        }
271
 
                        else
272
 
                        {
273
 
                                c.X += el.scrollLeft ;
274
 
                                c.Y += el.scrollTop  ;
275
 
                                break ;
276
 
                        }
277
 
                }
278
 
        }
279
 
 
280
 
        // Return the Coordinates object
281
 
        return c ;
282
 
}