Mimimum syndical pour en faire un produit zope / cmf.
[ckeditor.git] / skins / ckeditor / _source / core / loader.js
diff --git a/skins/ckeditor/_source/core/loader.js b/skins/ckeditor/_source/core/loader.js
new file mode 100644 (file)
index 0000000..d8a8302
--- /dev/null
@@ -0,0 +1,240 @@
+/*\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+/**\r
+ * @fileOverview Defines the {@link CKEDITOR.loader} objects, which is used to\r
+ *             load core scripts and their dependencies from _source.\r
+ */\r
+\r
+if ( typeof CKEDITOR == 'undefined' )\r
+       CKEDITOR = {};\r
+\r
+if ( !CKEDITOR.loader )\r
+{\r
+       /**\r
+        * Load core scripts and their dependencies from _source.\r
+        * @namespace\r
+        * @example\r
+        */\r
+       CKEDITOR.loader = (function()\r
+       {\r
+               // Table of script names and their dependencies.\r
+               var scripts =\r
+               {\r
+                       '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' ],\r
+                       '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' ],\r
+                       'core/ckeditor_base'    : [],\r
+                       'core/ckeditor_basic'   : [ 'core/editor_basic', 'core/env', 'core/event' ],\r
+                       'core/command'                  : [],\r
+                       'core/config'                   : [ 'core/ckeditor_base' ],\r
+                       'core/dom'                              : [],\r
+                       'core/dom/comment'              : [ 'core/dom/node' ],\r
+                       'core/dom/document'             : [ 'core/dom', 'core/dom/domobject', 'core/dom/window' ],\r
+                       'core/dom/documentfragment'     : [ 'core/dom/element' ],\r
+                       'core/dom/element'              : [ 'core/dom', 'core/dom/document', 'core/dom/domobject', 'core/dom/node', 'core/dom/nodelist', 'core/tools' ],\r
+                       'core/dom/elementpath'  : [ 'core/dom/element' ],\r
+                       'core/dom/event'                : [],\r
+                       'core/dom/node'                 : [ 'core/dom/domobject', 'core/tools' ],\r
+                       'core/dom/nodelist'             : [ 'core/dom/node' ],\r
+                       'core/dom/domobject'    : [ 'core/dom/event' ],\r
+                       'core/dom/range'                : [ 'core/dom/document', 'core/dom/documentfragment', 'core/dom/element', 'core/dom/walker' ],\r
+                       'core/dom/rangelist'    : [ 'core/dom/range' ],\r
+                       'core/dom/text'                 : [ 'core/dom/node', 'core/dom/domobject' ],\r
+                       'core/dom/walker'               : [ 'core/dom/node' ],\r
+                       'core/dom/window'               : [ 'core/dom/domobject' ],\r
+                       'core/dtd'                              : [ 'core/tools' ],\r
+                       'core/editor'                   : [ 'core/command', 'core/config', 'core/editor_basic', 'core/focusmanager', 'core/lang', 'core/plugins', 'core/skins', 'core/themes', 'core/tools', 'core/ui' ],\r
+                       'core/editor_basic'             : [ 'core/event' ],\r
+                       'core/env'                              : [],\r
+                       'core/event'                    : [],\r
+                       'core/focusmanager'             : [],\r
+                       'core/htmlparser'               : [],\r
+                       'core/htmlparser/comment'       : [ 'core/htmlparser' ],\r
+                       'core/htmlparser/element'       : [ 'core/htmlparser', 'core/htmlparser/fragment' ],\r
+                       'core/htmlparser/fragment'      : [ 'core/htmlparser', 'core/htmlparser/comment', 'core/htmlparser/text', 'core/htmlparser/cdata' ],\r
+                       'core/htmlparser/text'          : [ 'core/htmlparser' ],\r
+                       'core/htmlparser/cdata'         : [ 'core/htmlparser' ],\r
+                       'core/htmlparser/filter'        : [ 'core/htmlparser' ],\r
+                       'core/htmlparser/basicwriter': [ 'core/htmlparser' ],\r
+                       'core/lang'                             : [],\r
+                       'core/plugins'                  : [ 'core/resourcemanager' ],\r
+                       'core/resourcemanager'  : [ 'core/scriptloader', 'core/tools' ],\r
+                       'core/scriptloader'             : [ 'core/dom/element', 'core/env' ],\r
+                       'core/skins'                    : [ 'core/scriptloader' ],\r
+                       'core/themes'                   : [ 'core/resourcemanager' ],\r
+                       'core/tools'                    : [ 'core/env' ],\r
+                       'core/ui'                               : []\r
+               };\r
+\r
+               var basePath = (function()\r
+               {\r
+                       // This is a copy of CKEDITOR.basePath, but requires the script having\r
+                       // "_source/core/loader.js".\r
+                       if ( CKEDITOR && CKEDITOR.basePath )\r
+                               return CKEDITOR.basePath;\r
+\r
+                       // Find out the editor directory path, based on its <script> tag.\r
+                       var path = '';\r
+                       var scripts = document.getElementsByTagName( 'script' );\r
+\r
+                       for ( var i = 0 ; i < scripts.length ; i++ )\r
+                       {\r
+                               var match = scripts[i].src.match( /(^|.*?[\\\/])(?:_source\/)?core\/loader.js(?:\?.*)?$/i );\r
+\r
+                               if ( match )\r
+                               {\r
+                                       path = match[1];\r
+                                       break;\r
+                               }\r
+                       }\r
+\r
+                       // In IE (only) the script.src string is the raw valued entered in the\r
+                       // HTML. Other browsers return the full resolved URL instead.\r
+                       if ( path.indexOf('://') == -1 )\r
+                       {\r
+                               // Absolute path.\r
+                               if ( path.indexOf( '/' ) === 0 )\r
+                                       path = location.href.match( /^.*?:\/\/[^\/]*/ )[0] + path;\r
+                               // Relative path.\r
+                               else\r
+                                       path = location.href.match( /^[^\?]*\// )[0] + path;\r
+                       }\r
+\r
+                       return path;\r
+               })();\r
+\r
+               var timestamp = 'B5GJ5GG';\r
+\r
+               var getUrl = function( resource )\r
+               {\r
+                       if ( CKEDITOR && CKEDITOR.getUrl )\r
+                               return CKEDITOR.getUrl( resource );\r
+\r
+                       return basePath + resource +\r
+                               ( resource.indexOf( '?' ) >= 0 ? '&' : '?' ) +\r
+                               't=' + timestamp;\r
+               };\r
+\r
+               var pendingLoad = [];\r
+\r
+               /** @lends CKEDITOR.loader */\r
+               return {\r
+                       /**\r
+                        * The list of loaded scripts in their loading order.\r
+                        * @type Array\r
+                        * @example\r
+                        * // Alert the loaded script names.\r
+                        * alert( <b>CKEDITOR.loader.loadedScripts</b> );\r
+                        */\r
+                       loadedScripts : [],\r
+\r
+                       loadPending : function()\r
+                       {\r
+                               var scriptName = pendingLoad.shift();\r
+\r
+                               if ( !scriptName )\r
+                                       return;\r
+\r
+                               var scriptSrc = getUrl( '_source/' + scriptName + '.js' );\r
+\r
+                               var script = document.createElement( 'script' );\r
+                               script.type = 'text/javascript';\r
+                               script.src = scriptSrc;\r
+\r
+                               function onScriptLoaded()\r
+                               {\r
+                                       // Append this script to the list of loaded scripts.\r
+                                       CKEDITOR.loader.loadedScripts.push( scriptName );\r
+\r
+                                       // Load the next.\r
+                                       CKEDITOR.loader.loadPending();\r
+                               }\r
+\r
+                               // We must guarantee the execution order of the scripts, so we\r
+                               // need to load them one by one. (#4145)\r
+                               // The following if/else block has been taken from the scriptloader core code.\r
+                               if ( typeof(script.onreadystatechange) !== "undefined" )\r
+                               {\r
+                                       /** @ignore */\r
+                                       script.onreadystatechange = function()\r
+                                       {\r
+                                               if ( script.readyState == 'loaded' || script.readyState == 'complete' )\r
+                                               {\r
+                                                       script.onreadystatechange = null;\r
+                                                       onScriptLoaded();\r
+                                               }\r
+                                       };\r
+                               }\r
+                               else\r
+                               {\r
+                                       /** @ignore */\r
+                                       script.onload = function()\r
+                                       {\r
+                                               // Some browsers, such as Safari, may call the onLoad function\r
+                                               // immediately. Which will break the loading sequence. (#3661)\r
+                                               setTimeout( function() { onScriptLoaded( scriptName ); }, 0 );\r
+                                       };\r
+                               }\r
+\r
+                               document.body.appendChild( script );\r
+                       },\r
+\r
+                       /**\r
+                        * Loads a specific script, including its dependencies. This is not a\r
+                        * synchronous loading, which means that the code to be loaded will\r
+                        * not necessarily be available after this call.\r
+                        * @example\r
+                        * CKEDITOR.loader.load( 'core/dom/element' );\r
+                        */\r
+                       load : function( scriptName, defer )\r
+                       {\r
+                               // Check if the script has already been loaded.\r
+                               if ( scriptName in this.loadedScripts )\r
+                                       return;\r
+\r
+                               // Get the script dependencies list.\r
+                               var dependencies = scripts[ scriptName ];\r
+                               if ( !dependencies )\r
+                                       throw 'The script name"' + scriptName + '" is not defined.';\r
+\r
+                               // Mark the script as loaded, even before really loading it, to\r
+                               // avoid cross references recursion.\r
+                               this.loadedScripts[ scriptName ] = true;\r
+\r
+                               // Load all dependencies first.\r
+                               for ( var i = 0 ; i < dependencies.length ; i++ )\r
+                                       this.load( dependencies[ i ], true );\r
+\r
+                               var scriptSrc = getUrl( '_source/' + scriptName + '.js' );\r
+\r
+                               // Append the <script> element to the DOM.\r
+                               // If the page is fully loaded, we can't use document.write\r
+                               // but if the script is run while the body is loading then it's safe to use it\r
+                               // Unfortunately, Firefox <3.6 doesn't support document.readyState, so it won't get this improvement\r
+                               if ( document.body && (!document.readyState || document.readyState == 'complete') )\r
+                               {\r
+                                       pendingLoad.push( scriptName );\r
+\r
+                                       if ( !defer )\r
+                                               this.loadPending();\r
+                               }\r
+                               else\r
+                               {\r
+                                       // Append this script to the list of loaded scripts.\r
+                                       this.loadedScripts.push( scriptName );\r
+\r
+                                       document.write( '<script src="' + scriptSrc + '" type="text/javascript"><\/script>' );\r
+                               }\r
+                       }\r
+               };\r
+       })();\r
+}\r
+\r
+// Check if any script has been defined for autoload.\r
+if ( CKEDITOR._autoLoad )\r
+{\r
+       CKEDITOR.loader.load( CKEDITOR._autoLoad );\r
+       delete CKEDITOR._autoLoad;\r
+}\r