[2] | 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: fckconfig.js
|
---|
| 14 | * Creates and initializes the FCKConfig object.
|
---|
| 15 | *
|
---|
| 16 | * File Authors:
|
---|
| 17 | * Frederico Caldeira Knabben (fredck@fckeditor.net)
|
---|
| 18 | */
|
---|
| 19 |
|
---|
| 20 | var FCKConfig = FCK.Config = new Object() ;
|
---|
| 21 |
|
---|
| 22 | /*
|
---|
| 23 | For the next major version (probably 3.0) we should move all this stuff to
|
---|
| 24 | another dedicated object and leave FCKConfig as a holder object for settings only).
|
---|
| 25 | */
|
---|
| 26 |
|
---|
| 27 | // Editor Base Path
|
---|
| 28 | if ( document.location.protocol == 'file:' )
|
---|
| 29 | {
|
---|
| 30 | FCKConfig.BasePath = unescape( document.location.pathname.substr(1) ) ;
|
---|
| 31 | FCKConfig.BasePath = FCKConfig.BasePath.replace( /\\/gi, '/' ) ;
|
---|
| 32 | FCKConfig.BasePath = 'file://' + FCKConfig.BasePath.substring(0,FCKConfig.BasePath.lastIndexOf('/')+1) ;
|
---|
| 33 | FCKConfig.FullBasePath = FCKConfig.BasePath ;
|
---|
| 34 | }
|
---|
| 35 | else
|
---|
| 36 | {
|
---|
| 37 | FCKConfig.BasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('/')+1) ;
|
---|
| 38 | FCKConfig.FullBasePath = document.location.protocol + '//' + document.location.host + FCKConfig.BasePath ;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | FCKConfig.EditorPath = FCKConfig.BasePath.replace( /editor\/$/, '' ) ;
|
---|
| 42 |
|
---|
| 43 | // There is a bug in Gecko. If the editor is hidden on startup, an error is
|
---|
| 44 | // thrown when trying to get the screen dimentions.
|
---|
| 45 | try
|
---|
| 46 | {
|
---|
| 47 | FCKConfig.ScreenWidth = screen.width ;
|
---|
| 48 | FCKConfig.ScreenHeight = screen.height ;
|
---|
| 49 | }
|
---|
| 50 | catch (e)
|
---|
| 51 | {
|
---|
| 52 | FCKConfig.ScreenWidth = 800 ;
|
---|
| 53 | FCKConfig.ScreenHeight = 600 ;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | // Override the actual configuration values with the values passed throw the
|
---|
| 57 | // hidden field "<InstanceName>___Config".
|
---|
| 58 | FCKConfig.ProcessHiddenField = function()
|
---|
| 59 | {
|
---|
| 60 | this.PageConfig = new Object() ;
|
---|
| 61 |
|
---|
| 62 | // Get the hidden field.
|
---|
| 63 | var oConfigField = window.parent.document.getElementById( FCK.Name + '___Config' ) ;
|
---|
| 64 |
|
---|
| 65 | // Do nothing if the config field was not defined.
|
---|
| 66 | if ( ! oConfigField ) return ;
|
---|
| 67 |
|
---|
| 68 | var aCouples = oConfigField.value.split('&') ;
|
---|
| 69 |
|
---|
| 70 | for ( var i = 0 ; i < aCouples.length ; i++ )
|
---|
| 71 | {
|
---|
| 72 | if ( aCouples[i].length == 0 )
|
---|
| 73 | continue ;
|
---|
| 74 |
|
---|
| 75 | var aConfig = aCouples[i].split( '=' ) ;
|
---|
| 76 | var sKey = unescape( aConfig[0] ) ;
|
---|
| 77 | var sVal = unescape( aConfig[1] ) ;
|
---|
| 78 |
|
---|
| 79 | if ( sKey == 'CustomConfigurationsPath' ) // The Custom Config File path must be loaded immediately.
|
---|
| 80 | FCKConfig[ sKey ] = sVal ;
|
---|
| 81 |
|
---|
| 82 | else if ( sVal.toLowerCase() == "true" ) // If it is a boolean TRUE.
|
---|
| 83 | this.PageConfig[ sKey ] = true ;
|
---|
| 84 |
|
---|
| 85 | else if ( sVal.toLowerCase() == "false" ) // If it is a boolean FALSE.
|
---|
| 86 | this.PageConfig[ sKey ] = false ;
|
---|
| 87 |
|
---|
| 88 | else if ( sVal.length > 0 && !isNaN( sVal ) ) // If it is a number.
|
---|
| 89 | this.PageConfig[ sKey ] = parseInt( sVal ) ;
|
---|
| 90 |
|
---|
| 91 | else // In any other case it is a string.
|
---|
| 92 | this.PageConfig[ sKey ] = sVal ;
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | function FCKConfig_LoadPageConfig()
|
---|
| 97 | {
|
---|
| 98 | var oPageConfig = FCKConfig.PageConfig ;
|
---|
| 99 | for ( var sKey in oPageConfig )
|
---|
| 100 | FCKConfig[ sKey ] = oPageConfig[ sKey ] ;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | function FCKConfig_PreProcess()
|
---|
| 104 | {
|
---|
| 105 | var oConfig = FCKConfig ;
|
---|
| 106 |
|
---|
| 107 | // Force debug mode if fckdebug=true in the QueryString (main page).
|
---|
| 108 | if ( oConfig.AllowQueryStringDebug )
|
---|
| 109 | {
|
---|
| 110 | try
|
---|
| 111 | {
|
---|
| 112 | if ( (/fckdebug=true/i).test( window.top.location.search ) )
|
---|
| 113 | oConfig.Debug = true ;
|
---|
| 114 | }
|
---|
| 115 | catch (e) { /* Ignore it. Much probably we are inside a FRAME where the "top" is in another domain (security error). */ }
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | // Certifies that the "PluginsPath" configuration ends with a slash.
|
---|
| 119 | if ( !oConfig.PluginsPath.endsWith('/') )
|
---|
| 120 | oConfig.PluginsPath += '/' ;
|
---|
| 121 |
|
---|
| 122 | // EditorAreaCSS accepts an array of paths or a single path (as string).
|
---|
| 123 | // In the last case, transform it in an array.
|
---|
| 124 | if ( typeof( oConfig.EditorAreaCSS ) == 'string' )
|
---|
| 125 | oConfig.EditorAreaCSS = [ oConfig.EditorAreaCSS ] ;
|
---|
| 126 |
|
---|
| 127 | var sComboPreviewCSS = oConfig.ToolbarComboPreviewCSS ;
|
---|
| 128 | if ( !sComboPreviewCSS || sComboPreviewCSS.length == 0 )
|
---|
| 129 | oConfig.ToolbarComboPreviewCSS = oConfig.EditorAreaCSS ;
|
---|
| 130 | else if ( typeof( sComboPreviewCSS ) == 'string' )
|
---|
| 131 | oConfig.ToolbarComboPreviewCSS = [ sComboPreviewCSS ] ;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | // Define toolbar sets collection.
|
---|
| 135 | FCKConfig.ToolbarSets = new Object() ;
|
---|
| 136 |
|
---|
| 137 | // Defines the plugins collection.
|
---|
| 138 | FCKConfig.Plugins = new Object() ;
|
---|
| 139 | FCKConfig.Plugins.Items = new Array() ;
|
---|
| 140 |
|
---|
| 141 | FCKConfig.Plugins.Add = function( name, langs, path )
|
---|
| 142 | {
|
---|
| 143 | FCKConfig.Plugins.Items.AddItem( [name, langs, path] ) ;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | // FCKConfig.ProtectedSource: object that holds a collection of Regular
|
---|
| 147 | // Expressions that defined parts of the raw HTML that must remain untouched
|
---|
| 148 | // like custom tags, scripts, server side code, etc...
|
---|
| 149 | FCKConfig.ProtectedSource = new Object() ;
|
---|
| 150 |
|
---|
| 151 | // Initialize the regex array with the default ones.
|
---|
| 152 | FCKConfig.ProtectedSource.RegexEntries = [
|
---|
| 153 | // First of any other protection, we must protect all comments to avoid
|
---|
| 154 | // loosing them (of course, IE related).
|
---|
| 155 | /<!--[\s\S]*?-->/g ,
|
---|
| 156 |
|
---|
| 157 | // Script tags will also be forced to be protected, otherwise IE will execute them.
|
---|
| 158 | /<script[\s\S]*?<\/script>/gi,
|
---|
| 159 |
|
---|
| 160 | // <noscript> tags (get lost in IE and messed up in FF).
|
---|
| 161 | /<noscript[\s\S]*?<\/noscript>/gi
|
---|
| 162 | ] ;
|
---|
| 163 |
|
---|
| 164 | FCKConfig.ProtectedSource.Add = function( regexPattern )
|
---|
| 165 | {
|
---|
| 166 | this.RegexEntries.AddItem( regexPattern ) ;
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | FCKConfig.ProtectedSource.Protect = function( html )
|
---|
| 170 | {
|
---|
| 171 | function _Replace( protectedSource )
|
---|
| 172 | {
|
---|
| 173 | var index = FCKTempBin.AddElement( protectedSource ) ;
|
---|
| 174 | return '<!--{PS..' + index + '}-->' ;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | for ( var i = 0 ; i < this.RegexEntries.length ; i++ )
|
---|
| 178 | {
|
---|
| 179 | html = html.replace( this.RegexEntries[i], _Replace ) ;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | return html ;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | FCKConfig.ProtectedSource.Revert = function( html, clearBin )
|
---|
| 186 | {
|
---|
| 187 | function _Replace( m, opener, index )
|
---|
| 188 | {
|
---|
| 189 | var protectedValue = clearBin ? FCKTempBin.RemoveElement( index ) : FCKTempBin.Elements[ index ] ;
|
---|
| 190 | // There could be protected source inside another one.
|
---|
| 191 | return FCKConfig.ProtectedSource.Revert( protectedValue, clearBin ) ;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | return html.replace( /(<|<)!--\{PS..(\d+)\}--(>|>)/g, _Replace ) ;
|
---|
| 195 | } |
---|