1075 |
ddelon |
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_gecko.js
|
|
|
14 |
* Utility functions. (Gecko version).
|
|
|
15 |
*
|
|
|
16 |
* File Authors:
|
|
|
17 |
* Frederico Caldeira Knabben (fredck@fckeditor.net)
|
|
|
18 |
*/
|
|
|
19 |
|
|
|
20 |
// Constant for the Gecko Bogus Node.
|
|
|
21 |
var GECKO_BOGUS = FCKBrowserInfo.IsGecko ? '<br _moz_editor_bogus_node="TRUE">' : '' ;
|
|
|
22 |
|
|
|
23 |
FCKTools.CancelEvent = function( e )
|
|
|
24 |
{
|
|
|
25 |
if ( e )
|
|
|
26 |
e.preventDefault() ;
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
FCKTools.DisableSelection = function( element )
|
|
|
30 |
{
|
|
|
31 |
if ( FCKBrowserInfo.IsGecko )
|
|
|
32 |
element.style.MozUserSelect = 'none' ; // Gecko only.
|
|
|
33 |
else
|
|
|
34 |
element.style.userSelect = 'none' ; // CSS3 (not supported yet).
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
// Appends a CSS file to a document.
|
|
|
38 |
FCKTools._AppendStyleSheet = function( documentElement, cssFileUrl )
|
|
|
39 |
{
|
|
|
40 |
var e = documentElement.createElement( 'LINK' ) ;
|
|
|
41 |
e.rel = 'stylesheet' ;
|
|
|
42 |
e.type = 'text/css' ;
|
|
|
43 |
e.href = cssFileUrl ;
|
|
|
44 |
documentElement.getElementsByTagName("HEAD")[0].appendChild( e ) ;
|
|
|
45 |
return e ;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
// Removes all attributes and values from the element.
|
|
|
49 |
FCKTools.ClearElementAttributes = function( element )
|
|
|
50 |
{
|
|
|
51 |
// Loop throw all attributes in the element
|
|
|
52 |
for ( var i = 0 ; i < element.attributes.length ; i++ )
|
|
|
53 |
{
|
|
|
54 |
// Remove the element by name.
|
|
|
55 |
element.removeAttribute( element.attributes[i].name, 0 ) ; // 0 : Case Insensitive
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
// Returns an Array of strings with all defined in the elements inside another element.
|
|
|
60 |
FCKTools.GetAllChildrenIds = function( parentElement )
|
|
|
61 |
{
|
|
|
62 |
// Create the array that will hold all Ids.
|
|
|
63 |
var aIds = new Array() ;
|
|
|
64 |
|
|
|
65 |
// Define a recursive function that search for the Ids.
|
|
|
66 |
var fGetIds = function( parent )
|
|
|
67 |
{
|
|
|
68 |
for ( var i = 0 ; i < parent.childNodes.length ; i++ )
|
|
|
69 |
{
|
|
|
70 |
var sId = parent.childNodes[i].id ;
|
|
|
71 |
|
|
|
72 |
// Check if the Id is defined for the element.
|
|
|
73 |
if ( sId && sId.length > 0 ) aIds[ aIds.length ] = sId ;
|
|
|
74 |
|
|
|
75 |
// Recursive call.
|
|
|
76 |
fGetIds( parent.childNodes[i] ) ;
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
// Start the recursive calls.
|
|
|
81 |
fGetIds( parentElement ) ;
|
|
|
82 |
|
|
|
83 |
return aIds ;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
FCKTools.RemoveOuterTags = function( e )
|
|
|
87 |
{
|
|
|
88 |
var oFragment = e.ownerDocument.createDocumentFragment() ;
|
|
|
89 |
|
|
|
90 |
for ( var i = 0 ; i < e.childNodes.length ; i++ )
|
|
|
91 |
oFragment.appendChild( e.childNodes[i] ) ;
|
|
|
92 |
|
|
|
93 |
e.parentNode.replaceChild( oFragment, e ) ;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
FCKTools.CreateXmlObject = function( object )
|
|
|
97 |
{
|
|
|
98 |
switch ( object )
|
|
|
99 |
{
|
|
|
100 |
case 'XmlHttp' :
|
|
|
101 |
return new XMLHttpRequest() ;
|
|
|
102 |
case 'DOMDocument' :
|
|
|
103 |
return document.implementation.createDocument( '', '', null ) ;
|
|
|
104 |
}
|
|
|
105 |
return null ;
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
FCKTools.GetScrollPosition = function( relativeWindow )
|
|
|
109 |
{
|
|
|
110 |
return { X : relativeWindow.pageXOffset, Y : relativeWindow.pageYOffset } ;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
FCKTools.AddEventListener = function( sourceObject, eventName, listener )
|
|
|
114 |
{
|
|
|
115 |
sourceObject.addEventListener( eventName, listener, false ) ;
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
FCKTools.RemoveEventListener = function( sourceObject, eventName, listener )
|
|
|
119 |
{
|
|
|
120 |
sourceObject.removeEventListener( eventName, listener, false ) ;
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
// Listeners attached with this function cannot be detached.
|
|
|
124 |
FCKTools.AddEventListenerEx = function( sourceObject, eventName, listener, paramsArray )
|
|
|
125 |
{
|
|
|
126 |
sourceObject.addEventListener(
|
|
|
127 |
eventName,
|
|
|
128 |
function( e )
|
|
|
129 |
{
|
|
|
130 |
listener.apply( sourceObject, [ e ].concat( paramsArray || [] ) ) ;
|
|
|
131 |
},
|
|
|
132 |
false
|
|
|
133 |
) ;
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
// Returns and object with the "Width" and "Height" properties.
|
|
|
137 |
FCKTools.GetViewPaneSize = function( win )
|
|
|
138 |
{
|
|
|
139 |
return { Width : win.innerWidth, Height : win.innerHeight } ;
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
FCKTools.SaveStyles = function( element )
|
|
|
143 |
{
|
|
|
144 |
var oSavedStyles = new Object() ;
|
|
|
145 |
|
|
|
146 |
if ( element.className.length > 0 )
|
|
|
147 |
{
|
|
|
148 |
oSavedStyles.Class = element.className ;
|
|
|
149 |
element.className = '' ;
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
var sInlineStyle = element.getAttribute( 'style' ) ;
|
|
|
153 |
|
|
|
154 |
if ( sInlineStyle && sInlineStyle.length > 0 )
|
|
|
155 |
{
|
|
|
156 |
oSavedStyles.Inline = sInlineStyle ;
|
|
|
157 |
element.setAttribute( 'style', '', 0 ) ; // 0 : Case Insensitive
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
return oSavedStyles ;
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
FCKTools.RestoreStyles = function( element, savedStyles )
|
|
|
164 |
{
|
|
|
165 |
element.className = savedStyles.Class || '' ;
|
|
|
166 |
|
|
|
167 |
if ( savedStyles.Inline )
|
|
|
168 |
element.setAttribute( 'style', savedStyles.Inline, 0 ) ; // 0 : Case Insensitive
|
|
|
169 |
else
|
|
|
170 |
element.removeAttribute( 'style', 0 ) ;
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
FCKTools.RegisterDollarFunction = function( targetWindow )
|
|
|
174 |
{
|
|
|
175 |
targetWindow.$ = function( id )
|
|
|
176 |
{
|
|
|
177 |
return this.document.getElementById( id ) ;
|
|
|
178 |
} ;
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
FCKTools.AppendElement = function( target, elementName )
|
|
|
182 |
{
|
|
|
183 |
return target.appendChild( target.ownerDocument.createElement( elementName ) ) ;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
// Get the coordinates of an element.
|
|
|
187 |
// @el : The element to get the position.
|
|
|
188 |
// @relativeWindow: The window to which we want the coordinates relative to.
|
|
|
189 |
FCKTools.GetElementPosition = function( el, relativeWindow )
|
|
|
190 |
{
|
|
|
191 |
// Initializes the Coordinates object that will be returned by the function.
|
|
|
192 |
var c = { X:0, Y:0 } ;
|
|
|
193 |
|
|
|
194 |
var oWindow = relativeWindow || window ;
|
|
|
195 |
|
|
|
196 |
var oOwnerWindow = FCKTools.GetElementWindow( el ) ;
|
|
|
197 |
|
|
|
198 |
// Loop throw the offset chain.
|
|
|
199 |
while ( el )
|
|
|
200 |
{
|
|
|
201 |
var sPosition = oOwnerWindow.getComputedStyle(el, '').position ;
|
|
|
202 |
|
|
|
203 |
// Check for non "static" elements.
|
|
|
204 |
// 'FCKConfig.FloatingPanelsZIndex' -- Submenus are under a positioned IFRAME.
|
|
|
205 |
if ( sPosition && sPosition != 'static' && el.style.zIndex != FCKConfig.FloatingPanelsZIndex )
|
|
|
206 |
break ;
|
|
|
207 |
|
|
|
208 |
c.X += el.offsetLeft - el.scrollLeft ;
|
|
|
209 |
c.Y += el.offsetTop - el.scrollTop ;
|
|
|
210 |
|
|
|
211 |
if ( el.offsetParent )
|
|
|
212 |
el = el.offsetParent ;
|
|
|
213 |
else
|
|
|
214 |
{
|
|
|
215 |
if ( oOwnerWindow != oWindow )
|
|
|
216 |
{
|
|
|
217 |
if ( el = oOwnerWindow.frameElement )
|
|
|
218 |
oOwnerWindow = FCKTools.GetElementWindow( el ) ;
|
|
|
219 |
}
|
|
|
220 |
else
|
|
|
221 |
{
|
|
|
222 |
c.X += el.scrollLeft ;
|
|
|
223 |
c.Y += el.scrollTop ;
|
|
|
224 |
break ;
|
|
|
225 |
}
|
|
|
226 |
}
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
// Return the Coordinates object
|
|
|
230 |
return c ;
|
|
|
231 |
}
|