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. (IE version).
|
---|
22 | */
|
---|
23 |
|
---|
24 | FCKTools.CancelEvent = function( e )
|
---|
25 | {
|
---|
26 | return false ;
|
---|
27 | }
|
---|
28 |
|
---|
29 | // Appends one or more CSS files to a document.
|
---|
30 | FCKTools._AppendStyleSheet = function( documentElement, cssFileUrl )
|
---|
31 | {
|
---|
32 | return documentElement.createStyleSheet( cssFileUrl ).owningElement ;
|
---|
33 | }
|
---|
34 |
|
---|
35 | // Appends a CSS style string to a document.
|
---|
36 | FCKTools.AppendStyleString = function( documentElement, cssStyles )
|
---|
37 | {
|
---|
38 | if ( !cssStyles )
|
---|
39 | return null ;
|
---|
40 |
|
---|
41 | var s = documentElement.createStyleSheet( "" ) ;
|
---|
42 | s.cssText = cssStyles ;
|
---|
43 | return s ;
|
---|
44 | }
|
---|
45 |
|
---|
46 | // Removes all attributes and values from the element.
|
---|
47 | FCKTools.ClearElementAttributes = function( element )
|
---|
48 | {
|
---|
49 | element.clearAttributes() ;
|
---|
50 | }
|
---|
51 |
|
---|
52 | FCKTools.GetAllChildrenIds = function( parentElement )
|
---|
53 | {
|
---|
54 | var aIds = new Array() ;
|
---|
55 | for ( var i = 0 ; i < parentElement.all.length ; i++ )
|
---|
56 | {
|
---|
57 | var sId = parentElement.all[i].id ;
|
---|
58 | if ( sId && sId.length > 0 )
|
---|
59 | aIds[ aIds.length ] = sId ;
|
---|
60 | }
|
---|
61 | return aIds ;
|
---|
62 | }
|
---|
63 |
|
---|
64 | FCKTools.RemoveOuterTags = function( e )
|
---|
65 | {
|
---|
66 | e.insertAdjacentHTML( 'beforeBegin', e.innerHTML ) ;
|
---|
67 | e.parentNode.removeChild( e ) ;
|
---|
68 | }
|
---|
69 |
|
---|
70 | FCKTools.CreateXmlObject = function( object )
|
---|
71 | {
|
---|
72 | var aObjs ;
|
---|
73 |
|
---|
74 | switch ( object )
|
---|
75 | {
|
---|
76 | case 'XmlHttp' :
|
---|
77 | // Try the native XMLHttpRequest introduced with IE7.
|
---|
78 | if ( document.location.protocol != 'file:' )
|
---|
79 | try { return new XMLHttpRequest() ; } catch (e) {}
|
---|
80 |
|
---|
81 | aObjs = [ 'MSXML2.XmlHttp', 'Microsoft.XmlHttp' ] ;
|
---|
82 | break ;
|
---|
83 |
|
---|
84 | case 'DOMDocument' :
|
---|
85 | aObjs = [ 'MSXML2.DOMDocument', 'Microsoft.XmlDom' ] ;
|
---|
86 | break ;
|
---|
87 | }
|
---|
88 |
|
---|
89 | for ( var i = 0 ; i < 2 ; i++ )
|
---|
90 | {
|
---|
91 | try { return new ActiveXObject( aObjs[i] ) ; }
|
---|
92 | catch (e)
|
---|
93 | {}
|
---|
94 | }
|
---|
95 |
|
---|
96 | if ( FCKLang.NoActiveX )
|
---|
97 | {
|
---|
98 | alert( FCKLang.NoActiveX ) ;
|
---|
99 | FCKLang.NoActiveX = null ;
|
---|
100 | }
|
---|
101 | return null ;
|
---|
102 | }
|
---|
103 |
|
---|
104 | FCKTools.DisableSelection = function( element )
|
---|
105 | {
|
---|
106 | element.unselectable = 'on' ;
|
---|
107 |
|
---|
108 | var e, i = 0 ;
|
---|
109 | // The extra () is to avoid a warning with strict error checking. This is ok.
|
---|
110 | while ( (e = element.all[ i++ ]) )
|
---|
111 | {
|
---|
112 | switch ( e.tagName )
|
---|
113 | {
|
---|
114 | case 'IFRAME' :
|
---|
115 | case 'TEXTAREA' :
|
---|
116 | case 'INPUT' :
|
---|
117 | case 'SELECT' :
|
---|
118 | /* Ignore the above tags */
|
---|
119 | break ;
|
---|
120 | default :
|
---|
121 | e.unselectable = 'on' ;
|
---|
122 | }
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | FCKTools.GetScrollPosition = function( relativeWindow )
|
---|
127 | {
|
---|
128 | var oDoc = relativeWindow.document ;
|
---|
129 |
|
---|
130 | // Try with the doc element.
|
---|
131 | var oPos = { X : oDoc.documentElement.scrollLeft, Y : oDoc.documentElement.scrollTop } ;
|
---|
132 |
|
---|
133 | if ( oPos.X > 0 || oPos.Y > 0 )
|
---|
134 | return oPos ;
|
---|
135 |
|
---|
136 | // If no scroll, try with the body.
|
---|
137 | return { X : oDoc.body.scrollLeft, Y : oDoc.body.scrollTop } ;
|
---|
138 | }
|
---|
139 |
|
---|
140 | FCKTools.AddEventListener = function( sourceObject, eventName, listener )
|
---|
141 | {
|
---|
142 | sourceObject.attachEvent( 'on' + eventName, listener ) ;
|
---|
143 | }
|
---|
144 |
|
---|
145 | FCKTools.RemoveEventListener = function( sourceObject, eventName, listener )
|
---|
146 | {
|
---|
147 | sourceObject.detachEvent( 'on' + eventName, listener ) ;
|
---|
148 | }
|
---|
149 |
|
---|
150 | // Listeners attached with this function cannot be detached.
|
---|
151 | FCKTools.AddEventListenerEx = function( sourceObject, eventName, listener, paramsArray )
|
---|
152 | {
|
---|
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 )
|
---|
158 | {
|
---|
159 | return listener.apply( o.Source, [ ev ].concat( o.Params ) ) ;
|
---|
160 | }
|
---|
161 |
|
---|
162 | if ( FCK.IECleanup )
|
---|
163 | FCK.IECleanup.AddItem( null, function() { o.Source = null ; o.Params = null ; } ) ;
|
---|
164 |
|
---|
165 | sourceObject.attachEvent( 'on' + eventName, o.Listener ) ;
|
---|
166 |
|
---|
167 | sourceObject = null ; // Memory leak cleaner (because of the above closure).
|
---|
168 | paramsArray = null ; // Memory leak cleaner (because of the above closure).
|
---|
169 | }
|
---|
170 |
|
---|
171 | // Returns and object with the "Width" and "Height" properties.
|
---|
172 | FCKTools.GetViewPaneSize = function( win )
|
---|
173 | {
|
---|
174 | var oSizeSource ;
|
---|
175 |
|
---|
176 | var oDoc = win.document.documentElement ;
|
---|
177 | if ( oDoc && oDoc.clientWidth ) // IE6 Strict Mode
|
---|
178 | oSizeSource = oDoc ;
|
---|
179 | else
|
---|
180 | oSizeSource = win.document.body ; // Other IEs
|
---|
181 |
|
---|
182 | if ( oSizeSource )
|
---|
183 | return { Width : oSizeSource.clientWidth, Height : oSizeSource.clientHeight } ;
|
---|
184 | else
|
---|
185 | return { Width : 0, Height : 0 } ;
|
---|
186 | }
|
---|
187 |
|
---|
188 | FCKTools.SaveStyles = function( element )
|
---|
189 | {
|
---|
190 | var data = FCKTools.ProtectFormStyles( element ) ;
|
---|
191 |
|
---|
192 | var oSavedStyles = new Object() ;
|
---|
193 |
|
---|
194 | if ( element.className.length > 0 )
|
---|
195 | {
|
---|
196 | oSavedStyles.Class = element.className ;
|
---|
197 | element.className = '' ;
|
---|
198 | }
|
---|
199 |
|
---|
200 | var sInlineStyle = element.style.cssText ;
|
---|
201 |
|
---|
202 | if ( sInlineStyle.length > 0 )
|
---|
203 | {
|
---|
204 | oSavedStyles.Inline = sInlineStyle ;
|
---|
205 | element.style.cssText = '' ;
|
---|
206 | }
|
---|
207 |
|
---|
208 | FCKTools.RestoreFormStyles( element, data ) ;
|
---|
209 | return oSavedStyles ;
|
---|
210 | }
|
---|
211 |
|
---|
212 | FCKTools.RestoreStyles = function( element, savedStyles )
|
---|
213 | {
|
---|
214 | var data = FCKTools.ProtectFormStyles( element ) ;
|
---|
215 | element.className = savedStyles.Class || '' ;
|
---|
216 | element.style.cssText = savedStyles.Inline || '' ;
|
---|
217 | FCKTools.RestoreFormStyles( element, data ) ;
|
---|
218 | }
|
---|
219 |
|
---|
220 | FCKTools.RegisterDollarFunction = function( targetWindow )
|
---|
221 | {
|
---|
222 | targetWindow.$ = targetWindow.document.getElementById ;
|
---|
223 | }
|
---|
224 |
|
---|
225 | FCKTools.AppendElement = function( target, elementName )
|
---|
226 | {
|
---|
227 | return target.appendChild( this.GetElementDocument( target ).createElement( elementName ) ) ;
|
---|
228 | }
|
---|
229 |
|
---|
230 | // This function may be used by Regex replacements.
|
---|
231 | FCKTools.ToLowerCase = function( strValue )
|
---|
232 | {
|
---|
233 | return strValue.toLowerCase() ;
|
---|
234 | }
|
---|