source: trunk/admin/inc/FCKeditor/editor/_source/internals/fcktools.js@ 2

Last change on this file since 2 was 2, checked in by root, 15 years ago

importo il progetto

File size: 6.5 KB
Line 
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.js
14 * Utility functions.
15 *
16 * File Authors:
17 * Frederico Caldeira Knabben (fredck@fckeditor.net)
18 */
19
20var FCKTools = new Object() ;
21
22FCKTools.AppendStyleSheet = function( documentElement, cssFileUrlOrArray )
23{
24 if ( typeof( cssFileUrlOrArray ) == 'string' )
25 return this._AppendStyleSheet( documentElement, cssFileUrlOrArray ) ;
26 else
27 {
28 for ( var i = 0 ; i < cssFileUrlOrArray.length ; i++ )
29 this._AppendStyleSheet( documentElement, cssFileUrlOrArray[i] ) ;
30 }
31}
32
33/**
34 * Gets the value of the hidden INPUT element that is associated to the editor.
35 * This element has its ID set to the editor's instance name so the user refers
36 * to the instance name when getting the posted data.
37 */
38FCKTools.GetLinkedFieldValue = function()
39{
40 return FCK.LinkedField.value ;
41}
42
43/**
44 * Attachs a function call to the submit event of the linked field form. This
45 * function us generally used to update the linked field value before
46 * submitting the form.
47 */
48FCKTools.AttachToLinkedFieldFormSubmit = function( functionPointer )
49{
50 // Gets the linked field form
51 var oForm = FCK.LinkedField.form ;
52
53 // Return now if no form is available
54 if (!oForm) return ;
55
56 // Attaches the functionPointer call to the onsubmit event
57 if ( FCKBrowserInfo.IsIE )
58 oForm.attachEvent( "onsubmit", functionPointer ) ;
59 else
60 oForm.addEventListener( 'submit', functionPointer, false ) ;
61
62 //**
63 // Attaches the functionPointer call to the submit method
64 // This is done because IE doesn't fire onsubmit when the submit method is called
65 // BEGIN --
66
67 // Creates a Array in the form object that will hold all Attached function call
68 // (in the case there are more than one editor in the same page)
69 if (! oForm.updateFCKeditor) oForm.updateFCKeditor = new Array() ;
70
71 // Adds the function pointer to the array of functions to call when "submit" is called
72 oForm.updateFCKeditor[oForm.updateFCKeditor.length] = functionPointer ;
73
74 // Switches the original submit method with a new one that first call all functions
75 // on the above array and the call the original submit
76 // IE sees it oForm.submit function as an 'object'.
77 if (! oForm.originalSubmit && ( typeof( oForm.submit ) == 'function' || ( !oForm.submit.tagName && !oForm.submit.length ) ) )
78 {
79 // Creates a copy of the original submit
80 oForm.originalSubmit = oForm.submit ;
81
82 // Creates our replacement for the submit
83 oForm.submit = FCKTools_SubmitReplacer ;
84 }
85 // END --
86}
87
88function FCKTools_SubmitReplacer()
89{
90 if (this.updateFCKeditor)
91 {
92 // Calls all functions in the functions array
93 for (var i = 0 ; i < this.updateFCKeditor.length ; i++)
94 this.updateFCKeditor[i]() ;
95 }
96 // Calls the original "submit"
97 this.originalSubmit() ;
98}
99
100// Get the window object where the element is placed in.
101FCKTools.GetElementWindow = function( element )
102{
103 return this.GetDocumentWindow( this.GetElementDocument( element ) ) ;
104}
105
106FCKTools.GetDocumentWindow = function( doc )
107{
108 // With Safari, there is not way to retrieve the window from the document, so we must fix it.
109 if ( FCKBrowserInfo.IsSafari && !doc.parentWindow )
110 this.FixDocumentParentWindow( window.top ) ;
111
112 return doc.parentWindow || doc.defaultView ;
113}
114
115/*
116 This is a Safari specific function that fix the reference to the parent
117 window from the document object.
118*/
119FCKTools.FixDocumentParentWindow = function( targetWindow )
120{
121 targetWindow.document.parentWindow = targetWindow ;
122
123 for ( var i = 0 ; i < targetWindow.frames.length ; i++ )
124 FCKTools.FixDocumentParentWindow( targetWindow.frames[i] ) ;
125}
126
127FCKTools.GetParentWindow = function( document )
128{
129 return document.contentWindow ? document.contentWindow : document.parentWindow ;
130}
131
132FCKTools.HTMLEncode = function( text )
133{
134 if ( !text )
135 return '' ;
136
137 text = text.replace( /&/g, '&amp;' ) ;
138 text = text.replace( /</g, '&lt;' ) ;
139 text = text.replace( />/g, '&gt;' ) ;
140
141 return text ;
142}
143
144/**
145 * Adds an option to a SELECT element.
146 */
147FCKTools.AddSelectOption = function( selectElement, optionText, optionValue )
148{
149 var oOption = FCKTools.GetElementDocument( selectElement ).createElement( "OPTION" ) ;
150
151 oOption.text = optionText ;
152 oOption.value = optionValue ;
153
154 selectElement.options.add(oOption) ;
155
156 return oOption ;
157}
158
159FCKTools.RunFunction = function( func, thisObject, paramsArray, timerWindow )
160{
161 if ( func )
162 this.SetTimeout( func, 0, thisObject, paramsArray, timerWindow ) ;
163}
164
165FCKTools.SetTimeout = function( func, milliseconds, thisObject, paramsArray, timerWindow )
166{
167 return ( timerWindow || window ).setTimeout(
168 function()
169 {
170 if ( paramsArray )
171 func.apply( thisObject, [].concat( paramsArray ) ) ;
172 else
173 func.apply( thisObject ) ;
174 },
175 milliseconds ) ;
176}
177
178FCKTools.SetInterval = function( func, milliseconds, thisObject, paramsArray, timerWindow )
179{
180 return ( timerWindow || window ).setInterval(
181 function()
182 {
183 func.apply( thisObject, paramsArray || [] ) ;
184 },
185 milliseconds ) ;
186}
187
188FCKTools.ConvertStyleSizeToHtml = function( size )
189{
190 return size.endsWith( '%' ) ? size : parseInt( size ) ;
191}
192
193FCKTools.ConvertHtmlSizeToStyle = function( size )
194{
195 return size.endsWith( '%' ) ? size : ( size + 'px' ) ;
196}
197
198// START iCM MODIFICATIONS
199// Amended to accept a list of one or more ascensor tag names
200// Amended to check the element itself before working back up through the parent hierarchy
201FCKTools.GetElementAscensor = function( element, ascensorTagNames )
202{
203// var e = element.parentNode ;
204 var e = element ;
205 var lstTags = "," + ascensorTagNames.toUpperCase() + "," ;
206
207 while ( e )
208 {
209 if ( lstTags.indexOf( "," + e.nodeName.toUpperCase() + "," ) != -1 )
210 return e ;
211
212 e = e.parentNode ;
213 }
214 return null ;
215}
216// END iCM MODIFICATIONS
217
218FCKTools.CreateEventListener = function( func, params )
219{
220 var f = function()
221 {
222 var aAllParams = [] ;
223
224 for ( var i = 0 ; i < arguments.length ; i++ )
225 aAllParams.push( arguments[i] ) ;
226
227 func.apply( this, aAllParams.concat( params ) ) ;
228 }
229
230 return f ;
231}
232
233FCKTools.GetElementDocument = function ( element )
234{
235 return element.ownerDocument || element.document ;
236}
Note: See TracBrowser for help on using the repository browser.