source: trunk/phpgwapi/js/ckeditor/_source/core/loader.js @ 2862

Revision 2862, 8.4 KB checked in by rodsouza, 14 years ago (diff)

Ticket #663 - Atualizando e centralizando o CKEditor (v. 3.2.1)

Line 
1/*
2Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
3For licensing, see LICENSE.html or http://ckeditor.com/license
4*/
5
6/**
7 * @fileOverview Defines the {@link CKEDITOR.loader} objects, which is used to
8 *              load core scripts and their dependencies from _source.
9 */
10
11if ( typeof CKEDITOR == 'undefined' )
12        CKEDITOR = {};
13
14if ( !CKEDITOR.loader )
15{
16        /**
17         * Load core scripts and their dependencies from _source.
18         * @namespace
19         * @example
20         */
21        CKEDITOR.loader = (function()
22        {
23                // Table of script names and their dependencies.
24                var scripts =
25                {
26                        'core/_bootstrap'               : [ 'core/config', 'core/ckeditor', 'core/plugins', 'core/scriptloader', 'core/tools', /* The following are entries that we want to force loading at the end to avoid dependence recursion */ 'core/dom/comment', 'core/dom/elementpath', 'core/dom/text', 'core/dom/range' ],
27                        'core/ajax'                             : [ 'core/xml' ],
28                        'core/ckeditor'                 : [ 'core/ckeditor_basic', 'core/dom', 'core/dtd', 'core/dom/document', 'core/dom/element', 'core/editor', 'core/event', 'core/htmlparser', 'core/htmlparser/element', 'core/htmlparser/fragment', 'core/htmlparser/filter', 'core/htmlparser/basicwriter', 'core/tools' ],
29                        'core/ckeditor_base'    : [],
30                        'core/ckeditor_basic'   : [ 'core/editor_basic', 'core/env', 'core/event' ],
31                        'core/command'                  : [],
32                        'core/config'                   : [ 'core/ckeditor_base' ],
33                        'core/dom'                              : [],
34                        'core/dom/comment'              : [ 'core/dom/node' ],
35                        'core/dom/document'             : [ 'core/dom', 'core/dom/domobject', 'core/dom/window' ],
36                        'core/dom/documentfragment'     : [ 'core/dom/element' ],
37                        'core/dom/element'              : [ 'core/dom', 'core/dom/document', 'core/dom/domobject', 'core/dom/node', 'core/dom/nodelist', 'core/tools' ],
38                        'core/dom/elementpath'  : [ 'core/dom/element' ],
39                        'core/dom/event'                : [],
40                        'core/dom/node'                 : [ 'core/dom/domobject', 'core/tools' ],
41                        'core/dom/nodelist'             : [ 'core/dom/node' ],
42                        'core/dom/domobject'    : [ 'core/dom/event' ],
43                        'core/dom/range'                : [ 'core/dom/document', 'core/dom/documentfragment', 'core/dom/element', 'core/dom/walker' ],
44                        'core/dom/text'                 : [ 'core/dom/node', 'core/dom/domobject' ],
45                        'core/dom/walker'               : [ 'core/dom/node' ],
46                        'core/dom/window'               : [ 'core/dom/domobject' ],
47                        'core/dtd'                              : [ 'core/tools' ],
48                        'core/editor'                   : [ 'core/command', 'core/config', 'core/editor_basic', 'core/focusmanager', 'core/lang', 'core/plugins', 'core/skins', 'core/themes', 'core/tools', 'core/ui' ],
49                        'core/editor_basic'             : [ 'core/event' ],
50                        'core/env'                              : [],
51                        'core/event'                    : [],
52                        'core/focusmanager'             : [],
53                        'core/htmlparser'               : [],
54                        'core/htmlparser/comment'       : [ 'core/htmlparser' ],
55                        'core/htmlparser/element'       : [ 'core/htmlparser', 'core/htmlparser/fragment' ],
56                        'core/htmlparser/fragment'      : [ 'core/htmlparser', 'core/htmlparser/comment', 'core/htmlparser/text', 'core/htmlparser/cdata' ],
57                        'core/htmlparser/text'          : [ 'core/htmlparser' ],
58                        'core/htmlparser/cdata'         : [ 'core/htmlparser' ],
59                        'core/htmlparser/filter'        : [ 'core/htmlparser' ],
60                        'core/htmlparser/basicwriter': [ 'core/htmlparser' ],
61                        'core/imagecacher'              : [ 'core/dom/element' ],
62                        'core/lang'                             : [],
63                        'core/plugins'                  : [ 'core/resourcemanager' ],
64                        'core/resourcemanager'  : [ 'core/scriptloader', 'core/tools' ],
65                        'core/scriptloader'             : [ 'core/dom/element', 'core/env' ],
66                        'core/skins'                    : [ 'core/imagecacher', 'core/scriptloader' ],
67                        'core/themes'                   : [ 'core/resourcemanager' ],
68                        'core/tools'                    : [ 'core/env' ],
69                        'core/ui'                               : [],
70                        'core/xml'                              : [ 'core/env' ]
71                };
72
73                var basePath = (function()
74                {
75                        // This is a copy of CKEDITOR.basePath, but requires the script having
76                        // "_source/core/loader.js".
77                        if ( CKEDITOR && CKEDITOR.basePath )
78                                return CKEDITOR.basePath;
79
80                        // Find out the editor directory path, based on its <script> tag.
81                        var path = '';
82                        var scripts = document.getElementsByTagName( 'script' );
83
84                        for ( var i = 0 ; i < scripts.length ; i++ )
85                        {
86                                var match = scripts[i].src.match( /(^|.*[\\\/])core\/loader.js(?:\?.*)?$/i );
87
88                                if ( match )
89                                {
90                                        path = match[1];
91                                        break;
92                                }
93                        }
94
95                        // In IE (only) the script.src string is the raw valued entered in the
96                        // HTML. Other browsers return the full resolved URL instead.
97                        if ( path.indexOf('://') == -1 )
98                        {
99                                // Absolute path.
100                                if ( path.indexOf( '/' ) === 0 )
101                                        path = location.href.match( /^.*?:\/\/[^\/]*/ )[0] + path;
102                                // Relative path.
103                                else
104                                        path = location.href.match( /^[^\?]*\// )[0] + path;
105                        }
106
107                        return path;
108                })();
109
110                var timestamp = 'A39E';
111
112                var getUrl = function( resource )
113                {
114                        if ( CKEDITOR && CKEDITOR.getUrl )
115                                return CKEDITOR.getUrl( resource );
116
117                        return basePath + resource +
118                                ( resource.indexOf( '?' ) >= 0 ? '&' : '?' ) +
119                                't=' + timestamp;
120                };
121
122                var pendingLoad = [];
123
124                /** @lends CKEDITOR.loader */
125                return {
126                        /**
127                         * The list of loaded scripts in their loading order.
128                         * @type Array
129                         * @example
130                         * // Alert the loaded script names.
131                         * alert( <b>CKEDITOR.loader.loadedScripts</b> );
132                         */
133                        loadedScripts : [],
134
135                        loadPending : function()
136                        {
137                                var scriptName = pendingLoad.shift();
138
139                                if ( !scriptName )
140                                        return;
141
142                                var scriptSrc = getUrl( '_source/' + scriptName + '.js' );
143
144                                var script = document.createElement( 'script' );
145                                script.type = 'text/javascript';
146                                script.src = scriptSrc;
147
148                                function onScriptLoaded()
149                                {
150                                        // Append this script to the list of loaded scripts.
151                                        CKEDITOR.loader.loadedScripts.push( scriptName );
152
153                                        // Load the next.
154                                        CKEDITOR.loader.loadPending();
155                                }
156
157                                // We must guarantee the execution order of the scripts, so we
158                                // need to load them one by one. (#4145)
159                                // The following if/else block has been taken from the scriptloader core code.
160                                if ( typeof(script.onreadystatechange) !== "undefined" )
161                                {
162                                        /** @ignore */
163                                        script.onreadystatechange = function()
164                                        {
165                                                if ( script.readyState == 'loaded' || script.readyState == 'complete' )
166                                                {
167                                                        script.onreadystatechange = null;
168                                                        onScriptLoaded();
169                                                }
170                                        };
171                                }
172                                else
173                                {
174                                        /** @ignore */
175                                        script.onload = function()
176                                        {
177                                                // Some browsers, such as Safari, may call the onLoad function
178                                                // immediately. Which will break the loading sequence. (#3661)
179                                                setTimeout( function() { onScriptLoaded( scriptName ); }, 0 );
180                                        };
181                                }
182
183                                document.body.appendChild( script );
184                        },
185
186                        /**
187                         * Loads a specific script, including its dependencies. This is not a
188                         * synchronous loading, which means that the code to be loaded will
189                         * not necessarily be available after this call.
190                         * @example
191                         * CKEDITOR.loader.load( 'core/dom/element' );
192                         */
193                        load : function( scriptName, defer )
194                        {
195                                // Check if the script has already been loaded.
196                                if ( scriptName in this.loadedScripts )
197                                        if ( ! ( scriptName in Object.prototype ) )
198                                                return;
199
200                                // Get the script dependencies list.
201                                var dependencies = scripts[ scriptName ];
202                                if ( !dependencies )
203                                        throw 'The script name"' + scriptName + '" is not defined.';
204
205                                // Mark the script as loaded, even before really loading it, to
206                                // avoid cross references recursion.
207                                this.loadedScripts[ scriptName ] = true;
208
209                                // Load all dependencies first.
210                                for ( var i = 0 ; i < dependencies.length ; i++ )
211                                        this.load( dependencies[ i ], true );
212
213                                var scriptSrc = getUrl( '_source/' + scriptName + '.js' );
214
215                                // Append the <script> element to the DOM.
216                                // If the page is fully loaded, we can't use document.write
217                                // but if the script is run while the body is loading then it's safe to use it
218                                // Unfortunately, Firefox <3.6 doesn't support document.readyState, so it won't get this improvement
219                                if ( document.body && (!document.readyState || document.readyState == 'complete') )
220                                {
221                                        pendingLoad.push( scriptName );
222
223                                        if ( !defer )
224                                                this.loadPending();
225                                }
226                                else
227                                {
228                                        // Append this script to the list of loaded scripts.
229                                        this.loadedScripts.push( scriptName );
230
231                                        document.write( '<script src="' + scriptSrc + '" type="text/javascript"><\/script>' );
232                                }
233                        }
234                };
235        })();
236}
237
238// Check if any script has been defined for autoload.
239if ( CKEDITOR._autoLoad )
240{
241        CKEDITOR.loader.load( CKEDITOR._autoLoad );
242        delete CKEDITOR._autoLoad;
243}
Note: See TracBrowser for help on using the repository browser.