source: trunk/admin/inc/FCKeditor/fckeditor.js@ 64

Last change on this file since 64 was 2, checked in by root, 15 years ago

importo il progetto

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