Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 ddelon 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
	this.EnableSafari	= false ;		// This is a temporary property, while Safari support is under development.
35
 
36
	this.Config			= new Object() ;
37
 
38
	// Events
39
	this.OnError		= null ;	// function( source, errorNumber, errorDescription )
40
}
41
 
42
FCKeditor.prototype.Create = function()
43
{
44
	// Check for errors
45
	if ( !this.InstanceName || this.InstanceName.length == 0 )
46
	{
47
		this._ThrowError( 701, 'You must specify a instance name.' ) ;
48
		return ;
49
	}
50
 
51
	document.write( '<div>' ) ;
52
 
53
	if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
54
	{
55
		document.write( '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode( this.Value ) + '" />' ) ;
56
		document.write( this._GetConfigHtml() ) ;
57
		document.write( this._GetIFrameHtml() ) ;
58
	}
59
	else
60
	{
61
		var sWidth  = this.Width.toString().indexOf('%')  > 0 ? this.Width  : this.Width  + 'px' ;
62
		var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ;
63
		document.write('<textarea name="' + this.InstanceName + '" rows="4" cols="40" style="WIDTH: ' + sWidth + '; HEIGHT: ' + sHeight + '" wrap="virtual">' + this._HTMLEncode( this.Value ) + '<\/textarea>') ;
64
	}
65
 
66
	document.write( '</div>' ) ;
67
}
68
 
69
FCKeditor.prototype.ReplaceTextarea = function()
70
{
71
	if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
72
	{
73
		var oTextarea = document.getElementById( this.InstanceName ) ;
74
 
75
		if ( !oTextarea )
76
			oTextarea = document.getElementsByName( this.InstanceName )[0] ;
77
 
78
		if ( !oTextarea || oTextarea.tagName != 'TEXTAREA' )
79
		{
80
			alert( 'Error: The TEXTAREA id "' + this.InstanceName + '" was not found' ) ;
81
			return ;
82
		}
83
 
84
		oTextarea.style.display = 'none' ;
85
		this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ;
86
		this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ;
87
	}
88
}
89
 
90
FCKeditor.prototype._InsertHtmlBefore = function( html, element )
91
{
92
	if ( element.insertAdjacentHTML )	// IE
93
		element.insertAdjacentHTML( 'beforeBegin', html ) ;
94
	else								// Gecko
95
	{
96
		var oRange = document.createRange() ;
97
		oRange.setStartBefore( element ) ;
98
		var oFragment = oRange.createContextualFragment( html );
99
		element.parentNode.insertBefore( oFragment, element ) ;
100
	}
101
}
102
 
103
FCKeditor.prototype._GetConfigHtml = function()
104
{
105
	var sConfig = '' ;
106
	for ( var o in this.Config )
107
	{
108
		if ( sConfig.length > 0 ) sConfig += '&amp;' ;
109
		sConfig += escape(o) + '=' + escape( this.Config[o] ) ;
110
	}
111
 
112
	return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" />' ;
113
}
114
 
115
FCKeditor.prototype._GetIFrameHtml = function()
116
{
117
	var sLink = this.BasePath + 'editor/fckeditor.html?InstanceName=' + this.InstanceName ;
118
	if (this.ToolbarSet) sLink += '&Toolbar=' + this.ToolbarSet ;
119
 
120
	return '<iframe id="' + this.InstanceName + '___Frame" src="' + sLink + '" width="' + this.Width + '" height="' + this.Height + '" frameborder="no" scrolling="no"></iframe>' ;
121
}
122
 
123
FCKeditor.prototype._IsCompatibleBrowser = function()
124
{
125
	var sAgent = navigator.userAgent.toLowerCase() ;
126
 
127
	// Internet Explorer
128
	if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 )
129
	{
130
		var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ;
131
		return ( sBrowserVersion >= 5.5 ) ;
132
	}
133
	// Gecko
134
	else if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 )
135
		return true ;
136
	// Safari
137
	else if ( this.EnableSafari && sAgent.indexOf( 'safari' ) != -1 )
138
		return ( sAgent.match( /safari\/(\d+)/ )[1] >= 312 ) ;	// Build must be at least 312 (1.3)
139
	else
140
		return false ;
141
}
142
 
143
FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription )
144
{
145
	this.ErrorNumber		= errorNumber ;
146
	this.ErrorDescription	= errorDescription ;
147
 
148
	if ( this.DisplayErrors )
149
	{
150
		document.write( '<div style="COLOR: #ff0000">' ) ;
151
		document.write( '[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]' ) ;
152
		document.write( '</div>' ) ;
153
	}
154
 
155
	if ( typeof( this.OnError ) == 'function' )
156
		this.OnError( this, errorNumber, errorDescription ) ;
157
}
158
 
159
FCKeditor.prototype._HTMLEncode = function( text )
160
{
161
	if ( typeof( text ) != "string" )
162
		text = text.toString() ;
163
 
164
	text = text.replace(/&/g, "&amp;") ;
165
	text = text.replace(/"/g, "&quot;") ;
166
	text = text.replace(/</g, "&lt;") ;
167
	text = text.replace(/>/g, "&gt;") ;
168
	text = text.replace(/'/g, "&#39;") ;
169
 
170
	return text ;
171
}