[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/libraries/ckeditor/_source/core/ -> loader.js (source)

   1  /*

   2  Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.

   3  For 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  
  11  if ( typeof CKEDITOR == 'undefined' )
  12      CKEDITOR = {};
  13  
  14  if ( !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/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/imagecacher'        : [ 'core/dom/element' ],
  63              'core/lang'                : [],
  64              'core/plugins'            : [ 'core/resourcemanager' ],
  65              'core/resourcemanager'    : [ 'core/scriptloader', 'core/tools' ],
  66              'core/scriptloader'        : [ 'core/dom/element', 'core/env' ],
  67              'core/skins'            : [ 'core/imagecacher', 'core/scriptloader' ],
  68              'core/themes'            : [ 'core/resourcemanager' ],
  69              'core/tools'            : [ 'core/env' ],
  70              'core/ui'                : [],
  71              'core/xml'                : [ 'core/env' ]
  72          };
  73  
  74          var basePath = (function()
  75          {
  76              // This is a copy of CKEDITOR.basePath, but requires the script having

  77              // "_source/core/loader.js".

  78              if ( CKEDITOR && CKEDITOR.basePath )
  79                  return CKEDITOR.basePath;
  80  
  81              // Find out the editor directory path, based on its <script> tag.

  82              var path = '';
  83              var scripts = document.getElementsByTagName( 'script' );
  84  
  85              for ( var i = 0 ; i < scripts.length ; i++ )
  86              {
  87                  var match = scripts[i].src.match( /(^|.*[\\\/])core\/loader.js(?:\?.*)?$/i );
  88  
  89                  if ( match )
  90                  {
  91                      path = match[1];
  92                      break;
  93                  }
  94              }
  95  
  96              // In IE (only) the script.src string is the raw valued entered in the

  97              // HTML. Other browsers return the full resolved URL instead.

  98              if ( path.indexOf('://') == -1 )
  99              {
 100                  // Absolute path.

 101                  if ( path.indexOf( '/' ) === 0 )
 102                      path = location.href.match( /^.*?:\/\/[^\/]*/ )[0] + path;
 103                  // Relative path.

 104                  else
 105                      path = location.href.match( /^[^\?]*\// )[0] + path;
 106              }
 107  
 108              return path;
 109          })();
 110  
 111          var timestamp = 'A7HG4HT';
 112  
 113          var getUrl = function( resource )
 114          {
 115              if ( CKEDITOR && CKEDITOR.getUrl )
 116                  return CKEDITOR.getUrl( resource );
 117  
 118              return basePath + resource +
 119                  ( resource.indexOf( '?' ) >= 0 ? '&' : '?' ) +
 120                  't=' + timestamp;
 121          };
 122  
 123          var pendingLoad = [];
 124  
 125          /** @lends CKEDITOR.loader */

 126          return {
 127              /**

 128               * The list of loaded scripts in their loading order.

 129               * @type Array

 130               * @example

 131               * // Alert the loaded script names.

 132               * alert( <b>CKEDITOR.loader.loadedScripts</b> );

 133               */
 134              loadedScripts : [],
 135  
 136              loadPending : function()
 137              {
 138                  var scriptName = pendingLoad.shift();
 139  
 140                  if ( !scriptName )
 141                      return;
 142  
 143                  var scriptSrc = getUrl( '_source/' + scriptName + '.js' );
 144  
 145                  var script = document.createElement( 'script' );
 146                  script.type = 'text/javascript';
 147                  script.src = scriptSrc;
 148  
 149  				function onScriptLoaded()
 150                  {
 151                      // Append this script to the list of loaded scripts.

 152                      CKEDITOR.loader.loadedScripts.push( scriptName );
 153  
 154                      // Load the next.

 155                      CKEDITOR.loader.loadPending();
 156                  }
 157  
 158                  // We must guarantee the execution order of the scripts, so we

 159                  // need to load them one by one. (#4145)

 160                  // The following if/else block has been taken from the scriptloader core code.

 161                  if ( typeof(script.onreadystatechange) !== "undefined" )
 162                  {
 163                      /** @ignore */

 164                      script.onreadystatechange = function()
 165                      {
 166                          if ( script.readyState == 'loaded' || script.readyState == 'complete' )
 167                          {
 168                              script.onreadystatechange = null;
 169                              onScriptLoaded();
 170                          }
 171                      };
 172                  }
 173                  else
 174                  {
 175                      /** @ignore */

 176                      script.onload = function()
 177                      {
 178                          // Some browsers, such as Safari, may call the onLoad function

 179                          // immediately. Which will break the loading sequence. (#3661)

 180                          setTimeout( function() { onScriptLoaded( scriptName ); }, 0 );
 181                      };
 182                  }
 183  
 184                  document.body.appendChild( script );
 185              },
 186  
 187              /**

 188               * Loads a specific script, including its dependencies. This is not a

 189               * synchronous loading, which means that the code to be loaded will

 190               * not necessarily be available after this call.

 191               * @example

 192               * CKEDITOR.loader.load( 'core/dom/element' );

 193               */
 194              load : function( scriptName, defer )
 195              {
 196                  // Check if the script has already been loaded.

 197                  if ( scriptName in this.loadedScripts )
 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.

 239  if ( CKEDITOR._autoLoad )
 240  {
 241      CKEDITOR.loader.load( CKEDITOR._autoLoad );
 242      delete CKEDITOR._autoLoad;
 243  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7