PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/public/javascripts/editor/_source/internals/fckconfig.js

http://rorptm.googlecode.com/
JavaScript | 175 lines | 101 code | 33 blank | 41 comment | 23 complexity | aa8befe4ec01ff380a0fd77e72523a7a MD5 | raw file
Possible License(s): JSON
  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. var FCKConfig = FCK.Config = new Object() ;
  20. /*
  21. For the next major version (probably 3.0) we should move all this stuff to
  22. another dedicated object and leave FCKConfig as a holder object for settings only).
  23. */
  24. // Editor Base Path
  25. if ( document.location.protocol == 'file:' )
  26. {
  27. FCKConfig.BasePath = unescape( document.location.pathname.substr(1) ) ;
  28. FCKConfig.BasePath = FCKConfig.BasePath.replace( /\\/gi, '/' ) ;
  29. FCKConfig.BasePath = 'file://' + FCKConfig.BasePath.substring(0,FCKConfig.BasePath.lastIndexOf('/')+1) ;
  30. FCKConfig.FullBasePath = FCKConfig.BasePath ;
  31. }
  32. else
  33. {
  34. FCKConfig.BasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('/')+1) ;
  35. FCKConfig.FullBasePath = document.location.protocol + '//' + document.location.host + FCKConfig.BasePath ;
  36. }
  37. FCKConfig.EditorPath = FCKConfig.BasePath.replace( /editor\/$/, '' ) ;
  38. // There is a bug in Gecko. If the editor is hidden on startup, an error is
  39. // thrown when trying to get the screen dimentions.
  40. try
  41. {
  42. FCKConfig.ScreenWidth = screen.width ;
  43. FCKConfig.ScreenHeight = screen.height ;
  44. }
  45. catch (e)
  46. {
  47. FCKConfig.ScreenWidth = 800 ;
  48. FCKConfig.ScreenHeight = 600 ;
  49. }
  50. // Override the actual configuration values with the values passed throw the
  51. // hidden field "<InstanceName>___Config".
  52. FCKConfig.ProcessHiddenField = function()
  53. {
  54. this.PageConfig = new Object() ;
  55. // Get the hidden field.
  56. var oConfigField = window.parent.document.getElementById( FCK.Name + '___Config' ) ;
  57. // Do nothing if the config field was not defined.
  58. if ( ! oConfigField ) return ;
  59. var aCouples = oConfigField.value.split('&') ;
  60. for ( var i = 0 ; i < aCouples.length ; i++ )
  61. {
  62. if ( aCouples[i].length == 0 )
  63. continue ;
  64. var aConfig = aCouples[i].split( '=' ) ;
  65. var sKey = unescape( aConfig[0] ) ;
  66. var sVal = unescape( aConfig[1] ) ;
  67. if ( sKey == 'CustomConfigurationsPath' ) // The Custom Config File path must be loaded immediately.
  68. FCKConfig[ sKey ] = sVal ;
  69. else if ( sVal.toLowerCase() == "true" ) // If it is a boolean TRUE.
  70. this.PageConfig[ sKey ] = true ;
  71. else if ( sVal.toLowerCase() == "false" ) // If it is a boolean FALSE.
  72. this.PageConfig[ sKey ] = false ;
  73. else if ( ! isNaN( sVal ) ) // If it is a number.
  74. this.PageConfig[ sKey ] = parseInt( sVal ) ;
  75. else // In any other case it is a string.
  76. this.PageConfig[ sKey ] = sVal ;
  77. }
  78. }
  79. function FCKConfig_LoadPageConfig()
  80. {
  81. var oPageConfig = FCKConfig.PageConfig ;
  82. for ( var sKey in oPageConfig )
  83. FCKConfig[ sKey ] = oPageConfig[ sKey ] ;
  84. }
  85. function FCKConfig_PreProcess()
  86. {
  87. var oConfig = FCKConfig ;
  88. // Force debug mode if fckdebug=true in the QueryString (main page).
  89. if ( oConfig.AllowQueryStringDebug && (/fckdebug=true/i).test( window.top.location.search ) )
  90. oConfig.Debug = true ;
  91. // Certifies that the "PluginsPath" configuration ends with a slash.
  92. if ( !oConfig.PluginsPath.endsWith('/') )
  93. oConfig.PluginsPath += '/' ;
  94. // EditorAreaCSS accepts an array of paths or a single path (as string).
  95. // In the last case, transform it in an array.
  96. if ( typeof( oConfig.EditorAreaCSS ) == 'string' )
  97. oConfig.EditorAreaCSS = [ oConfig.EditorAreaCSS ] ;
  98. }
  99. // Define toolbar sets collection.
  100. FCKConfig.ToolbarSets = new Object() ;
  101. // Defines the plugins collection.
  102. FCKConfig.Plugins = new Object() ;
  103. FCKConfig.Plugins.Items = new Array() ;
  104. FCKConfig.Plugins.Add = function( name, langs, path )
  105. {
  106. FCKConfig.Plugins.Items.AddItem( [name, langs, path] ) ;
  107. }
  108. // FCKConfig.ProtectedSource: object that holds a collection of Regular
  109. // Expressions that defined parts of the raw HTML that must remain untouched
  110. // like custom tags, scripts, server side code, etc...
  111. FCKConfig.ProtectedSource = new Object() ;
  112. FCKConfig.ProtectedSource.RegexEntries = new Array() ;
  113. FCKConfig.ProtectedSource.Add = function( regexPattern )
  114. {
  115. this.RegexEntries.AddItem( regexPattern ) ;
  116. }
  117. FCKConfig.ProtectedSource.Protect = function( html )
  118. {
  119. function _Replace( protectedSource )
  120. {
  121. var index = FCKTempBin.AddElement( protectedSource ) ;
  122. return '<!--{PS..' + index + '}-->' ;
  123. }
  124. for ( var i = 0 ; i < this.RegexEntries.length ; i++ )
  125. {
  126. html = html.replace( this.RegexEntries[i], _Replace ) ;
  127. }
  128. return html ;
  129. }
  130. FCKConfig.ProtectedSource.Revert = function( html, clearBin )
  131. {
  132. function _Replace( m, opener, index )
  133. {
  134. var protectedValue = clearBin ? FCKTempBin.RemoveElement( index ) : FCKTempBin.Elements[ index ] ;
  135. // There could be protected source inside another one.
  136. return FCKConfig.ProtectedSource.Revert( protectedValue, clearBin ) ;
  137. }
  138. return html.replace( /(<|&lt;)!--\{PS..(\d+)\}--(>|&gt;)/g, _Replace ) ;
  139. }
  140. // First of any other protection, we must protect all comments to avoid
  141. // loosing them (of course, IE related).
  142. FCKConfig.ProtectedSource.Add( /<!--[\s\S]*?-->/g ) ;