2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2010 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. (IE version).
24
FCKTools.CancelEvent = function( e )
29
// Appends one or more CSS files to a document.
30
FCKTools._AppendStyleSheet = function( documentElement, cssFileUrl )
32
return documentElement.createStyleSheet( cssFileUrl ).owningElement ;
35
// Appends a CSS style string to a document.
36
FCKTools.AppendStyleString = function( documentElement, cssStyles )
41
var s = documentElement.createStyleSheet( "" ) ;
42
s.cssText = cssStyles ;
46
// Removes all attributes and values from the element.
47
FCKTools.ClearElementAttributes = function( element )
49
element.clearAttributes() ;
52
FCKTools.GetAllChildrenIds = function( parentElement )
54
var aIds = new Array() ;
55
for ( var i = 0 ; i < parentElement.all.length ; i++ )
57
var sId = parentElement.all[i].id ;
58
if ( sId && sId.length > 0 )
59
aIds[ aIds.length ] = sId ;
64
FCKTools.RemoveOuterTags = function( e )
66
e.insertAdjacentHTML( 'beforeBegin', e.innerHTML ) ;
67
e.parentNode.removeChild( e ) ;
70
FCKTools.CreateXmlObject = function( object )
77
// Try the native XMLHttpRequest introduced with IE7.
78
if ( document.location.protocol != 'file:' )
79
try { return new XMLHttpRequest() ; } catch (e) {}
81
aObjs = [ 'MSXML2.XmlHttp', 'Microsoft.XmlHttp' ] ;
85
aObjs = [ 'MSXML2.DOMDocument', 'Microsoft.XmlDom' ] ;
89
for ( var i = 0 ; i < 2 ; i++ )
91
try { return new ActiveXObject( aObjs[i] ) ; }
96
if ( FCKLang.NoActiveX )
98
alert( FCKLang.NoActiveX ) ;
99
FCKLang.NoActiveX = null ;
104
FCKTools.DisableSelection = function( element )
106
element.unselectable = 'on' ;
109
// The extra () is to avoid a warning with strict error checking. This is ok.
110
while ( (e = element.all[ i++ ]) )
118
/* Ignore the above tags */
121
e.unselectable = 'on' ;
126
FCKTools.GetScrollPosition = function( relativeWindow )
128
var oDoc = relativeWindow.document ;
130
// Try with the doc element.
131
var oPos = { X : oDoc.documentElement.scrollLeft, Y : oDoc.documentElement.scrollTop } ;
133
if ( oPos.X > 0 || oPos.Y > 0 )
136
// If no scroll, try with the body.
137
return { X : oDoc.body.scrollLeft, Y : oDoc.body.scrollTop } ;
140
FCKTools.AddEventListener = function( sourceObject, eventName, listener )
142
sourceObject.attachEvent( 'on' + eventName, listener ) ;
145
FCKTools.RemoveEventListener = function( sourceObject, eventName, listener )
147
sourceObject.detachEvent( 'on' + eventName, listener ) ;
150
// Listeners attached with this function cannot be detached.
151
FCKTools.AddEventListenerEx = function( sourceObject, eventName, listener, paramsArray )
153
// Ok... this is a closures party, but is the only way to make it clean of memory leaks.
154
var o = new Object() ;
155
o.Source = sourceObject ;
156
o.Params = paramsArray || [] ; // Memory leak if we have DOM objects here.
157
o.Listener = function( ev )
159
return listener.apply( o.Source, [ ev ].concat( o.Params ) ) ;
163
FCK.IECleanup.AddItem( null, function() { o.Source = null ; o.Params = null ; } ) ;
165
sourceObject.attachEvent( 'on' + eventName, o.Listener ) ;
167
sourceObject = null ; // Memory leak cleaner (because of the above closure).
168
paramsArray = null ; // Memory leak cleaner (because of the above closure).
171
// Returns and object with the "Width" and "Height" properties.
172
FCKTools.GetViewPaneSize = function( win )
176
var oDoc = win.document.documentElement ;
177
if ( oDoc && oDoc.clientWidth ) // IE6 Strict Mode
180
oSizeSource = win.document.body ; // Other IEs
183
return { Width : oSizeSource.clientWidth, Height : oSizeSource.clientHeight } ;
185
return { Width : 0, Height : 0 } ;
188
FCKTools.SaveStyles = function( element )
190
var data = FCKTools.ProtectFormStyles( element ) ;
192
var oSavedStyles = new Object() ;
194
if ( element.className.length > 0 )
196
oSavedStyles.Class = element.className ;
197
element.className = '' ;
200
var sInlineStyle = element.style.cssText ;
202
if ( sInlineStyle.length > 0 )
204
oSavedStyles.Inline = sInlineStyle ;
205
element.style.cssText = '' ;
208
FCKTools.RestoreFormStyles( element, data ) ;
209
return oSavedStyles ;
212
FCKTools.RestoreStyles = function( element, savedStyles )
214
var data = FCKTools.ProtectFormStyles( element ) ;
215
element.className = savedStyles.Class || '' ;
216
element.style.cssText = savedStyles.Inline || '' ;
217
FCKTools.RestoreFormStyles( element, data ) ;
220
FCKTools.RegisterDollarFunction = function( targetWindow )
222
targetWindow.$ = targetWindow.document.getElementById ;
225
FCKTools.AppendElement = function( target, elementName )
227
return target.appendChild( this.GetElementDocument( target ).createElement( elementName ) ) ;
230
// This function may be used by Regex replacements.
231
FCKTools.ToLowerCase = function( strValue )
233
return strValue.toLowerCase() ;