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