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