2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2010 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
* Create the FCKeditorAPI object that is available as a global object in
22
* the page where the editor is placed in.
27
function InitializeAPI()
29
var oParentWindow = window.parent ;
31
if ( !( FCKeditorAPI = oParentWindow.FCKeditorAPI ) )
33
// Make the FCKeditorAPI object available in the parent window. Use
34
// eval so this core runs in the parent's scope and so it will still be
35
// available if the editor instance is removed ("Can't execute code
36
// from a freed script" error).
38
// Note: we check the existence of oEditor.GetParentForm because some external
39
// code (like JSON) can extend the Object prototype and we get then extra oEditor
40
// objects that aren't really FCKeditor instances.
42
'window.FCKeditorAPI = {' +
43
'Version : "2.6.6",' +
44
'VersionBuild : "25427",' +
45
'Instances : window.FCKeditorAPI && window.FCKeditorAPI.Instances || {},' +
47
'GetInstance : function( name )' +
49
'return this.Instances[ name ];' +
52
'_FormSubmit : function()' +
54
'for ( var name in FCKeditorAPI.Instances )' +
56
'var oEditor = FCKeditorAPI.Instances[ name ] ;' +
57
'if ( oEditor.GetParentForm && oEditor.GetParentForm() == this )' +
58
'oEditor.UpdateLinkedField() ;' +
60
'this._FCKOriginalSubmit() ;' +
63
'_FunctionQueue : window.FCKeditorAPI && window.FCKeditorAPI._FunctionQueue || {' +
64
'Functions : new Array(),' +
65
'IsRunning : false,' +
67
'Add : function( f )' +
69
'this.Functions.push( f );' +
70
'if ( !this.IsRunning )' +
74
'StartNext : function()' +
76
'var aQueue = this.Functions ;' +
77
'if ( aQueue.length > 0 )' +
79
'this.IsRunning = true;' +
83
'this.IsRunning = false;' +
86
'Remove : function( f )' +
88
'var aQueue = this.Functions;' +
90
'while( (fFunc = aQueue[ i ]) )' +
93
'aQueue.splice( i,1 );' +
101
// In IE, the "eval" function is not always available (it works with
102
// the JavaScript samples, but not with the ASP ones, for example).
103
// So, let's use the execScript instead.
104
if ( oParentWindow.execScript )
105
oParentWindow.execScript( sScript, 'JavaScript' ) ;
108
if ( FCKBrowserInfo.IsGecko10 )
110
// FF 1.0.4 gives an error with the request bellow. The
111
// following seams to work well.
112
eval.call( oParentWindow, sScript ) ;
114
else if( FCKBrowserInfo.IsAIR )
116
FCKAdobeAIR.FCKeditorAPI_Evaluate( oParentWindow, sScript ) ;
118
else if ( FCKBrowserInfo.IsSafari )
120
// oParentWindow.eval in Safari executes in the calling window
121
// environment, instead of the parent one. The following should
123
var oParentDocument = oParentWindow.document ;
124
var eScript = oParentDocument.createElement('script') ;
125
eScript.appendChild( oParentDocument.createTextNode( sScript ) ) ;
126
oParentDocument.documentElement.appendChild( eScript ) ;
129
oParentWindow.eval( sScript ) ;
132
FCKeditorAPI = oParentWindow.FCKeditorAPI ;
134
// The __Instances properly has been changed to the public Instances,
135
// but we should still have the "deprecated" version of it.
136
FCKeditorAPI.__Instances = FCKeditorAPI.Instances ;
139
// Add the current instance to the FCKeditorAPI's instances collection.
140
FCKeditorAPI.Instances[ FCK.Name ] = FCK ;
143
// Attach to the form onsubmit event and to the form.submit().
144
function _AttachFormSubmitToAPI()
146
// Get the linked field form.
147
var oForm = FCK.GetParentForm() ;
151
// Attach to the onsubmit event.
152
FCKTools.AddEventListener( oForm, 'submit', FCK.UpdateLinkedField ) ;
154
// IE sees oForm.submit function as an 'object'.
155
if ( !oForm._FCKOriginalSubmit && ( typeof( oForm.submit ) == 'function' || ( !oForm.submit.tagName && !oForm.submit.length ) ) )
157
// Save the original submit.
158
oForm._FCKOriginalSubmit = oForm.submit ;
160
// Create our replacement for the submit.
161
oForm.submit = FCKeditorAPI._FormSubmit ;
166
function FCKeditorAPI_Cleanup()
168
if ( window.FCKConfig && FCKConfig.MsWebBrowserControlCompat
169
&& !window.FCKUnloadFlag )
171
delete FCKeditorAPI.Instances[ FCK.Name ] ;
173
function FCKeditorAPI_ConfirmCleanup()
175
if ( window.FCKConfig && FCKConfig.MsWebBrowserControlCompat )
176
window.FCKUnloadFlag = true ;
178
FCKTools.AddEventListener( window, 'unload', FCKeditorAPI_Cleanup ) ;
179
FCKTools.AddEventListener( window, 'beforeunload', FCKeditorAPI_ConfirmCleanup) ;