2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2007 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
* Utility functions. (Gecko version).
24
FCKTools.CancelEvent = function( e )
30
FCKTools.DisableSelection = function( element )
32
if ( FCKBrowserInfo.IsGecko )
33
element.style.MozUserSelect = 'none' ; // Gecko only.
35
element.style.userSelect = 'none' ; // CSS3 (not supported yet).
38
// Appends a CSS file to a document.
39
FCKTools._AppendStyleSheet = function( documentElement, cssFileUrl )
41
var e = documentElement.createElement( 'LINK' ) ;
42
e.rel = 'stylesheet' ;
45
documentElement.getElementsByTagName("HEAD")[0].appendChild( e ) ;
49
// Removes all attributes and values from the element.
50
FCKTools.ClearElementAttributes = function( element )
52
// Loop throw all attributes in the element
53
for ( var i = 0 ; i < element.attributes.length ; i++ )
55
// Remove the element by name.
56
element.removeAttribute( element.attributes[i].name, 0 ) ; // 0 : Case Insensitive
60
// Returns an Array of strings with all defined in the elements inside another element.
61
FCKTools.GetAllChildrenIds = function( parentElement )
63
// Create the array that will hold all Ids.
64
var aIds = new Array() ;
66
// Define a recursive function that search for the Ids.
67
var fGetIds = function( parent )
69
for ( var i = 0 ; i < parent.childNodes.length ; i++ )
71
var sId = parent.childNodes[i].id ;
73
// Check if the Id is defined for the element.
74
if ( sId && sId.length > 0 ) aIds[ aIds.length ] = sId ;
77
fGetIds( parent.childNodes[i] ) ;
81
// Start the recursive calls.
82
fGetIds( parentElement ) ;
87
// Replaces a tag with its contents. For example "<span>My <b>tag</b></span>"
88
// will be replaced with "My <b>tag</b>".
89
FCKTools.RemoveOuterTags = function( e )
91
var oFragment = e.ownerDocument.createDocumentFragment() ;
93
for ( var i = 0 ; i < e.childNodes.length ; i++ )
94
oFragment.appendChild( e.childNodes[i].cloneNode(true) ) ;
96
e.parentNode.replaceChild( oFragment, e ) ;
99
FCKTools.CreateXmlObject = function( object )
104
return new XMLHttpRequest() ;
106
return document.implementation.createDocument( '', '', null ) ;
111
FCKTools.GetScrollPosition = function( relativeWindow )
113
return { X : relativeWindow.pageXOffset, Y : relativeWindow.pageYOffset } ;
116
FCKTools.AddEventListener = function( sourceObject, eventName, listener )
118
sourceObject.addEventListener( eventName, listener, false ) ;
121
FCKTools.RemoveEventListener = function( sourceObject, eventName, listener )
123
sourceObject.removeEventListener( eventName, listener, false ) ;
126
// Listeners attached with this function cannot be detached.
127
FCKTools.AddEventListenerEx = function( sourceObject, eventName, listener, paramsArray )
129
sourceObject.addEventListener(
133
listener.apply( sourceObject, [ e ].concat( paramsArray || [] ) ) ;
139
// Returns and object with the "Width" and "Height" properties.
140
FCKTools.GetViewPaneSize = function( win )
142
return { Width : win.innerWidth, Height : win.innerHeight } ;
145
FCKTools.SaveStyles = function( element )
147
var oSavedStyles = new Object() ;
149
if ( element.className.length > 0 )
151
oSavedStyles.Class = element.className ;
152
element.className = '' ;
155
var sInlineStyle = element.getAttribute( 'style' ) ;
157
if ( sInlineStyle && sInlineStyle.length > 0 )
159
oSavedStyles.Inline = sInlineStyle ;
160
element.setAttribute( 'style', '', 0 ) ; // 0 : Case Insensitive
163
return oSavedStyles ;
166
FCKTools.RestoreStyles = function( element, savedStyles )
168
element.className = savedStyles.Class || '' ;
170
if ( savedStyles.Inline )
171
element.setAttribute( 'style', savedStyles.Inline, 0 ) ; // 0 : Case Insensitive
173
element.removeAttribute( 'style', 0 ) ;
176
FCKTools.RegisterDollarFunction = function( targetWindow )
178
targetWindow.$ = function( id )
180
return this.document.getElementById( id ) ;
184
FCKTools.AppendElement = function( target, elementName )
186
return target.appendChild( target.ownerDocument.createElement( elementName ) ) ;
189
// Get the coordinates of an element.
190
// @el : The element to get the position.
191
// @relativeWindow: The window to which we want the coordinates relative to.
192
FCKTools.GetElementPosition = function( el, relativeWindow )
194
// Initializes the Coordinates object that will be returned by the function.
195
var c = { X:0, Y:0 } ;
197
var oWindow = relativeWindow || window ;
199
var oOwnerWindow = FCKTools.GetElementWindow( el ) ;
201
// Loop throw the offset chain.
204
var sPosition = oOwnerWindow.getComputedStyle(el, '').position ;
206
// Check for non "static" elements.
207
// 'FCKConfig.FloatingPanelsZIndex' -- Submenus are under a positioned IFRAME.
208
if ( sPosition && sPosition != 'static' && el.style.zIndex != FCKConfig.FloatingPanelsZIndex )
211
c.X += el.offsetLeft - el.scrollLeft ;
212
c.Y += el.offsetTop - el.scrollTop ;
214
if ( el.offsetParent )
215
el = el.offsetParent ;
218
if ( oOwnerWindow != oWindow )
220
el = oOwnerWindow.frameElement ;
222
oOwnerWindow = FCKTools.GetElementWindow( el ) ;
226
c.X += el.scrollLeft ;
227
c.Y += el.scrollTop ;
233
// Return the Coordinates object
b'\\ No newline at end of file'