source: sandbox/filemanager/tp/fckeditor/editor/_source/internals/fckconfig.js @ 1575

Revision 1575, 7.7 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Implentação, melhorias do modulo gerenciador de arquivos

  • Property svn:executable set to *
Line 
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 * Creates and initializes the FCKConfig object.
22 */
23
24var FCKConfig = FCK.Config = new Object() ;
25
26/*
27        For the next major version (probably 3.0) we should move all this stuff to
28        another dedicated object and leave FCKConfig as a holder object for settings only).
29*/
30
31// Editor Base Path
32if ( document.location.protocol == 'file:' )
33{
34        FCKConfig.BasePath = decodeURIComponent( document.location.pathname.substr(1) ) ;
35        FCKConfig.BasePath = FCKConfig.BasePath.replace( /\\/gi, '/' ) ;
36
37        // The way to address local files is different according to the OS.
38        // In Windows it is file:// but in MacOs it is file:/// so let's get it automatically
39        var sFullProtocol = document.location.href.match( /^(file\:\/{2,3})/ )[1] ;
40        // #945 Opera does strange things with files loaded from the disk, and it fails in Mac to load xml files
41        if ( FCKBrowserInfo.IsOpera )
42                sFullProtocol += 'localhost/' ;
43
44        FCKConfig.BasePath = sFullProtocol + FCKConfig.BasePath.substring( 0, FCKConfig.BasePath.lastIndexOf( '/' ) + 1) ;
45}
46else
47        FCKConfig.BasePath = document.location.protocol + '//' + document.location.host +
48                document.location.pathname.substring( 0, document.location.pathname.lastIndexOf( '/' ) + 1) ;
49
50FCKConfig.FullBasePath = FCKConfig.BasePath ;
51
52FCKConfig.EditorPath = FCKConfig.BasePath.replace( /editor\/$/, '' ) ;
53
54// There is a bug in Gecko. If the editor is hidden on startup, an error is
55// thrown when trying to get the screen dimensions.
56try
57{
58        FCKConfig.ScreenWidth   = screen.width ;
59        FCKConfig.ScreenHeight  = screen.height ;
60}
61catch (e)
62{
63        FCKConfig.ScreenWidth   = 800 ;
64        FCKConfig.ScreenHeight  = 600 ;
65}
66
67// Override the actual configuration values with the values passed throw the
68// hidden field "<InstanceName>___Config".
69FCKConfig.ProcessHiddenField = function()
70{
71        this.PageConfig = new Object() ;
72
73        // Get the hidden field.
74        var oConfigField = window.parent.document.getElementById( FCK.Name + '___Config' ) ;
75
76        // Do nothing if the config field was not defined.
77        if ( ! oConfigField ) return ;
78
79        var aCouples = oConfigField.value.split('&') ;
80
81        for ( var i = 0 ; i < aCouples.length ; i++ )
82        {
83                if ( aCouples[i].length == 0 )
84                        continue ;
85
86                var aConfig = aCouples[i].split( '=' ) ;
87                var sKey = decodeURIComponent( aConfig[0] ) ;
88                var sVal = decodeURIComponent( aConfig[1] ) ;
89
90                if ( sKey == 'CustomConfigurationsPath' )       // The Custom Config File path must be loaded immediately.
91                        FCKConfig[ sKey ] = sVal ;
92
93                else if ( sVal.toLowerCase() == "true" )        // If it is a boolean TRUE.
94                        this.PageConfig[ sKey ] = true ;
95
96                else if ( sVal.toLowerCase() == "false" )       // If it is a boolean FALSE.
97                        this.PageConfig[ sKey ] = false ;
98
99                else if ( sVal.length > 0 && !isNaN( sVal ) )   // If it is a number.
100                        this.PageConfig[ sKey ] = parseFloat( sVal ) ;
101
102                else                                                                            // In any other case it is a string.
103                        this.PageConfig[ sKey ] = sVal ;
104        }
105}
106
107function FCKConfig_LoadPageConfig()
108{
109        var oPageConfig = FCKConfig.PageConfig ;
110        for ( var sKey in oPageConfig )
111                FCKConfig[ sKey ] = oPageConfig[ sKey ] ;
112}
113
114function FCKConfig_PreProcess()
115{
116        var oConfig = FCKConfig ;
117
118        // Force debug mode if fckdebug=true in the QueryString (main page).
119        if ( oConfig.AllowQueryStringDebug )
120        {
121                try
122                {
123                        if ( (/fckdebug=true/i).test( window.top.location.search ) )
124                                oConfig.Debug = true ;
125                }
126                catch (e) { /* Ignore it. Much probably we are inside a FRAME where the "top" is in another domain (security error). */ }
127        }
128
129        // Certifies that the "PluginsPath" configuration ends with a slash.
130        if ( !oConfig.PluginsPath.EndsWith('/') )
131                oConfig.PluginsPath += '/' ;
132
133        // If no ToolbarComboPreviewCSS, point it to EditorAreaCSS.
134        var sComboPreviewCSS = oConfig.ToolbarComboPreviewCSS ;
135        if ( !sComboPreviewCSS || sComboPreviewCSS.length == 0 )
136                oConfig.ToolbarComboPreviewCSS = oConfig.EditorAreaCSS ;
137
138        // Turn the attributes that will be removed in the RemoveFormat from a string to an array
139        oConfig.RemoveAttributesArray = (oConfig.RemoveAttributes || '').split( ',' );
140
141        if ( !FCKConfig.SkinEditorCSS || FCKConfig.SkinEditorCSS.length == 0 )
142                FCKConfig.SkinEditorCSS = FCKConfig.SkinPath + 'fck_editor.css' ;
143
144        if ( !FCKConfig.SkinDialogCSS || FCKConfig.SkinDialogCSS.length == 0 )
145                FCKConfig.SkinDialogCSS = FCKConfig.SkinPath + 'fck_dialog.css' ;
146}
147
148// Define toolbar sets collection.
149FCKConfig.ToolbarSets = new Object() ;
150
151// Defines the plugins collection.
152FCKConfig.Plugins = new Object() ;
153FCKConfig.Plugins.Items = new Array() ;
154
155FCKConfig.Plugins.Add = function( name, langs, path )
156{
157        FCKConfig.Plugins.Items.push( [name, langs, path] ) ;
158}
159
160// FCKConfig.ProtectedSource: object that holds a collection of Regular
161// Expressions that defined parts of the raw HTML that must remain untouched
162// like custom tags, scripts, server side code, etc...
163FCKConfig.ProtectedSource = new Object() ;
164
165// Generates a string used to identify and locate the Protected Tags comments.
166FCKConfig.ProtectedSource._CodeTag = (new Date()).valueOf() ;
167
168// Initialize the regex array with the default ones.
169FCKConfig.ProtectedSource.RegexEntries = [
170        // First of any other protection, we must protect all comments to avoid
171        // loosing them (of course, IE related).
172        /<!--[\s\S]*?-->/g ,
173
174        // Script tags will also be forced to be protected, otherwise IE will execute them.
175        /<script[\s\S]*?<\/script>/gi,
176
177        // <noscript> tags (get lost in IE and messed up in FF).
178        /<noscript[\s\S]*?<\/noscript>/gi
179] ;
180
181FCKConfig.ProtectedSource.Add = function( regexPattern )
182{
183        this.RegexEntries.push( regexPattern ) ;
184}
185
186FCKConfig.ProtectedSource.Protect = function( html )
187{
188        var codeTag = this._CodeTag ;
189        function _Replace( protectedSource )
190        {
191                var index = FCKTempBin.AddElement( protectedSource ) ;
192                return '<!--{' + codeTag + index + '}-->' ;
193        }
194
195        for ( var i = 0 ; i < this.RegexEntries.length ; i++ )
196        {
197                html = html.replace( this.RegexEntries[i], _Replace ) ;
198        }
199
200        return html ;
201}
202
203FCKConfig.ProtectedSource.Revert = function( html, clearBin )
204{
205        function _Replace( m, opener, index )
206        {
207                var protectedValue = clearBin ? FCKTempBin.RemoveElement( index ) : FCKTempBin.Elements[ index ] ;
208                // There could be protected source inside another one.
209                return FCKConfig.ProtectedSource.Revert( protectedValue, clearBin ) ;
210        }
211
212        var regex = new RegExp( "(<|&lt;)!--\\{" + this._CodeTag + "(\\d+)\\}--(>|&gt;)", "g" ) ;
213        return html.replace( regex, _Replace ) ;
214}
215
216// Returns a string with the attributes that must be appended to the body
217FCKConfig.GetBodyAttributes = function()
218{
219        var bodyAttributes = '' ;
220        // Add id and class to the body.
221        if ( this.BodyId && this.BodyId.length > 0 )
222                bodyAttributes += ' id="' + this.BodyId + '"' ;
223        if ( this.BodyClass && this.BodyClass.length > 0 )
224                bodyAttributes += ' class="' + this.BodyClass + '"' ;
225
226        return bodyAttributes ;
227}
228
229// Sets the body attributes directly on the node
230FCKConfig.ApplyBodyAttributes = function( oBody )
231{
232        // Add ID and Class to the body
233        if ( this.BodyId && this.BodyId.length > 0 )
234                oBody.id = FCKConfig.BodyId ;
235        if ( this.BodyClass && this.BodyClass.length > 0 )
236                oBody.className += ' ' + FCKConfig.BodyClass ;
237}
Note: See TracBrowser for help on using the repository browser.