3
Copyright 2012 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('loader-base', function(Y) {
12
* @submodule loader-base
15
if (!YUI.Env[Y.version]) {
18
var VERSION = Y.version,
20
ROOT = VERSION + BUILD,
21
CDN_BASE = Y.Env.base,
22
GALLERY_VERSION = 'gallery-2012.04.10-14-57',
25
YUI2_VERSION = '2.9.0',
26
COMBO_BASE = CDN_BASE + 'combo?',
27
META = { version: VERSION,
30
comboBase: COMBO_BASE,
31
skin: { defaultSkin: 'sam',
32
base: 'assets/skins/',
43
yui2Update = function(tnt, yui2, config) {
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;
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;
71
comboBase: COMBO_BASE,
72
update: galleryUpdate,
73
patterns: { 'gallery-': { },
75
'gallerycss-': { type: 'css' } }
81
comboBase: COMBO_BASE,
85
configFn: function(me) {
86
if (/-skin|reset|fonts|grids|base/.test(me.name)) {
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');
102
YUI.Env[VERSION] = META;
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
117
* @submodule loader-base
121
NO_REQUIREMENTS = [],
122
MAX_URL_LENGTH = 1024,
123
GLOBAL_ENV = YUI.Env,
124
GLOBAL_LOADED = GLOBAL_ENV._loaded,
131
oeach = YObject.each,
133
_queue = GLOBAL_ENV._loaderQueue,
134
META = GLOBAL_ENV[VERSION],
135
SKIN_PREFIX = 'skin-',
137
ON_PAGE = GLOBAL_ENV.mods,
140
_path = function(dir, file, type, nomin) {
141
var path = dir + '/' + file;
145
path += '.' + (type || CSS);
151
* The component metadata is stored in Y.Env.meta.
152
* Part of the loader module.
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.
168
var loader = new Y.Loader({
173
require: ['node', 'dd', 'console']
175
var out = loader.resolve(true);
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.
203
Y.Loader = function(o) {
205
var defaults = META.modules,
208
//Catch no config passed.
211
modulekey = META.md5;
214
* Internal callback to handle multiple internal insert() calls
215
* so that css is inserted prior to js
216
* @property _internalCallback
219
// self._internalCallback = null;
222
* Callback that will be executed when the loader is finished
227
// self.onSuccess = null;
230
* Callback that will be executed if there is a failure
234
// self.onFailure = null;
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.
244
// self.onCSS = null;
247
* Callback executed each time a script or css file is loaded
251
// self.onProgress = null;
254
* Callback that will be executed if a timeout occurs
258
// self.onTimeout = null;
261
* The execution context for all callbacks
263
* @default {YUI} the YUI instance
268
* Data that is passed to all callbacks
274
* Node reference or id where new nodes should be inserted before
275
* @property insertBefore
276
* @type string|HTMLElement
278
// self.insertBefore = null;
281
* The charset attribute for inserted nodes
284
* @deprecated , use cssAttributes or jsAttributes.
286
// self.charset = null;
289
* An object literal containing attributes to add to link nodes
290
* @property cssAttributes
293
// self.cssAttributes = null;
296
* An object literal containing attributes to add to script nodes
297
* @property jsAttributes
300
// self.jsAttributes = null;
303
* The base directory.
306
* @default http://yui.yahooapis.com/[YUI VERSION]/build/
308
self.base = Y.Env.meta.base + Y.Env.meta.root;
311
* Base path for the combo service
312
* @property comboBase
314
* @default http://yui.yahooapis.com/combo?
316
self.comboBase = Y.Env.meta.comboBase;
319
* Base path for language packs.
321
// self.langBase = Y.Env.meta.langBase;
325
* If configured, the loader will attempt to use the combo
326
* service for YUI resources and configured external resources.
329
* @default true if a base dir isn't in the config
331
self.combine = o.base &&
332
(o.base.indexOf(self.comboBase.substr(0, 20)) > -1);
335
* The default seperator to use between files in a combo URL
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.
349
* @property maxURLLength
352
self.maxURLLength = MAX_URL_LENGTH;
355
* Ignore modules registered on the YUI global
356
* @property ignoreRegistered
359
//self.ignoreRegistered = false;
362
* Root path to prepend to module path for the combo
366
* @default [YUI VERSION]/build/
368
self.root = Y.Env.meta.root;
371
* Timeout value in milliseconds. If set, self value will be used by
372
* the get utility. the timeout event will fire if
380
* A list of modules that should not be loaded, even if
381
* they turn up in the dependency tree
385
// self.ignore = null;
388
* A list of modules that should always be loaded, even
389
* if they have already been inserted into the page.
393
// self.force = null;
398
* Should we allow rollups
399
* @property allowRollup
403
self.allowRollup = false;
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
413
* <dd>Selects the debug versions of the library (e.g., event-debug.js).
414
* This option will automatically include the Logger widget</dd>
416
* <dd>Selects the non-minified version of the library (e.g., event.js).
419
* You can also define a custom filter, which must be an object literal
420
* containing a search expression and a replace string:
423
* 'searchExp': "-min\\.js",
424
* 'replaceStr': "-debug.js"
428
* @type string| {searchExp: string, replaceStr: string}
430
// self.filter = null;
433
* per-component filter specification. If specified for a given
434
* component, this overrides the filter config.
441
* The list of requested modules
443
* @type {string: boolean}
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.
452
* At the moment only supporting module prefixes, but anticipate
453
* supporting at least regular expressions.
457
// self.patterns = Y.merge(Y.Env.meta.patterns);
461
* The library metadata
462
* @property moduleInfo
464
// self.moduleInfo = Y.merge(Y.Env.meta.moduleInfo);
465
self.moduleInfo = {};
467
self.groups = Y.merge(Y.Env.meta.groups);
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:
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',
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/',
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.
491
* calendar: ['skin1', 'skin2']
497
self.skin = Y.merge(Y.Env.meta.skin);
500
* Map of conditional modules
503
self.conditions = {};
505
// map of modules with a hash of modules that meet the requirement
506
// self.provides = {};
509
self._internal = true;
512
cache = GLOBAL_ENV._renderedMods;
515
oeach(cache, function modCache(v, k) {
516
self.moduleInfo[k] = Y.merge(v);
519
cache = GLOBAL_ENV._conditions;
521
oeach(cache, function condCache(v, k) {
522
self.conditions[k] = Y.merge(v);
526
oeach(defaults, self.addModule, self);
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.
536
* @type {string: boolean}
538
self.loaded = GLOBAL_LOADED[VERSION];
543
self._internal = false;
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;
556
* List of rollup files found in the library metadata
559
// self.rollups = null;
562
* Whether or not to load optional dependencies for
563
* the requested modules
564
* @property loadOptional
568
// self.loadOptional = false;
571
* All of the derived dependencies in sorted order, which
572
* will be populated when either calculate() or insert()
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
584
// self.attaching = null;
587
* Flag to indicate the dependency tree needs to be recomputed
588
* if insert is called again.
596
* List of modules inserted by the utility
598
* @type {string: boolean}
603
* List of skipped modules during insert() because the module
609
// Y.on('yui:load', self.loadNext, self);
614
* Cached sorted calculate results
622
Y.Loader.prototype = {
624
Regex that matches a CSS URL. Used to guess the file type when it's not
633
REGEX_CSS: /\.css(?:[?;].*)?$/i,
636
* Default filters for raw and debug
637
* @property FILTER_DEFS
644
'searchExp': '-min\\.js',
648
'searchExp': '-min\\.js',
649
'replaceStr': '-debug.js'
653
* Check the pages meta-data and cache the result.
654
* @method _inspectPage
657
_inspectPage: function() {
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
Y.log('Found CSS module on page: ' + v.name, 'info', 'loader');
664
this.loaded[k] = true;
669
oeach(ON_PAGE, function(v, k) {
671
var m = this.moduleInfo[k],
672
req = v.details.requires,
673
mr = m && m.requires;
675
if (!m._inspected && req && mr.length != req.length) {
676
// console.log('deleting ' + m.name);
680
m = this.addModule(v.details, k);
687
* returns true if b is not loaded, and is required directly or by means of modules it supersedes.
690
* @param {String} mod1 The first module to compare
691
* @param {String} mod2 The second module to compare
693
_requires: function(mod1, mod2) {
695
var i, rm, after_map, s,
696
info = this.moduleInfo,
705
after_map = m.after_map;
707
// check if this module should be sorted after the other
708
// do this first to short circut circular deps
709
if (after_map && (mod2 in after_map)) {
713
after_map = other.after_map;
716
if (after_map && (mod1 in after_map)) {
720
// check if this module requires one the other supersedes
721
s = info[mod2] && info[mod2].supersedes;
723
for (i = 0; i < s.length; i++) {
724
if (this._requires(mod1, s[i])) {
730
s = info[mod1] && info[mod1].supersedes;
732
for (i = 0; i < s.length; i++) {
733
if (this._requires(mod2, s[i])) {
739
// check if this module requires the other directly
740
// if (r && YArray.indexOf(r, mod2) > -1) {
741
if (rm && (mod2 in rm)) {
745
// external css files should be sorted below yui css
746
if (m.ext && m.type == CSS && !other.ext && other.type == CSS) {
753
* Apply a new config to the Loader instance
756
* @param {Object} o The new configuration
758
_config: function(o) {
759
var i, j, val, f, group, groupName, self = this;
760
// apply config values
763
if (o.hasOwnProperty(i)) {
765
if (i == 'require') {
767
} else if (i == 'skin') {
768
//If the config.skin is a string, format to the expected object
769
if (typeof val === 'string') {
770
self.skin.defaultSkin = o.skin;
776
Y.mix(self.skin, val, true);
777
} else if (i == 'groups') {
779
if (val.hasOwnProperty(j)) {
780
// Y.log('group: ' + j);
783
self.addGroup(group, groupName);
785
oeach(group.aliases, self.addAlias, self);
790
} else if (i == 'modules') {
791
// add a hash of module definitions
792
oeach(val, self.addModule, self);
793
} else if (i === 'aliases') {
794
oeach(val, self.addAlias, self);
795
} else if (i == 'gallery') {
796
this.groups.gallery.update(val, o);
797
} else if (i == 'yui2' || i == '2in3') {
798
this.groups.yui2.update(o['2in3'], o.yui2, o);
812
self.filter = self.FILTER_DEFS[f];
814
self.require('yui-log', 'dump');
820
//Removed this so that when Loader is invoked
821
//it doesn't request what it doesn't need.
822
//self.require('intl-base', 'intl');
828
* Returns the skin module name for the specified skin name. If a
829
* module name is supplied, the returned skin module name is
830
* specific to the module passed in.
832
* @param {string} skin the name of the skin.
833
* @param {string} mod optional: the name of a module to skin.
834
* @return {string} the full skin module name.
836
formatSkin: function(skin, mod) {
837
var s = SKIN_PREFIX + skin;
846
* Adds the skin def to the module info
848
* @param {string} skin the name of the skin.
849
* @param {string} mod the name of the module.
850
* @param {string} parent parent module if this is a skin of a
851
* submodule or plugin.
852
* @return {string} the module name for the skin.
855
_addSkin: function(skin, mod, parent) {
856
var mdef, pkg, name, nmod,
857
info = this.moduleInfo,
859
ext = info[mod] && info[mod].ext;
861
// Add a module definition for the module-specific skin css
863
name = this.formatSkin(skin, mod);
866
pkg = mdef.pkg || mod;
872
path: (parent || pkg) + '/' + sinf.base + skin +
877
nmod.base = mdef.base;
880
nmod.configFn = mdef.configFn;
882
this.addModule(nmod, name);
884
Y.log('Adding skin (' + name + '), ' + parent + ', ' + pkg + ', ' + info[name].path, 'info', 'loader');
891
* Adds an alias module to the system
893
* @param {Array} use An array of modules that makes up this alias
894
* @param {String} name The name of the alias
896
* var loader = new Y.Loader({});
897
* loader.addAlias([ 'node', 'yql' ], 'davglass');
898
* loader.require(['davglass']);
899
* var out = loader.resolve(true);
901
* //out.js will contain Node and YQL modules
903
addAlias: function(use, name) {
904
YUI.Env.aliases[name] = use;
911
* Add a new module group
913
* @param {Object} config An object containing the group configuration data
914
* @param {String} config.name required, the group name
915
* @param {String} config.base The base directory for this module group
916
* @param {String} config.root The root path to add to each combo resource path
917
* @param {Boolean} config.combine Should the request be combined
918
* @param {String} config.comboBase Combo service base path
919
* @param {Object} config.modules The group of modules
920
* @param {String} name the group name.
922
* var loader = new Y.Loader({});
926
* comboBase: '/combo?',
933
addGroup: function(o, name) {
934
var mods = o.modules,
936
name = name || o.name;
938
self.groups[name] = o;
941
oeach(o.patterns, function(v, k) {
943
self.patterns[k] = v;
948
oeach(mods, function(v, k) {
949
if (typeof v === 'string') {
950
v = { name: k, fullpath: v };
953
self.addModule(v, k);
959
* Add a new module to the component metadata.
961
* @param {Object} config An object containing the module data.
962
* @param {String} config.name Required, the component name
963
* @param {String} config.type Required, the component type (js or css)
964
* @param {String} config.path Required, the path to the script from `base`
965
* @param {Array} config.requires Array of modules required by this component
966
* @param {Array} [config.optional] Array of optional modules for this component
967
* @param {Array} [config.supersedes] Array of the modules this component replaces
968
* @param {Array} [config.after] Array of modules the components which, if present, should be sorted above this one
969
* @param {Object} [config.after_map] Faster alternative to 'after' -- supply a hash instead of an array
970
* @param {Number} [config.rollup] The number of superseded modules required for automatic rollup
971
* @param {String} [config.fullpath] If `fullpath` is specified, this is used instead of the configured `base + path`
972
* @param {Boolean} [config.skinnable] Flag to determine if skin assets should automatically be pulled in
973
* @param {Object} [config.submodules] Hash of submodules
974
* @param {String} [config.group] The group the module belongs to -- this is set automatically when it is added as part of a group configuration.
975
* @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"]`
976
* @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:
977
* @param {String} [config.condition.trigger] The name of a module that can trigger the auto-load
978
* @param {Function} [config.condition.test] A function that returns true when the module is to be loaded.
979
* @param {String} [config.condition.when] Specifies the load order of the conditional module
980
* with regard to the position of the trigger module.
981
* This should be one of three values: `before`, `after`, or `instead`. The default is `after`.
982
* @param {Object} [config.testresults] A hash of test results from `Y.Features.all()`
983
* @param {Function} [config.configFn] A function to exectute when configuring this module
984
* @param {Object} config.configFn.mod The module config, modifying this object will modify it's config. Returning false will delete the module's config.
985
* @param {String} [name] The module name, required if not in the module data.
986
* @return {Object} the module definition or null if the object passed in did not provide all required attributes.
988
addModule: function(o, name) {
989
name = name || o.name;
991
if (typeof o === 'string') {
992
o = { name: name, fullpath: o };
995
//Only merge this data if the temp flag is set
996
//from an earlier pass from a pattern or else
997
//an override module (YUI_config) can not be used to
998
//replace a default module.
999
if (this.moduleInfo[name] && this.moduleInfo[name].temp) {
1000
//This catches temp modules loaded via a pattern
1001
// The module will be added twice, once from the pattern and
1002
// Once from the actual add call, this ensures that properties
1003
// that were added to the module the first time around (group: gallery)
1004
// are also added the second time around too.
1005
o = Y.merge(this.moduleInfo[name], o);
1010
if (!o || !o.name) {
1015
//Always assume it's javascript unless the CSS pattern is matched.
1017
var p = o.path || o.fullpath;
1018
if (p && this.REGEX_CSS.test(p)) {
1019
Y.log('Auto determined module type as CSS', 'warn', 'loader');
1024
if (!o.path && !o.fullpath) {
1025
o.path = _path(name, name, o.type);
1027
o.supersedes = o.supersedes || o.use;
1029
o.ext = ('ext' in o) ? o.ext : (this._internal) ? false : true;
1031
// Handle submodule logic
1032
var subs = o.submodules, i, l, t, sup, s, smod, plugins, plug,
1033
j, langs, packName, supName, flatSup, flatLang, lang, ret,
1034
overrides, skinname, when,
1035
conditions = this.conditions, trigger;
1036
// , existing = this.moduleInfo[name], newr;
1038
this.moduleInfo[name] = o;
1040
o.requires = o.requires || [];
1043
skinname = this._addSkin(this.skin.defaultSkin, name);
1044
o.requires.unshift(skinname);
1047
o.requires = this.filterRequires(o.requires) || [];
1049
if (!o.langPack && o.lang) {
1050
langs = YArray(o.lang);
1051
for (j = 0; j < langs.length; j++) {
1053
packName = this.getLangPackName(lang, name);
1054
smod = this.moduleInfo[packName];
1056
smod = this._addLangPack(lang, o, packName);
1063
sup = o.supersedes || [];
1067
if (subs.hasOwnProperty(i)) {
1070
s.path = s.path || _path(name, i, o.type);
1075
sup = sup.concat(s.supersedes);
1078
smod = this.addModule(s, i);
1081
if (smod.skinnable) {
1083
overrides = this.skin.overrides;
1084
if (overrides && overrides[i]) {
1085
for (j = 0; j < overrides[i].length; j++) {
1086
skinname = this._addSkin(overrides[i][j],
1091
skinname = this._addSkin(this.skin.defaultSkin,
1096
// looks like we are expected to work out the metadata
1097
// for the parent module language packs from what is
1098
// specified in the child modules.
1099
if (s.lang && s.lang.length) {
1101
langs = YArray(s.lang);
1102
for (j = 0; j < langs.length; j++) {
1104
packName = this.getLangPackName(lang, name);
1105
supName = this.getLangPackName(lang, i);
1106
smod = this.moduleInfo[packName];
1109
smod = this._addLangPack(lang, o, packName);
1112
flatSup = flatSup || YArray.hash(smod.supersedes);
1114
if (!(supName in flatSup)) {
1115
smod.supersedes.push(supName);
1118
o.lang = o.lang || [];
1120
flatLang = flatLang || YArray.hash(o.lang);
1122
if (!(lang in flatLang)) {
1126
// Y.log('pack ' + packName + ' should supersede ' + supName);
1127
// Add rollup file, need to add to supersedes list too
1130
packName = this.getLangPackName(ROOT_LANG, name);
1131
supName = this.getLangPackName(ROOT_LANG, i);
1133
smod = this.moduleInfo[packName];
1136
smod = this._addLangPack(lang, o, packName);
1139
if (!(supName in flatSup)) {
1140
smod.supersedes.push(supName);
1143
// Y.log('pack ' + packName + ' should supersede ' + supName);
1144
// Add rollup file, need to add to supersedes list too
1152
//o.supersedes = YObject.keys(YArray.hash(sup));
1153
o.supersedes = YArray.dedupe(sup);
1154
if (this.allowRollup) {
1155
o.rollup = (l < 4) ? l : Math.min(l - 1, 4);
1159
plugins = o.plugins;
1161
for (i in plugins) {
1162
if (plugins.hasOwnProperty(i)) {
1165
plug.path = plug.path || _path(name, i, o.type);
1166
plug.requires = plug.requires || [];
1167
plug.group = o.group;
1168
this.addModule(plug, i);
1170
this._addSkin(this.skin.defaultSkin, i, name);
1178
t = o.condition.trigger;
1179
if (YUI.Env.aliases[t]) {
1180
t = YUI.Env.aliases[t];
1182
if (!Y.Lang.isArray(t)) {
1186
for (i = 0; i < t.length; i++) {
1188
when = o.condition.when;
1189
conditions[trigger] = conditions[trigger] || {};
1190
conditions[trigger][name] = o.condition;
1191
// the 'when' attribute can be 'before', 'after', or 'instead'
1192
// the default is after.
1193
if (when && when != 'after') {
1194
if (when == 'instead') { // replace the trigger
1195
o.supersedes = o.supersedes || [];
1196
o.supersedes.push(trigger);
1197
} else { // before the trigger
1198
// the trigger requires the conditional mod,
1199
// so it should appear before the conditional
1200
// mod if we do not intersede.
1202
} else { // after the trigger
1203
o.after = o.after || [];
1204
o.after.push(trigger);
1210
o.supersedes = this.filterRequires(o.supersedes);
1214
o.after = this.filterRequires(o.after);
1215
o.after_map = YArray.hash(o.after);
1218
// this.dirty = true;
1221
ret = o.configFn(o);
1222
if (ret === false) {
1223
Y.log('Config function returned false for ' + name + ', skipping.', 'info', 'loader');
1224
delete this.moduleInfo[name];
1225
delete GLOBAL_ENV._renderedMods[name];
1229
//Add to global cache
1231
if (!GLOBAL_ENV._renderedMods) {
1232
GLOBAL_ENV._renderedMods = {};
1234
GLOBAL_ENV._renderedMods[name] = Y.merge(o);
1235
GLOBAL_ENV._conditions = conditions;
1242
* Add a requirement for one or more module
1244
* @param {string[] | string*} what the modules to load.
1246
require: function(what) {
1247
var a = (typeof what === 'string') ? YArray(arguments) : what;
1249
this.required = Y.merge(this.required, YArray.hash(this.filterRequires(a)));
1251
this._explodeRollups();
1254
* Grab all the items that were asked for, check to see if the Loader
1255
* meta-data contains a "use" array. If it doesm remove the asked item and replace it with
1256
* the content of the "use".
1257
* This will make asking for: "dd"
1258
* Actually ask for: "dd-ddm-base,dd-ddm,dd-ddm-drop,dd-drag,dd-proxy,dd-constrain,dd-drop,dd-scroll,dd-drop-plugin"
1260
* @method _explodeRollups
1262
_explodeRollups: function() {
1265
if (!self.allowRollup) {
1266
oeach(r, function(v, name) {
1267
m = self.getModule(name);
1270
YArray.each(m.use, function(v) {
1271
m = self.getModule(v);
1274
YArray.each(m.use, function(v) {
1288
* Explodes the required array to remove aliases and replace them with real modules
1289
* @method filterRequires
1290
* @param {Array} r The original requires array
1291
* @return {Array} The new array of exploded requirements
1293
filterRequires: function(r) {
1295
if (!Y.Lang.isArray(r)) {
1299
var c = [], i, mod, o, m;
1301
for (i = 0; i < r.length; i++) {
1302
mod = this.getModule(r[i]);
1303
if (mod && mod.use) {
1304
for (o = 0; o < mod.use.length; o++) {
1305
//Must walk the other modules in case a module is a rollup of rollups (datatype)
1306
m = this.getModule(mod.use[o]);
1308
c = Y.Array.dedupe([].concat(c, this.filterRequires(m.use)));
1322
* Returns an object containing properties for all modules required
1323
* in order to load the requested module
1324
* @method getRequires
1325
* @param {object} mod The module definition from moduleInfo.
1326
* @return {array} the expanded requirement list.
1328
getRequires: function(mod) {
1331
//console.log('returning no reqs for ' + mod.name);
1332
return NO_REQUIREMENTS;
1336
//console.log('returning requires for ' + mod.name, mod.requires);
1337
return mod.expanded || NO_REQUIREMENTS;
1340
//TODO add modue cache here out of scope..
1342
var i, m, j, add, packName, lang, testresults = this.testresults,
1343
name = mod.name, cond,
1344
adddef = ON_PAGE[name] && ON_PAGE[name].details,
1347
o, skinmod, skindef, skinpar, skinname,
1348
intl = mod.lang || mod.intl,
1349
info = this.moduleInfo,
1350
ftests = Y.Features && Y.Features.tests.load,
1353
// console.log(name);
1355
// pattern match leaves module stub that needs to be filled out
1356
if (mod.temp && adddef) {
1358
mod = this.addModule(adddef, name);
1359
mod.group = old_mod.group;
1360
mod.pkg = old_mod.pkg;
1361
delete mod.expanded;
1364
// console.log('cache: ' + mod.langCache + ' == ' + this.lang);
1366
// if (mod.expanded && (!mod.langCache || mod.langCache == this.lang)) {
1367
if (mod.expanded && (!this.lang || mod.langCache === this.lang)) {
1368
//Y.log('Already expanded ' + name + ', ' + mod.expanded);
1369
return mod.expanded;
1375
r = this.filterRequires(mod.requires);
1377
//If a module has a lang attribute, auto add the intl requirement.
1382
o = this.filterRequires(mod.optional);
1384
// Y.log("getRequires: " + name + " (dirty:" + this.dirty +
1385
// ", expanded:" + mod.expanded + ")");
1388
mod.langCache = this.lang;
1390
for (i = 0; i < r.length; i++) {
1391
//Y.log(name + ' requiring ' + r[i], 'info', 'loader');
1395
m = this.getModule(r[i]);
1397
add = this.getRequires(m);
1398
intl = intl || (m.expanded_map &&
1399
(INTL in m.expanded_map));
1400
for (j = 0; j < add.length; j++) {
1407
// get the requirements from superseded modules, if any
1408
r = this.filterRequires(mod.supersedes);
1410
for (i = 0; i < r.length; i++) {
1412
// if this module has submodules, the requirements list is
1413
// expanded to include the submodules. This is so we can
1414
// prevent dups when a submodule is already loaded and the
1415
// parent is requested.
1416
if (mod.submodules) {
1421
m = this.getModule(r[i]);
1424
add = this.getRequires(m);
1425
intl = intl || (m.expanded_map &&
1426
(INTL in m.expanded_map));
1427
for (j = 0; j < add.length; j++) {
1435
if (o && this.loadOptional) {
1436
for (i = 0; i < o.length; i++) {
1442
add = this.getRequires(m);
1443
intl = intl || (m.expanded_map &&
1444
(INTL in m.expanded_map));
1445
for (j = 0; j < add.length; j++) {
1453
cond = this.conditions[name];
1456
//Set the module to not parsed since we have conditionals and this could change the dependency tree.
1457
mod._parsed = false;
1458
if (testresults && ftests) {
1459
oeach(testresults, function(result, id) {
1460
var condmod = ftests[id].name;
1461
if (!hash[condmod] && ftests[id].trigger == name) {
1462
if (result && ftests[id]) {
1463
hash[condmod] = true;
1469
oeach(cond, function(def, condmod) {
1470
if (!hash[condmod]) {
1471
//first see if they've specfied a ua check
1472
//then see if they've got a test fn & if it returns true
1473
//otherwise just having a condition block is enough
1474
var go = def && ((!def.ua && !def.test) || (def.ua && Y.UA[def.ua]) ||
1475
(def.test && def.test(Y, r)));
1478
hash[condmod] = true;
1480
m = this.getModule(condmod);
1482
add = this.getRequires(m);
1483
for (j = 0; j < add.length; j++) {
1494
// Create skin modules
1495
if (mod.skinnable) {
1496
skindef = this.skin.overrides;
1497
oeach(YUI.Env.aliases, function(o, n) {
1498
if (Y.Array.indexOf(o, name) > -1) {
1502
if (skindef && (skindef[name] || (skinpar && skindef[skinpar]))) {
1504
if (skindef[skinpar]) {
1507
for (i = 0; i < skindef[skinname].length; i++) {
1508
skinmod = this._addSkin(skindef[skinname][i], name);
1509
if (!this.isCSSLoaded(skinmod, this._boot)) {
1514
skinmod = this._addSkin(this.skin.defaultSkin, name);
1515
if (!this.isCSSLoaded(skinmod, this._boot)) {
1521
mod._parsed = false;
1525
if (mod.lang && !mod.langPack && Y.Intl) {
1526
lang = Y.Intl.lookupBestLang(this.lang || ROOT_LANG, mod.lang);
1527
//Y.log('Best lang: ' + lang + ', this.lang: ' + this.lang + ', mod.lang: ' + mod.lang);
1528
packName = this.getLangPackName(lang, name);
1530
d.unshift(packName);
1536
mod.expanded_map = YArray.hash(d);
1538
mod.expanded = YObject.keys(mod.expanded_map);
1540
return mod.expanded;
1543
* Check to see if named css module is already loaded on the page
1544
* @method isCSSLoaded
1545
* @param {String} name The name of the css file
1548
isCSSLoaded: function(name, skip) {
1549
//TODO - Make this call a batching call with name being an array
1550
if (!name || !YUI.Env.cssStampEl || (!skip && this.ignoreRegistered)) {
1551
Y.log('isCSSLoaded was skipped for ' + name, 'warn', 'loader');
1555
var el = YUI.Env.cssStampEl,
1557
style = el.currentStyle; //IE
1559
//Add the classname to the element
1560
el.className = name;
1563
style = Y.config.doc.defaultView.getComputedStyle(el, null);
1566
if (style && style['display'] === 'none') {
1570
Y.log('Has Skin? ' + name + ' : ' + ret, 'info', 'loader');
1572
el.className = ''; //Reset the classname to ''
1577
* Returns a hash of module names the supplied module satisfies.
1578
* @method getProvides
1579
* @param {string} name The name of the module.
1580
* @return {object} what this module provides.
1582
getProvides: function(name) {
1583
var m = this.getModule(name), o, s;
1584
// supmap = this.provides;
1590
if (m && !m.provides) {
1595
YArray.each(s, function(v) {
1596
Y.mix(o, this.getProvides(v));
1609
* Calculates the dependency tree, the result is stored in the sorted
1612
* @param {object} o optional options object.
1613
* @param {string} type optional argument to prune modules.
1615
calculate: function(o, type) {
1616
if (o || type || this.dirty) {
1628
if (this.allowRollup) {
1631
this._explodeRollups();
1638
* Creates a "psuedo" package for languages provided in the lang array
1639
* @method _addLangPack
1641
* @param {String} lang The language to create
1642
* @param {Object} m The module definition to create the language pack around
1643
* @param {String} packName The name of the package (e.g: lang/datatype-date-en-US)
1644
* @return {Object} The module definition
1646
_addLangPack: function(lang, m, packName) {
1649
existing = this.moduleInfo[packName];
1653
packPath = _path((m.pkg || name), packName, JS, true);
1665
conf.configFn = m.configFn;
1668
this.addModule(conf, packName);
1671
Y.Env.lang = Y.Env.lang || {};
1672
Y.Env.lang[lang] = Y.Env.lang[lang] || {};
1673
Y.Env.lang[lang][name] = true;
1677
return this.moduleInfo[packName];
1681
* Investigates the current YUI configuration on the page. By default,
1682
* modules already detected will not be loaded again unless a force
1683
* option is encountered. Called by calculate()
1687
_setup: function() {
1688
var info = this.moduleInfo, name, i, j, m, l,
1691
for (name in info) {
1692
if (info.hasOwnProperty(name)) {
1697
//m.requires = YObject.keys(YArray.hash(m.requires));
1698
m.requires = YArray.dedupe(m.requires);
1700
// Create lang pack modules
1701
if (m.lang && m.lang.length) {
1702
// Setup root package if the module has lang defined,
1703
// it needs to provide a root language pack
1704
packName = this.getLangPackName(ROOT_LANG, name);
1705
this._addLangPack(null, m, packName);
1713
//l = Y.merge(this.inserted);
1716
// available modules
1717
if (!this.ignoreRegistered) {
1718
Y.mix(l, GLOBAL_ENV.mods);
1721
// add the ignore list to the list of loaded packages
1723
Y.mix(l, YArray.hash(this.ignore));
1726
// expand the list to include superseded modules
1728
if (l.hasOwnProperty(j)) {
1729
Y.mix(l, this.getProvides(j));
1733
// remove modules on the force list from the loaded list
1735
for (i = 0; i < this.force.length; i++) {
1736
if (this.force[i] in l) {
1737
delete l[this.force[i]];
1742
Y.mix(this.loaded, l);
1748
* Builds a module name for a language pack
1749
* @method getLangPackName
1750
* @param {string} lang the language code.
1751
* @param {string} mname the module to build it for.
1752
* @return {string} the language pack module name.
1754
getLangPackName: function(lang, mname) {
1755
return ('lang/' + mname + ((lang) ? '_' + lang : ''));
1758
* Inspects the required modules list looking for additional
1759
* dependencies. Expands the required list to include all
1760
* required modules. Called by calculate()
1764
_explode: function() {
1765
//TODO Move done out of scope
1766
var r = this.required, m, reqs, done = {},
1769
// the setup phase is over, all modules have been created
1772
self._explodeRollups();
1775
oeach(r, function(v, name) {
1778
m = self.getModule(name);
1780
var expound = m.expound;
1783
r[expound] = self.getModule(expound);
1784
reqs = self.getRequires(r[expound]);
1785
Y.mix(r, YArray.hash(reqs));
1788
reqs = self.getRequires(m);
1789
Y.mix(r, YArray.hash(reqs));
1794
// Y.log('After explode: ' + YObject.keys(r));
1797
* Get's the loader meta data for the requested module
1799
* @param {String} mname The module name to get
1800
* @return {Object} The module metadata
1802
getModule: function(mname) {
1803
//TODO: Remove name check - it's a quick hack to fix pattern WIP
1808
var p, found, pname,
1809
m = this.moduleInfo[mname],
1810
patterns = this.patterns;
1812
// check the patterns library to see if we should automatically add
1813
// the module with defaults
1815
// Y.log('testing patterns ' + YObject.keys(patterns));
1816
for (pname in patterns) {
1817
if (patterns.hasOwnProperty(pname)) {
1818
// Y.log('testing pattern ' + i);
1819
p = patterns[pname];
1821
//There is no test method, create a default one that tests
1822
// the pattern against the mod name
1824
p.test = function(mname, pname) {
1825
return (mname.indexOf(pname) > -1);
1829
if (p.test(mname, pname)) {
1830
// use the metadata supplied for the pattern
1831
// as the module definition.
1840
// Y.log('executing pattern action: ' + pname);
1841
p.action.call(this, mname, pname);
1843
Y.log('Undefined module: ' + mname + ', matched a pattern: ' +
1844
pname, 'info', 'loader');
1845
// ext true or false?
1846
m = this.addModule(Y.merge(found), mname);
1855
// impl in rollup submodule
1856
_rollup: function() { },
1859
* Remove superceded modules and loaded modules. Called by
1860
* calculate() after we have the mega list of all dependencies
1862
* @return {object} the reduced dependency hash.
1865
_reduce: function(r) {
1867
r = r || this.required;
1869
var i, j, s, m, type = this.loadType,
1870
ignore = this.ignore ? YArray.hash(this.ignore) : false;
1873
if (r.hasOwnProperty(i)) {
1874
m = this.getModule(i);
1875
// remove if already loaded
1876
if (((this.loaded[i] || ON_PAGE[i]) &&
1877
!this.forceMap[i] && !this.ignoreRegistered) ||
1878
(type && m && m.type != type)) {
1881
if (ignore && ignore[i]) {
1884
// remove anything this module supersedes
1885
s = m && m.supersedes;
1887
for (j = 0; j < s.length; j++) {
1899
* Handles the queue when a module has been loaded for all cases
1902
* @param {String} msg The message from Loader
1903
* @param {Boolean} success A boolean denoting success or failure
1905
_finish: function(msg, success) {
1906
Y.log('loader finishing: ' + msg + ', ' + Y.id + ', ' +
1907
this.data, 'info', 'loader');
1909
_queue.running = false;
1911
var onEnd = this.onEnd;
1913
onEnd.call(this.context, {
1922
* The default Loader onSuccess handler, calls this.onSuccess with a payload
1923
* @method _onSuccess
1926
_onSuccess: function() {
1927
var self = this, skipped = Y.merge(self.skipped), fn,
1928
failed = [], rreg = self.requireRegistration,
1931
oeach(skipped, function(k) {
1932
delete self.inserted[k];
1937
oeach(self.inserted, function(v, k) {
1938
var mod = self.getModule(k);
1939
if (mod && rreg && mod.type == JS && !(k in YUI.Env.mods)) {
1942
Y.mix(self.loaded, self.getProvides(k));
1946
fn = self.onSuccess;
1947
msg = (failed.length) ? 'notregistered' : 'success';
1948
success = !(failed.length);
1950
fn.call(self.context, {
1958
self._finish(msg, success);
1961
* The default Loader onProgress handler, calls this.onProgress with a payload
1962
* @method _onProgress
1965
_onProgress: function(e) {
1967
if (self.onProgress) {
1968
self.onProgress.call(self.context, {
1975
* The default Loader onFailure handler, calls this.onFailure with a payload
1976
* @method _onFailure
1979
_onFailure: function(o) {
1980
var f = this.onFailure, msg = [], i = 0, len = o.errors.length;
1982
for (i; i < len; i++) {
1983
msg.push(o.errors[i].error);
1986
msg = msg.join(',');
1988
Y.log('load error: ' + msg + ', ' + Y.id, 'error', 'loader');
1991
f.call(this.context, {
1998
this._finish(msg, false);
2003
* The default Loader onTimeout handler, calls this.onTimeout with a payload
2004
* @method _onTimeout
2007
_onTimeout: function() {
2008
Y.log('loader timeout: ' + Y.id, 'error', 'loader');
2009
var f = this.onTimeout;
2011
f.call(this.context, {
2020
* Sorts the dependency tree. The last step of calculate()
2026
// create an indexed list
2027
var s = YObject.keys(this.required),
2028
// loaded = this.loaded,
2029
//TODO Move this out of scope
2031
p = 0, l, a, b, j, k, moved, doneKey;
2033
// keep going until we make a pass without moving anything
2039
// start the loop after items that are already sorted
2040
for (j = p; j < l; j++) {
2042
// check the next module on the list to see if its
2043
// dependencies have been met
2046
// check everything below current item and move if we
2047
// find a requirement for the current item
2048
for (k = j + 1; k < l; k++) {
2051
if (!done[doneKey] && this._requires(a, s[k])) {
2053
// extract the dependency so we can move it up
2056
// insert the dependency above the item that
2058
s.splice(j, 0, b[0]);
2060
// only swap two dependencies once to short circut
2061
// circular dependencies
2062
done[doneKey] = true;
2071
// jump out of loop if we moved something
2074
// this item is sorted, move our pointer and keep going
2080
// when we make it here and moved is false, we are
2092
* Handles the actual insertion of script/link tags
2095
* @param {Object} source The YUI instance the request came from
2096
* @param {Object} o The metadata to include
2097
* @param {String} type JS or CSS
2098
* @param {Boolean} [skipcalc=false] Do a Loader.calculate on the meta
2100
_insert: function(source, o, type, skipcalc) {
2102
Y.log('private _insert() ' + (type || '') + ', ' + Y.id, "info", "loader");
2104
// restore the state at the time of the request
2106
this._config(source);
2109
// build the dependency list
2110
// don't include type so we can process CSS and script in
2111
// one pass when the type is not specified.
2116
var modules = this.resolve(),
2117
self = this, comp = 0, actions = 0;
2120
//Filter out the opposite type and reset the array so the checks later work
2121
modules[((type === JS) ? CSS : JS)] = [];
2123
if (modules.js.length) {
2126
if (modules.css.length) {
2130
//console.log('Resolved Modules: ', modules);
2132
var complete = function(d) {
2134
var errs = {}, i = 0, u = '', fn;
2136
if (d && d.errors) {
2137
for (i = 0; i < d.errors.length; i++) {
2138
if (d.errors[i].request) {
2139
u = d.errors[i].request.url;
2147
if (d && d.data && d.data.length && (d.type === 'success')) {
2148
for (i = 0; i < d.data.length; i++) {
2149
self.inserted[d.data[i].name] = true;
2153
if (actions === comp) {
2154
self._loading = null;
2155
Y.log('Loader actions complete!', 'info', 'loader');
2157
Y.log('Firing final Loader callback!', 'info', 'loader');
2165
this._loading = true;
2167
if (!modules.js.length && !modules.css.length) {
2168
Y.log('No modules resolved..', 'warn', 'loader');
2177
if (modules.css.length) { //Load CSS first
2178
Y.log('Loading CSS modules', 'info', 'loader');
2179
Y.Get.css(modules.css, {
2180
data: modules.cssMods,
2181
attributes: self.cssAttributes,
2182
insertBefore: self.insertBefore,
2183
charset: self.charset,
2184
timeout: self.timeout,
2186
onProgress: function(e) {
2187
self._onProgress.call(self, e);
2189
onTimeout: function(d) {
2190
self._onTimeout.call(self, d);
2192
onSuccess: function(d) {
2194
d.fn = self._onSuccess;
2195
complete.call(self, d);
2197
onFailure: function(d) {
2199
d.fn = self._onFailure;
2200
complete.call(self, d);
2205
if (modules.js.length) {
2206
Y.log('Loading JS modules', 'info', 'loader');
2207
Y.Get.js(modules.js, {
2208
data: modules.jsMods,
2209
insertBefore: self.insertBefore,
2210
attributes: self.jsAttributes,
2211
charset: self.charset,
2212
timeout: self.timeout,
2216
onProgress: function(e) {
2217
self._onProgress.call(self, e);
2219
onTimeout: function(d) {
2220
self._onTimeout.call(self, d);
2222
onSuccess: function(d) {
2224
d.fn = self._onSuccess;
2225
complete.call(self, d);
2227
onFailure: function(d) {
2229
d.fn = self._onFailure;
2230
complete.call(self, d);
2236
* Once a loader operation is completely finished, process any additional queued items.
2240
_continue: function() {
2241
if (!(_queue.running) && _queue.size() > 0) {
2242
_queue.running = true;
2248
* inserts the requested modules and their dependencies.
2249
* <code>type</code> can be "js" or "css". Both script and
2250
* css are inserted if type is not provided.
2252
* @param {object} o optional options object.
2253
* @param {string} type the type of dependency to insert.
2255
insert: function(o, type, skipsort) {
2256
Y.log('public insert() ' + (type || '') + ', ' +
2257
Y.Object.keys(this.required), "info", "loader");
2258
var self = this, copy = Y.merge(this);
2259
delete copy.require;
2261
_queue.add(function() {
2262
self._insert(copy, o, type, skipsort);
2268
* Executed every time a module is loaded, and if we are in a load
2269
* cycle, we attempt to load the next script. Public so that it
2270
* is possible to call this if using a method other than
2271
* Y.register to determine when scripts are fully loaded
2274
* @param {string} mname optional the name of the module that has
2275
* been loaded (which is usually why it is time to load the next
2278
loadNext: function(mname) {
2279
Y.log('loadNext was called..', 'error', 'loader');
2284
* Apply filter defined for this instance to a url/path
2286
* @param {string} u the string to filter.
2287
* @param {string} name the name of the module, if we are processing
2288
* a single module as opposed to a combined url.
2289
* @return {string} the filtered string.
2292
_filter: function(u, name, group) {
2293
var f = this.filter,
2294
hasFilter = name && (name in this.filters),
2295
modFilter = hasFilter && this.filters[name],
2296
groupName = group || (this.moduleInfo[name] ? this.moduleInfo[name].group : null);
2298
if (groupName && this.groups[groupName] && this.groups[groupName].filter) {
2299
modFilter = this.groups[groupName].filter;
2305
f = (L.isString(modFilter)) ?
2306
this.FILTER_DEFS[modFilter.toUpperCase()] || null :
2310
u = u.replace(new RegExp(f.searchExp, 'g'), f.replaceStr);
2318
* Generates the full url for a module
2320
* @param {string} path the path fragment.
2321
* @param {String} name The name of the module
2322
* @param {String} [base=self.base] The base url to use
2323
* @return {string} the full url.
2326
_url: function(path, name, base) {
2327
return this._filter((base || this.base || '') + path, name);
2330
* Returns an Object hash of file arrays built from `loader.sorted` or from an arbitrary list of sorted modules.
2332
* @param {Boolean} [calc=false] Perform a loader.calculate() before anything else
2333
* @param {Array} [s=loader.sorted] An override for the loader.sorted array
2334
* @return {Object} Object hash (js and css) of two arrays of file lists
2335
* @example This method can be used as an off-line dep calculator
2338
* var loader = new Y.Loader({
2343
* require: ['node', 'dd', 'console']
2345
* var out = loader.resolve(true);
2348
resolve: function(calc, s) {
2350
var len, i, m, url, fn, msg, attr, group, groupName, j, frag,
2351
comboSource, comboSources, mods, comboBase,
2352
base, urls, u = [], tmpBase, baseLen, resCombos = {},
2353
self = this, comboSep, maxURLLength, singles = [],
2354
inserted = (self.ignoreRegistered) ? {} : self.inserted,
2355
resolved = { js: [], jsMods: [], css: [], cssMods: [] },
2356
type = self.loadType || 'js';
2361
s = s || self.sorted;
2363
var addSingle = function(m) {
2366
group = (m.group && self.groups[m.group]) || NOT_FOUND;
2368
//Always assume it's async
2369
if (group.async === false) {
2370
m.async = group.async;
2373
url = (m.fullpath) ? self._filter(m.fullpath, s[i]) :
2374
self._url(m.path, s[i], group.base || m.base);
2376
if (m.attributes || m.async === false) {
2382
url.attributes = m.attributes
2385
resolved[m.type].push(url);
2386
resolved[m.type + 'Mods'].push(m);
2388
Y.log('Undefined Module', 'warn', 'loader');
2395
// the default combo base
2396
comboBase = self.comboBase;
2402
for (i = 0; i < len; i++) {
2403
comboSource = comboBase;
2404
m = self.getModule(s[i]);
2405
groupName = m && m.group;
2406
group = self.groups[groupName];
2407
if (groupName && group) {
2409
if (!group.combine || m.fullpath) {
2410
//This is not a combo module, skip it and load it singly later.
2411
//singles.push(s[i]);
2416
if (group.comboBase) {
2417
comboSource = group.comboBase;
2420
if ("root" in group && L.isValue(group.root)) {
2421
m.root = group.root;
2423
m.comboSep = group.comboSep || self.comboSep;
2424
m.maxURLLength = group.maxURLLength || self.maxURLLength;
2426
if (!self.combine) {
2427
//This is not a combo module, skip it and load it singly later.
2428
//singles.push(s[i]);
2434
comboSources[comboSource] = comboSources[comboSource] || [];
2435
comboSources[comboSource].push(m);
2438
for (j in comboSources) {
2439
if (comboSources.hasOwnProperty(j)) {
2440
resCombos[j] = resCombos[j] || { js: [], jsMods: [], css: [], cssMods: [] };
2442
mods = comboSources[j];
2446
for (i = 0; i < len; i++) {
2447
if (inserted[mods[i]]) {
2451
// Do not try to combine non-yui JS unless combo def
2453
if (m && (m.combine || !m.ext)) {
2454
resCombos[j].comboSep = m.comboSep;
2455
resCombos[j].group = m.group;
2456
resCombos[j].maxURLLength = m.maxURLLength;
2457
frag = ((L.isValue(m.root)) ? m.root : self.root) + (m.path || m.fullpath);
2458
frag = self._filter(frag, m.name);
2459
resCombos[j][m.type].push(frag);
2460
resCombos[j][m.type + 'Mods'].push(m);
2462
//Add them to the next process..
2464
//singles.push(mods[i].name);
2475
for (j in resCombos) {
2477
comboSep = resCombos[base].comboSep || self.comboSep;
2478
maxURLLength = resCombos[base].maxURLLength || self.maxURLLength;
2479
Y.log('Using maxURLLength of ' + maxURLLength, 'info', 'loader');
2480
for (type in resCombos[base]) {
2481
if (type === JS || type === CSS) {
2482
urls = resCombos[base][type];
2483
mods = resCombos[base][type + 'Mods'];
2485
tmpBase = base + urls.join(comboSep);
2486
baseLen = tmpBase.length;
2487
if (maxURLLength <= base.length) {
2488
Y.log('maxURLLength (' + maxURLLength + ') is lower than the comboBase length (' + base.length + '), resetting to default (' + MAX_URL_LENGTH + ')', 'error', 'loader');
2489
maxURLLength = MAX_URL_LENGTH;
2493
if (baseLen > maxURLLength) {
2494
Y.log('Exceeded maxURLLength (' + maxURLLength + ') for ' + type + ', splitting', 'info', 'loader');
2496
for (s = 0; s < len; s++) {
2498
tmpBase = base + u.join(comboSep);
2500
if (tmpBase.length > maxURLLength) {
2502
tmpBase = base + u.join(comboSep)
2503
resolved[type].push(self._filter(tmpBase, null, resCombos[base].group));
2511
tmpBase = base + u.join(comboSep);
2512
resolved[type].push(self._filter(tmpBase, null, resCombos[base].group));
2515
resolved[type].push(self._filter(tmpBase, null, resCombos[base].group));
2518
resolved[type + 'Mods'] = resolved[type + 'Mods'].concat(mods);
2528
Shortcut to calculate, resolve and load all modules.
2530
var loader = new Y.Loader({
2531
ignoreRegistered: true,
2539
loader.load(function() {
2540
console.log('All modules have loaded..');
2545
@param {Callback} cb Executed after all load operations are complete
2547
load: function(cb) {
2549
Y.log('No callback supplied to load()', 'error', 'loader');
2553
out = self.resolve(true);
2557
self.onEnd = function() {
2558
cb.apply(self.context || self, arguments);
2567
}, '3.5.1' ,{requires:['get', 'features']});