2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
\r
3 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
\r
5 * == BEGIN LICENSE ==
\r
7 * Licensed under the terms of any of the following licenses at your
\r
10 * - GNU General Public License Version 2 or later (the "GPL")
\r
11 * http://www.gnu.org/licenses/gpl.html
\r
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
\r
14 * http://www.gnu.org/licenses/lgpl.html
\r
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
\r
17 * http://www.mozilla.org/MPL/MPL-1.1.html
\r
21 * Creates and initializes the FCKConfig object.
\r
24 var FCKConfig = FCK.Config = new Object() ;
\r
27 For the next major version (probably 3.0) we should move all this stuff to
\r
28 another dedicated object and leave FCKConfig as a holder object for settings only).
\r
32 if ( document.location.protocol == 'file:' )
\r
34 FCKConfig.BasePath = decodeURIComponent( document.location.pathname.substr(1) ) ;
\r
35 FCKConfig.BasePath = FCKConfig.BasePath.replace( /\\/gi, '/' ) ;
\r
37 // The way to address local files is different according to the OS.
\r
38 // In Windows it is file:// but in MacOs it is file:/// so let's get it automatically
\r
39 var sFullProtocol = document.location.href.match( /^(file\:\/{2,3})/ )[1] ;
\r
40 // #945 Opera does strange things with files loaded from the disk, and it fails in Mac to load xml files
\r
41 if ( FCKBrowserInfo.IsOpera )
\r
42 sFullProtocol += 'localhost/' ;
\r
44 FCKConfig.BasePath = sFullProtocol + FCKConfig.BasePath.substring( 0, FCKConfig.BasePath.lastIndexOf( '/' ) + 1) ;
\r
47 FCKConfig.BasePath = document.location.protocol + '//' + document.location.host +
\r
48 document.location.pathname.substring( 0, document.location.pathname.lastIndexOf( '/' ) + 1) ;
\r
50 FCKConfig.FullBasePath = FCKConfig.BasePath ;
\r
52 FCKConfig.EditorPath = FCKConfig.BasePath.replace( /editor\/$/, '' ) ;
\r
54 // There is a bug in Gecko. If the editor is hidden on startup, an error is
\r
55 // thrown when trying to get the screen dimensions.
\r
58 FCKConfig.ScreenWidth = screen.width ;
\r
59 FCKConfig.ScreenHeight = screen.height ;
\r
63 FCKConfig.ScreenWidth = 800 ;
\r
64 FCKConfig.ScreenHeight = 600 ;
\r
67 // Override the actual configuration values with the values passed throw the
\r
68 // hidden field "<InstanceName>___Config".
\r
69 FCKConfig.ProcessHiddenField = function()
\r
71 this.PageConfig = new Object() ;
\r
73 // Get the hidden field.
\r
74 var oConfigField = window.parent.document.getElementById( FCK.Name + '___Config' ) ;
\r
76 // Do nothing if the config field was not defined.
\r
77 if ( ! oConfigField ) return ;
\r
79 var aCouples = oConfigField.value.split('&') ;
\r
81 for ( var i = 0 ; i < aCouples.length ; i++ )
\r
83 if ( aCouples[i].length == 0 )
\r
86 var aConfig = aCouples[i].split( '=' ) ;
\r
87 var sKey = decodeURIComponent( aConfig[0] ) ;
\r
88 var sVal = decodeURIComponent( aConfig[1] ) ;
\r
90 if ( sKey == 'CustomConfigurationsPath' ) // The Custom Config File path must be loaded immediately.
\r
91 FCKConfig[ sKey ] = sVal ;
\r
93 else if ( sVal.toLowerCase() == "true" ) // If it is a boolean TRUE.
\r
94 this.PageConfig[ sKey ] = true ;
\r
96 else if ( sVal.toLowerCase() == "false" ) // If it is a boolean FALSE.
\r
97 this.PageConfig[ sKey ] = false ;
\r
99 else if ( sVal.length > 0 && !isNaN( sVal ) ) // If it is a number.
\r
100 this.PageConfig[ sKey ] = parseInt( sVal, 10 ) ;
\r
102 else // In any other case it is a string.
\r
103 this.PageConfig[ sKey ] = sVal ;
\r
107 function FCKConfig_LoadPageConfig()
\r
109 var oPageConfig = FCKConfig.PageConfig ;
\r
110 for ( var sKey in oPageConfig )
\r
111 FCKConfig[ sKey ] = oPageConfig[ sKey ] ;
\r
114 function FCKConfig_PreProcess()
\r
116 var oConfig = FCKConfig ;
\r
118 // Force debug mode if fckdebug=true in the QueryString (main page).
\r
119 if ( oConfig.AllowQueryStringDebug )
\r
123 if ( (/fckdebug=true/i).test( window.top.location.search ) )
\r
124 oConfig.Debug = true ;
\r
126 catch (e) { /* Ignore it. Much probably we are inside a FRAME where the "top" is in another domain (security error). */ }
\r
129 // Certifies that the "PluginsPath" configuration ends with a slash.
\r
130 if ( !oConfig.PluginsPath.EndsWith('/') )
\r
131 oConfig.PluginsPath += '/' ;
\r
133 // If no ToolbarComboPreviewCSS, point it to EditorAreaCSS.
\r
134 var sComboPreviewCSS = oConfig.ToolbarComboPreviewCSS ;
\r
135 if ( !sComboPreviewCSS || sComboPreviewCSS.length == 0 )
\r
136 oConfig.ToolbarComboPreviewCSS = oConfig.EditorAreaCSS ;
\r
138 // Turn the attributes that will be removed in the RemoveFormat from a string to an array
\r
139 oConfig.RemoveAttributesArray = (oConfig.RemoveAttributes || '').split( ',' );
\r
141 if ( !FCKConfig.SkinEditorCSS || FCKConfig.SkinEditorCSS.length == 0 )
\r
142 FCKConfig.SkinEditorCSS = FCKConfig.SkinPath + 'fck_editor.css' ;
\r
144 if ( !FCKConfig.SkinDialogCSS || FCKConfig.SkinDialogCSS.length == 0 )
\r
145 FCKConfig.SkinDialogCSS = FCKConfig.SkinPath + 'fck_dialog.css' ;
\r
148 // Define toolbar sets collection.
\r
149 FCKConfig.ToolbarSets = new Object() ;
\r
151 // Defines the plugins collection.
\r
152 FCKConfig.Plugins = new Object() ;
\r
153 FCKConfig.Plugins.Items = new Array() ;
\r
155 FCKConfig.Plugins.Add = function( name, langs, path )
\r
157 FCKConfig.Plugins.Items.push( [name, langs, path] ) ;
\r
160 // FCKConfig.ProtectedSource: object that holds a collection of Regular
\r
161 // Expressions that defined parts of the raw HTML that must remain untouched
\r
162 // like custom tags, scripts, server side code, etc...
\r
163 FCKConfig.ProtectedSource = new Object() ;
\r
165 // Generates a string used to identify and locate the Protected Tags comments.
\r
166 FCKConfig.ProtectedSource._CodeTag = (new Date()).valueOf() ;
\r
168 // Initialize the regex array with the default ones.
\r
169 FCKConfig.ProtectedSource.RegexEntries = [
\r
170 // First of any other protection, we must protect all comments to avoid
\r
171 // loosing them (of course, IE related).
\r
172 /<!--[\s\S]*?-->/g ,
\r
174 // Script tags will also be forced to be protected, otherwise IE will execute them.
\r
175 /<script[\s\S]*?<\/script>/gi,
\r
177 // <noscript> tags (get lost in IE and messed up in FF).
\r
178 /<noscript[\s\S]*?<\/noscript>/gi
\r
181 FCKConfig.ProtectedSource.Add = function( regexPattern )
\r
183 this.RegexEntries.push( regexPattern ) ;
\r
186 FCKConfig.ProtectedSource.Protect = function( html )
\r
188 var codeTag = this._CodeTag ;
\r
189 function _Replace( protectedSource )
\r
191 var index = FCKTempBin.AddElement( protectedSource ) ;
\r
192 return '<!--{' + codeTag + index + '}-->' ;
\r
195 for ( var i = 0 ; i < this.RegexEntries.length ; i++ )
\r
197 html = html.replace( this.RegexEntries[i], _Replace ) ;
\r
203 FCKConfig.ProtectedSource.Revert = function( html, clearBin )
\r
205 function _Replace( m, opener, index )
\r
207 var protectedValue = clearBin ? FCKTempBin.RemoveElement( index ) : FCKTempBin.Elements[ index ] ;
\r
208 // There could be protected source inside another one.
\r
209 return FCKConfig.ProtectedSource.Revert( protectedValue, clearBin ) ;
\r
212 var regex = new RegExp( "(<|<)!--\\{" + this._CodeTag + "(\\d+)\\}--(>|>)", "g" ) ;
\r
213 return html.replace( regex, _Replace ) ;
\r
216 // Returns a string with the attributes that must be appended to the body
\r
217 FCKConfig.GetBodyAttributes = function()
\r
219 var bodyAttributes = '' ;
\r
220 // Add id and class to the body.
\r
221 if ( this.BodyId && this.BodyId.length > 0 )
\r
222 bodyAttributes += ' id="' + this.BodyId + '"' ;
\r
223 if ( this.BodyClass && this.BodyClass.length > 0 )
\r
224 bodyAttributes += ' class="' + this.BodyClass + '"' ;
\r
226 return bodyAttributes ;
\r
229 // Sets the body attributes directly on the node
\r
230 FCKConfig.ApplyBodyAttributes = function( oBody )
\r
232 // Add ID and Class to the body
\r
233 if ( this.BodyId && this.BodyId.length > 0 )
\r
234 oBody.id = FCKConfig.BodyId ;
\r
235 if ( this.BodyClass && this.BodyClass.length > 0 )
\r
236 oBody.className += ' ' + FCKConfig.BodyClass ;
\r