source: branches/1.2/workflow/js/fckeditor/editor/_source/internals/fcktools.js @ 1349

Revision 1349, 5.6 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

  • Property svn:executable set to *
Line 
1/*
2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3 * Copyright (C) 2003-2007 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.
22 */
23
24// Constant for the Gecko Bogus Node.
25//var GECKO_BOGUS = '<br _moz_editor_bogus_node="TRUE">' ;
26var GECKO_BOGUS = '<br type="_moz">' ;
27
28var FCKTools = new Object() ;
29
30FCKTools.CreateBogusBR = function( targetDocument )
31{
32        var eBR = targetDocument.createElement( 'br' ) ;
33//      eBR.setAttribute( '_moz_editor_bogus_node', 'TRUE' ) ;
34        eBR.setAttribute( 'type', '_moz' ) ;
35        return eBR ;
36}
37
38// Returns a reference to the appended style sheet or an array with all the appended references
39FCKTools.AppendStyleSheet = function( documentElement, cssFileUrlOrArray )
40{
41        if ( typeof( cssFileUrlOrArray ) == 'string' )
42                return this._AppendStyleSheet( documentElement, cssFileUrlOrArray ) ;
43        else
44        {
45                var aStyleSheeArray = new Array() ;
46
47                for ( var i = 0 ; i < cssFileUrlOrArray.length ; i++ )
48                        aStyleSheeArray.push(this._AppendStyleSheet( documentElement, cssFileUrlOrArray[i] ) ) ;
49
50                return aStyleSheeArray ;
51        }
52}
53
54FCKTools.GetElementDocument = function ( element )
55{
56        return element.ownerDocument || element.document ;
57}
58
59// Get the window object where the element is placed in.
60FCKTools.GetElementWindow = function( element )
61{
62        return this.GetDocumentWindow( this.GetElementDocument( element ) ) ;
63}
64
65FCKTools.GetDocumentWindow = function( document )
66{
67        // With Safari, there is not way to retrieve the window from the document, so we must fix it.
68        if ( FCKBrowserInfo.IsSafari && !document.parentWindow )
69                this.FixDocumentParentWindow( window.top ) ;
70
71        return document.parentWindow || document.defaultView ;
72}
73
74/*
75        This is a Safari specific function that fix the reference to the parent
76        window from the document object.
77*/
78FCKTools.FixDocumentParentWindow = function( targetWindow )
79{
80        targetWindow.document.parentWindow = targetWindow ;
81
82        for ( var i = 0 ; i < targetWindow.frames.length ; i++ )
83                FCKTools.FixDocumentParentWindow( targetWindow.frames[i] ) ;
84}
85
86FCKTools.HTMLEncode = function( text )
87{
88        if ( !text )
89                return '' ;
90
91        text = text.replace( /&/g, '&amp;' ) ;
92        text = text.replace( /</g, '&lt;' ) ;
93        text = text.replace( />/g, '&gt;' ) ;
94
95        return text ;
96}
97
98FCKTools.HTMLDecode = function( text )
99{
100        if ( !text )
101                return '' ;
102
103        text = text.replace( /&gt;/g, '>' ) ;
104        text = text.replace( /&lt;/g, '<' ) ;
105        text = text.replace( /&amp;/g, '&' ) ;
106
107        return text ;
108}
109
110/**
111 * Adds an option to a SELECT element.
112 */
113FCKTools.AddSelectOption = function( selectElement, optionText, optionValue )
114{
115        var oOption = FCKTools.GetElementDocument( selectElement ).createElement( "OPTION" ) ;
116
117        oOption.text    = optionText ;
118        oOption.value   = optionValue ;
119
120        selectElement.options.add(oOption) ;
121
122        return oOption ;
123}
124
125FCKTools.RunFunction = function( func, thisObject, paramsArray, timerWindow )
126{
127        if ( func )
128                this.SetTimeout( func, 0, thisObject, paramsArray, timerWindow ) ;
129}
130
131FCKTools.SetTimeout = function( func, milliseconds, thisObject, paramsArray, timerWindow )
132{
133        return ( timerWindow || window ).setTimeout(
134                function()
135                {
136                        if ( paramsArray )
137                                func.apply( thisObject, [].concat( paramsArray ) ) ;
138                        else
139                                func.apply( thisObject ) ;
140                },
141                milliseconds ) ;
142}
143
144FCKTools.SetInterval = function( func, milliseconds, thisObject, paramsArray, timerWindow )
145{
146        return ( timerWindow || window ).setInterval(
147                function()
148                {
149                        func.apply( thisObject, paramsArray || [] ) ;
150                },
151                milliseconds ) ;
152}
153
154FCKTools.ConvertStyleSizeToHtml = function( size )
155{
156        return size.EndsWith( '%' ) ? size : parseInt( size, 10 ) ;
157}
158
159FCKTools.ConvertHtmlSizeToStyle = function( size )
160{
161        return size.EndsWith( '%' ) ? size : ( size + 'px' ) ;
162}
163
164// START iCM MODIFICATIONS
165// Amended to accept a list of one or more ascensor tag names
166// Amended to check the element itself before working back up through the parent hierarchy
167FCKTools.GetElementAscensor = function( element, ascensorTagNames )
168{
169//      var e = element.parentNode ;
170        var e = element ;
171        var lstTags = "," + ascensorTagNames.toUpperCase() + "," ;
172
173        while ( e )
174        {
175                if ( lstTags.indexOf( "," + e.nodeName.toUpperCase() + "," ) != -1 )
176                        return e ;
177
178                e = e.parentNode ;
179        }
180        return null ;
181}
182// END iCM MODIFICATIONS
183
184FCKTools.CreateEventListener = function( func, params )
185{
186        var f = function()
187        {
188                var aAllParams = [] ;
189
190                for ( var i = 0 ; i < arguments.length ; i++ )
191                        aAllParams.push( arguments[i] ) ;
192
193                func.apply( this, aAllParams.concat( params ) ) ;
194        }
195
196        return f ;
197}
198
199FCKTools.IsStrictMode = function( document )
200{
201        // There is no compatMode in Safari, but it seams that it always behave as
202        // CSS1Compat, so let's assume it as the default.
203        return ( 'CSS1Compat' == ( document.compatMode || 'CSS1Compat' ) ) ;
204}
205
206// Transforms a "arguments" object to an array.
207FCKTools.ArgumentsToArray = function( args, startIndex, maxLength )
208{
209        startIndex = startIndex || 0 ;
210        maxLength = maxLength || args.length ;
211
212        var argsArray = new Array() ;
213
214        for ( var i = startIndex ; i < startIndex + maxLength && i < args.length ; i++ )
215                argsArray.push( args[i] ) ;
216
217        return argsArray ;
218}
219
220FCKTools.CloneObject = function( sourceObject )
221{
222        var fCloneCreator = function() {} ;
223        fCloneCreator.prototype = sourceObject ;
224        return new fCloneCreator ;
225}
Note: See TracBrowser for help on using the repository browser.