src/cm/media/js/lib/yui/yui3-3.15.0/build/loader-base/loader-base.js
changeset 602 e16a97fb364a
equal deleted inserted replaced
601:d334a616c023 602:e16a97fb364a
       
     1 YUI.add('loader-base', function (Y, NAME) {
       
     2 
       
     3 /**
       
     4  * The YUI loader core
       
     5  * @module loader
       
     6  * @submodule loader-base
       
     7  */
       
     8 
       
     9 (function() {
       
    10     var VERSION = Y.version,
       
    11         BUILD = '/build/',
       
    12         ROOT = VERSION + '/',
       
    13         CDN_BASE = Y.Env.base,
       
    14         GALLERY_VERSION = 'gallery-2014.02.20-23-55',
       
    15         TNT = '2in3',
       
    16         TNT_VERSION = '4',
       
    17         YUI2_VERSION = '2.9.0',
       
    18         COMBO_BASE = CDN_BASE + 'combo?',
       
    19         META = {
       
    20             version: VERSION,
       
    21             root: ROOT,
       
    22             base: Y.Env.base,
       
    23             comboBase: COMBO_BASE,
       
    24             skin: {
       
    25                 defaultSkin: 'sam',
       
    26                 base: 'assets/skins/',
       
    27                 path: 'skin.css',
       
    28                 after: [
       
    29                     'cssreset',
       
    30                     'cssfonts',
       
    31                     'cssgrids',
       
    32                     'cssbase',
       
    33                     'cssreset-context',
       
    34                     'cssfonts-context'
       
    35                 ]
       
    36             },
       
    37             groups: {},
       
    38             patterns: {}
       
    39         },
       
    40         groups = META.groups,
       
    41         yui2Update = function(tnt, yui2, config) {
       
    42             var root = TNT + '.' +
       
    43                     (tnt || TNT_VERSION) + '/' +
       
    44                     (yui2 || YUI2_VERSION) + BUILD,
       
    45                 base = (config && config.base) ? config.base : CDN_BASE,
       
    46                 combo = (config && config.comboBase) ? config.comboBase : COMBO_BASE;
       
    47 
       
    48             groups.yui2.base = base + root;
       
    49             groups.yui2.root = root;
       
    50             groups.yui2.comboBase = combo;
       
    51         },
       
    52         galleryUpdate = function(tag, config) {
       
    53             var root = (tag || GALLERY_VERSION) + BUILD,
       
    54                 base = (config && config.base) ? config.base : CDN_BASE,
       
    55                 combo = (config && config.comboBase) ? config.comboBase : COMBO_BASE;
       
    56 
       
    57             groups.gallery.base = base + root;
       
    58             groups.gallery.root = root;
       
    59             groups.gallery.comboBase = combo;
       
    60         };
       
    61 
       
    62 
       
    63     groups[VERSION] = {};
       
    64 
       
    65     groups.gallery = {
       
    66         ext: false,
       
    67         combine: true,
       
    68         comboBase: COMBO_BASE,
       
    69         update: galleryUpdate,
       
    70         patterns: {
       
    71             'gallery-': {},
       
    72             'lang/gallery-': {},
       
    73             'gallerycss-': {
       
    74                 type: 'css'
       
    75             }
       
    76         }
       
    77     };
       
    78 
       
    79     groups.yui2 = {
       
    80         combine: true,
       
    81         ext: false,
       
    82         comboBase: COMBO_BASE,
       
    83         update: yui2Update,
       
    84         patterns: {
       
    85             'yui2-': {
       
    86                 configFn: function(me) {
       
    87                     if (/-skin|reset|fonts|grids|base/.test(me.name)) {
       
    88                         me.type = 'css';
       
    89                         me.path = me.path.replace(/\.js/, '.css');
       
    90                         // this makes skins in builds earlier than
       
    91                         // 2.6.0 work as long as combine is false
       
    92                         me.path = me.path.replace(/\/yui2-skin/,
       
    93                                             '/assets/skins/sam/yui2-skin');
       
    94                     }
       
    95                 }
       
    96             }
       
    97         }
       
    98     };
       
    99 
       
   100     galleryUpdate();
       
   101     yui2Update();
       
   102 
       
   103     if (YUI.Env[VERSION]) {
       
   104         Y.mix(META, YUI.Env[VERSION], false, [
       
   105             'modules',
       
   106             'groups',
       
   107             'skin'
       
   108         ], 0, true);
       
   109     }
       
   110 
       
   111     YUI.Env[VERSION] = META;
       
   112 }());
       
   113 /*jslint forin: true, maxlen: 350 */
       
   114 
       
   115 /**
       
   116  * Loader dynamically loads script and css files.  It includes the dependency
       
   117  * information for the version of the library in use, and will automatically pull in
       
   118  * dependencies for the modules requested. It can also load the
       
   119  * files from the Yahoo! CDN, and it can utilize the combo service provided on
       
   120  * this network to reduce the number of http connections required to download
       
   121  * YUI files.
       
   122  *
       
   123  * @module loader
       
   124  * @main loader
       
   125  * @submodule loader-base
       
   126  */
       
   127 
       
   128 var NOT_FOUND = {},
       
   129     NO_REQUIREMENTS = [],
       
   130     MAX_URL_LENGTH = 1024,
       
   131     GLOBAL_ENV = YUI.Env,
       
   132     GLOBAL_LOADED = GLOBAL_ENV._loaded,
       
   133     CSS = 'css',
       
   134     JS = 'js',
       
   135     INTL = 'intl',
       
   136     DEFAULT_SKIN = 'sam',
       
   137     VERSION = Y.version,
       
   138     ROOT_LANG = '',
       
   139     YObject = Y.Object,
       
   140     oeach = YObject.each,
       
   141     yArray = Y.Array,
       
   142     _queue = GLOBAL_ENV._loaderQueue,
       
   143     META = GLOBAL_ENV[VERSION],
       
   144     SKIN_PREFIX = 'skin-',
       
   145     L = Y.Lang,
       
   146     ON_PAGE = GLOBAL_ENV.mods,
       
   147     modulekey,
       
   148     _path = function(dir, file, type, nomin) {
       
   149         var path = dir + '/' + file;
       
   150         if (!nomin) {
       
   151             path += '-min';
       
   152         }
       
   153         path += '.' + (type || CSS);
       
   154 
       
   155         return path;
       
   156     };
       
   157 
       
   158 
       
   159     if (!YUI.Env._cssLoaded) {
       
   160         YUI.Env._cssLoaded = {};
       
   161     }
       
   162 
       
   163 
       
   164 /**
       
   165  * The component metadata is stored in Y.Env.meta.
       
   166  * Part of the loader module.
       
   167  * @property meta
       
   168  * @for YUI
       
   169  */
       
   170 Y.Env.meta = META;
       
   171 
       
   172 /**
       
   173  * Loader dynamically loads script and css files.  It includes the dependency
       
   174  * info for the version of the library in use, and will automatically pull in
       
   175  * dependencies for the modules requested. It can load the
       
   176  * files from the Yahoo! CDN, and it can utilize the combo service provided on
       
   177  * this network to reduce the number of http connections required to download
       
   178  * YUI files. You can also specify an external, custom combo service to host
       
   179  * your modules as well.
       
   180 
       
   181         var Y = YUI();
       
   182         var loader = new Y.Loader({
       
   183             filter: 'debug',
       
   184             base: '../../',
       
   185             root: 'build/',
       
   186             combine: true,
       
   187             require: ['node', 'dd', 'console']
       
   188         });
       
   189         var out = loader.resolve(true);
       
   190 
       
   191  * @constructor
       
   192  * @class Loader
       
   193  * @param {Object} config an optional set of configuration options.
       
   194  * @param {String} config.base The base dir which to fetch this module from
       
   195  * @param {String} config.comboBase The Combo service base path. Ex: `http://yui.yahooapis.com/combo?`
       
   196  * @param {String} config.root The root path to prepend to module names for the combo service. Ex: `2.5.2/build/`
       
   197  * @param {String|Object} config.filter A filter to apply to result urls. <a href="#property_filter">See filter property</a>
       
   198  * @param {Object} config.filters Per-component filter specification.  If specified for a given component, this overrides the filter config.
       
   199  * @param {Boolean} config.combine Use a combo service to reduce the number of http connections required to load your dependencies
       
   200  * @param {Boolean} [config.async=true] Fetch files in async
       
   201  * @param {Array} config.ignore: A list of modules that should never be dynamically loaded
       
   202  * @param {Array} config.force A list of modules that should always be loaded when required, even if already present on the page
       
   203  * @param {HTMLElement|String} config.insertBefore Node or id for a node that should be used as the insertion point for new nodes
       
   204  * @param {Object} config.jsAttributes Object literal containing attributes to add to script nodes
       
   205  * @param {Object} config.cssAttributes Object literal containing attributes to add to link nodes
       
   206  * @param {Number} config.timeout The number of milliseconds before a timeout occurs when dynamically loading nodes.  If not set, there is no timeout
       
   207  * @param {Object} config.context Execution context for all callbacks
       
   208  * @param {Function} config.onSuccess Callback for the 'success' event
       
   209  * @param {Function} config.onFailure Callback for the 'failure' event
       
   210  * @param {Function} config.onCSS Callback for the 'CSSComplete' event.  When loading YUI components with CSS the CSS is loaded first, then the script.  This provides a moment you can tie into to improve the presentation of the page while the script is loading.
       
   211  * @param {Function} config.onTimeout Callback for the 'timeout' event
       
   212  * @param {Function} config.onProgress Callback executed each time a script or css file is loaded
       
   213  * @param {Object} config.modules A list of module definitions.  See <a href="#method_addModule">Loader.addModule</a> for the supported module metadata
       
   214  * @param {Object} config.groups A list of group definitions.  Each group can contain specific definitions for `base`, `comboBase`, `combine`, and accepts a list of `modules`.
       
   215  * @param {String} config.2in3 The version of the YUI 2 in 3 wrapper to use.  The intrinsic support for YUI 2 modules in YUI 3 relies on versions of the YUI 2 components inside YUI 3 module wrappers.  These wrappers change over time to accomodate the issues that arise from running YUI 2 in a YUI 3 sandbox.
       
   216  * @param {String} config.yui2 When using the 2in3 project, you can select the version of YUI 2 to use.  Valid values are `2.2.2`, `2.3.1`, `2.4.1`, `2.5.2`, `2.6.0`, `2.7.0`, `2.8.0`, `2.8.1` and `2.9.0` [default] -- plus all versions of YUI 2 going forward.
       
   217  */
       
   218 Y.Loader = function(o) {
       
   219 
       
   220     var self = this;
       
   221 
       
   222     //Catch no config passed.
       
   223     o = o || {};
       
   224 
       
   225     modulekey = META.md5;
       
   226 
       
   227     /**
       
   228      * Internal callback to handle multiple internal insert() calls
       
   229      * so that css is inserted prior to js
       
   230      * @property _internalCallback
       
   231      * @private
       
   232      */
       
   233     // self._internalCallback = null;
       
   234 
       
   235     /**
       
   236      * Callback that will be executed when the loader is finished
       
   237      * with an insert
       
   238      * @method onSuccess
       
   239      * @type function
       
   240      */
       
   241     // self.onSuccess = null;
       
   242 
       
   243     /**
       
   244      * Callback that will be executed if there is a failure
       
   245      * @method onFailure
       
   246      * @type function
       
   247      */
       
   248     // self.onFailure = null;
       
   249 
       
   250     /**
       
   251      * Callback for the 'CSSComplete' event.  When loading YUI components
       
   252      * with CSS the CSS is loaded first, then the script.  This provides
       
   253      * a moment you can tie into to improve the presentation of the page
       
   254      * while the script is loading.
       
   255      * @method onCSS
       
   256      * @type function
       
   257      */
       
   258     // self.onCSS = null;
       
   259 
       
   260     /**
       
   261      * Callback executed each time a script or css file is loaded
       
   262      * @method onProgress
       
   263      * @type function
       
   264      */
       
   265     // self.onProgress = null;
       
   266 
       
   267     /**
       
   268      * Callback that will be executed if a timeout occurs
       
   269      * @method onTimeout
       
   270      * @type function
       
   271      */
       
   272     // self.onTimeout = null;
       
   273 
       
   274     /**
       
   275      * The execution context for all callbacks
       
   276      * @property context
       
   277      * @default {YUI} the YUI instance
       
   278      */
       
   279     self.context = Y;
       
   280 
       
   281     /**
       
   282      * Data that is passed to all callbacks
       
   283      * @property data
       
   284      */
       
   285     // self.data = null;
       
   286 
       
   287     /**
       
   288      * Node reference or id where new nodes should be inserted before
       
   289      * @property insertBefore
       
   290      * @type string|HTMLElement
       
   291      */
       
   292     // self.insertBefore = null;
       
   293 
       
   294     /**
       
   295      * The charset attribute for inserted nodes
       
   296      * @property charset
       
   297      * @type string
       
   298      * @deprecated , use cssAttributes or jsAttributes.
       
   299      */
       
   300     // self.charset = null;
       
   301 
       
   302     /**
       
   303      * An object literal containing attributes to add to link nodes
       
   304      * @property cssAttributes
       
   305      * @type object
       
   306      */
       
   307     // self.cssAttributes = null;
       
   308 
       
   309     /**
       
   310      * An object literal containing attributes to add to script nodes
       
   311      * @property jsAttributes
       
   312      * @type object
       
   313      */
       
   314     // self.jsAttributes = null;
       
   315 
       
   316     /**
       
   317      * The base directory.
       
   318      * @property base
       
   319      * @type string
       
   320      * @default http://yui.yahooapis.com/[YUI VERSION]/build/
       
   321      */
       
   322     self.base = Y.Env.meta.base + Y.Env.meta.root;
       
   323 
       
   324     /**
       
   325      * Base path for the combo service
       
   326      * @property comboBase
       
   327      * @type string
       
   328      * @default http://yui.yahooapis.com/combo?
       
   329      */
       
   330     self.comboBase = Y.Env.meta.comboBase;
       
   331 
       
   332     /*
       
   333      * Base path for language packs.
       
   334      */
       
   335     // self.langBase = Y.Env.meta.langBase;
       
   336     // self.lang = "";
       
   337 
       
   338     /**
       
   339      * If configured, the loader will attempt to use the combo
       
   340      * service for YUI resources and configured external resources.
       
   341      * @property combine
       
   342      * @type boolean
       
   343      * @default true if a base dir isn't in the config
       
   344      */
       
   345     self.combine = o.base &&
       
   346         (o.base.indexOf(self.comboBase.substr(0, 20)) > -1);
       
   347 
       
   348     /**
       
   349     * The default seperator to use between files in a combo URL
       
   350     * @property comboSep
       
   351     * @type {String}
       
   352     * @default Ampersand
       
   353     */
       
   354     self.comboSep = '&';
       
   355     /**
       
   356      * Max url length for combo urls.  The default is 1024. This is the URL
       
   357      * limit for the Yahoo! hosted combo servers.  If consuming
       
   358      * a different combo service that has a different URL limit
       
   359      * it is possible to override this default by supplying
       
   360      * the maxURLLength config option.  The config option will
       
   361      * only take effect if lower than the default.
       
   362      *
       
   363      * @property maxURLLength
       
   364      * @type int
       
   365      */
       
   366     self.maxURLLength = MAX_URL_LENGTH;
       
   367 
       
   368     /**
       
   369      * Ignore modules registered on the YUI global
       
   370      * @property ignoreRegistered
       
   371      * @default false
       
   372      */
       
   373     self.ignoreRegistered = o.ignoreRegistered;
       
   374 
       
   375     /**
       
   376      * Root path to prepend to module path for the combo
       
   377      * service
       
   378      * @property root
       
   379      * @type string
       
   380      * @default [YUI VERSION]/build/
       
   381      */
       
   382     self.root = Y.Env.meta.root;
       
   383 
       
   384     /**
       
   385      * Timeout value in milliseconds.  If set, self value will be used by
       
   386      * the get utility.  the timeout event will fire if
       
   387      * a timeout occurs.
       
   388      * @property timeout
       
   389      * @type int
       
   390      */
       
   391     self.timeout = 0;
       
   392 
       
   393     /**
       
   394      * A list of modules that should not be loaded, even if
       
   395      * they turn up in the dependency tree
       
   396      * @property ignore
       
   397      * @type string[]
       
   398      */
       
   399     // self.ignore = null;
       
   400 
       
   401     /**
       
   402      * A list of modules that should always be loaded, even
       
   403      * if they have already been inserted into the page.
       
   404      * @property force
       
   405      * @type string[]
       
   406      */
       
   407     // self.force = null;
       
   408 
       
   409     self.forceMap = {};
       
   410 
       
   411     /**
       
   412      * Should we allow rollups
       
   413      * @property allowRollup
       
   414      * @type boolean
       
   415      * @default false
       
   416      */
       
   417     self.allowRollup = false;
       
   418 
       
   419     /**
       
   420      * A filter to apply to result urls.  This filter will modify the default
       
   421      * path for all modules.  The default path for the YUI library is the
       
   422      * minified version of the files (e.g., event-min.js).  The filter property
       
   423      * can be a predefined filter or a custom filter.  The valid predefined
       
   424      * filters are:
       
   425      * <dl>
       
   426      *  <dt>DEBUG</dt>
       
   427      *  <dd>Selects the debug versions of the library (e.g., event-debug.js).
       
   428      *      This option will automatically include the Logger widget</dd>
       
   429      *  <dt>RAW</dt>
       
   430      *  <dd>Selects the non-minified version of the library (e.g., event.js).
       
   431      *  </dd>
       
   432      * </dl>
       
   433      * You can also define a custom filter, which must be an object literal
       
   434      * containing a search expression and a replace string:
       
   435      *
       
   436      *      myFilter: {
       
   437      *          'searchExp': "-min\\.js",
       
   438      *          'replaceStr': "-debug.js"
       
   439      *      }
       
   440      *
       
   441      * @property filter
       
   442      * @type string| {searchExp: string, replaceStr: string}
       
   443      */
       
   444     // self.filter = null;
       
   445 
       
   446     /**
       
   447      * per-component filter specification.  If specified for a given
       
   448      * component, this overrides the filter config.
       
   449      * @property filters
       
   450      * @type object
       
   451      */
       
   452     self.filters = {};
       
   453 
       
   454     /**
       
   455      * The list of requested modules
       
   456      * @property required
       
   457      * @type {string: boolean}
       
   458      */
       
   459     self.required = {};
       
   460 
       
   461     /**
       
   462      * If a module name is predefined when requested, it is checked againsts
       
   463      * the patterns provided in this property.  If there is a match, the
       
   464      * module is added with the default configuration.
       
   465      *
       
   466      * At the moment only supporting module prefixes, but anticipate
       
   467      * supporting at least regular expressions.
       
   468      * @property patterns
       
   469      * @type Object
       
   470      */
       
   471     // self.patterns = Y.merge(Y.Env.meta.patterns);
       
   472     self.patterns = {};
       
   473 
       
   474     /**
       
   475      * The library metadata
       
   476      * @property moduleInfo
       
   477      */
       
   478     // self.moduleInfo = Y.merge(Y.Env.meta.moduleInfo);
       
   479     self.moduleInfo = {};
       
   480 
       
   481     self.groups = Y.merge(Y.Env.meta.groups);
       
   482 
       
   483     /**
       
   484      * Provides the information used to skin the skinnable components.
       
   485      * The following skin definition would result in 'skin1' and 'skin2'
       
   486      * being loaded for calendar (if calendar was requested), and
       
   487      * 'sam' for all other skinnable components:
       
   488      *
       
   489      *      skin: {
       
   490      *          // The default skin, which is automatically applied if not
       
   491      *          // overriden by a component-specific skin definition.
       
   492      *          // Change this in to apply a different skin globally
       
   493      *          defaultSkin: 'sam',
       
   494      *
       
   495      *          // This is combined with the loader base property to get
       
   496      *          // the default root directory for a skin. ex:
       
   497      *          // http://yui.yahooapis.com/2.3.0/build/assets/skins/sam/
       
   498      *          base: 'assets/skins/',
       
   499      *
       
   500      *          // Any component-specific overrides can be specified here,
       
   501      *          // making it possible to load different skins for different
       
   502      *          // components.  It is possible to load more than one skin
       
   503      *          // for a given component as well.
       
   504      *          overrides: {
       
   505      *              calendar: ['skin1', 'skin2']
       
   506      *          }
       
   507      *      }
       
   508      * @property skin
       
   509      * @type {Object}
       
   510      */
       
   511     self.skin = Y.merge(Y.Env.meta.skin);
       
   512 
       
   513     /*
       
   514      * Map of conditional modules
       
   515      * @since 3.2.0
       
   516      */
       
   517     self.conditions = {};
       
   518 
       
   519     // map of modules with a hash of modules that meet the requirement
       
   520     // self.provides = {};
       
   521 
       
   522     self.config = o;
       
   523     self._internal = true;
       
   524 
       
   525     self._populateCache();
       
   526 
       
   527     /**
       
   528      * Set when beginning to compute the dependency tree.
       
   529      * Composed of what YUI reports to be loaded combined
       
   530      * with what has been loaded by any instance on the page
       
   531      * with the version number specified in the metadata.
       
   532      * @property loaded
       
   533      * @type {string: boolean}
       
   534      */
       
   535     self.loaded = GLOBAL_LOADED[VERSION];
       
   536 
       
   537 
       
   538     /**
       
   539     * Should Loader fetch scripts in `async`, defaults to `true`
       
   540     * @property async
       
   541     */
       
   542 
       
   543     self.async = true;
       
   544 
       
   545     self._inspectPage();
       
   546 
       
   547     self._internal = false;
       
   548 
       
   549     self._config(o);
       
   550 
       
   551     self.forceMap = (self.force) ? Y.Array.hash(self.force) : {};
       
   552 
       
   553     self.testresults = null;
       
   554 
       
   555     if (Y.config.tests) {
       
   556         self.testresults = Y.config.tests;
       
   557     }
       
   558 
       
   559     /**
       
   560      * List of rollup files found in the library metadata
       
   561      * @property rollups
       
   562      */
       
   563     // self.rollups = null;
       
   564 
       
   565     /**
       
   566      * Whether or not to load optional dependencies for
       
   567      * the requested modules
       
   568      * @property loadOptional
       
   569      * @type boolean
       
   570      * @default false
       
   571      */
       
   572     // self.loadOptional = false;
       
   573 
       
   574     /**
       
   575      * All of the derived dependencies in sorted order, which
       
   576      * will be populated when either calculate() or insert()
       
   577      * is called
       
   578      * @property sorted
       
   579      * @type string[]
       
   580      */
       
   581     self.sorted = [];
       
   582 
       
   583     /*
       
   584      * A list of modules to attach to the YUI instance when complete.
       
   585      * If not supplied, the sorted list of dependencies are applied.
       
   586      * @property attaching
       
   587      */
       
   588     // self.attaching = null;
       
   589 
       
   590     /**
       
   591      * Flag to indicate the dependency tree needs to be recomputed
       
   592      * if insert is called again.
       
   593      * @property dirty
       
   594      * @type boolean
       
   595      * @default true
       
   596      */
       
   597     self.dirty = true;
       
   598 
       
   599     /**
       
   600      * List of modules inserted by the utility
       
   601      * @property inserted
       
   602      * @type {string: boolean}
       
   603      */
       
   604     self.inserted = {};
       
   605 
       
   606     /**
       
   607      * List of skipped modules during insert() because the module
       
   608      * was not defined
       
   609      * @property skipped
       
   610      */
       
   611     self.skipped = {};
       
   612 
       
   613     // Y.on('yui:load', self.loadNext, self);
       
   614 
       
   615     self.tested = {};
       
   616 
       
   617     /*
       
   618      * Cached sorted calculate results
       
   619      * @property results
       
   620      * @since 3.2.0
       
   621      */
       
   622     //self.results = {};
       
   623 
       
   624     if (self.ignoreRegistered) {
       
   625         //Clear inpage already processed modules.
       
   626         self._resetModules();
       
   627     }
       
   628 
       
   629 };
       
   630 
       
   631 Y.Loader.prototype = {
       
   632     /**
       
   633     * Checks the cache for modules and conditions, if they do not exist
       
   634     * process the default metadata and populate the local moduleInfo hash.
       
   635     * @method _populateCache
       
   636     * @private
       
   637     */
       
   638     _populateCache: function() {
       
   639         var self = this,
       
   640             defaults = META.modules,
       
   641             cache = GLOBAL_ENV._renderedMods,
       
   642             i;
       
   643 
       
   644         if (cache && !self.ignoreRegistered) {
       
   645             for (i in cache) {
       
   646                 if (cache.hasOwnProperty(i)) {
       
   647                     self.moduleInfo[i] = Y.merge(cache[i]);
       
   648                 }
       
   649             }
       
   650 
       
   651             cache = GLOBAL_ENV._conditions;
       
   652             for (i in cache) {
       
   653                 if (cache.hasOwnProperty(i)) {
       
   654                     self.conditions[i] = Y.merge(cache[i]);
       
   655                 }
       
   656             }
       
   657 
       
   658         } else {
       
   659             for (i in defaults) {
       
   660                 if (defaults.hasOwnProperty(i)) {
       
   661                     self.addModule(defaults[i], i);
       
   662                 }
       
   663             }
       
   664         }
       
   665 
       
   666     },
       
   667     /**
       
   668     * Reset modules in the module cache to a pre-processed state so additional
       
   669     * computations with a different skin or language will work as expected.
       
   670     * @method _resetModules
       
   671     * @private
       
   672     */
       
   673     _resetModules: function() {
       
   674         var self = this, i, o,
       
   675             mod, name, details;
       
   676         for (i in self.moduleInfo) {
       
   677             if (self.moduleInfo.hasOwnProperty(i)) {
       
   678                 mod = self.moduleInfo[i];
       
   679                 name = mod.name;
       
   680                 details  = (YUI.Env.mods[name] ? YUI.Env.mods[name].details : null);
       
   681 
       
   682                 if (details) {
       
   683                     self.moduleInfo[name]._reset = true;
       
   684                     self.moduleInfo[name].requires = details.requires || [];
       
   685                     self.moduleInfo[name].optional = details.optional || [];
       
   686                     self.moduleInfo[name].supersedes = details.supercedes || [];
       
   687                 }
       
   688 
       
   689                 if (mod.defaults) {
       
   690                     for (o in mod.defaults) {
       
   691                         if (mod.defaults.hasOwnProperty(o)) {
       
   692                             if (mod[o]) {
       
   693                                 mod[o] = mod.defaults[o];
       
   694                             }
       
   695                         }
       
   696                     }
       
   697                 }
       
   698                 delete mod.langCache;
       
   699                 delete mod.skinCache;
       
   700                 if (mod.skinnable) {
       
   701                     self._addSkin(self.skin.defaultSkin, mod.name);
       
   702                 }
       
   703             }
       
   704         }
       
   705     },
       
   706     /**
       
   707     Regex that matches a CSS URL. Used to guess the file type when it's not
       
   708     specified.
       
   709 
       
   710     @property REGEX_CSS
       
   711     @type RegExp
       
   712     @final
       
   713     @protected
       
   714     @since 3.5.0
       
   715     **/
       
   716     REGEX_CSS: /\.css(?:[?;].*)?$/i,
       
   717 
       
   718     /**
       
   719     * Default filters for raw and debug
       
   720     * @property FILTER_DEFS
       
   721     * @type Object
       
   722     * @final
       
   723     * @protected
       
   724     */
       
   725     FILTER_DEFS: {
       
   726         RAW: {
       
   727             'searchExp': '-min\\.js',
       
   728             'replaceStr': '.js'
       
   729         },
       
   730         DEBUG: {
       
   731             'searchExp': '-min\\.js',
       
   732             'replaceStr': '-debug.js'
       
   733         },
       
   734         COVERAGE: {
       
   735             'searchExp': '-min\\.js',
       
   736             'replaceStr': '-coverage.js'
       
   737         }
       
   738     },
       
   739     /*
       
   740     * Check the pages meta-data and cache the result.
       
   741     * @method _inspectPage
       
   742     * @private
       
   743     */
       
   744     _inspectPage: function() {
       
   745         var self = this, v, m, req, mr, i;
       
   746 
       
   747         //Inspect the page for CSS only modules and mark them as loaded.
       
   748         for (i in self.moduleInfo) {
       
   749             if (self.moduleInfo.hasOwnProperty(i)) {
       
   750                 v = self.moduleInfo[i];
       
   751                 if (v.type && v.type === CSS) {
       
   752                     if (self.isCSSLoaded(v.name)) {
       
   753                         self.loaded[i] = true;
       
   754                     }
       
   755                 }
       
   756             }
       
   757         }
       
   758         for (i in ON_PAGE) {
       
   759             if (ON_PAGE.hasOwnProperty(i)) {
       
   760                 v = ON_PAGE[i];
       
   761                 if (v.details) {
       
   762                     m = self.moduleInfo[v.name];
       
   763                     req = v.details.requires;
       
   764                     mr = m && m.requires;
       
   765 
       
   766                    if (m) {
       
   767                        if (!m._inspected && req && mr.length !== req.length) {
       
   768                            // console.log('deleting ' + m.name);
       
   769                            delete m.expanded;
       
   770                        }
       
   771                    } else {
       
   772                        m = self.addModule(v.details, i);
       
   773                    }
       
   774                    m._inspected = true;
       
   775                }
       
   776             }
       
   777         }
       
   778     },
       
   779     /*
       
   780     * returns true if b is not loaded, and is required directly or by means of modules it supersedes.
       
   781     * @private
       
   782     * @method _requires
       
   783     * @param {String} mod1 The first module to compare
       
   784     * @param {String} mod2 The second module to compare
       
   785     */
       
   786    _requires: function(mod1, mod2) {
       
   787 
       
   788         var i, rm, after_map, s,
       
   789             info = this.moduleInfo,
       
   790             m = info[mod1],
       
   791             other = info[mod2];
       
   792 
       
   793         if (!m || !other) {
       
   794             return false;
       
   795         }
       
   796 
       
   797         rm = m.expanded_map;
       
   798         after_map = m.after_map;
       
   799 
       
   800         // check if this module should be sorted after the other
       
   801         // do this first to short circut circular deps
       
   802         if (after_map && (mod2 in after_map)) {
       
   803             return true;
       
   804         }
       
   805 
       
   806         after_map = other.after_map;
       
   807 
       
   808         // and vis-versa
       
   809         if (after_map && (mod1 in after_map)) {
       
   810             return false;
       
   811         }
       
   812 
       
   813         // check if this module requires one the other supersedes
       
   814         s = info[mod2] && info[mod2].supersedes;
       
   815         if (s) {
       
   816             for (i = 0; i < s.length; i++) {
       
   817                 if (this._requires(mod1, s[i])) {
       
   818                     return true;
       
   819                 }
       
   820             }
       
   821         }
       
   822 
       
   823         s = info[mod1] && info[mod1].supersedes;
       
   824         if (s) {
       
   825             for (i = 0; i < s.length; i++) {
       
   826                 if (this._requires(mod2, s[i])) {
       
   827                     return false;
       
   828                 }
       
   829             }
       
   830         }
       
   831 
       
   832         // check if this module requires the other directly
       
   833         // if (r && yArray.indexOf(r, mod2) > -1) {
       
   834         if (rm && (mod2 in rm)) {
       
   835             return true;
       
   836         }
       
   837 
       
   838         // external css files should be sorted below yui css
       
   839         if (m.ext && m.type === CSS && !other.ext && other.type === CSS) {
       
   840             return true;
       
   841         }
       
   842 
       
   843         return false;
       
   844     },
       
   845     /**
       
   846     * Apply a new config to the Loader instance
       
   847     * @method _config
       
   848     * @private
       
   849     * @param {Object} o The new configuration
       
   850     */
       
   851     _config: function(o) {
       
   852         var i, j, val, a, f, group, groupName, self = this,
       
   853             mods = [], mod;
       
   854         // apply config values
       
   855         if (o) {
       
   856             for (i in o) {
       
   857                 if (o.hasOwnProperty(i)) {
       
   858                     val = o[i];
       
   859                     //TODO This should be a case
       
   860                     if (i === 'require') {
       
   861                         self.require(val);
       
   862                     } else if (i === 'skin') {
       
   863                         //If the config.skin is a string, format to the expected object
       
   864                         if (typeof val === 'string') {
       
   865                             self.skin.defaultSkin = o.skin;
       
   866                             val = {
       
   867                                 defaultSkin: val
       
   868                             };
       
   869                         }
       
   870 
       
   871                         Y.mix(self.skin, val, true);
       
   872                     } else if (i === 'groups') {
       
   873                         for (j in val) {
       
   874                             if (val.hasOwnProperty(j)) {
       
   875                                 groupName = j;
       
   876                                 group = val[j];
       
   877                                 self.addGroup(group, groupName);
       
   878                                 if (group.aliases) {
       
   879                                     for (a in group.aliases) {
       
   880                                         if (group.aliases.hasOwnProperty(a)) {
       
   881                                             self.addAlias(group.aliases[a], a);
       
   882                                         }
       
   883                                     }
       
   884                                 }
       
   885                             }
       
   886                         }
       
   887 
       
   888                     } else if (i === 'modules') {
       
   889                         // add a hash of module definitions
       
   890                         for (j in val) {
       
   891                             if (val.hasOwnProperty(j)) {
       
   892                                 self.addModule(val[j], j);
       
   893                             }
       
   894                         }
       
   895                     } else if (i === 'aliases') {
       
   896                         for (j in val) {
       
   897                             if (val.hasOwnProperty(j)) {
       
   898                                 self.addAlias(val[j], j);
       
   899                             }
       
   900                         }
       
   901                     } else if (i === 'gallery') {
       
   902                         if (this.groups.gallery.update) {
       
   903                             this.groups.gallery.update(val, o);
       
   904                         }
       
   905                     } else if (i === 'yui2' || i === '2in3') {
       
   906                         if (this.groups.yui2.update) {
       
   907                             this.groups.yui2.update(o['2in3'], o.yui2, o);
       
   908                         }
       
   909                     } else {
       
   910                         self[i] = val;
       
   911                     }
       
   912                 }
       
   913             }
       
   914         }
       
   915 
       
   916         // fix filter
       
   917         f = self.filter;
       
   918 
       
   919         if (L.isString(f)) {
       
   920             f = f.toUpperCase();
       
   921             self.filterName = f;
       
   922             self.filter = self.FILTER_DEFS[f];
       
   923             if (f === 'DEBUG') {
       
   924                 self.require('yui-log', 'dump');
       
   925             }
       
   926         }
       
   927 
       
   928         if (self.filterName && self.coverage) {
       
   929             if (self.filterName === 'COVERAGE' && L.isArray(self.coverage) && self.coverage.length) {
       
   930                 for (i = 0; i < self.coverage.length; i++) {
       
   931                     mod = self.coverage[i];
       
   932                     if (self.moduleInfo[mod] && self.moduleInfo[mod].use) {
       
   933                         mods = [].concat(mods, self.moduleInfo[mod].use);
       
   934                     } else {
       
   935                         mods.push(mod);
       
   936                     }
       
   937                 }
       
   938                 self.filters = self.filters || {};
       
   939                 Y.Array.each(mods, function(mod) {
       
   940                     self.filters[mod] = self.FILTER_DEFS.COVERAGE;
       
   941                 });
       
   942                 self.filterName = 'RAW';
       
   943                 self.filter = self.FILTER_DEFS[self.filterName];
       
   944             }
       
   945         }
       
   946 
       
   947     },
       
   948 
       
   949     /**
       
   950      * Returns the skin module name for the specified skin name.  If a
       
   951      * module name is supplied, the returned skin module name is
       
   952      * specific to the module passed in.
       
   953      * @method formatSkin
       
   954      * @param {string} skin the name of the skin.
       
   955      * @param {string} mod optional: the name of a module to skin.
       
   956      * @return {string} the full skin module name.
       
   957      */
       
   958     formatSkin: function(skin, mod) {
       
   959         var s = SKIN_PREFIX + skin;
       
   960         if (mod) {
       
   961             s = s + '-' + mod;
       
   962         }
       
   963 
       
   964         return s;
       
   965     },
       
   966 
       
   967     /**
       
   968      * Adds the skin def to the module info
       
   969      * @method _addSkin
       
   970      * @param {string} skin the name of the skin.
       
   971      * @param {string} mod the name of the module.
       
   972      * @param {string} parent parent module if this is a skin of a
       
   973      * submodule or plugin.
       
   974      * @return {string} the module name for the skin.
       
   975      * @private
       
   976      */
       
   977     _addSkin: function(skin, mod, parent) {
       
   978         var mdef, pkg, name, nmod,
       
   979             info = this.moduleInfo,
       
   980             sinf = this.skin,
       
   981             ext = info[mod] && info[mod].ext;
       
   982 
       
   983         // Add a module definition for the module-specific skin css
       
   984         if (mod) {
       
   985             name = this.formatSkin(skin, mod);
       
   986             if (!info[name]) {
       
   987                 mdef = info[mod];
       
   988                 pkg = mdef.pkg || mod;
       
   989                 nmod = {
       
   990                     skin: true,
       
   991                     name: name,
       
   992                     group: mdef.group,
       
   993                     type: 'css',
       
   994                     after: sinf.after,
       
   995                     path: (parent || pkg) + '/' + sinf.base + skin +
       
   996                           '/' + mod + '.css',
       
   997                     ext: ext
       
   998                 };
       
   999                 if (mdef.base) {
       
  1000                     nmod.base = mdef.base;
       
  1001                 }
       
  1002                 if (mdef.configFn) {
       
  1003                     nmod.configFn = mdef.configFn;
       
  1004                 }
       
  1005                 this.addModule(nmod, name);
       
  1006 
       
  1007             }
       
  1008         }
       
  1009 
       
  1010         return name;
       
  1011     },
       
  1012     /**
       
  1013     * Adds an alias module to the system
       
  1014     * @method addAlias
       
  1015     * @param {Array} use An array of modules that makes up this alias
       
  1016     * @param {String} name The name of the alias
       
  1017     * @example
       
  1018     *       var loader = new Y.Loader({});
       
  1019     *       loader.addAlias([ 'node', 'yql' ], 'davglass');
       
  1020     *       loader.require(['davglass']);
       
  1021     *       var out = loader.resolve(true);
       
  1022     *
       
  1023     *       //out.js will contain Node and YQL modules
       
  1024     */
       
  1025     addAlias: function(use, name) {
       
  1026         YUI.Env.aliases[name] = use;
       
  1027         this.addModule({
       
  1028             name: name,
       
  1029             use: use
       
  1030         });
       
  1031     },
       
  1032     /**
       
  1033      * Add a new module group
       
  1034      * @method addGroup
       
  1035      * @param {Object} config An object containing the group configuration data
       
  1036      * @param {String} config.name required, the group name
       
  1037      * @param {String} config.base The base directory for this module group
       
  1038      * @param {String} config.root The root path to add to each combo resource path
       
  1039      * @param {Boolean} config.combine Should the request be combined
       
  1040      * @param {String} config.comboBase Combo service base path
       
  1041      * @param {Object} config.modules The group of modules
       
  1042      * @param {String} name the group name.
       
  1043      * @example
       
  1044      *      var loader = new Y.Loader({});
       
  1045      *      loader.addGroup({
       
  1046      *          name: 'davglass',
       
  1047      *          combine: true,
       
  1048      *          comboBase: '/combo?',
       
  1049      *          root: '',
       
  1050      *          modules: {
       
  1051      *              //Module List here
       
  1052      *          }
       
  1053      *      }, 'davglass');
       
  1054      */
       
  1055     addGroup: function(o, name) {
       
  1056         var mods = o.modules,
       
  1057             self = this, i, v;
       
  1058 
       
  1059         name = name || o.name;
       
  1060         o.name = name;
       
  1061         self.groups[name] = o;
       
  1062 
       
  1063         if (o.patterns) {
       
  1064             for (i in o.patterns) {
       
  1065                 if (o.patterns.hasOwnProperty(i)) {
       
  1066                     o.patterns[i].group = name;
       
  1067                     self.patterns[i] = o.patterns[i];
       
  1068                 }
       
  1069             }
       
  1070         }
       
  1071 
       
  1072         if (mods) {
       
  1073             for (i in mods) {
       
  1074                 if (mods.hasOwnProperty(i)) {
       
  1075                     v = mods[i];
       
  1076                     if (typeof v === 'string') {
       
  1077                         v = { name: i, fullpath: v };
       
  1078                     }
       
  1079                     v.group = name;
       
  1080                     self.addModule(v, i);
       
  1081                 }
       
  1082             }
       
  1083         }
       
  1084     },
       
  1085 
       
  1086     /**
       
  1087      * Add a new module to the component metadata.
       
  1088      * @method addModule
       
  1089      * @param {Object} config An object containing the module data.
       
  1090      * @param {String} config.name Required, the component name
       
  1091      * @param {String} config.type Required, the component type (js or css)
       
  1092      * @param {String} config.path Required, the path to the script from `base`
       
  1093      * @param {Array} config.requires Array of modules required by this component
       
  1094      * @param {Array} [config.optional] Array of optional modules for this component
       
  1095      * @param {Array} [config.supersedes] Array of the modules this component replaces
       
  1096      * @param {Array} [config.after] Array of modules the components which, if present, should be sorted above this one
       
  1097      * @param {Object} [config.after_map] Faster alternative to 'after' -- supply a hash instead of an array
       
  1098      * @param {Number} [config.rollup] The number of superseded modules required for automatic rollup
       
  1099      * @param {String} [config.fullpath] If `fullpath` is specified, this is used instead of the configured `base + path`
       
  1100      * @param {Boolean} [config.skinnable] Flag to determine if skin assets should automatically be pulled in
       
  1101      * @param {Object} [config.submodules] Hash of submodules
       
  1102      * @param {String} [config.group] The group the module belongs to -- this is set automatically when it is added as part of a group configuration.
       
  1103      * @param {Array} [config.lang] Array of BCP 47 language tags of languages for which this module has localized resource bundles, e.g., `["en-GB", "zh-Hans-CN"]`
       
  1104      * @param {Object} [config.condition] Specifies that the module should be loaded automatically if a condition is met. This is an object with up to four fields:
       
  1105      * @param {String} [config.condition.trigger] The name of a module that can trigger the auto-load
       
  1106      * @param {Function} [config.condition.test] A function that returns true when the module is to be loaded.
       
  1107      * @param {String} [config.condition.ua] The UA name of <a href="UA.html">Y.UA</a> object that returns true when the module is to be loaded. e.g., `"ie"`, `"nodejs"`.
       
  1108      * @param {String} [config.condition.when] Specifies the load order of the conditional module
       
  1109      *  with regard to the position of the trigger module.
       
  1110      *  This should be one of three values: `before`, `after`, or `instead`.  The default is `after`.
       
  1111      * @param {Object} [config.testresults] A hash of test results from `Y.Features.all()`
       
  1112      * @param {Function} [config.configFn] A function to exectute when configuring this module
       
  1113      * @param {Object} config.configFn.mod The module config, modifying this object will modify it's config. Returning false will delete the module's config.
       
  1114      * @param {String} [name] The module name, required if not in the module data.
       
  1115      * @return {Object} the module definition or null if the object passed in did not provide all required attributes.
       
  1116      */
       
  1117     addModule: function(o, name) {
       
  1118         name = name || o.name;
       
  1119 
       
  1120         if (typeof o === 'string') {
       
  1121             o = { name: name, fullpath: o };
       
  1122         }
       
  1123 
       
  1124 
       
  1125         var subs, i, l, t, sup, s, smod, plugins, plug,
       
  1126             j, langs, packName, supName, flatSup, flatLang, lang, ret,
       
  1127             overrides, skinname, when, g, p,
       
  1128             conditions = this.conditions, trigger;
       
  1129 
       
  1130         //Only merge this data if the temp flag is set
       
  1131         //from an earlier pass from a pattern or else
       
  1132         //an override module (YUI_config) can not be used to
       
  1133         //replace a default module.
       
  1134         if (this.moduleInfo[name] && this.moduleInfo[name].temp) {
       
  1135             //This catches temp modules loaded via a pattern
       
  1136             // The module will be added twice, once from the pattern and
       
  1137             // Once from the actual add call, this ensures that properties
       
  1138             // that were added to the module the first time around (group: gallery)
       
  1139             // are also added the second time around too.
       
  1140             o = Y.merge(this.moduleInfo[name], o);
       
  1141         }
       
  1142 
       
  1143         o.name = name;
       
  1144 
       
  1145         if (!o || !o.name) {
       
  1146             return null;
       
  1147         }
       
  1148 
       
  1149         if (!o.type) {
       
  1150             //Always assume it's javascript unless the CSS pattern is matched.
       
  1151             o.type = JS;
       
  1152             p = o.path || o.fullpath;
       
  1153             if (p && this.REGEX_CSS.test(p)) {
       
  1154                 o.type = CSS;
       
  1155             }
       
  1156         }
       
  1157 
       
  1158         if (!o.path && !o.fullpath) {
       
  1159             o.path = _path(name, name, o.type);
       
  1160         }
       
  1161         o.supersedes = o.supersedes || o.use;
       
  1162 
       
  1163         o.ext = ('ext' in o) ? o.ext : (this._internal) ? false : true;
       
  1164 
       
  1165         // Handle submodule logic
       
  1166         subs = o.submodules;
       
  1167 
       
  1168         this.moduleInfo[name] = o;
       
  1169 
       
  1170         o.requires = o.requires || [];
       
  1171 
       
  1172         /*
       
  1173         Only allowing the cascade of requires information, since
       
  1174         optional and supersedes are far more fine grained than
       
  1175         a blanket requires is.
       
  1176         */
       
  1177         if (this.requires) {
       
  1178             for (i = 0; i < this.requires.length; i++) {
       
  1179                 o.requires.push(this.requires[i]);
       
  1180             }
       
  1181         }
       
  1182         if (o.group && this.groups && this.groups[o.group]) {
       
  1183             g = this.groups[o.group];
       
  1184             if (g.requires) {
       
  1185                 for (i = 0; i < g.requires.length; i++) {
       
  1186                     o.requires.push(g.requires[i]);
       
  1187                 }
       
  1188             }
       
  1189         }
       
  1190 
       
  1191 
       
  1192         if (!o.defaults) {
       
  1193             o.defaults = {
       
  1194                 requires: o.requires ? [].concat(o.requires) : null,
       
  1195                 supersedes: o.supersedes ? [].concat(o.supersedes) : null,
       
  1196                 optional: o.optional ? [].concat(o.optional) : null
       
  1197             };
       
  1198         }
       
  1199 
       
  1200         if (o.skinnable && o.ext && o.temp) {
       
  1201             skinname = this._addSkin(this.skin.defaultSkin, name);
       
  1202             o.requires.unshift(skinname);
       
  1203         }
       
  1204 
       
  1205         if (o.requires.length) {
       
  1206             o.requires = this.filterRequires(o.requires) || [];
       
  1207         }
       
  1208 
       
  1209         if (!o.langPack && o.lang) {
       
  1210             langs = yArray(o.lang);
       
  1211             for (j = 0; j < langs.length; j++) {
       
  1212                 lang = langs[j];
       
  1213                 packName = this.getLangPackName(lang, name);
       
  1214                 smod = this.moduleInfo[packName];
       
  1215                 if (!smod) {
       
  1216                     smod = this._addLangPack(lang, o, packName);
       
  1217                 }
       
  1218             }
       
  1219         }
       
  1220 
       
  1221 
       
  1222         if (subs) {
       
  1223             sup = o.supersedes || [];
       
  1224             l = 0;
       
  1225 
       
  1226             for (i in subs) {
       
  1227                 if (subs.hasOwnProperty(i)) {
       
  1228                     s = subs[i];
       
  1229 
       
  1230                     s.path = s.path || _path(name, i, o.type);
       
  1231                     s.pkg = name;
       
  1232                     s.group = o.group;
       
  1233 
       
  1234                     if (s.supersedes) {
       
  1235                         sup = sup.concat(s.supersedes);
       
  1236                     }
       
  1237 
       
  1238                     smod = this.addModule(s, i);
       
  1239                     sup.push(i);
       
  1240 
       
  1241                     if (smod.skinnable) {
       
  1242                         o.skinnable = true;
       
  1243                         overrides = this.skin.overrides;
       
  1244                         if (overrides && overrides[i]) {
       
  1245                             for (j = 0; j < overrides[i].length; j++) {
       
  1246                                 skinname = this._addSkin(overrides[i][j],
       
  1247                                          i, name);
       
  1248                                 sup.push(skinname);
       
  1249                             }
       
  1250                         }
       
  1251                         skinname = this._addSkin(this.skin.defaultSkin,
       
  1252                                         i, name);
       
  1253                         sup.push(skinname);
       
  1254                     }
       
  1255 
       
  1256                     // looks like we are expected to work out the metadata
       
  1257                     // for the parent module language packs from what is
       
  1258                     // specified in the child modules.
       
  1259                     if (s.lang && s.lang.length) {
       
  1260 
       
  1261                         langs = yArray(s.lang);
       
  1262                         for (j = 0; j < langs.length; j++) {
       
  1263                             lang = langs[j];
       
  1264                             packName = this.getLangPackName(lang, name);
       
  1265                             supName = this.getLangPackName(lang, i);
       
  1266                             smod = this.moduleInfo[packName];
       
  1267 
       
  1268                             if (!smod) {
       
  1269                                 smod = this._addLangPack(lang, o, packName);
       
  1270                             }
       
  1271 
       
  1272                             flatSup = flatSup || yArray.hash(smod.supersedes);
       
  1273 
       
  1274                             if (!(supName in flatSup)) {
       
  1275                                 smod.supersedes.push(supName);
       
  1276                             }
       
  1277 
       
  1278                             o.lang = o.lang || [];
       
  1279 
       
  1280                             flatLang = flatLang || yArray.hash(o.lang);
       
  1281 
       
  1282                             if (!(lang in flatLang)) {
       
  1283                                 o.lang.push(lang);
       
  1284                             }
       
  1285 
       
  1286 // Add rollup file, need to add to supersedes list too
       
  1287 
       
  1288                             // default packages
       
  1289                             packName = this.getLangPackName(ROOT_LANG, name);
       
  1290                             supName = this.getLangPackName(ROOT_LANG, i);
       
  1291 
       
  1292                             smod = this.moduleInfo[packName];
       
  1293 
       
  1294                             if (!smod) {
       
  1295                                 smod = this._addLangPack(lang, o, packName);
       
  1296                             }
       
  1297 
       
  1298                             if (!(supName in flatSup)) {
       
  1299                                 smod.supersedes.push(supName);
       
  1300                             }
       
  1301 
       
  1302 // Add rollup file, need to add to supersedes list too
       
  1303 
       
  1304                         }
       
  1305                     }
       
  1306 
       
  1307                     l++;
       
  1308                 }
       
  1309             }
       
  1310             //o.supersedes = YObject.keys(yArray.hash(sup));
       
  1311             o.supersedes = yArray.dedupe(sup);
       
  1312             if (this.allowRollup) {
       
  1313                 o.rollup = (l < 4) ? l : Math.min(l - 1, 4);
       
  1314             }
       
  1315         }
       
  1316 
       
  1317         plugins = o.plugins;
       
  1318         if (plugins) {
       
  1319             for (i in plugins) {
       
  1320                 if (plugins.hasOwnProperty(i)) {
       
  1321                     plug = plugins[i];
       
  1322                     plug.pkg = name;
       
  1323                     plug.path = plug.path || _path(name, i, o.type);
       
  1324                     plug.requires = plug.requires || [];
       
  1325                     plug.group = o.group;
       
  1326                     this.addModule(plug, i);
       
  1327                     if (o.skinnable) {
       
  1328                         this._addSkin(this.skin.defaultSkin, i, name);
       
  1329                     }
       
  1330 
       
  1331                 }
       
  1332             }
       
  1333         }
       
  1334 
       
  1335         if (o.condition) {
       
  1336             t = o.condition.trigger;
       
  1337             if (YUI.Env.aliases[t]) {
       
  1338                 t = YUI.Env.aliases[t];
       
  1339             }
       
  1340             if (!Y.Lang.isArray(t)) {
       
  1341                 t = [t];
       
  1342             }
       
  1343 
       
  1344             for (i = 0; i < t.length; i++) {
       
  1345                 trigger = t[i];
       
  1346                 when = o.condition.when;
       
  1347                 conditions[trigger] = conditions[trigger] || {};
       
  1348                 conditions[trigger][name] = o.condition;
       
  1349                 // the 'when' attribute can be 'before', 'after', or 'instead'
       
  1350                 // the default is after.
       
  1351                 if (when && when !== 'after') {
       
  1352                     if (when === 'instead') { // replace the trigger
       
  1353                         o.supersedes = o.supersedes || [];
       
  1354                         o.supersedes.push(trigger);
       
  1355                     }
       
  1356                     // before the trigger
       
  1357                         // the trigger requires the conditional mod,
       
  1358                         // so it should appear before the conditional
       
  1359                         // mod if we do not intersede.
       
  1360                 } else { // after the trigger
       
  1361                     o.after = o.after || [];
       
  1362                     o.after.push(trigger);
       
  1363                 }
       
  1364             }
       
  1365         }
       
  1366 
       
  1367         if (o.supersedes) {
       
  1368             o.supersedes = this.filterRequires(o.supersedes);
       
  1369         }
       
  1370 
       
  1371         if (o.after) {
       
  1372             o.after = this.filterRequires(o.after);
       
  1373             o.after_map = yArray.hash(o.after);
       
  1374         }
       
  1375 
       
  1376         // this.dirty = true;
       
  1377 
       
  1378         if (o.configFn) {
       
  1379             ret = o.configFn(o);
       
  1380             if (ret === false) {
       
  1381                 delete this.moduleInfo[name];
       
  1382                 delete GLOBAL_ENV._renderedMods[name];
       
  1383                 o = null;
       
  1384             }
       
  1385         }
       
  1386         //Add to global cache
       
  1387         if (o) {
       
  1388             if (!GLOBAL_ENV._renderedMods) {
       
  1389                 GLOBAL_ENV._renderedMods = {};
       
  1390             }
       
  1391             GLOBAL_ENV._renderedMods[name] = Y.mix(GLOBAL_ENV._renderedMods[name] || {}, o);
       
  1392             GLOBAL_ENV._conditions = conditions;
       
  1393         }
       
  1394 
       
  1395         return o;
       
  1396     },
       
  1397 
       
  1398     /**
       
  1399      * Add a requirement for one or more module
       
  1400      * @method require
       
  1401      * @param {string[] | string*} what the modules to load.
       
  1402      */
       
  1403     require: function(what) {
       
  1404         var a = (typeof what === 'string') ? yArray(arguments) : what;
       
  1405         this.dirty = true;
       
  1406         this.required = Y.merge(this.required, yArray.hash(this.filterRequires(a)));
       
  1407 
       
  1408         this._explodeRollups();
       
  1409     },
       
  1410     /**
       
  1411     * Grab all the items that were asked for, check to see if the Loader
       
  1412     * meta-data contains a "use" array. If it doesm remove the asked item and replace it with
       
  1413     * the content of the "use".
       
  1414     * This will make asking for: "dd"
       
  1415     * Actually ask for: "dd-ddm-base,dd-ddm,dd-ddm-drop,dd-drag,dd-proxy,dd-constrain,dd-drop,dd-scroll,dd-drop-plugin"
       
  1416     * @private
       
  1417     * @method _explodeRollups
       
  1418     */
       
  1419     _explodeRollups: function() {
       
  1420         var self = this, m, m2, i, a, v, len, len2,
       
  1421         r = self.required;
       
  1422 
       
  1423         if (!self.allowRollup) {
       
  1424             for (i in r) {
       
  1425                 if (r.hasOwnProperty(i)) {
       
  1426                     m = self.getModule(i);
       
  1427                     if (m && m.use) {
       
  1428                         len = m.use.length;
       
  1429                         for (a = 0; a < len; a++) {
       
  1430                             m2 = self.getModule(m.use[a]);
       
  1431                             if (m2 && m2.use) {
       
  1432                                 len2 = m2.use.length;
       
  1433                                 for (v = 0; v < len2; v++) {
       
  1434                                     r[m2.use[v]] = true;
       
  1435                                 }
       
  1436                             } else {
       
  1437                                 r[m.use[a]] = true;
       
  1438                             }
       
  1439                         }
       
  1440                     }
       
  1441                 }
       
  1442             }
       
  1443             self.required = r;
       
  1444         }
       
  1445 
       
  1446     },
       
  1447     /**
       
  1448     * Explodes the required array to remove aliases and replace them with real modules
       
  1449     * @method filterRequires
       
  1450     * @param {Array} r The original requires array
       
  1451     * @return {Array} The new array of exploded requirements
       
  1452     */
       
  1453     filterRequires: function(r) {
       
  1454         if (r) {
       
  1455             if (!Y.Lang.isArray(r)) {
       
  1456                 r = [r];
       
  1457             }
       
  1458             r = Y.Array(r);
       
  1459             var c = [], i, mod, o, m;
       
  1460 
       
  1461             for (i = 0; i < r.length; i++) {
       
  1462                 mod = this.getModule(r[i]);
       
  1463                 if (mod && mod.use) {
       
  1464                     for (o = 0; o < mod.use.length; o++) {
       
  1465                         //Must walk the other modules in case a module is a rollup of rollups (datatype)
       
  1466                         m = this.getModule(mod.use[o]);
       
  1467                         if (m && m.use && (m.name !== mod.name)) {
       
  1468                             c = Y.Array.dedupe([].concat(c, this.filterRequires(m.use)));
       
  1469                         } else {
       
  1470                             c.push(mod.use[o]);
       
  1471                         }
       
  1472                     }
       
  1473                 } else {
       
  1474                     c.push(r[i]);
       
  1475                 }
       
  1476             }
       
  1477             r = c;
       
  1478         }
       
  1479         return r;
       
  1480     },
       
  1481     /**
       
  1482      * Returns an object containing properties for all modules required
       
  1483      * in order to load the requested module
       
  1484      * @method getRequires
       
  1485      * @param {object}  mod The module definition from moduleInfo.
       
  1486      * @return {array} the expanded requirement list.
       
  1487      */
       
  1488     getRequires: function(mod) {
       
  1489 
       
  1490         if (!mod) {
       
  1491             //console.log('returning no reqs for ' + mod.name);
       
  1492             return NO_REQUIREMENTS;
       
  1493         }
       
  1494 
       
  1495         if (mod._parsed) {
       
  1496             //console.log('returning requires for ' + mod.name, mod.requires);
       
  1497             return mod.expanded || NO_REQUIREMENTS;
       
  1498         }
       
  1499 
       
  1500         //TODO add modue cache here out of scope..
       
  1501 
       
  1502         var i, m, j, add, packName, lang, testresults = this.testresults,
       
  1503             name = mod.name, cond,
       
  1504             adddef = ON_PAGE[name] && ON_PAGE[name].details,
       
  1505             d, go, def,
       
  1506             r, old_mod,
       
  1507             o, skinmod, skindef, skinpar, skinname,
       
  1508             intl = mod.lang || mod.intl,
       
  1509             info = this.moduleInfo,
       
  1510             ftests = Y.Features && Y.Features.tests.load,
       
  1511             hash, reparse;
       
  1512 
       
  1513         // console.log(name);
       
  1514 
       
  1515         // pattern match leaves module stub that needs to be filled out
       
  1516         if (mod.temp && adddef) {
       
  1517             old_mod = mod;
       
  1518             mod = this.addModule(adddef, name);
       
  1519             mod.group = old_mod.group;
       
  1520             mod.pkg = old_mod.pkg;
       
  1521             delete mod.expanded;
       
  1522         }
       
  1523 
       
  1524         // console.log('cache: ' + mod.langCache + ' == ' + this.lang);
       
  1525 
       
  1526         //If a skin or a lang is different, reparse..
       
  1527         reparse = !((!this.lang || mod.langCache === this.lang) && (mod.skinCache === this.skin.defaultSkin));
       
  1528 
       
  1529         if (mod.expanded && !reparse) {
       
  1530             return mod.expanded;
       
  1531         }
       
  1532 
       
  1533 
       
  1534         d = [];
       
  1535         hash = {};
       
  1536         r = this.filterRequires(mod.requires);
       
  1537         if (mod.lang) {
       
  1538             //If a module has a lang attribute, auto add the intl requirement.
       
  1539             d.unshift('intl');
       
  1540             r.unshift('intl');
       
  1541             intl = true;
       
  1542         }
       
  1543         o = this.filterRequires(mod.optional);
       
  1544 
       
  1545 
       
  1546         mod._parsed = true;
       
  1547         mod.langCache = this.lang;
       
  1548         mod.skinCache = this.skin.defaultSkin;
       
  1549 
       
  1550         for (i = 0; i < r.length; i++) {
       
  1551             if (!hash[r[i]]) {
       
  1552                 d.push(r[i]);
       
  1553                 hash[r[i]] = true;
       
  1554                 m = this.getModule(r[i]);
       
  1555                 if (m) {
       
  1556                     add = this.getRequires(m);
       
  1557                     intl = intl || (m.expanded_map &&
       
  1558                         (INTL in m.expanded_map));
       
  1559                     for (j = 0; j < add.length; j++) {
       
  1560                         d.push(add[j]);
       
  1561                     }
       
  1562                 }
       
  1563             }
       
  1564         }
       
  1565 
       
  1566         // get the requirements from superseded modules, if any
       
  1567         r = this.filterRequires(mod.supersedes);
       
  1568         if (r) {
       
  1569             for (i = 0; i < r.length; i++) {
       
  1570                 if (!hash[r[i]]) {
       
  1571                     // if this module has submodules, the requirements list is
       
  1572                     // expanded to include the submodules.  This is so we can
       
  1573                     // prevent dups when a submodule is already loaded and the
       
  1574                     // parent is requested.
       
  1575                     if (mod.submodules) {
       
  1576                         d.push(r[i]);
       
  1577                     }
       
  1578 
       
  1579                     hash[r[i]] = true;
       
  1580                     m = this.getModule(r[i]);
       
  1581 
       
  1582                     if (m) {
       
  1583                         add = this.getRequires(m);
       
  1584                         intl = intl || (m.expanded_map &&
       
  1585                             (INTL in m.expanded_map));
       
  1586                         for (j = 0; j < add.length; j++) {
       
  1587                             d.push(add[j]);
       
  1588                         }
       
  1589                     }
       
  1590                 }
       
  1591             }
       
  1592         }
       
  1593 
       
  1594         if (o && this.loadOptional) {
       
  1595             for (i = 0; i < o.length; i++) {
       
  1596                 if (!hash[o[i]]) {
       
  1597                     d.push(o[i]);
       
  1598                     hash[o[i]] = true;
       
  1599                     m = info[o[i]];
       
  1600                     if (m) {
       
  1601                         add = this.getRequires(m);
       
  1602                         intl = intl || (m.expanded_map &&
       
  1603                             (INTL in m.expanded_map));
       
  1604                         for (j = 0; j < add.length; j++) {
       
  1605                             d.push(add[j]);
       
  1606                         }
       
  1607                     }
       
  1608                 }
       
  1609             }
       
  1610         }
       
  1611 
       
  1612         cond = this.conditions[name];
       
  1613 
       
  1614         if (cond) {
       
  1615             //Set the module to not parsed since we have conditionals and this could change the dependency tree.
       
  1616             mod._parsed = false;
       
  1617             if (testresults && ftests) {
       
  1618                 oeach(testresults, function(result, id) {
       
  1619                     var condmod = ftests[id].name;
       
  1620                     if (!hash[condmod] && ftests[id].trigger === name) {
       
  1621                         if (result && ftests[id]) {
       
  1622                             hash[condmod] = true;
       
  1623                             d.push(condmod);
       
  1624                         }
       
  1625                     }
       
  1626                 });
       
  1627             } else {
       
  1628                 for (i in cond) {
       
  1629                     if (cond.hasOwnProperty(i)) {
       
  1630                         if (!hash[i]) {
       
  1631                             def = cond[i];
       
  1632                             //first see if they've specfied a ua check
       
  1633                             //then see if they've got a test fn & if it returns true
       
  1634                             //otherwise just having a condition block is enough
       
  1635                             go = def && ((!def.ua && !def.test) || (def.ua && Y.UA[def.ua]) ||
       
  1636                                         (def.test && def.test(Y, r)));
       
  1637 
       
  1638                             if (go) {
       
  1639                                 hash[i] = true;
       
  1640                                 d.push(i);
       
  1641                                 m = this.getModule(i);
       
  1642                                 if (m) {
       
  1643                                     add = this.getRequires(m);
       
  1644                                     for (j = 0; j < add.length; j++) {
       
  1645                                         d.push(add[j]);
       
  1646                                     }
       
  1647 
       
  1648                                 }
       
  1649                             }
       
  1650                         }
       
  1651                     }
       
  1652                 }
       
  1653             }
       
  1654         }
       
  1655 
       
  1656         // Create skin modules
       
  1657         if (mod.skinnable) {
       
  1658             skindef = this.skin.overrides;
       
  1659             for (i in YUI.Env.aliases) {
       
  1660                 if (YUI.Env.aliases.hasOwnProperty(i)) {
       
  1661                     if (Y.Array.indexOf(YUI.Env.aliases[i], name) > -1) {
       
  1662                         skinpar = i;
       
  1663                     }
       
  1664                 }
       
  1665             }
       
  1666             if (skindef && (skindef[name] || (skinpar && skindef[skinpar]))) {
       
  1667                 skinname = name;
       
  1668                 if (skindef[skinpar]) {
       
  1669                     skinname = skinpar;
       
  1670                 }
       
  1671                 for (i = 0; i < skindef[skinname].length; i++) {
       
  1672                     skinmod = this._addSkin(skindef[skinname][i], name);
       
  1673                     if (!this.isCSSLoaded(skinmod, this._boot)) {
       
  1674                         d.push(skinmod);
       
  1675                     }
       
  1676                 }
       
  1677             } else {
       
  1678                 skinmod = this._addSkin(this.skin.defaultSkin, name);
       
  1679                 if (!this.isCSSLoaded(skinmod, this._boot)) {
       
  1680                     d.push(skinmod);
       
  1681                 }
       
  1682             }
       
  1683         }
       
  1684 
       
  1685         mod._parsed = false;
       
  1686 
       
  1687         if (intl) {
       
  1688 
       
  1689             if (mod.lang && !mod.langPack && Y.Intl) {
       
  1690                 lang = Y.Intl.lookupBestLang(this.lang || ROOT_LANG, mod.lang);
       
  1691                 packName = this.getLangPackName(lang, name);
       
  1692                 if (packName) {
       
  1693                     d.unshift(packName);
       
  1694                 }
       
  1695             }
       
  1696             d.unshift(INTL);
       
  1697         }
       
  1698 
       
  1699         mod.expanded_map = yArray.hash(d);
       
  1700 
       
  1701         mod.expanded = YObject.keys(mod.expanded_map);
       
  1702 
       
  1703         return mod.expanded;
       
  1704     },
       
  1705     /**
       
  1706     * Check to see if named css module is already loaded on the page
       
  1707     * @method isCSSLoaded
       
  1708     * @param {String} name The name of the css file
       
  1709     * @return Boolean
       
  1710     */
       
  1711     isCSSLoaded: function(name, skip) {
       
  1712         //TODO - Make this call a batching call with name being an array
       
  1713         if (!name || !YUI.Env.cssStampEl || (!skip && this.ignoreRegistered)) {
       
  1714             return false;
       
  1715         }
       
  1716         var el = YUI.Env.cssStampEl,
       
  1717             ret = false,
       
  1718             mod = YUI.Env._cssLoaded[name],
       
  1719             style = el.currentStyle; //IE
       
  1720 
       
  1721 
       
  1722         if (mod !== undefined) {
       
  1723             return mod;
       
  1724         }
       
  1725 
       
  1726         //Add the classname to the element
       
  1727         el.className = name;
       
  1728 
       
  1729         if (!style) {
       
  1730             style = Y.config.doc.defaultView.getComputedStyle(el, null);
       
  1731         }
       
  1732 
       
  1733         if (style && style.display === 'none') {
       
  1734             ret = true;
       
  1735         }
       
  1736 
       
  1737 
       
  1738         el.className = ''; //Reset the classname to ''
       
  1739 
       
  1740         YUI.Env._cssLoaded[name] = ret;
       
  1741 
       
  1742         return ret;
       
  1743     },
       
  1744 
       
  1745     /**
       
  1746      * Returns a hash of module names the supplied module satisfies.
       
  1747      * @method getProvides
       
  1748      * @param {string} name The name of the module.
       
  1749      * @return {object} what this module provides.
       
  1750      */
       
  1751     getProvides: function(name) {
       
  1752         var m = this.getModule(name), o, s;
       
  1753             // supmap = this.provides;
       
  1754 
       
  1755         if (!m) {
       
  1756             return NOT_FOUND;
       
  1757         }
       
  1758 
       
  1759         if (m && !m.provides) {
       
  1760             o = {};
       
  1761             s = m.supersedes;
       
  1762 
       
  1763             if (s) {
       
  1764                 yArray.each(s, function(v) {
       
  1765                     Y.mix(o, this.getProvides(v));
       
  1766                 }, this);
       
  1767             }
       
  1768 
       
  1769             o[name] = true;
       
  1770             m.provides = o;
       
  1771 
       
  1772         }
       
  1773 
       
  1774         return m.provides;
       
  1775     },
       
  1776 
       
  1777     /**
       
  1778      * Calculates the dependency tree, the result is stored in the sorted
       
  1779      * property.
       
  1780      * @method calculate
       
  1781      * @param {object} o optional options object.
       
  1782      * @param {string} type optional argument to prune modules.
       
  1783      */
       
  1784     calculate: function(o, type) {
       
  1785         if (o || type || this.dirty) {
       
  1786 
       
  1787             if (o) {
       
  1788                 this._config(o);
       
  1789             }
       
  1790 
       
  1791             if (!this._init) {
       
  1792                 this._setup();
       
  1793             }
       
  1794 
       
  1795             this._explode();
       
  1796 
       
  1797             if (this.allowRollup) {
       
  1798                 this._rollup();
       
  1799             } else {
       
  1800                 this._explodeRollups();
       
  1801             }
       
  1802             this._reduce();
       
  1803             this._sort();
       
  1804         }
       
  1805     },
       
  1806     /**
       
  1807     * Creates a "psuedo" package for languages provided in the lang array
       
  1808     * @method _addLangPack
       
  1809     * @private
       
  1810     * @param {String} lang The language to create
       
  1811     * @param {Object} m The module definition to create the language pack around
       
  1812     * @param {String} packName The name of the package (e.g: lang/datatype-date-en-US)
       
  1813     * @return {Object} The module definition
       
  1814     */
       
  1815     _addLangPack: function(lang, m, packName) {
       
  1816         var name = m.name,
       
  1817             packPath, conf,
       
  1818             existing = this.moduleInfo[packName];
       
  1819 
       
  1820         if (!existing) {
       
  1821 
       
  1822             packPath = _path((m.pkg || name), packName, JS, true);
       
  1823 
       
  1824             conf = {
       
  1825                 path: packPath,
       
  1826                 intl: true,
       
  1827                 langPack: true,
       
  1828                 ext: m.ext,
       
  1829                 group: m.group,
       
  1830                 supersedes: []
       
  1831             };
       
  1832             if (m.root) {
       
  1833                 conf.root = m.root;
       
  1834             }
       
  1835             if (m.base) {
       
  1836                 conf.base = m.base;
       
  1837             }
       
  1838 
       
  1839             if (m.configFn) {
       
  1840                 conf.configFn = m.configFn;
       
  1841             }
       
  1842 
       
  1843             this.addModule(conf, packName);
       
  1844 
       
  1845             if (lang) {
       
  1846                 Y.Env.lang = Y.Env.lang || {};
       
  1847                 Y.Env.lang[lang] = Y.Env.lang[lang] || {};
       
  1848                 Y.Env.lang[lang][name] = true;
       
  1849             }
       
  1850         }
       
  1851 
       
  1852         return this.moduleInfo[packName];
       
  1853     },
       
  1854 
       
  1855     /**
       
  1856      * Investigates the current YUI configuration on the page.  By default,
       
  1857      * modules already detected will not be loaded again unless a force
       
  1858      * option is encountered.  Called by calculate()
       
  1859      * @method _setup
       
  1860      * @private
       
  1861      */
       
  1862     _setup: function() {
       
  1863         var info = this.moduleInfo, name, i, j, m, l,
       
  1864             packName;
       
  1865 
       
  1866         for (name in info) {
       
  1867             if (info.hasOwnProperty(name)) {
       
  1868                 m = info[name];
       
  1869                 if (m) {
       
  1870 
       
  1871                     // remove dups
       
  1872                     //m.requires = YObject.keys(yArray.hash(m.requires));
       
  1873                     m.requires = yArray.dedupe(m.requires);
       
  1874 
       
  1875                     // Create lang pack modules
       
  1876                     //if (m.lang && m.lang.length) {
       
  1877                     if (m.lang) {
       
  1878                         // Setup root package if the module has lang defined,
       
  1879                         // it needs to provide a root language pack
       
  1880                         packName = this.getLangPackName(ROOT_LANG, name);
       
  1881                         this._addLangPack(null, m, packName);
       
  1882                     }
       
  1883 
       
  1884                 }
       
  1885             }
       
  1886         }
       
  1887 
       
  1888 
       
  1889         //l = Y.merge(this.inserted);
       
  1890         l = {};
       
  1891 
       
  1892         // available modules
       
  1893         if (!this.ignoreRegistered) {
       
  1894             Y.mix(l, GLOBAL_ENV.mods);
       
  1895         }
       
  1896 
       
  1897         // add the ignore list to the list of loaded packages
       
  1898         if (this.ignore) {
       
  1899             Y.mix(l, yArray.hash(this.ignore));
       
  1900         }
       
  1901 
       
  1902         // expand the list to include superseded modules
       
  1903         for (j in l) {
       
  1904             if (l.hasOwnProperty(j)) {
       
  1905                 Y.mix(l, this.getProvides(j));
       
  1906             }
       
  1907         }
       
  1908 
       
  1909         // remove modules on the force list from the loaded list
       
  1910         if (this.force) {
       
  1911             for (i = 0; i < this.force.length; i++) {
       
  1912                 if (this.force[i] in l) {
       
  1913                     delete l[this.force[i]];
       
  1914                 }
       
  1915             }
       
  1916         }
       
  1917 
       
  1918         Y.mix(this.loaded, l);
       
  1919 
       
  1920         this._init = true;
       
  1921     },
       
  1922 
       
  1923     /**
       
  1924      * Builds a module name for a language pack
       
  1925      * @method getLangPackName
       
  1926      * @param {string} lang the language code.
       
  1927      * @param {string} mname the module to build it for.
       
  1928      * @return {string} the language pack module name.
       
  1929      */
       
  1930     getLangPackName: function(lang, mname) {
       
  1931         return ('lang/' + mname + ((lang) ? '_' + lang : ''));
       
  1932     },
       
  1933     /**
       
  1934      * Inspects the required modules list looking for additional
       
  1935      * dependencies.  Expands the required list to include all
       
  1936      * required modules.  Called by calculate()
       
  1937      * @method _explode
       
  1938      * @private
       
  1939      */
       
  1940     _explode: function() {
       
  1941         //TODO Move done out of scope
       
  1942         var r = this.required, m, reqs, done = {},
       
  1943             self = this, name, expound;
       
  1944 
       
  1945         // the setup phase is over, all modules have been created
       
  1946         self.dirty = false;
       
  1947 
       
  1948         self._explodeRollups();
       
  1949         r = self.required;
       
  1950 
       
  1951         for (name in r) {
       
  1952             if (r.hasOwnProperty(name)) {
       
  1953                 if (!done[name]) {
       
  1954                     done[name] = true;
       
  1955                     m = self.getModule(name);
       
  1956                     if (m) {
       
  1957                         expound = m.expound;
       
  1958 
       
  1959                         if (expound) {
       
  1960                             r[expound] = self.getModule(expound);
       
  1961                             reqs = self.getRequires(r[expound]);
       
  1962                             Y.mix(r, yArray.hash(reqs));
       
  1963                         }
       
  1964 
       
  1965                         reqs = self.getRequires(m);
       
  1966                         Y.mix(r, yArray.hash(reqs));
       
  1967                     }
       
  1968                 }
       
  1969             }
       
  1970         }
       
  1971 
       
  1972     },
       
  1973     /**
       
  1974     * The default method used to test a module against a pattern
       
  1975     * @method _patternTest
       
  1976     * @private
       
  1977     * @param {String} mname The module being tested
       
  1978     * @param {String} pname The pattern to match
       
  1979     */
       
  1980     _patternTest: function(mname, pname) {
       
  1981         return (mname.indexOf(pname) > -1);
       
  1982     },
       
  1983     /**
       
  1984     * Get's the loader meta data for the requested module
       
  1985     * @method getModule
       
  1986     * @param {String} mname The module name to get
       
  1987     * @return {Object} The module metadata
       
  1988     */
       
  1989     getModule: function(mname) {
       
  1990         //TODO: Remove name check - it's a quick hack to fix pattern WIP
       
  1991         if (!mname) {
       
  1992             return null;
       
  1993         }
       
  1994 
       
  1995         var p, found, pname,
       
  1996             m = this.moduleInfo[mname],
       
  1997             patterns = this.patterns;
       
  1998 
       
  1999         // check the patterns library to see if we should automatically add
       
  2000         // the module with defaults
       
  2001         if (!m || (m && m.ext)) {
       
  2002             for (pname in patterns) {
       
  2003                 if (patterns.hasOwnProperty(pname)) {
       
  2004                     p = patterns[pname];
       
  2005 
       
  2006                     //There is no test method, create a default one that tests
       
  2007                     // the pattern against the mod name
       
  2008                     if (!p.test) {
       
  2009                         p.test = this._patternTest;
       
  2010                     }
       
  2011 
       
  2012                     if (p.test(mname, pname)) {
       
  2013                         // use the metadata supplied for the pattern
       
  2014                         // as the module definition.
       
  2015                         found = p;
       
  2016                         break;
       
  2017                     }
       
  2018                 }
       
  2019             }
       
  2020         }
       
  2021 
       
  2022         if (!m) {
       
  2023             if (found) {
       
  2024                 if (p.action) {
       
  2025                     p.action.call(this, mname, pname);
       
  2026                 } else {
       
  2027                     // ext true or false?
       
  2028                     m = this.addModule(Y.merge(found), mname);
       
  2029                     if (found.configFn) {
       
  2030                         m.configFn = found.configFn;
       
  2031                     }
       
  2032                     m.temp = true;
       
  2033                 }
       
  2034             }
       
  2035         } else {
       
  2036             if (found && m && found.configFn && !m.configFn) {
       
  2037                 m.configFn = found.configFn;
       
  2038                 m.configFn(m);
       
  2039             }
       
  2040         }
       
  2041 
       
  2042         return m;
       
  2043     },
       
  2044 
       
  2045     // impl in rollup submodule
       
  2046     _rollup: function() { },
       
  2047 
       
  2048     /**
       
  2049      * Remove superceded modules and loaded modules.  Called by
       
  2050      * calculate() after we have the mega list of all dependencies
       
  2051      * @method _reduce
       
  2052      * @return {object} the reduced dependency hash.
       
  2053      * @private
       
  2054      */
       
  2055     _reduce: function(r) {
       
  2056 
       
  2057         r = r || this.required;
       
  2058 
       
  2059         var i, j, s, m, type = this.loadType,
       
  2060         ignore = this.ignore ? yArray.hash(this.ignore) : false;
       
  2061 
       
  2062         for (i in r) {
       
  2063             if (r.hasOwnProperty(i)) {
       
  2064                 m = this.getModule(i);
       
  2065                 // remove if already loaded
       
  2066                 if (((this.loaded[i] || ON_PAGE[i]) &&
       
  2067                         !this.forceMap[i] && !this.ignoreRegistered) ||
       
  2068                         (type && m && m.type !== type)) {
       
  2069                     delete r[i];
       
  2070                 }
       
  2071                 if (ignore && ignore[i]) {
       
  2072                     delete r[i];
       
  2073                 }
       
  2074                 // remove anything this module supersedes
       
  2075                 s = m && m.supersedes;
       
  2076                 if (s) {
       
  2077                     for (j = 0; j < s.length; j++) {
       
  2078                         if (s[j] in r) {
       
  2079                             delete r[s[j]];
       
  2080                         }
       
  2081                     }
       
  2082                 }
       
  2083             }
       
  2084         }
       
  2085 
       
  2086         return r;
       
  2087     },
       
  2088     /**
       
  2089     * Handles the queue when a module has been loaded for all cases
       
  2090     * @method _finish
       
  2091     * @private
       
  2092     * @param {String} msg The message from Loader
       
  2093     * @param {Boolean} success A boolean denoting success or failure
       
  2094     */
       
  2095     _finish: function(msg, success) {
       
  2096 
       
  2097         _queue.running = false;
       
  2098 
       
  2099         var onEnd = this.onEnd;
       
  2100         if (onEnd) {
       
  2101             onEnd.call(this.context, {
       
  2102                 msg: msg,
       
  2103                 data: this.data,
       
  2104                 success: success
       
  2105             });
       
  2106         }
       
  2107         this._continue();
       
  2108     },
       
  2109     /**
       
  2110     * The default Loader onSuccess handler, calls this.onSuccess with a payload
       
  2111     * @method _onSuccess
       
  2112     * @private
       
  2113     */
       
  2114     _onSuccess: function() {
       
  2115         var self = this, skipped = Y.merge(self.skipped), fn,
       
  2116             failed = [], rreg = self.requireRegistration,
       
  2117             success, msg, i, mod;
       
  2118 
       
  2119         for (i in skipped) {
       
  2120             if (skipped.hasOwnProperty(i)) {
       
  2121                 delete self.inserted[i];
       
  2122             }
       
  2123         }
       
  2124 
       
  2125         self.skipped = {};
       
  2126 
       
  2127         for (i in self.inserted) {
       
  2128             if (self.inserted.hasOwnProperty(i)) {
       
  2129                 mod = self.getModule(i);
       
  2130                 if (mod && rreg && mod.type === JS && !(i in YUI.Env.mods)) {
       
  2131                     failed.push(i);
       
  2132                 } else {
       
  2133                     Y.mix(self.loaded, self.getProvides(i));
       
  2134                 }
       
  2135             }
       
  2136         }
       
  2137 
       
  2138         fn = self.onSuccess;
       
  2139         msg = (failed.length) ? 'notregistered' : 'success';
       
  2140         success = !(failed.length);
       
  2141         if (fn) {
       
  2142             fn.call(self.context, {
       
  2143                 msg: msg,
       
  2144                 data: self.data,
       
  2145                 success: success,
       
  2146                 failed: failed,
       
  2147                 skipped: skipped
       
  2148             });
       
  2149         }
       
  2150         self._finish(msg, success);
       
  2151     },
       
  2152     /**
       
  2153     * The default Loader onProgress handler, calls this.onProgress with a payload
       
  2154     * @method _onProgress
       
  2155     * @private
       
  2156     */
       
  2157     _onProgress: function(e) {
       
  2158         var self = this, i;
       
  2159         //set the internal cache to what just came in.
       
  2160         if (e.data && e.data.length) {
       
  2161             for (i = 0; i < e.data.length; i++) {
       
  2162                 e.data[i] = self.getModule(e.data[i].name);
       
  2163             }
       
  2164         }
       
  2165         if (self.onProgress) {
       
  2166             self.onProgress.call(self.context, {
       
  2167                 name: e.url,
       
  2168                 data: e.data
       
  2169             });
       
  2170         }
       
  2171     },
       
  2172     /**
       
  2173     * The default Loader onFailure handler, calls this.onFailure with a payload
       
  2174     * @method _onFailure
       
  2175     * @private
       
  2176     */
       
  2177     _onFailure: function(o) {
       
  2178         var f = this.onFailure, msg = [], i = 0, len = o.errors.length;
       
  2179 
       
  2180         for (i; i < len; i++) {
       
  2181             msg.push(o.errors[i].error);
       
  2182         }
       
  2183 
       
  2184         msg = msg.join(',');
       
  2185 
       
  2186 
       
  2187         if (f) {
       
  2188             f.call(this.context, {
       
  2189                 msg: msg,
       
  2190                 data: this.data,
       
  2191                 success: false
       
  2192             });
       
  2193         }
       
  2194 
       
  2195         this._finish(msg, false);
       
  2196 
       
  2197     },
       
  2198 
       
  2199     /**
       
  2200     * The default Loader onTimeout handler, calls this.onTimeout with a payload
       
  2201     * @method _onTimeout
       
  2202     * @param {Get.Transaction} transaction The Transaction object from `Y.Get`
       
  2203     * @private
       
  2204     */
       
  2205     _onTimeout: function(transaction) {
       
  2206         var f = this.onTimeout;
       
  2207         if (f) {
       
  2208             f.call(this.context, {
       
  2209                 msg: 'timeout',
       
  2210                 data: this.data,
       
  2211                 success: false,
       
  2212                 transaction: transaction
       
  2213             });
       
  2214         }
       
  2215     },
       
  2216 
       
  2217     /**
       
  2218      * Sorts the dependency tree.  The last step of calculate()
       
  2219      * @method _sort
       
  2220      * @private
       
  2221      */
       
  2222     _sort: function() {
       
  2223         var name, 
       
  2224 
       
  2225             // Object containing module names.
       
  2226             required = this.required, 
       
  2227 
       
  2228             // Keep track of whether we've visited a module.
       
  2229             visited = {};
       
  2230 
       
  2231         // Will contain modules names, in the correct order, 
       
  2232         // according to dependencies.
       
  2233         this.sorted = [];
       
  2234 
       
  2235         for (name in required) {
       
  2236             if (!visited[name] && required.hasOwnProperty(name)) {
       
  2237                 this._visit(name, visited);
       
  2238             }
       
  2239         }
       
  2240     },
       
  2241 
       
  2242     /**
       
  2243      * Recursively visits the dependencies of the module name
       
  2244      * passed in, and appends each module name to the `sorted` property.
       
  2245      * @param {String} name The name of a module.
       
  2246      * @param {Object} visited Keeps track of whether a module was visited.
       
  2247      * @method _visit
       
  2248      * @private
       
  2249      */ 
       
  2250     _visit: function (name, visited) {
       
  2251         var required, moduleInfo, dependency, dependencies, i, l;     
       
  2252 
       
  2253         visited[name] = true;
       
  2254         required = this.required;
       
  2255         moduleInfo = this.moduleInfo[name];
       
  2256 
       
  2257         if (moduleInfo) {
       
  2258             // Recurse on each dependency of this module, 
       
  2259             // figuring out its dependencies, and so on.
       
  2260             dependencies = moduleInfo.requires;
       
  2261             for (i = 0, l = dependencies.length; i < l; ++i) {
       
  2262                 dependency = dependencies[i];
       
  2263                 
       
  2264                 // Is this module name in the required list of modules,
       
  2265                 // and have we not already visited it?
       
  2266                 if (required[dependency] && !visited[dependency]) {
       
  2267                     this._visit(dependency, visited);
       
  2268                 }
       
  2269             }
       
  2270         }
       
  2271 
       
  2272         this.sorted.push(name);
       
  2273     },
       
  2274 
       
  2275     /**
       
  2276     * Handles the actual insertion of script/link tags
       
  2277     * @method _insert
       
  2278     * @private
       
  2279     * @param {Object} source The YUI instance the request came from
       
  2280     * @param {Object} o The metadata to include
       
  2281     * @param {String} type JS or CSS
       
  2282     * @param {Boolean} [skipcalc=false] Do a Loader.calculate on the meta
       
  2283     */
       
  2284     _insert: function(source, o, type, skipcalc) {
       
  2285 
       
  2286 
       
  2287         // restore the state at the time of the request
       
  2288         if (source) {
       
  2289             this._config(source);
       
  2290         }
       
  2291 
       
  2292         // build the dependency list
       
  2293         // don't include type so we can process CSS and script in
       
  2294         // one pass when the type is not specified.
       
  2295 
       
  2296         var modules = this.resolve(!skipcalc),
       
  2297             self = this, comp = 0, actions = 0,
       
  2298             mods = {}, deps, complete;
       
  2299 
       
  2300         self._refetch = [];
       
  2301 
       
  2302         if (type) {
       
  2303             //Filter out the opposite type and reset the array so the checks later work
       
  2304             modules[((type === JS) ? CSS : JS)] = [];
       
  2305         }
       
  2306         if (!self.fetchCSS) {
       
  2307             modules.css = [];
       
  2308         }
       
  2309         if (modules.js.length) {
       
  2310             comp++;
       
  2311         }
       
  2312         if (modules.css.length) {
       
  2313             comp++;
       
  2314         }
       
  2315 
       
  2316         //console.log('Resolved Modules: ', modules);
       
  2317 
       
  2318         complete = function(d) {
       
  2319             actions++;
       
  2320             var errs = {}, i = 0, o = 0, u = '', fn,
       
  2321                 modName, resMods;
       
  2322 
       
  2323             if (d && d.errors) {
       
  2324                 for (i = 0; i < d.errors.length; i++) {
       
  2325                     if (d.errors[i].request) {
       
  2326                         u = d.errors[i].request.url;
       
  2327                     } else {
       
  2328                         u = d.errors[i];
       
  2329                     }
       
  2330                     errs[u] = u;
       
  2331                 }
       
  2332             }
       
  2333 
       
  2334             if (d && d.data && d.data.length && (d.type === 'success')) {
       
  2335                 for (i = 0; i < d.data.length; i++) {
       
  2336                     self.inserted[d.data[i].name] = true;
       
  2337                     //If the external module has a skin or a lang, reprocess it
       
  2338                     if (d.data[i].lang || d.data[i].skinnable) {
       
  2339                         delete self.inserted[d.data[i].name];
       
  2340                         self._refetch.push(d.data[i].name);
       
  2341                     }
       
  2342                 }
       
  2343             }
       
  2344 
       
  2345             if (actions === comp) {
       
  2346                 self._loading = null;
       
  2347                 if (self._refetch.length) {
       
  2348                     //Get the deps for the new meta-data and reprocess
       
  2349                     for (i = 0; i < self._refetch.length; i++) {
       
  2350                         deps = self.getRequires(self.getModule(self._refetch[i]));
       
  2351                         for (o = 0; o < deps.length; o++) {
       
  2352                             if (!self.inserted[deps[o]]) {
       
  2353                                 //We wouldn't be to this point without the module being here
       
  2354                                 mods[deps[o]] = deps[o];
       
  2355                             }
       
  2356                         }
       
  2357                     }
       
  2358                     mods = Y.Object.keys(mods);
       
  2359                     if (mods.length) {
       
  2360                         self.require(mods);
       
  2361                         resMods = self.resolve(true);
       
  2362                         if (resMods.cssMods.length) {
       
  2363                             for (i=0; i <  resMods.cssMods.length; i++) {
       
  2364                                 modName = resMods.cssMods[i].name;
       
  2365                                 delete YUI.Env._cssLoaded[modName];
       
  2366                                 if (self.isCSSLoaded(modName)) {
       
  2367                                     self.inserted[modName] = true;
       
  2368                                     delete self.required[modName];
       
  2369                                 }
       
  2370                             }
       
  2371                             self.sorted = [];
       
  2372                             self._sort();
       
  2373                         }
       
  2374                         d = null; //bail
       
  2375                         self._insert(); //insert the new deps
       
  2376                     }
       
  2377                 }
       
  2378                 if (d && d.fn) {
       
  2379                     fn = d.fn;
       
  2380                     delete d.fn;
       
  2381                     fn.call(self, d);
       
  2382                 }
       
  2383             }
       
  2384         };
       
  2385 
       
  2386         this._loading = true;
       
  2387 
       
  2388         if (!modules.js.length && !modules.css.length) {
       
  2389             actions = -1;
       
  2390             complete({
       
  2391                 fn: self._onSuccess
       
  2392             });
       
  2393             return;
       
  2394         }
       
  2395 
       
  2396 
       
  2397         if (modules.css.length) { //Load CSS first
       
  2398             Y.Get.css(modules.css, {
       
  2399                 data: modules.cssMods,
       
  2400                 attributes: self.cssAttributes,
       
  2401                 insertBefore: self.insertBefore,
       
  2402                 charset: self.charset,
       
  2403                 timeout: self.timeout,
       
  2404                 context: self,
       
  2405                 onProgress: function(e) {
       
  2406                     self._onProgress.call(self, e);
       
  2407                 },
       
  2408                 onTimeout: function(d) {
       
  2409                     self._onTimeout.call(self, d);
       
  2410                 },
       
  2411                 onSuccess: function(d) {
       
  2412                     d.type = 'success';
       
  2413                     d.fn = self._onSuccess;
       
  2414                     complete.call(self, d);
       
  2415                 },
       
  2416                 onFailure: function(d) {
       
  2417                     d.type = 'failure';
       
  2418                     d.fn = self._onFailure;
       
  2419                     complete.call(self, d);
       
  2420                 }
       
  2421             });
       
  2422         }
       
  2423 
       
  2424         if (modules.js.length) {
       
  2425             Y.Get.js(modules.js, {
       
  2426                 data: modules.jsMods,
       
  2427                 insertBefore: self.insertBefore,
       
  2428                 attributes: self.jsAttributes,
       
  2429                 charset: self.charset,
       
  2430                 timeout: self.timeout,
       
  2431                 autopurge: false,
       
  2432                 context: self,
       
  2433                 async: self.async,
       
  2434                 onProgress: function(e) {
       
  2435                     self._onProgress.call(self, e);
       
  2436                 },
       
  2437                 onTimeout: function(d) {
       
  2438                     self._onTimeout.call(self, d);
       
  2439                 },
       
  2440                 onSuccess: function(d) {
       
  2441                     d.type = 'success';
       
  2442                     d.fn = self._onSuccess;
       
  2443                     complete.call(self, d);
       
  2444                 },
       
  2445                 onFailure: function(d) {
       
  2446                     d.type = 'failure';
       
  2447                     d.fn = self._onFailure;
       
  2448                     complete.call(self, d);
       
  2449                 }
       
  2450             });
       
  2451         }
       
  2452     },
       
  2453     /**
       
  2454     * Once a loader operation is completely finished, process any additional queued items.
       
  2455     * @method _continue
       
  2456     * @private
       
  2457     */
       
  2458     _continue: function() {
       
  2459         if (!(_queue.running) && _queue.size() > 0) {
       
  2460             _queue.running = true;
       
  2461             _queue.next()();
       
  2462         }
       
  2463     },
       
  2464 
       
  2465     /**
       
  2466      * inserts the requested modules and their dependencies.
       
  2467      * <code>type</code> can be "js" or "css".  Both script and
       
  2468      * css are inserted if type is not provided.
       
  2469      * @method insert
       
  2470      * @param {object} o optional options object.
       
  2471      * @param {string} type the type of dependency to insert.
       
  2472      */
       
  2473     insert: function(o, type, skipsort) {
       
  2474         var self = this, copy = Y.merge(this);
       
  2475         delete copy.require;
       
  2476         delete copy.dirty;
       
  2477         _queue.add(function() {
       
  2478             self._insert(copy, o, type, skipsort);
       
  2479         });
       
  2480         this._continue();
       
  2481     },
       
  2482 
       
  2483     /**
       
  2484      * Executed every time a module is loaded, and if we are in a load
       
  2485      * cycle, we attempt to load the next script.  Public so that it
       
  2486      * is possible to call this if using a method other than
       
  2487      * Y.register to determine when scripts are fully loaded
       
  2488      * @method loadNext
       
  2489      * @deprecated
       
  2490      * @param {string} mname optional the name of the module that has
       
  2491      * been loaded (which is usually why it is time to load the next
       
  2492      * one).
       
  2493      */
       
  2494     loadNext: function() {
       
  2495         return;
       
  2496     },
       
  2497 
       
  2498     /**
       
  2499      * Apply filter defined for this instance to a url/path
       
  2500      * @method _filter
       
  2501      * @param {string} u the string to filter.
       
  2502      * @param {string} name the name of the module, if we are processing
       
  2503      * a single module as opposed to a combined url.
       
  2504      * @return {string} the filtered string.
       
  2505      * @private
       
  2506      */
       
  2507     _filter: function(u, name, group) {
       
  2508         var f = this.filter,
       
  2509             hasFilter = name && (name in this.filters),
       
  2510             modFilter = hasFilter && this.filters[name],
       
  2511             groupName = group || (this.moduleInfo[name] ? this.moduleInfo[name].group : null);
       
  2512 
       
  2513         if (groupName && this.groups[groupName] && this.groups[groupName].filter) {
       
  2514             modFilter = this.groups[groupName].filter;
       
  2515             hasFilter = true;
       
  2516         }
       
  2517 
       
  2518         if (u) {
       
  2519             if (hasFilter) {
       
  2520                 f = (L.isString(modFilter)) ? this.FILTER_DEFS[modFilter.toUpperCase()] || null : modFilter;
       
  2521             }
       
  2522             if (f) {
       
  2523                 u = u.replace(new RegExp(f.searchExp, 'g'), f.replaceStr);
       
  2524             }
       
  2525         }
       
  2526         return u;
       
  2527     },
       
  2528 
       
  2529     /**
       
  2530      * Generates the full url for a module
       
  2531      * @method _url
       
  2532      * @param {string} path the path fragment.
       
  2533      * @param {String} name The name of the module
       
  2534      * @param {String} [base] The base url to use. Defaults to self.base
       
  2535      * @return {string} the full url.
       
  2536      * @private
       
  2537      */
       
  2538     _url: function(path, name, base) {
       
  2539         return this._filter((base || this.base || '') + path, name);
       
  2540     },
       
  2541     /**
       
  2542     * Returns an Object hash of file arrays built from `loader.sorted` or from an arbitrary list of sorted modules.
       
  2543     * @method resolve
       
  2544     * @param {Boolean} [calc=false] Perform a loader.calculate() before anything else
       
  2545     * @param {Array} [s] An override for the loader.sorted array. Defaults to
       
  2546     * `loader.sorted`.
       
  2547     * @return {Object} Object hash (js and css) of two arrays of file lists
       
  2548     * @example This method can be used as an off-line dep calculator
       
  2549     *
       
  2550     *        var Y = YUI();
       
  2551     *        var loader = new Y.Loader({
       
  2552     *            filter: 'debug',
       
  2553     *            base: '../../',
       
  2554     *            root: 'build/',
       
  2555     *            combine: true,
       
  2556     *            require: ['node', 'dd', 'console']
       
  2557     *        });
       
  2558     *        var out = loader.resolve(true);
       
  2559     *
       
  2560     */
       
  2561     resolve: function(calc, s) {
       
  2562 
       
  2563         var len, i, m, url, group, groupName, j, frag,
       
  2564             comboSource, comboSources, mods, comboBase,
       
  2565             base, urls, u = [], tmpBase, baseLen, resCombos = {},
       
  2566             self = this, comboSep, maxURLLength,
       
  2567             inserted = (self.ignoreRegistered) ? {} : self.inserted,
       
  2568             resolved = { js: [], jsMods: [], css: [], cssMods: [] },
       
  2569             type = self.loadType || 'js', addSingle;
       
  2570 
       
  2571         if (self.skin.overrides || self.skin.defaultSkin !== DEFAULT_SKIN || self.ignoreRegistered) {
       
  2572             self._resetModules();
       
  2573         }
       
  2574 
       
  2575         if (calc) {
       
  2576             self.calculate();
       
  2577         }
       
  2578         s = s || self.sorted;
       
  2579 
       
  2580         addSingle = function(m) {
       
  2581 
       
  2582             if (m) {
       
  2583                 group = (m.group && self.groups[m.group]) || NOT_FOUND;
       
  2584 
       
  2585                 //Always assume it's async
       
  2586                 if (group.async === false) {
       
  2587                     m.async = group.async;
       
  2588                 }
       
  2589 
       
  2590                 url = (m.fullpath) ? self._filter(m.fullpath, s[i]) :
       
  2591                       self._url(m.path, s[i], group.base || m.base);
       
  2592 
       
  2593                 if (m.attributes || m.async === false) {
       
  2594                     url = {
       
  2595                         url: url,
       
  2596                         async: m.async
       
  2597                     };
       
  2598                     if (m.attributes) {
       
  2599                         url.attributes = m.attributes;
       
  2600                     }
       
  2601                 }
       
  2602                 resolved[m.type].push(url);
       
  2603                 resolved[m.type + 'Mods'].push(m);
       
  2604             } else {
       
  2605             }
       
  2606 
       
  2607         };
       
  2608 
       
  2609         len = s.length;
       
  2610 
       
  2611         // the default combo base
       
  2612         comboBase = self.comboBase;
       
  2613 
       
  2614         url = comboBase;
       
  2615 
       
  2616         comboSources = {};
       
  2617 
       
  2618         for (i = 0; i < len; i++) {
       
  2619             comboSource = comboBase;
       
  2620             m = self.getModule(s[i]);
       
  2621             groupName = m && m.group;
       
  2622             group = self.groups[groupName];
       
  2623             if (groupName && group) {
       
  2624 
       
  2625                 if (!group.combine || m.fullpath) {
       
  2626                     //This is not a combo module, skip it and load it singly later.
       
  2627                     addSingle(m);
       
  2628                     continue;
       
  2629                 }
       
  2630                 m.combine = true;
       
  2631                 if (group.comboBase) {
       
  2632                     comboSource = group.comboBase;
       
  2633                 }
       
  2634 
       
  2635                 if ("root" in group && L.isValue(group.root)) {
       
  2636                     m.root = group.root;
       
  2637                 }
       
  2638                 m.comboSep = group.comboSep || self.comboSep;
       
  2639                 m.maxURLLength = group.maxURLLength || self.maxURLLength;
       
  2640             } else {
       
  2641                 if (!self.combine) {
       
  2642                     //This is not a combo module, skip it and load it singly later.
       
  2643                     addSingle(m);
       
  2644                     continue;
       
  2645                 }
       
  2646             }
       
  2647 
       
  2648             comboSources[comboSource] = comboSources[comboSource] || [];
       
  2649             comboSources[comboSource].push(m);
       
  2650         }
       
  2651 
       
  2652         for (j in comboSources) {
       
  2653             if (comboSources.hasOwnProperty(j)) {
       
  2654                 resCombos[j] = resCombos[j] || { js: [], jsMods: [], css: [], cssMods: [] };
       
  2655                 url = j;
       
  2656                 mods = comboSources[j];
       
  2657                 len = mods.length;
       
  2658 
       
  2659                 if (len) {
       
  2660                     for (i = 0; i < len; i++) {
       
  2661                         if (inserted[mods[i]]) {
       
  2662                             continue;
       
  2663                         }
       
  2664                         m = mods[i];
       
  2665                         // Do not try to combine non-yui JS unless combo def
       
  2666                         // is found
       
  2667                         if (m && (m.combine || !m.ext)) {
       
  2668                             resCombos[j].comboSep = m.comboSep;
       
  2669                             resCombos[j].group = m.group;
       
  2670                             resCombos[j].maxURLLength = m.maxURLLength;
       
  2671                             frag = ((L.isValue(m.root)) ? m.root : self.root) + (m.path || m.fullpath);
       
  2672                             frag = self._filter(frag, m.name);
       
  2673                             resCombos[j][m.type].push(frag);
       
  2674                             resCombos[j][m.type + 'Mods'].push(m);
       
  2675                         } else {
       
  2676                             //Add them to the next process..
       
  2677                             if (mods[i]) {
       
  2678                                 addSingle(mods[i]);
       
  2679                             }
       
  2680                         }
       
  2681 
       
  2682                     }
       
  2683                 }
       
  2684             }
       
  2685         }
       
  2686 
       
  2687 
       
  2688         for (j in resCombos) {
       
  2689             if (resCombos.hasOwnProperty(j)) {
       
  2690                 base = j;
       
  2691                 comboSep = resCombos[base].comboSep || self.comboSep;
       
  2692                 maxURLLength = resCombos[base].maxURLLength || self.maxURLLength;
       
  2693                 for (type in resCombos[base]) {
       
  2694                     if (type === JS || type === CSS) {
       
  2695                         urls = resCombos[base][type];
       
  2696                         mods = resCombos[base][type + 'Mods'];
       
  2697                         len = urls.length;
       
  2698                         tmpBase = base + urls.join(comboSep);
       
  2699                         baseLen = tmpBase.length;
       
  2700                         if (maxURLLength <= base.length) {
       
  2701                             maxURLLength = MAX_URL_LENGTH;
       
  2702                         }
       
  2703 
       
  2704                         if (len) {
       
  2705                             if (baseLen > maxURLLength) {
       
  2706                                 u = [];
       
  2707                                 for (s = 0; s < len; s++) {
       
  2708                                     u.push(urls[s]);
       
  2709                                     tmpBase = base + u.join(comboSep);
       
  2710 
       
  2711                                     if (tmpBase.length > maxURLLength) {
       
  2712                                         m = u.pop();
       
  2713                                         tmpBase = base + u.join(comboSep);
       
  2714                                         resolved[type].push(self._filter(tmpBase, null, resCombos[base].group));
       
  2715                                         u = [];
       
  2716                                         if (m) {
       
  2717                                             u.push(m);
       
  2718                                         }
       
  2719                                     }
       
  2720                                 }
       
  2721                                 if (u.length) {
       
  2722                                     tmpBase = base + u.join(comboSep);
       
  2723                                     resolved[type].push(self._filter(tmpBase, null, resCombos[base].group));
       
  2724                                 }
       
  2725                             } else {
       
  2726                                 resolved[type].push(self._filter(tmpBase, null, resCombos[base].group));
       
  2727                             }
       
  2728                         }
       
  2729                         resolved[type + 'Mods'] = resolved[type + 'Mods'].concat(mods);
       
  2730                     }
       
  2731                 }
       
  2732             }
       
  2733         }
       
  2734 
       
  2735         resCombos = null;
       
  2736 
       
  2737         return resolved;
       
  2738     },
       
  2739     /**
       
  2740     Shortcut to calculate, resolve and load all modules.
       
  2741 
       
  2742         var loader = new Y.Loader({
       
  2743             ignoreRegistered: true,
       
  2744             modules: {
       
  2745                 mod: {
       
  2746                     path: 'mod.js'
       
  2747                 }
       
  2748             },
       
  2749             requires: [ 'mod' ]
       
  2750         });
       
  2751         loader.load(function() {
       
  2752             console.log('All modules have loaded..');
       
  2753         });
       
  2754 
       
  2755 
       
  2756     @method load
       
  2757     @param {Function} cb Executed after all load operations are complete
       
  2758     */
       
  2759     load: function(cb) {
       
  2760         if (!cb) {
       
  2761             return;
       
  2762         }
       
  2763         var self = this,
       
  2764             out = self.resolve(true);
       
  2765 
       
  2766         self.data = out;
       
  2767 
       
  2768         self.onEnd = function() {
       
  2769             cb.apply(self.context || self, arguments);
       
  2770         };
       
  2771 
       
  2772         self.insert();
       
  2773     }
       
  2774 };
       
  2775 
       
  2776 
       
  2777 
       
  2778 }, '@VERSION@', {"requires": ["get", "features"]});