Nation Notes module contributed by Z&H Healthcare.
[openemr.git] / library / custom_template / ckeditor / _source / core / loader.js
blob9bbb467b990f1b79fe5c8860c8911b27604a3006
1 /*
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
4 */
6 /**
7  * @fileOverview Defines the {@link CKEDITOR.loader} objects, which is used to
8  *              load core scripts and their dependencies from _source.
9  */
11 if ( typeof CKEDITOR == 'undefined' )
12         CKEDITOR = {};
14 if ( !CKEDITOR.loader )
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/rangelist' ],
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/rangelist'    : [ 'core/dom/range' ],
45                         'core/dom/text'                 : [ 'core/dom/node', 'core/dom/domobject' ],
46                         'core/dom/walker'               : [ 'core/dom/node' ],
47                         'core/dom/window'               : [ 'core/dom/domobject' ],
48                         'core/dtd'                              : [ 'core/tools' ],
49                         'core/editor'                   : [ 'core/command', 'core/config', 'core/editor_basic', 'core/focusmanager', 'core/lang', 'core/plugins', 'core/skins', 'core/themes', 'core/tools', 'core/ui' ],
50                         'core/editor_basic'             : [ 'core/event' ],
51                         'core/env'                              : [],
52                         'core/event'                    : [],
53                         'core/focusmanager'             : [],
54                         'core/htmlparser'               : [],
55                         'core/htmlparser/comment'       : [ 'core/htmlparser' ],
56                         'core/htmlparser/element'       : [ 'core/htmlparser', 'core/htmlparser/fragment' ],
57                         'core/htmlparser/fragment'      : [ 'core/htmlparser', 'core/htmlparser/comment', 'core/htmlparser/text', 'core/htmlparser/cdata' ],
58                         'core/htmlparser/text'          : [ 'core/htmlparser' ],
59                         'core/htmlparser/cdata'         : [ 'core/htmlparser' ],
60                         'core/htmlparser/filter'        : [ 'core/htmlparser' ],
61                         'core/htmlparser/basicwriter': [ 'core/htmlparser' ],
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/scriptloader' ],
67                         'core/themes'                   : [ 'core/resourcemanager' ],
68                         'core/tools'                    : [ 'core/env' ],
69                         'core/ui'                               : [],
70                         'core/xml'                              : [ 'core/env' ]
71                 };
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;
80                         // Find out the editor directory path, based on its <script> tag.
81                         var path = '';
82                         var scripts = document.getElementsByTagName( 'script' );
84                         for ( var i = 0 ; i < scripts.length ; i++ )
85                         {
86                                 var match = scripts[i].src.match( /(^|.*?[\\\/])(?:_source\/)?core\/loader.js(?:\?.*)?$/i );
88                                 if ( match )
89                                 {
90                                         path = match[1];
91                                         break;
92                                 }
93                         }
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                         }
107                         return path;
108                 })();
110                 var timestamp = 'B1GG4Z6';
112                 var getUrl = function( resource )
113                 {
114                         if ( CKEDITOR && CKEDITOR.getUrl )
115                                 return CKEDITOR.getUrl( resource );
117                         return basePath + resource +
118                                 ( resource.indexOf( '?' ) >= 0 ? '&' : '?' ) +
119                                 't=' + timestamp;
120                 };
122                 var pendingLoad = [];
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 : [],
135                         loadPending : function()
136                         {
137                                 var scriptName = pendingLoad.shift();
139                                 if ( !scriptName )
140                                         return;
142                                 var scriptSrc = getUrl( '_source/' + scriptName + '.js' );
144                                 var script = document.createElement( 'script' );
145                                 script.type = 'text/javascript';
146                                 script.src = scriptSrc;
148                                 function onScriptLoaded()
149                                 {
150                                         // Append this script to the list of loaded scripts.
151                                         CKEDITOR.loader.loadedScripts.push( scriptName );
153                                         // Load the next.
154                                         CKEDITOR.loader.loadPending();
155                                 }
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                                 }
183                                 document.body.appendChild( script );
184                         },
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                                         return;
199                                 // Get the script dependencies list.
200                                 var dependencies = scripts[ scriptName ];
201                                 if ( !dependencies )
202                                         throw 'The script name"' + scriptName + '" is not defined.';
204                                 // Mark the script as loaded, even before really loading it, to
205                                 // avoid cross references recursion.
206                                 this.loadedScripts[ scriptName ] = true;
208                                 // Load all dependencies first.
209                                 for ( var i = 0 ; i < dependencies.length ; i++ )
210                                         this.load( dependencies[ i ], true );
212                                 var scriptSrc = getUrl( '_source/' + scriptName + '.js' );
214                                 // Append the <script> element to the DOM.
215                                 // If the page is fully loaded, we can't use document.write
216                                 // but if the script is run while the body is loading then it's safe to use it
217                                 // Unfortunately, Firefox <3.6 doesn't support document.readyState, so it won't get this improvement
218                                 if ( document.body && (!document.readyState || document.readyState == 'complete') )
219                                 {
220                                         pendingLoad.push( scriptName );
222                                         if ( !defer )
223                                                 this.loadPending();
224                                 }
225                                 else
226                                 {
227                                         // Append this script to the list of loaded scripts.
228                                         this.loadedScripts.push( scriptName );
230                                         document.write( '<script src="' + scriptSrc + '" type="text/javascript"><\/script>' );
231                                 }
232                         }
233                 };
234         })();
237 // Check if any script has been defined for autoload.
238 if ( CKEDITOR._autoLoad )
240         CKEDITOR.loader.load( CKEDITOR._autoLoad );
241         delete CKEDITOR._autoLoad;