2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2007 Frederico Caldeira Knabben
7
* Licensed under the terms of any of the following licenses at your
10
* - GNU General Public License Version 2 or later (the "GPL")
11
* http://www.gnu.org/licenses/gpl.html
13
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
* http://www.gnu.org/licenses/lgpl.html
16
* - Mozilla Public License Version 1.1 or later (the "MPL")
17
* http://www.mozilla.org/MPL/MPL-1.1.html
21
* This is the integration file for JavaScript.
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.
29
var FCKeditor = function( instanceName, width, height, toolbarSet, value )
32
this.InstanceName = instanceName ;
33
this.Width = width || '100%' ;
34
this.Height = height || '300' ;
35
this.ToolbarSet = toolbarSet || 'Default' ;
36
this.Value = value || '' ;
37
this.BasePath = '/fckeditor/' ;
38
this.CheckBrowser = true ;
39
this.DisplayErrors = true ;
40
this.EnableSafari = true ; // This is a temporary property, while Safari support is under development.
41
this.EnableOpera = true ; // This is a temporary property, while Opera support is under development.
43
this.Config = new Object() ;
46
this.OnError = null ; // function( source, errorNumber, errorDescription )
49
FCKeditor.prototype.Version = '2.4.3' ;
50
FCKeditor.prototype.VersionBuild = '15657' ;
52
FCKeditor.prototype.Create = function()
54
document.write( this.CreateHtml() ) ;
57
FCKeditor.prototype.CreateHtml = function()
60
if ( !this.InstanceName || this.InstanceName.length == 0 )
62
this._ThrowError( 701, 'You must specify an instance name.' ) ;
68
if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
70
sHtml += '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode( this.Value ) + '" style="display:none" />' ;
71
sHtml += this._GetConfigHtml() ;
72
sHtml += this._GetIFrameHtml() ;
76
var sWidth = this.Width.toString().indexOf('%') > 0 ? this.Width : this.Width + 'px' ;
77
var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ;
78
sHtml += '<textarea name="' + this.InstanceName + '" rows="4" cols="40" style="width:' + sWidth + ';height:' + sHeight + '">' + this._HTMLEncode( this.Value ) + '<\/textarea>' ;
86
FCKeditor.prototype.ReplaceTextarea = function()
88
if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
90
// We must check the elements firstly using the Id and then the name.
91
var oTextarea = document.getElementById( this.InstanceName ) ;
92
var colElementsByName = document.getElementsByName( this.InstanceName ) ;
94
while ( oTextarea || i == 0 )
96
if ( oTextarea && oTextarea.tagName.toLowerCase() == 'textarea' )
98
oTextarea = colElementsByName[i++] ;
103
alert( 'Error: The TEXTAREA with id or name set to "' + this.InstanceName + '" was not found' ) ;
107
oTextarea.style.display = 'none' ;
108
this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ;
109
this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ;
113
FCKeditor.prototype._InsertHtmlBefore = function( html, element )
115
if ( element.insertAdjacentHTML ) // IE
116
element.insertAdjacentHTML( 'beforeBegin', html ) ;
119
var oRange = document.createRange() ;
120
oRange.setStartBefore( element ) ;
121
var oFragment = oRange.createContextualFragment( html );
122
element.parentNode.insertBefore( oFragment, element ) ;
126
FCKeditor.prototype._GetConfigHtml = function()
129
for ( var o in this.Config )
131
if ( sConfig.length > 0 ) sConfig += '&' ;
132
sConfig += encodeURIComponent( o ) + '=' + encodeURIComponent( this.Config[o] ) ;
135
return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" style="display:none" />' ;
138
FCKeditor.prototype._GetIFrameHtml = function()
140
var sFile = 'fckeditor.html' ;
144
if ( (/fcksource=true/i).test( window.top.location.search ) )
145
sFile = 'fckeditor.original.html' ;
147
catch (e) { /* Ignore it. Much probably we are inside a FRAME where the "top" is in another domain (security error). */ }
149
var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.InstanceName ) ;
150
if (this.ToolbarSet) sLink += '&Toolbar=' + this.ToolbarSet ;
152
return '<iframe id="' + this.InstanceName + '___Frame" src="' + sLink + '" width="' + this.Width + '" height="' + this.Height + '" frameborder="0" scrolling="no"></iframe>' ;
155
FCKeditor.prototype._IsCompatibleBrowser = function()
157
return FCKeditor_IsCompatibleBrowser( this.EnableSafari, this.EnableOpera ) ;
160
FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription )
162
this.ErrorNumber = errorNumber ;
163
this.ErrorDescription = errorDescription ;
165
if ( this.DisplayErrors )
167
document.write( '<div style="COLOR: #ff0000">' ) ;
168
document.write( '[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]' ) ;
169
document.write( '</div>' ) ;
172
if ( typeof( this.OnError ) == 'function' )
173
this.OnError( this, errorNumber, errorDescription ) ;
176
FCKeditor.prototype._HTMLEncode = function( text )
178
if ( typeof( text ) != "string" )
179
text = text.toString() ;
182
/&/g, "&").replace(
183
/"/g, """).replace(
184
/</g, "<").replace(
190
function FCKeditor_IsCompatibleBrowser( enableSafari, enableOpera )
192
var sAgent = navigator.userAgent.toLowerCase() ;
195
if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 )
197
var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ;
198
return ( sBrowserVersion >= 5.5 ) ;
201
// Gecko (Opera 9 tries to behave like Gecko at this point).
202
if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 && !( typeof(opera) == 'object' && opera.postError ) )
206
if ( enableOpera && sAgent.indexOf( 'opera' ) == 0 && parseInt( navigator.appVersion, 10 ) >= 9 )
210
if ( enableSafari && sAgent.indexOf( 'safari' ) != -1 )
211
return ( sAgent.match( /safari\/(\d+)/ )[1] >= 312 ) ; // Build must be at least 312 (1.3)
b'\\ No newline at end of file'