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 * 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 FCKConfig.FullBasePath = FCKConfig.BasePath ; 46} 47else 48{ 49 FCKConfig.BasePath = document.location.pathname.substring( 0, document.location.pathname.lastIndexOf( '/' ) + 1) ; 50 FCKConfig.FullBasePath = document.location.protocol + '//' + document.location.host + FCKConfig.BasePath ; 51} 52 53FCKConfig.EditorPath = FCKConfig.BasePath.replace( /editor\/$/, '' ) ; 54 55// There is a bug in Gecko. If the editor is hidden on startup, an error is 56// thrown when trying to get the screen dimensions. 57try 58{ 59 FCKConfig.ScreenWidth = screen.width ; 60 FCKConfig.ScreenHeight = screen.height ; 61} 62catch (e) 63{ 64 FCKConfig.ScreenWidth = 800 ; 65 FCKConfig.ScreenHeight = 600 ; 66} 67 68// Override the actual configuration values with the values passed throw the 69// hidden field "<InstanceName>___Config". 70FCKConfig.ProcessHiddenField = function() 71{ 72 this.PageConfig = new Object() ; 73 74 // Get the hidden field. 75 var oConfigField = window.parent.document.getElementById( FCK.Name + '___Config' ) ; 76 77 // Do nothing if the config field was not defined. 78 if ( ! oConfigField ) return ; 79 80 var aCouples = oConfigField.value.split('&') ; 81 82 for ( var i = 0 ; i < aCouples.length ; i++ ) 83 { 84 if ( aCouples[i].length == 0 ) 85 continue ; 86 87 var aConfig = aCouples[i].split( '=' ) ; 88 var sKey = decodeURIComponent( aConfig[0] ) ; 89 var sVal = decodeURIComponent( aConfig[1] ) ; 90 91 if ( sKey == 'CustomConfigurationsPath' ) // The Custom Config File path must be loaded immediately. 92 FCKConfig[ sKey ] = sVal ; 93 94 else if ( sVal.toLowerCase() == "true" ) // If it is a boolean TRUE. 95 this.PageConfig[ sKey ] = true ; 96 97 else if ( sVal.toLowerCase() == "false" ) // If it is a boolean FALSE. 98 this.PageConfig[ sKey ] = false ; 99 100 else if ( sVal.length > 0 && !isNaN( sVal ) ) // If it is a number. 101 this.PageConfig[ sKey ] = parseInt( sVal, 10 ) ; 102 103 else // In any other case it is a string. 104 this.PageConfig[ sKey ] = sVal ; 105 } 106} 107 108function FCKConfig_LoadPageConfig() 109{ 110 var oPageConfig = FCKConfig.PageConfig ; 111 for ( var sKey in oPageConfig ) 112 FCKConfig[ sKey ] = oPageConfig[ sKey ] ; 113} 114 115function FCKConfig_PreProcess() 116{ 117 var oConfig = FCKConfig ; 118 119 // Force debug mode if fckdebug=true in the QueryString (main page). 120 if ( oConfig.AllowQueryStringDebug ) 121 { 122 try 123 { 124 if ( (/fckdebug=true/i).test( window.top.location.search ) ) 125 oConfig.Debug = true ; 126 } 127 catch (e) { /* Ignore it. Much probably we are inside a FRAME where the "top" is in another domain (security error). */ } 128 } 129 130 // Certifies that the "PluginsPath" configuration ends with a slash. 131 if ( !oConfig.PluginsPath.EndsWith('/') ) 132 oConfig.PluginsPath += '/' ; 133 134 // EditorAreaCSS accepts a single path string, a list of paths separated by 135 // a comma or and array of paths. 136 // In the string cases, transform it in an array. 137 if ( typeof( oConfig.EditorAreaCSS ) == 'string' ) 138 oConfig.EditorAreaCSS = oConfig.EditorAreaCSS.split(',') ; 139 140 var sComboPreviewCSS = oConfig.ToolbarComboPreviewCSS ; 141 if ( !sComboPreviewCSS || sComboPreviewCSS.length == 0 ) 142 oConfig.ToolbarComboPreviewCSS = oConfig.EditorAreaCSS ; 143 else if ( typeof( sComboPreviewCSS ) == 'string' ) 144 oConfig.ToolbarComboPreviewCSS = [ sComboPreviewCSS ] ; 145} 146 147// Define toolbar sets collection. 148FCKConfig.ToolbarSets = new Object() ; 149 150// Defines the plugins collection. 151FCKConfig.Plugins = new Object() ; 152FCKConfig.Plugins.Items = new Array() ; 153 154FCKConfig.Plugins.Add = function( name, langs, path ) 155{ 156 FCKConfig.Plugins.Items.AddItem( [name, langs, path] ) ; 157} 158 159// FCKConfig.ProtectedSource: object that holds a collection of Regular 160// Expressions that defined parts of the raw HTML that must remain untouched 161// like custom tags, scripts, server side code, etc... 162FCKConfig.ProtectedSource = new Object() ; 163 164// Generates a string used to identify and locate the Protected Tags comments. 165FCKConfig.ProtectedSource._CodeTag = (new Date()).valueOf() ; 166 167// Initialize the regex array with the default ones. 168FCKConfig.ProtectedSource.RegexEntries = [ 169 // First of any other protection, we must protect all comments to avoid 170 // loosing them (of course, IE related). 171 /<!--[\s\S]*?-->/g , 172 173 // Script tags will also be forced to be protected, otherwise IE will execute them. 174 /<script[\s\S]*?<\/script>/gi, 175 176 // <noscript> tags (get lost in IE and messed up in FF). 177 /<noscript[\s\S]*?<\/noscript>/gi, 178 179 // Protect <object> tags. See #359. 180 /<object[\s\S]+?<\/object>/gi 181] ; 182 183FCKConfig.ProtectedSource.Add = function( regexPattern ) 184{ 185 this.RegexEntries.AddItem( regexPattern ) ; 186} 187 188FCKConfig.ProtectedSource.Protect = function( html ) 189{ 190 var codeTag = this._CodeTag ; 191 function _Replace( protectedSource ) 192 { 193 var index = FCKTempBin.AddElement( protectedSource ) ; 194 return '<!--{' + codeTag + index + '}-->' ; 195 } 196 197 for ( var i = 0 ; i < this.RegexEntries.length ; i++ ) 198 { 199 html = html.replace( this.RegexEntries[i], _Replace ) ; 200 } 201 202 return html ; 203} 204 205FCKConfig.ProtectedSource.Revert = function( html, clearBin ) 206{ 207 function _Replace( m, opener, index ) 208 { 209 var protectedValue = clearBin ? FCKTempBin.RemoveElement( index ) : FCKTempBin.Elements[ index ] ; 210 // There could be protected source inside another one. 211 return FCKConfig.ProtectedSource.Revert( protectedValue, clearBin ) ; 212 } 213 214 var regex = new RegExp( "(<|<)!--\\{" + this._CodeTag + "(\\d+)\\}--(>|>)", "g" ) ; 215 return html.replace( regex, _Replace ) ; 216} 217 218// Returns a string with the attributes that must be appended to the body 219FCKConfig.GetBodyAttributes = function() 220{ 221 var bodyAttributes = '' ; 222 // Add id and class to the body. 223 if ( this.BodyId && this.BodyId.length > 0 ) 224 bodyAttributes += ' id="' + this.BodyId + '"' ; 225 if ( this.BodyClass && this.BodyClass.length > 0 ) 226 bodyAttributes += ' class="' + this.BodyClass + '"' ; 227 228 return bodyAttributes ; 229} 230 231// Sets the body attributes directly on the node 232FCKConfig.ApplyBodyAttributes = function( oBody ) 233{ 234 // Add ID and Class to the body 235 if ( this.BodyId && this.BodyId.length > 0 ) 236 oBody.id = FCKConfig.BodyId ; 237 if ( this.BodyClass && this.BodyClass.length > 0 ) 238 oBody.className += ' ' + FCKConfig.BodyClass ; 239} 240