431 |
ddelon |
1 |
/*
|
|
|
2 |
* FCKeditor - The text editor for internet
|
875 |
ddelon |
3 |
* Copyright (C) 2003-2006 Frederico Caldeira Knabben
|
431 |
ddelon |
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 |
*
|
875 |
ddelon |
11 |
* "Support Open Source software. What about a donation today?"
|
|
|
12 |
*
|
431 |
ddelon |
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 |
|
|
|
24 |
// FCKeditor Class
|
|
|
25 |
var FCKeditor = function( instanceName, width, height, toolbarSet, value )
|
|
|
26 |
{
|
|
|
27 |
// Properties
|
|
|
28 |
this.InstanceName = instanceName ;
|
|
|
29 |
this.Width = width || '100%' ;
|
|
|
30 |
this.Height = height || '200' ;
|
|
|
31 |
this.ToolbarSet = toolbarSet || 'Default' ;
|
|
|
32 |
this.Value = value || '' ;
|
|
|
33 |
this.BasePath = '/fckeditor/' ;
|
|
|
34 |
this.CheckBrowser = true ;
|
|
|
35 |
this.DisplayErrors = true ;
|
|
|
36 |
this.EnableSafari = false ; // This is a temporary property, while Safari support is under development.
|
875 |
ddelon |
37 |
this.EnableOpera = false ; // This is a temporary property, while Opera support is under development.
|
431 |
ddelon |
38 |
|
|
|
39 |
this.Config = new Object() ;
|
|
|
40 |
|
|
|
41 |
// Events
|
|
|
42 |
this.OnError = null ; // function( source, errorNumber, errorDescription )
|
|
|
43 |
}
|
|
|
44 |
|
875 |
ddelon |
45 |
FCKeditor.prototype.Version = '2.3' ;
|
|
|
46 |
FCKeditor.prototype.VersionBuild = '1054' ;
|
|
|
47 |
|
431 |
ddelon |
48 |
FCKeditor.prototype.Create = function()
|
|
|
49 |
{
|
|
|
50 |
// Check for errors
|
|
|
51 |
if ( !this.InstanceName || this.InstanceName.length == 0 )
|
|
|
52 |
{
|
875 |
ddelon |
53 |
this._ThrowError( 701, 'You must specify an instance name.' ) ;
|
431 |
ddelon |
54 |
return ;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
document.write( '<div>' ) ;
|
|
|
58 |
|
|
|
59 |
if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
|
|
|
60 |
{
|
875 |
ddelon |
61 |
document.write( '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode( this.Value ) + '" style="display:none" />' ) ;
|
431 |
ddelon |
62 |
document.write( this._GetConfigHtml() ) ;
|
|
|
63 |
document.write( this._GetIFrameHtml() ) ;
|
|
|
64 |
}
|
|
|
65 |
else
|
|
|
66 |
{
|
|
|
67 |
var sWidth = this.Width.toString().indexOf('%') > 0 ? this.Width : this.Width + 'px' ;
|
|
|
68 |
var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ;
|
875 |
ddelon |
69 |
document.write('<textarea name="' + this.InstanceName + '" rows="4" cols="40" style="WIDTH: ' + sWidth + '; HEIGHT: ' + sHeight + '">' + this._HTMLEncode( this.Value ) + '<\/textarea>') ;
|
431 |
ddelon |
70 |
}
|
|
|
71 |
|
|
|
72 |
document.write( '</div>' ) ;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
FCKeditor.prototype.ReplaceTextarea = function()
|
|
|
76 |
{
|
|
|
77 |
if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
|
|
|
78 |
{
|
875 |
ddelon |
79 |
// We must check the elements firstly using the Id and then the name.
|
431 |
ddelon |
80 |
var oTextarea = document.getElementById( this.InstanceName ) ;
|
875 |
ddelon |
81 |
var colElementsByName = document.getElementsByName( this.InstanceName ) ;
|
|
|
82 |
var i = 0;
|
|
|
83 |
while ( oTextarea || i == 0 )
|
|
|
84 |
{
|
|
|
85 |
if ( oTextarea && oTextarea.tagName == 'TEXTAREA' )
|
|
|
86 |
break ;
|
|
|
87 |
oTextarea = colElementsByName[i++] ;
|
|
|
88 |
}
|
431 |
ddelon |
89 |
|
|
|
90 |
if ( !oTextarea )
|
|
|
91 |
{
|
875 |
ddelon |
92 |
alert( 'Error: The TEXTAREA with id or name set to "' + this.InstanceName + '" was not found' ) ;
|
431 |
ddelon |
93 |
return ;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
oTextarea.style.display = 'none' ;
|
|
|
97 |
this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ;
|
|
|
98 |
this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ;
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
FCKeditor.prototype._InsertHtmlBefore = function( html, element )
|
|
|
103 |
{
|
|
|
104 |
if ( element.insertAdjacentHTML ) // IE
|
|
|
105 |
element.insertAdjacentHTML( 'beforeBegin', html ) ;
|
|
|
106 |
else // Gecko
|
|
|
107 |
{
|
|
|
108 |
var oRange = document.createRange() ;
|
|
|
109 |
oRange.setStartBefore( element ) ;
|
|
|
110 |
var oFragment = oRange.createContextualFragment( html );
|
|
|
111 |
element.parentNode.insertBefore( oFragment, element ) ;
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
FCKeditor.prototype._GetConfigHtml = function()
|
|
|
116 |
{
|
|
|
117 |
var sConfig = '' ;
|
|
|
118 |
for ( var o in this.Config )
|
|
|
119 |
{
|
|
|
120 |
if ( sConfig.length > 0 ) sConfig += '&' ;
|
|
|
121 |
sConfig += escape(o) + '=' + escape( this.Config[o] ) ;
|
|
|
122 |
}
|
|
|
123 |
|
875 |
ddelon |
124 |
return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" style="display:none" />' ;
|
431 |
ddelon |
125 |
}
|
|
|
126 |
|
|
|
127 |
FCKeditor.prototype._GetIFrameHtml = function()
|
|
|
128 |
{
|
875 |
ddelon |
129 |
var sFile = (/fcksource=true/i).test( window.top.location.search ) ? 'fckeditor.original.html' : 'fckeditor.html' ;
|
|
|
130 |
|
|
|
131 |
var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + this.InstanceName ;
|
431 |
ddelon |
132 |
if (this.ToolbarSet) sLink += '&Toolbar=' + this.ToolbarSet ;
|
|
|
133 |
|
875 |
ddelon |
134 |
return '<iframe id="' + this.InstanceName + '___Frame" src="' + sLink + '" width="' + this.Width + '" height="' + this.Height + '" frameborder="0" scrolling="no"></iframe>' ;
|
431 |
ddelon |
135 |
}
|
|
|
136 |
|
|
|
137 |
FCKeditor.prototype._IsCompatibleBrowser = function()
|
|
|
138 |
{
|
|
|
139 |
var sAgent = navigator.userAgent.toLowerCase() ;
|
875 |
ddelon |
140 |
|
431 |
ddelon |
141 |
// Internet Explorer
|
|
|
142 |
if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 )
|
|
|
143 |
{
|
|
|
144 |
var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ;
|
|
|
145 |
return ( sBrowserVersion >= 5.5 ) ;
|
|
|
146 |
}
|
875 |
ddelon |
147 |
|
431 |
ddelon |
148 |
// Gecko
|
875 |
ddelon |
149 |
if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 )
|
431 |
ddelon |
150 |
return true ;
|
875 |
ddelon |
151 |
|
|
|
152 |
// Opera
|
|
|
153 |
if ( this.EnableOpera )
|
|
|
154 |
{
|
|
|
155 |
var aMatch = sAgent.match( /^opera\/(\d+\.\d+)/ ) ;
|
|
|
156 |
if ( aMatch && aMatch[1] >= 9.0 )
|
|
|
157 |
return true ;
|
|
|
158 |
}
|
|
|
159 |
|
431 |
ddelon |
160 |
// Safari
|
875 |
ddelon |
161 |
if ( this.EnableSafari && sAgent.indexOf( 'safari' ) != -1 )
|
431 |
ddelon |
162 |
return ( sAgent.match( /safari\/(\d+)/ )[1] >= 312 ) ; // Build must be at least 312 (1.3)
|
875 |
ddelon |
163 |
|
|
|
164 |
return false ;
|
431 |
ddelon |
165 |
}
|
|
|
166 |
|
|
|
167 |
FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription )
|
|
|
168 |
{
|
|
|
169 |
this.ErrorNumber = errorNumber ;
|
|
|
170 |
this.ErrorDescription = errorDescription ;
|
|
|
171 |
|
|
|
172 |
if ( this.DisplayErrors )
|
|
|
173 |
{
|
|
|
174 |
document.write( '<div style="COLOR: #ff0000">' ) ;
|
|
|
175 |
document.write( '[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]' ) ;
|
|
|
176 |
document.write( '</div>' ) ;
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
if ( typeof( this.OnError ) == 'function' )
|
|
|
180 |
this.OnError( this, errorNumber, errorDescription ) ;
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
FCKeditor.prototype._HTMLEncode = function( text )
|
|
|
184 |
{
|
|
|
185 |
if ( typeof( text ) != "string" )
|
|
|
186 |
text = text.toString() ;
|
|
|
187 |
|
|
|
188 |
text = text.replace(/&/g, "&") ;
|
|
|
189 |
text = text.replace(/"/g, """) ;
|
|
|
190 |
text = text.replace(/</g, "<") ;
|
|
|
191 |
text = text.replace(/>/g, ">") ;
|
|
|
192 |
text = text.replace(/'/g, "'") ;
|
|
|
193 |
|
|
|
194 |
return text ;
|
|
|
195 |
}
|