fckeditor.js
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:7k
源码类别:

OA系统

开发平台:

C#

  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: fckeditor.js
  14.  *  This is the integration file for JavaScript.
  15.  * 
  16.  *  It defines the FCKeditor class that can be used to create editor
  17.  *  instances in a HTML page in the client side. For server side
  18.  *  operations, use the specific integration system.
  19.  * 
  20.  * File Authors:
  21.  *  Frederico Caldeira Knabben (fredck@fckeditor.net)
  22.  */
  23. // FCKeditor Class
  24. var FCKeditor = function( instanceName, width, height, toolbarSet, value )
  25. {
  26. // Properties
  27. this.InstanceName = instanceName ;
  28. this.Width = width || '100%' ;
  29. this.Height = height || '200' ;
  30. this.ToolbarSet = toolbarSet || 'Default' ;
  31. this.Value = value || '' ;
  32. this.BasePath = '/fckeditor/' ;
  33. this.CheckBrowser = true ;
  34. this.DisplayErrors = true ;
  35. this.EnableSafari = false ; // This is a temporary property, while Safari support is under development.
  36. this.EnableOpera = false ; // This is a temporary property, while Opera support is under development.
  37. this.Config = new Object() ;
  38. // Events
  39. this.OnError = null ; // function( source, errorNumber, errorDescription )
  40. }
  41. FCKeditor.prototype.Version = '2.3.2' ;
  42. FCKeditor.prototype.VersionBuild = '1082' ;
  43. FCKeditor.prototype.Create = function()
  44. {
  45. document.write( this.CreateHtml() ) ;
  46. }
  47. FCKeditor.prototype.CreateHtml = function()
  48. {
  49. // Check for errors
  50. if ( !this.InstanceName || this.InstanceName.length == 0 )
  51. {
  52. this._ThrowError( 701, 'You must specify an instance name.' ) ;
  53. return ;
  54. }
  55. var sHtml = '<div>' ;
  56. if ( !this.CheckBrowser || FCKeditor_IsCompatibleBrowser() )
  57. {
  58. sHtml += '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode( this.Value ) + '" style="display:none" />' ;
  59. sHtml += this._GetConfigHtml() ;
  60. sHtml += this._GetIFrameHtml() ;
  61. }
  62. else
  63. {
  64. var sWidth  = this.Width.toString().indexOf('%')  > 0 ? this.Width  : this.Width  + 'px' ;
  65. var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ;
  66. sHtml += '<textarea name="' + this.InstanceName + '" rows="4" cols="40" style="width:' + sWidth + ';height:' + sHeight + '">' + this._HTMLEncode( this.Value ) + '</textarea>' ;
  67. }
  68. sHtml += '</div>' ;
  69. return sHtml ;
  70. }
  71. FCKeditor.prototype.ReplaceTextarea = function()
  72. {
  73. if ( !this.CheckBrowser || FCKeditor_IsCompatibleBrowser() )
  74. {
  75. // We must check the elements firstly using the Id and then the name.
  76. var oTextarea = document.getElementById( this.InstanceName ) ;
  77. var colElementsByName = document.getElementsByName( this.InstanceName ) ;
  78. var i = 0;
  79. while ( oTextarea || i == 0 )
  80. {
  81. if ( oTextarea && oTextarea.tagName.toLowerCase() == 'textarea' )
  82. break ;
  83. oTextarea = colElementsByName[i++] ;
  84. }
  85. if ( !oTextarea )
  86. {
  87. alert( 'Error: The TEXTAREA with id or name set to "' + this.InstanceName + '" was not found' ) ;
  88. return ;
  89. }
  90. oTextarea.style.display = 'none' ;
  91. this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ;
  92. this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ;
  93. }
  94. }
  95. FCKeditor.prototype._InsertHtmlBefore = function( html, element )
  96. {
  97. if ( element.insertAdjacentHTML ) // IE
  98. element.insertAdjacentHTML( 'beforeBegin', html ) ;
  99. else // Gecko
  100. {
  101. var oRange = document.createRange() ;
  102. oRange.setStartBefore( element ) ;
  103. var oFragment = oRange.createContextualFragment( html );
  104. element.parentNode.insertBefore( oFragment, element ) ;
  105. }
  106. }
  107. FCKeditor.prototype._GetConfigHtml = function()
  108. {
  109. var sConfig = '' ;
  110. for ( var o in this.Config )
  111. {
  112. if ( sConfig.length > 0 ) sConfig += '&amp;' ;
  113. sConfig += escape(o) + '=' + escape( this.Config[o] ) ;
  114. }
  115. return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" style="display:none" />' ;
  116. }
  117. FCKeditor.prototype._GetIFrameHtml = function()
  118. {
  119. var sFile = 'fckeditor.html' ;
  120. try
  121. {
  122. if ( (/fcksource=true/i).test( window.top.location.search ) )
  123. sFile = 'fckeditor.original.html' ;
  124. }
  125. catch (e) { /* Ignore it. Much probably we are inside a FRAME where the "top" is in another domain (security error). */ }
  126. var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + this.InstanceName ;
  127. if (this.ToolbarSet) sLink += '&amp;Toolbar=' + this.ToolbarSet ;
  128. return '<iframe id="' + this.InstanceName + '___Frame" src="' + sLink + '" width="' + this.Width + '" height="' + this.Height + '" frameborder="0" scrolling="no"></iframe>' ;
  129. }
  130. // Deprecated (to be removed in the 3.0).
  131. FCKeditor.prototype._IsCompatibleBrowser = function()
  132. {
  133. return FCKeditor_IsCompatibleBrowser() ;
  134. }
  135. FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription )
  136. {
  137. this.ErrorNumber = errorNumber ;
  138. this.ErrorDescription = errorDescription ;
  139. if ( this.DisplayErrors )
  140. {
  141. document.write( '<div style="COLOR: #ff0000">' ) ;
  142. document.write( '[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]' ) ;
  143. document.write( '</div>' ) ;
  144. }
  145. if ( typeof( this.OnError ) == 'function' )
  146. this.OnError( this, errorNumber, errorDescription ) ;
  147. }
  148. FCKeditor.prototype._HTMLEncode = function( text )
  149. {
  150. if ( typeof( text ) != "string" )
  151. text = text.toString() ;
  152. text = text.replace(
  153. /&/g, "&amp;").replace(
  154. /"/g, "&quot;").replace(
  155. /</g, "&lt;").replace(
  156. />/g, "&gt;") ;
  157. return text ;
  158. }
  159. function FCKeditor_IsCompatibleBrowser()
  160. {
  161. var sAgent = navigator.userAgent.toLowerCase() ;
  162. // Internet Explorer
  163. if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 )
  164. {
  165. var sBrowserVersion = navigator.appVersion.match(/MSIE (...)/)[1] ;
  166. return ( sBrowserVersion >= 5.5 ) ;
  167. }
  168. // Gecko (Opera 9 tries to behave like Gecko at this point).
  169. if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 && !( typeof(opera) == 'object' && opera.postError ) )
  170. return true ;
  171. // Opera
  172. if ( this.EnableOpera && navigator.appName == 'Opera' && parseInt( navigator.appVersion ) >= 9 )
  173. return true ;
  174. // Safari
  175. if ( this.EnableSafari && sAgent.indexOf( 'safari' ) != -1 )
  176. return ( sAgent.match( /safari/(d+)/ )[1] >= 312 ) ; // Build must be at least 312 (1.3)
  177. return false ;
  178. }