1 | /* |
---|
2 | * FCKeditor - The text editor for internet |
---|
3 | * Copyright (C) 2003-2006 Frederico Caldeira Knabben |
---|
4 | * |
---|
5 | * Licensed under the terms of the GNU Lesser General Public License: |
---|
6 | * http://www.opensource.org/licenses/lgpl-license.php |
---|
7 | * |
---|
8 | * For further information visit: |
---|
9 | * http://www.fckeditor.net/ |
---|
10 | * |
---|
11 | * "Support Open Source software. What about a donation today?" |
---|
12 | * |
---|
13 | * File Name: fcktools_ie.js |
---|
14 | * Utility functions. (IE version). |
---|
15 | * |
---|
16 | * File Authors: |
---|
17 | * Frederico Caldeira Knabben (fredck@fckeditor.net) |
---|
18 | */ |
---|
19 | |
---|
20 | FCKTools.CancelEvent = function( e ) |
---|
21 | { |
---|
22 | return false ; |
---|
23 | } |
---|
24 | |
---|
25 | // Appends one or more CSS files to a document. |
---|
26 | FCKTools._AppendStyleSheet = function( documentElement, cssFileUrl ) |
---|
27 | { |
---|
28 | return documentElement.createStyleSheet( cssFileUrl ).owningElement ; |
---|
29 | } |
---|
30 | |
---|
31 | // Removes all attributes and values from the element. |
---|
32 | FCKTools.ClearElementAttributes = function( element ) |
---|
33 | { |
---|
34 | element.clearAttributes() ; |
---|
35 | } |
---|
36 | |
---|
37 | FCKTools.GetAllChildrenIds = function( parentElement ) |
---|
38 | { |
---|
39 | var aIds = new Array() ; |
---|
40 | for ( var i = 0 ; i < parentElement.all.length ; i++ ) |
---|
41 | { |
---|
42 | var sId = parentElement.all[i].id ; |
---|
43 | if ( sId && sId.length > 0 ) |
---|
44 | aIds[ aIds.length ] = sId ; |
---|
45 | } |
---|
46 | return aIds ; |
---|
47 | } |
---|
48 | |
---|
49 | FCKTools.RemoveOuterTags = function( e ) |
---|
50 | { |
---|
51 | e.insertAdjacentHTML( 'beforeBegin', e.innerHTML ) ; |
---|
52 | e.parentNode.removeChild( e ) ; |
---|
53 | } |
---|
54 | |
---|
55 | FCKTools.CreateXmlObject = function( object ) |
---|
56 | { |
---|
57 | var aObjs ; |
---|
58 | |
---|
59 | switch ( object ) |
---|
60 | { |
---|
61 | case 'XmlHttp' : |
---|
62 | aObjs = [ 'MSXML2.XmlHttp', 'Microsoft.XmlHttp' ] ; |
---|
63 | break ; |
---|
64 | |
---|
65 | case 'DOMDocument' : |
---|
66 | aObjs = [ 'MSXML2.DOMDocument', 'Microsoft.XmlDom' ] ; |
---|
67 | break ; |
---|
68 | } |
---|
69 | |
---|
70 | for ( var i = 0 ; i < 2 ; i++ ) |
---|
71 | { |
---|
72 | try { return new ActiveXObject( aObjs[i] ) ; } |
---|
73 | catch (e) |
---|
74 | {} |
---|
75 | } |
---|
76 | |
---|
77 | if ( FCKLang.NoActiveX ) |
---|
78 | { |
---|
79 | alert( FCKLang.NoActiveX ) ; |
---|
80 | FCKLang.NoActiveX = null ; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | FCKTools.DisableSelection = function( element ) |
---|
85 | { |
---|
86 | element.unselectable = 'on' ; |
---|
87 | |
---|
88 | var e, i = 0 ; |
---|
89 | while ( e = element.all[ i++ ] ) |
---|
90 | { |
---|
91 | switch ( e.tagName ) |
---|
92 | { |
---|
93 | case 'IFRAME' : |
---|
94 | case 'TEXTAREA' : |
---|
95 | case 'INPUT' : |
---|
96 | case 'SELECT' : |
---|
97 | /* Ignore the above tags */ |
---|
98 | break ; |
---|
99 | default : |
---|
100 | e.unselectable = 'on' ; |
---|
101 | } |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | FCKTools.GetScrollPosition = function( relativeWindow ) |
---|
106 | { |
---|
107 | var oDoc = relativeWindow.document ; |
---|
108 | |
---|
109 | // Try with the doc element. |
---|
110 | var oPos = { X : oDoc.documentElement.scrollLeft, Y : oDoc.documentElement.scrollTop } ; |
---|
111 | |
---|
112 | if ( oPos.X > 0 || oPos.Y > 0 ) |
---|
113 | return oPos ; |
---|
114 | |
---|
115 | // If no scroll, try with the body. |
---|
116 | return { X : oDoc.body.scrollLeft, Y : oDoc.body.scrollTop } ; |
---|
117 | } |
---|
118 | |
---|
119 | FCKTools.AddEventListener = function( sourceObject, eventName, listener ) |
---|
120 | { |
---|
121 | sourceObject.attachEvent( 'on' + eventName, listener ) ; |
---|
122 | } |
---|
123 | |
---|
124 | FCKTools.RemoveEventListener = function( sourceObject, eventName, listener ) |
---|
125 | { |
---|
126 | sourceObject.detachEvent( 'on' + eventName, listener ) ; |
---|
127 | } |
---|
128 | |
---|
129 | // Listeners attached with this function cannot be detached. |
---|
130 | FCKTools.AddEventListenerEx = function( sourceObject, eventName, listener, paramsArray ) |
---|
131 | { |
---|
132 | // Ok... this is a closures party, but is the only way to make it clean of memory leaks. |
---|
133 | var o = new Object() ; |
---|
134 | o.Source = sourceObject ; |
---|
135 | o.Params = paramsArray || [] ; // Memory leak if we have DOM objects here. |
---|
136 | o.Listener = function( ev ) |
---|
137 | { |
---|
138 | return listener.apply( o.Source, [ ev ].concat( o.Params ) ) ; |
---|
139 | } |
---|
140 | |
---|
141 | if ( FCK.IECleanup ) |
---|
142 | FCK.IECleanup.AddItem( null, function() { o.Source = null ; o.Params = null ; } ) ; |
---|
143 | |
---|
144 | sourceObject.attachEvent( 'on' + eventName, o.Listener ) ; |
---|
145 | |
---|
146 | sourceObject = null ; // Memory leak cleaner (because of the above closure). |
---|
147 | paramsArray = null ; // Memory leak cleaner (because of the above closure). |
---|
148 | } |
---|
149 | |
---|
150 | // Returns and object with the "Width" and "Height" properties. |
---|
151 | FCKTools.GetViewPaneSize = function( win ) |
---|
152 | { |
---|
153 | var oSizeSource ; |
---|
154 | |
---|
155 | var oDoc = win.document.documentElement ; |
---|
156 | if ( oDoc && oDoc.clientWidth ) // IE6 Strict Mode |
---|
157 | oSizeSource = oDoc ; |
---|
158 | else |
---|
159 | oSizeSource = top.document.body ; // Other IEs |
---|
160 | |
---|
161 | if ( oSizeSource ) |
---|
162 | return { Width : oSizeSource.clientWidth, Height : oSizeSource.clientHeight } ; |
---|
163 | else |
---|
164 | return { Width : 0, Height : 0 } ; |
---|
165 | } |
---|
166 | |
---|
167 | FCKTools.SaveStyles = function( element ) |
---|
168 | { |
---|
169 | var oSavedStyles = new Object() ; |
---|
170 | |
---|
171 | if ( element.className.length > 0 ) |
---|
172 | { |
---|
173 | oSavedStyles.Class = element.className ; |
---|
174 | element.className = '' ; |
---|
175 | } |
---|
176 | |
---|
177 | var sInlineStyle = element.style.cssText ; |
---|
178 | |
---|
179 | if ( sInlineStyle.length > 0 ) |
---|
180 | { |
---|
181 | oSavedStyles.Inline = sInlineStyle ; |
---|
182 | element.style.cssText = '' ; |
---|
183 | } |
---|
184 | |
---|
185 | return oSavedStyles ; |
---|
186 | } |
---|
187 | |
---|
188 | FCKTools.RestoreStyles = function( element, savedStyles ) |
---|
189 | { |
---|
190 | element.className = savedStyles.Class || '' ; |
---|
191 | element.style.cssText = savedStyles.Inline || '' ; |
---|
192 | } |
---|
193 | |
---|
194 | FCKTools.RegisterDollarFunction = function( targetWindow ) |
---|
195 | { |
---|
196 | targetWindow.$ = targetWindow.document.getElementById ; |
---|
197 | } |
---|
198 | |
---|
199 | FCKTools.AppendElement = function( target, elementName ) |
---|
200 | { |
---|
201 | return target.appendChild( this.GetElementDocument( target ).createElement( elementName ) ) ; |
---|
202 | } |
---|