import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / internals / fckconfig.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
4  *\r
5  * == BEGIN LICENSE ==\r
6  *\r
7  * Licensed under the terms of any of the following licenses at your\r
8  * choice:\r
9  *\r
10  *  - GNU General Public License Version 2 or later (the "GPL")\r
11  *    http://www.gnu.org/licenses/gpl.html\r
12  *\r
13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
14  *    http://www.gnu.org/licenses/lgpl.html\r
15  *\r
16  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
17  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
18  *\r
19  * == END LICENSE ==\r
20  *\r
21  * Creates and initializes the FCKConfig object.\r
22  */\r
23 \r
24 var FCKConfig = FCK.Config = new Object() ;\r
25 \r
26 /*\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
29 */\r
30 \r
31 // Editor Base Path\r
32 if ( document.location.protocol == 'file:' )\r
33 {\r
34         FCKConfig.BasePath = decodeURIComponent( document.location.pathname.substr(1) ) ;\r
35         FCKConfig.BasePath = FCKConfig.BasePath.replace( /\\/gi, '/' ) ;\r
36 \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
43 \r
44         FCKConfig.BasePath = sFullProtocol + FCKConfig.BasePath.substring( 0, FCKConfig.BasePath.lastIndexOf( '/' ) + 1) ;\r
45 }\r
46 else\r
47         FCKConfig.BasePath = document.location.protocol + '//' + document.location.host +\r
48                 document.location.pathname.substring( 0, document.location.pathname.lastIndexOf( '/' ) + 1) ;\r
49 \r
50 FCKConfig.FullBasePath = FCKConfig.BasePath ;\r
51 \r
52 FCKConfig.EditorPath = FCKConfig.BasePath.replace( /editor\/$/, '' ) ;\r
53 \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
56 try\r
57 {\r
58         FCKConfig.ScreenWidth   = screen.width ;\r
59         FCKConfig.ScreenHeight  = screen.height ;\r
60 }\r
61 catch (e)\r
62 {\r
63         FCKConfig.ScreenWidth   = 800 ;\r
64         FCKConfig.ScreenHeight  = 600 ;\r
65 }\r
66 \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
70 {\r
71         this.PageConfig = new Object() ;\r
72 \r
73         // Get the hidden field.\r
74         var oConfigField = window.parent.document.getElementById( FCK.Name + '___Config' ) ;\r
75 \r
76         // Do nothing if the config field was not defined.\r
77         if ( ! oConfigField ) return ;\r
78 \r
79         var aCouples = oConfigField.value.split('&') ;\r
80 \r
81         for ( var i = 0 ; i < aCouples.length ; i++ )\r
82         {\r
83                 if ( aCouples[i].length == 0 )\r
84                         continue ;\r
85 \r
86                 var aConfig = aCouples[i].split( '=' ) ;\r
87                 var sKey = decodeURIComponent( aConfig[0] ) ;\r
88                 var sVal = decodeURIComponent( aConfig[1] ) ;\r
89 \r
90                 if ( sKey == 'CustomConfigurationsPath' )       // The Custom Config File path must be loaded immediately.\r
91                         FCKConfig[ sKey ] = sVal ;\r
92 \r
93                 else if ( sVal.toLowerCase() == "true" )        // If it is a boolean TRUE.\r
94                         this.PageConfig[ sKey ] = true ;\r
95 \r
96                 else if ( sVal.toLowerCase() == "false" )       // If it is a boolean FALSE.\r
97                         this.PageConfig[ sKey ] = false ;\r
98 \r
99                 else if ( sVal.length > 0 && !isNaN( sVal ) )   // If it is a number.\r
100                         this.PageConfig[ sKey ] = parseInt( sVal, 10 ) ;\r
101 \r
102                 else                                                                            // In any other case it is a string.\r
103                         this.PageConfig[ sKey ] = sVal ;\r
104         }\r
105 }\r
106 \r
107 function FCKConfig_LoadPageConfig()\r
108 {\r
109         var oPageConfig = FCKConfig.PageConfig ;\r
110         for ( var sKey in oPageConfig )\r
111                 FCKConfig[ sKey ] = oPageConfig[ sKey ] ;\r
112 }\r
113 \r
114 function FCKConfig_PreProcess()\r
115 {\r
116         var oConfig = FCKConfig ;\r
117 \r
118         // Force debug mode if fckdebug=true in the QueryString (main page).\r
119         if ( oConfig.AllowQueryStringDebug )\r
120         {\r
121                 try\r
122                 {\r
123                         if ( (/fckdebug=true/i).test( window.top.location.search ) )\r
124                                 oConfig.Debug = true ;\r
125                 }\r
126                 catch (e) { /* Ignore it. Much probably we are inside a FRAME where the "top" is in another domain (security error). */ }\r
127         }\r
128 \r
129         // Certifies that the "PluginsPath" configuration ends with a slash.\r
130         if ( !oConfig.PluginsPath.EndsWith('/') )\r
131                 oConfig.PluginsPath += '/' ;\r
132 \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
137 \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
140 \r
141         if ( !FCKConfig.SkinEditorCSS || FCKConfig.SkinEditorCSS.length == 0 )\r
142                 FCKConfig.SkinEditorCSS = FCKConfig.SkinPath + 'fck_editor.css' ;\r
143 \r
144         if ( !FCKConfig.SkinDialogCSS || FCKConfig.SkinDialogCSS.length == 0 )\r
145                 FCKConfig.SkinDialogCSS = FCKConfig.SkinPath + 'fck_dialog.css' ;\r
146 }\r
147 \r
148 // Define toolbar sets collection.\r
149 FCKConfig.ToolbarSets = new Object() ;\r
150 \r
151 // Defines the plugins collection.\r
152 FCKConfig.Plugins = new Object() ;\r
153 FCKConfig.Plugins.Items = new Array() ;\r
154 \r
155 FCKConfig.Plugins.Add = function( name, langs, path )\r
156 {\r
157         FCKConfig.Plugins.Items.push( [name, langs, path] ) ;\r
158 }\r
159 \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
164 \r
165 // Generates a string used to identify and locate the Protected Tags comments.\r
166 FCKConfig.ProtectedSource._CodeTag = (new Date()).valueOf() ;\r
167 \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
173 \r
174         // Script tags will also be forced to be protected, otherwise IE will execute them.\r
175         /<script[\s\S]*?<\/script>/gi,\r
176 \r
177         // <noscript> tags (get lost in IE and messed up in FF).\r
178         /<noscript[\s\S]*?<\/noscript>/gi\r
179 ] ;\r
180 \r
181 FCKConfig.ProtectedSource.Add = function( regexPattern )\r
182 {\r
183         this.RegexEntries.push( regexPattern ) ;\r
184 }\r
185 \r
186 FCKConfig.ProtectedSource.Protect = function( html )\r
187 {\r
188         var codeTag = this._CodeTag ;\r
189         function _Replace( protectedSource )\r
190         {\r
191                 var index = FCKTempBin.AddElement( protectedSource ) ;\r
192                 return '<!--{' + codeTag + index + '}-->' ;\r
193         }\r
194 \r
195         for ( var i = 0 ; i < this.RegexEntries.length ; i++ )\r
196         {\r
197                 html = html.replace( this.RegexEntries[i], _Replace ) ;\r
198         }\r
199 \r
200         return html ;\r
201 }\r
202 \r
203 FCKConfig.ProtectedSource.Revert = function( html, clearBin )\r
204 {\r
205         function _Replace( m, opener, index )\r
206         {\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
210         }\r
211 \r
212         var regex = new RegExp( "(<|&lt;)!--\\{" + this._CodeTag + "(\\d+)\\}--(>|&gt;)", "g" ) ;\r
213         return html.replace( regex, _Replace ) ;\r
214 }\r
215 \r
216 // Returns a string with the attributes that must be appended to the body\r
217 FCKConfig.GetBodyAttributes = function()\r
218 {\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
225 \r
226         return bodyAttributes ;\r
227 }\r
228 \r
229 // Sets the body attributes directly on the node\r
230 FCKConfig.ApplyBodyAttributes = function( oBody )\r
231 {\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
237 }\r