Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
392 jpm 1
/*
2
 * FCKeditor - The text editor for internet
3
 * Copyright (C) 2003-2005 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
 * File Name: fckeditor.js
12
 * 	This is the integration file for JavaScript.
13
 *
14
 * 	It defines the FCKeditor class that can be used to create editor
15
 * 	instances in a HTML page in the client side. For server side
16
 * 	operations, use the specific integration system.
17
 *
18
 * File Authors:
19
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
20
 */
21
 
22
// FCKeditor Class
23
var FCKeditor = function( instanceName, width, height, toolbarSet, value )
24
{
25
	// Properties
26
	this.InstanceName	= instanceName ;
27
	this.Width			= width			|| '100%' ;
28
	this.Height			= height		|| '200' ;
29
	this.ToolbarSet		= toolbarSet	|| 'Default' ;
30
	this.Value			= value			|| '' ;
31
	this.BasePath		= '/fckeditor/' ;
32
	this.CheckBrowser	= true ;
33
	this.DisplayErrors	= true ;
34
 
35
	this.Config			= new Object() ;
36
 
37
	// Events
38
	this.OnError		= null ;	// function( source, errorNumber, errorDescription )
39
}
40
 
41
FCKeditor.prototype.Create = function()
42
{
43
	// Check for errors
44
	if ( !this.InstanceName || this.InstanceName.length == 0 )
45
	{
46
		this._ThrowError( 701, 'You must specify a instance name.' ) ;
47
		return ;
48
	}
49
 
50
	document.write( '<div>' ) ;
51
 
52
	if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
53
	{
54
		document.write( '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode( this.Value ) + '" />' ) ;
55
		document.write( this._GetConfigHtml() ) ;
56
		document.write( this._GetIFrameHtml() ) ;
57
	}
58
	else
59
	{
60
		var sWidth  = this.Width.toString().indexOf('%')  > 0 ? this.Width  : this.Width  + 'px' ;
61
		var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ;
62
		document.write('<textarea name="' + this.InstanceName + '" rows="4" cols="40" style="WIDTH: ' + sWidth + '; HEIGHT: ' + sHeight + '" wrap="virtual">' + this._HTMLEncode( this.Value ) + '<\/textarea>') ;
63
	}
64
 
65
	document.write( '</div>' ) ;
66
}
67
 
68
FCKeditor.prototype.ReplaceTextarea = function()
69
{
70
	if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
71
	{
72
		var oTextarea = document.getElementById( this.InstanceName ) ;
73
 
74
		if ( !oTextarea )
75
			oTextarea = document.getElementsByName( this.InstanceName )[0] ;
76
 
77
		if ( !oTextarea || oTextarea.tagName != 'TEXTAREA' )
78
		{
79
			alert( 'Error: The TEXTAREA id "' + this.InstanceName + '" was not found' ) ;
80
			return ;
81
		}
82
 
83
		oTextarea.style.display = 'none' ;
84
		this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ;
85
		this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ;
86
	}
87
}
88
 
89
FCKeditor.prototype._InsertHtmlBefore = function( html, element )
90
{
91
	if ( element.insertAdjacentHTML )	// IE
92
		element.insertAdjacentHTML( 'beforeBegin', html ) ;
93
	else								// Gecko
94
	{
95
		var oRange = document.createRange() ;
96
		oRange.setStartBefore( element ) ;
97
		var oFragment = oRange.createContextualFragment( html );
98
		element.parentNode.insertBefore( oFragment, element ) ;
99
	}
100
}
101
 
102
FCKeditor.prototype._GetConfigHtml = function()
103
{
104
	var sConfig = '' ;
105
	for ( var o in this.Config )
106
	{
107
		if ( sConfig.length > 0 ) sConfig += '&amp;' ;
108
		sConfig += escape(o) + '=' + escape( this.Config[o] ) ;
109
	}
110
 
111
	return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" />' ;
112
}
113
 
114
FCKeditor.prototype._GetIFrameHtml = function()
115
{
116
	var sLink = this.BasePath + 'editor/fckeditor.html?InstanceName=' + this.InstanceName ;
117
	if (this.ToolbarSet) sLink += '&Toolbar=' + this.ToolbarSet ;
118
 
119
	return '<iframe id="' + this.InstanceName + '___Frame" src="' + sLink + '" width="' + this.Width + '" height="' + this.Height + '" frameborder="no" scrolling="no"></iframe>' ;
120
}
121
 
122
FCKeditor.prototype._IsCompatibleBrowser = function()
123
{
124
	var sAgent = navigator.userAgent.toLowerCase() ;
125
 
126
	// Internet Explorer
127
	if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 )
128
	{
129
		var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ;
130
		return ( sBrowserVersion >= 5.5 ) ;
131
	}
132
	// Gecko
133
	else if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 )
134
		return true ;
135
	else
136
		return false ;
137
}
138
 
139
FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription )
140
{
141
	this.ErrorNumber		= errorNumber ;
142
	this.ErrorDescription	= errorDescription ;
143
 
144
	if ( this.DisplayErrors )
145
	{
146
		document.write( '<div style="COLOR: #ff0000">' ) ;
147
		document.write( '[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]' ) ;
148
		document.write( '</div>' ) ;
149
	}
150
 
151
	if ( typeof( this.OnError ) == 'function' )
152
		this.OnError( this, errorNumber, errorDescription ) ;
153
}
154
 
155
FCKeditor.prototype._HTMLEncode = function( text )
156
{
157
	if ( typeof( text ) != "string" )
158
		text = text.toString() ;
159
 
160
	text = text.replace(/&/g, "&amp;") ;
161
	text = text.replace(/"/g, "&quot;") ;
162
	text = text.replace(/</g, "&lt;") ;
163
	text = text.replace(/>/g, "&gt;") ;
164
	text = text.replace(/'/g, "&#39;") ;
165
 
166
	return text ;
167
}