温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:博客源代码(课程设计,3层架构)
当前文件:
MVCBlog/fckeditor/fckeditor.js,打开代码结构图
MVCBlog/fckeditor/fckeditor.js,打开代码结构图1/* 2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net 3
* Copyright (C) 2003-2008 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
* This is the integration file for JavaScript. 22
* 23
* It defines the FCKeditor class that can be used to create editor 24
* instances in a HTML page in the client side. For server side 25
* operations, use the specific integration system. 26
*/ 27
28
// FCKeditor Class 29
var FCKeditor = function( instanceName, width, height, toolbarSet, value ) 30
{ 31
// Properties 32
this.InstanceName = instanceName ; 33
this.Width = width || '100%' ; 34
this.Height = height || '200' ; 35
this.ToolbarSet = toolbarSet || 'Default' ; 36
this.Value = value || '' ; 37
this.BasePath = FCKeditor.BasePath ; 38
this.CheckBrowser = true ; 39
this.DisplayErrors = true ; 40
41
this.Config = new Object() ; 42
43
// Events 44
this.OnError = null ; // function( source, errorNumber, errorDescription ) 45
} 46
47
/** 48
* This is the default BasePath used by all editor instances. 49
*/ 50
FCKeditor.BasePath = '/fckeditor/' ; 51
52
/** 53
* The minimum height used when replacing textareas. 54
*/ 55
FCKeditor.MinHeight = 200 ; 56
57
/** 58
* The minimum width used when replacing textareas. 59
*/ 60
FCKeditor.MinWidth = 750 ; 61
62
FCKeditor.prototype.Version = '2.6' ; 63
FCKeditor.prototype.VersionBuild = '18638' ; 64
65
FCKeditor.prototype.Create = function() 66
{ 67
document.write( this.CreateHtml() ) ; 68
} 69
70
FCKeditor.prototype.CreateHtml = function() 71
{ 72
// Check for errors 73
if ( !this.InstanceName || this.InstanceName.length == 0 ) 74
{ 75
this._ThrowError( 701, 'You must specify an instance name.' ) ; 76
return '' ; 77
} 78
79
var sHtml = '' ; 80
81
if ( !this.CheckBrowser || this._IsCompatibleBrowser() ) 82
{ 83
sHtml += '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode( this.Value ) + '" style="display:none" />' ; 84
sHtml += this._GetConfigHtml() ; 85
sHtml += this._GetIFrameHtml() ; 86
} 87
else 88
{ 89
var sWidth = this.Width.toString().indexOf('%') > 0 ? this.Width : this.Width + 'px' ; 90
var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ; 91
sHtml += '<textarea name="' + this.InstanceName + '" rows="4" cols="40" style="width:' + sWidth + ';height:' + sHeight + '">' + this._HTMLEncode( this.Value ) + '<\/textarea>' ; 92
} 93
94
return sHtml ; 95
} 96
97
FCKeditor.prototype.ReplaceTextarea = function() 98
{ 99
if ( !this.CheckBrowser || this._IsCompatibleBrowser() ) 100
{ 101
// We must check the elements firstly using the Id and then the name. 102
var oTextarea = document.getElementById( this.InstanceName ) ; 103
var colElementsByName = document.getElementsByName( this.InstanceName ) ; 104
var i = 0; 105
while ( oTextarea || i == 0 ) 106
{ 107
if ( oTextarea && oTextarea.tagName.toLowerCase() == 'textarea' ) 108
break ; 109
oTextarea = colElementsByName[i++] ; 110
} 111
112
if ( !oTextarea ) 113
{ 114
alert( 'Error: The TEXTAREA with id or name set to "' + this.InstanceName + '" was not found' ) ; 115
return ; 116
} 117
118
oTextarea.style.display = 'none' ; 119
this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ; 120
this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ; 121
} 122
} 123
124
FCKeditor.prototype._InsertHtmlBefore = function( html, element ) 125
{ 126
if ( element.insertAdjacentHTML ) // IE 127
element.insertAdjacentHTML( 'beforeBegin', html ) ; 128
else // Gecko 129
{ 130
var oRange = document.createRange() ; 131
oRange.setStartBefore( element ) ; 132
var oFragment = oRange.createContextualFragment( html ); 133
element.parentNode.insertBefore( oFragment, element ) ; 134
} 135
} 136
137
FCKeditor.prototype._GetConfigHtml = function() 138
{ 139
var sConfig = '' ; 140
for ( var o in this.Config ) 141
{ 142
if ( sConfig.length > 0 ) sConfig += '&' ; 143
sConfig += encodeURIComponent( o ) + '=' + encodeURIComponent( this.Config[o] ) ; 144
} 145
146
return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" style="display:none" />' ; 147
} 148
149
FCKeditor.prototype._GetIFrameHtml = function() 150
{ 151
var sFile = 'fckeditor.html' ; 152
153
try 154
{ 155
if ( (/fcksource=true/i).test( window.top.location.search ) ) 156
sFile = 'fckeditor.original.html' ; 157
} 158
catch (e) { /* Ignore it. Much probably we are inside a FRAME where the "top" is in another domain (security error). */ } 159
160
var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.InstanceName ) ; 161
if (this.ToolbarSet) sLink += '&Toolbar=' + this.ToolbarSet ; 162
163
return '<iframe id="' + this.InstanceName + '___Frame" src="' + sLink + '" width="' + this.Width + '" height="' + this.Height + '" frameborder="0" scrolling="no"></iframe>' ; 164
} 165
166
FCKeditor.prototype._IsCompatibleBrowser = function() 167
{ 168
return FCKeditor_IsCompatibleBrowser() ; 169
} 170
171
FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription ) 172
{ 173
this.ErrorNumber = errorNumber ; 174
this.ErrorDescription = errorDescription ; 175
176
if ( this.DisplayErrors ) 177
{ 178
document.write( '<div style="COLOR: #ff0000">' ) ; 179
document.write( '[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]' ) ; 180
document.write( '</div>' ) ; 181
} 182
183
if ( typeof( this.OnError ) == 'function' ) 184
this.OnError( this, errorNumber, errorDescription ) ; 185
} 186
187
FCKeditor.prototype._HTMLEncode = function( text ) 188
{ 189
if ( typeof( text ) != "string" ) 190
text = text.toString() ; 191
192
text = text.replace( 193
/&/g, "&").replace( 194
/"/g, """).replace( 195
/</g, "<").replace( 196
/>/g, ">") ; 197
198
return text ; 199
} 200
201
;(function() 202
{ 203
var textareaToEditor = function( textarea ) 204
{ 205
var editor = new FCKeditor( textarea.name ) ; 206
207
editor.Width = Math.max( textarea.offsetWidth, FCKeditor.MinWidth ) ; 208
editor.Height = Math.max( textarea.offsetHeight, FCKeditor.MinHeight ) ; 209
210
return editor ; 211
} 212
213
/** 214
* Replace all <textarea> elements available in the document with FCKeditor 215
* instances. 216
* 217
* // Replace all <textarea> elements in the page. 218
* FCKeditor.ReplaceAllTextareas() ; 219
* 220
* // Replace all <textarea class="myClassName"> elements in the page. 221
* FCKeditor.ReplaceAllTextareas( 'myClassName' ) ; 222
* 223
* // Selectively replace <textarea> elements, based on custom assertions. 224
* FCKeditor.ReplaceAllTextareas( function( textarea, editor ) 225
* { 226
* // Custom code to evaluate the replace, returning false if it 227
* // must not be done. 228
* // It also passes the "editor" parameter, so the developer can 229
* // customize the instance. 230
* } ) ; 231
*/ 232
FCKeditor.ReplaceAllTextareas = function() 233
{ 234
var textareas = document.getElementsByTagName( 'textarea' ) ; 235
236
for ( var i = 0 ; i < textareas.length ; i++ ) 237
{ 238
var editor = null ; 239
var textarea = textareas[i] ; 240
var name = textarea.name ; 241
242
// The "name" attribute must exist. 243
if ( !name || name.length == 0 ) 244
continue ; 245
246
if ( typeof arguments[0] == 'string' ) 247
{ 248
// The textarea class name could be passed as the function 249
// parameter. 250
251
var classRegex = new RegExp( '(?:^| )' + arguments[0] + '(?:$| )' ) ; 252
253
if ( !classRegex.test( textarea.className ) ) 254
continue ; 255
} 256
else if ( typeof arguments[0] == 'function' ) 257
{ 258
// An assertion function could be passed as the function parameter. 259
// It must explicitly return "false" to ignore a specific <textarea>. 260
editor = textareaToEditor( textarea ) ; 261
if ( arguments[0]( textarea, editor ) === false ) 262
continue ; 263
} 264
265
if ( !editor ) 266
editor = textareaToEditor( textarea ) ; 267
268
editor.ReplaceTextarea() ; 269
} 270
} 271
})() ; 272
273
function FCKeditor_IsCompatibleBrowser() 274
{ 275
var sAgent = navigator.userAgent.toLowerCase() ; 276
277
// Internet Explorer 5.5+ 278
if ( /*@cc_on!@*/false && sAgent.indexOf("mac") == -1 ) 279
{ 280
var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ; 281
return ( sBrowserVersion >= 5.5 ) ; 282
} 283
284
// Gecko (Opera 9 tries to behave like Gecko at this point). 285
if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 && !( typeof(opera) == 'object' && opera.postError ) ) 286
return true ; 287
288
// Opera 9.50+ 289
if ( window.opera && window.opera.version && parseFloat( window.opera.version() ) >= 9.5 ) 290
return true ; 291
292
// Adobe AIR 293
// Checked before Safari because AIR have the WebKit rich text editor 294
// features from Safari 3.0.4, but the version reported is 420. 295
if ( sAgent.indexOf( ' adobeair/' ) != -1 ) 296
return ( sAgent.match( / adobeair\/(\d+)/ )[1] >= 1 ) ; // Build must be at least v1 297
298
// Safari 3+ 299
if ( sAgent.indexOf( ' applewebkit/' ) != -1 ) 300
return ( sAgent.match( / applewebkit\/(\d+)/ )[1] >= 522 ) ; // Build must be at least 522 (v3) 301
302
return false ; 303
} 304



* FCKeditor - The text editor for Internet - http://www.fckeditor.net

}