3
Copyright 2011 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-2011.09.14-20-40',
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) {
44
var root = TNT + '.' +
45
(tnt || TNT_VERSION) + '/' +
46
(yui2 || YUI2_VERSION) + BUILD;
47
groups.yui2.base = CDN_BASE + root;
48
groups.yui2.root = root;
50
galleryUpdate = function(tag) {
51
var root = (tag || GALLERY_VERSION) + BUILD;
52
groups.gallery.base = CDN_BASE + root;
53
groups.gallery.root = root;
61
comboBase: COMBO_BASE,
62
update: galleryUpdate,
63
patterns: { 'gallery-': { },
65
'gallerycss-': { type: 'css' } }
71
comboBase: COMBO_BASE,
75
configFn: function(me) {
76
if (/-skin|reset|fonts|grids|base/.test(me.name)) {
78
me.path = me.path.replace(/\.js/, '.css');
79
// this makes skins in builds earlier than
80
// 2.6.0 work as long as combine is false
81
me.path = me.path.replace(/\/yui2-skin/,
82
'/assets/skins/sam/yui2-skin');
92
YUI.Env[VERSION] = META;
98
* Loader dynamically loads script and css files. It includes the dependency
99
* info for the version of the library in use, and will automatically pull in
100
* dependencies for the modules requested. It supports rollup files and will
101
* automatically use these when appropriate in order to minimize the number of
102
* http connections required to load all of the dependencies. It can load the
103
* files from the Yahoo! CDN, and it can utilize the combo service provided on
104
* this network to reduce the number of http connections required to download
109
* @submodule loader-base
113
NO_REQUIREMENTS = [],
114
MAX_URL_LENGTH = 2048,
115
GLOBAL_ENV = YUI.Env,
116
GLOBAL_LOADED = GLOBAL_ENV._loaded,
123
oeach = YObject.each,
125
_queue = GLOBAL_ENV._loaderQueue,
126
META = GLOBAL_ENV[VERSION],
127
SKIN_PREFIX = 'skin-',
129
ON_PAGE = GLOBAL_ENV.mods,
132
_path = function(dir, file, type, nomin) {
133
var path = dir + '/' + file;
137
path += '.' + (type || CSS);
142
if (YUI.Env.aliases) {
143
YUI.Env.aliases = {}; //Don't need aliases if Loader is present
147
* The component metadata is stored in Y.Env.meta.
148
* Part of the loader module.
155
* Loader dynamically loads script and css files. It includes the dependency
156
* info for the version of the library in use, and will automatically pull in
157
* dependencies for the modules requested. It supports rollup files and will
158
* automatically use these when appropriate in order to minimize the number of
159
* http connections required to load all of the dependencies. It can load the
160
* files from the Yahoo! CDN, and it can utilize the combo service provided on
161
* this network to reduce the number of http connections required to download
164
* While the loader can be instantiated by the end user, it normally is not.
165
* @see YUI.use for the normal use case. The use function automatically will
166
* pull in missing dependencies.
170
* @param {object} o an optional set of configuration options. Valid options:
175
* The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?</li>
177
* The root path to prepend to module names for the combo service.
178
* Ex: 2.5.2/build/</li>
181
* A filter to apply to result urls. This filter will modify the default
182
* path for all modules. The default path for the YUI library is the
183
* minified version of the files (e.g., event-min.js). The filter property
184
* can be a predefined filter or a custom filter. The valid predefined
188
* <dd>Selects the debug versions of the library (e.g., event-debug.js).
189
* This option will automatically include the Logger widget</dd>
191
* <dd>Selects the non-minified version of the library (e.g., event.js).
194
* You can also define a custom filter, which must be an object literal
195
* containing a search expression and a replace string:
198
* 'searchExp': "-min\\.js",
199
* 'replaceStr': "-debug.js"
204
* <li>filters: per-component filter specification. If specified
205
* for a given component, this overrides the filter config. _Note:_ This does not work on combo urls, use the filter property instead.</li>
207
* Use the YUI combo service to reduce the number of http connections
208
* required to load your dependencies</li>
210
* A list of modules that should never be dynamically loaded</li>
212
* A list of modules that should always be loaded when required, even if
213
* already present on the page</li>
215
* Node or id for a node that should be used as the insertion point for
218
* charset for dynamic nodes (deprecated, use jsAttributes or cssAttributes)
220
* <li>jsAttributes: object literal containing attributes to add to script
222
* <li>cssAttributes: object literal containing attributes to add to link
225
* The number of milliseconds before a timeout occurs when dynamically
226
* loading nodes. If not set, there is no timeout</li>
228
* execution context for all callbacks</li>
230
* callback for the 'success' event</li>
231
* <li>onFailure: callback for the 'failure' event</li>
232
* <li>onCSS: callback for the 'CSSComplete' event. When loading YUI
233
* components with CSS the CSS is loaded first, then the script. This
234
* provides a moment you can tie into to improve
235
* the presentation of the page while the script is loading.</li>
237
* callback for the 'timeout' event</li>
239
* callback executed each time a script or css file is loaded</li>
241
* A list of module definitions. See Loader.addModule for the supported
242
* module metadata</li>
244
* A list of group definitions. Each group can contain specific definitions
245
* for base, comboBase, combine, and accepts a list of modules. See above
246
* for the description of these properties.</li>
247
* <li>2in3: the version of the YUI 2 in 3 wrapper to use. The intrinsic
248
* support for YUI 2 modules in YUI 3 relies on versions of the YUI 2
249
* components inside YUI 3 module wrappers. These wrappers
250
* change over time to accomodate the issues that arise from running YUI 2
251
* in a YUI 3 sandbox.</li>
252
* <li>yui2: when using the 2in3 project, you can select the version of
253
* YUI 2 to use. Valid values * are 2.2.2, 2.3.1, 2.4.1, 2.5.2, 2.6.0,
254
* 2.7.0, 2.8.0, and 2.8.1 [default] -- plus all versions of YUI 2
255
* going forward.</li>
258
Y.Loader = function(o) {
260
var defaults = META.modules,
263
modulekey = META.md5;
266
* Internal callback to handle multiple internal insert() calls
267
* so that css is inserted prior to js
268
* @property _internalCallback
271
// self._internalCallback = null;
274
* Callback that will be executed when the loader is finished
279
// self.onSuccess = null;
282
* Callback that will be executed if there is a failure
286
// self.onFailure = null;
289
* Callback for the 'CSSComplete' event. When loading YUI components
290
* with CSS the CSS is loaded first, then the script. This provides
291
* a moment you can tie into to improve the presentation of the page
292
* while the script is loading.
296
// self.onCSS = null;
299
* Callback executed each time a script or css file is loaded
303
// self.onProgress = null;
306
* Callback that will be executed if a timeout occurs
310
// self.onTimeout = null;
313
* The execution context for all callbacks
315
* @default {YUI} the YUI instance
320
* Data that is passed to all callbacks
326
* Node reference or id where new nodes should be inserted before
327
* @property insertBefore
328
* @type string|HTMLElement
330
// self.insertBefore = null;
333
* The charset attribute for inserted nodes
336
* @deprecated , use cssAttributes or jsAttributes.
338
// self.charset = null;
341
* An object literal containing attributes to add to link nodes
342
* @property cssAttributes
345
// self.cssAttributes = null;
348
* An object literal containing attributes to add to script nodes
349
* @property jsAttributes
352
// self.jsAttributes = null;
355
* The base directory.
358
* @default http://yui.yahooapis.com/[YUI VERSION]/build/
360
self.base = Y.Env.meta.base + Y.Env.meta.root;
363
* Base path for the combo service
364
* @property comboBase
366
* @default http://yui.yahooapis.com/combo?
368
self.comboBase = Y.Env.meta.comboBase;
371
* Base path for language packs.
373
// self.langBase = Y.Env.meta.langBase;
377
* If configured, the loader will attempt to use the combo
378
* service for YUI resources and configured external resources.
381
* @default true if a base dir isn't in the config
383
self.combine = o.base &&
384
(o.base.indexOf(self.comboBase.substr(0, 20)) > -1);
387
* The default seperator to use between files in a combo URL
394
* Max url length for combo urls. The default is 2048. This is the URL
395
* limit for the Yahoo! hosted combo servers. If consuming
396
* a different combo service that has a different URL limit
397
* it is possible to override this default by supplying
398
* the maxURLLength config option. The config option will
399
* only take effect if lower than the default.
401
* @property maxURLLength
404
self.maxURLLength = MAX_URL_LENGTH;
407
* Ignore modules registered on the YUI global
408
* @property ignoreRegistered
411
// self.ignoreRegistered = false;
414
* Root path to prepend to module path for the combo
418
* @default [YUI VERSION]/build/
420
self.root = Y.Env.meta.root;
423
* Timeout value in milliseconds. If set, self value will be used by
424
* the get utility. the timeout event will fire if
432
* A list of modules that should not be loaded, even if
433
* they turn up in the dependency tree
437
// self.ignore = null;
440
* A list of modules that should always be loaded, even
441
* if they have already been inserted into the page.
445
// self.force = null;
450
* Should we allow rollups
451
* @property allowRollup
455
self.allowRollup = false;
458
* A filter to apply to result urls. This filter will modify the default
459
* path for all modules. The default path for the YUI library is the
460
* minified version of the files (e.g., event-min.js). The filter property
461
* can be a predefined filter or a custom filter. The valid predefined
465
* <dd>Selects the debug versions of the library (e.g., event-debug.js).
466
* This option will automatically include the Logger widget</dd>
468
* <dd>Selects the non-minified version of the library (e.g., event.js).
471
* You can also define a custom filter, which must be an object literal
472
* containing a search expression and a replace string:
475
* 'searchExp': "-min\\.js",
476
* 'replaceStr': "-debug.js"
480
* @type string| {searchExp: string, replaceStr: string}
482
// self.filter = null;
485
* per-component filter specification. If specified for a given
486
* component, this overrides the filter config.
493
* The list of requested modules
495
* @type {string: boolean}
500
* If a module name is predefined when requested, it is checked againsts
501
* the patterns provided in this property. If there is a match, the
502
* module is added with the default configuration.
504
* At the moment only supporting module prefixes, but anticipate
505
* supporting at least regular expressions.
509
// self.patterns = Y.merge(Y.Env.meta.patterns);
513
* The library metadata
514
* @property moduleInfo
516
// self.moduleInfo = Y.merge(Y.Env.meta.moduleInfo);
517
self.moduleInfo = {};
519
self.groups = Y.merge(Y.Env.meta.groups);
522
* Provides the information used to skin the skinnable components.
523
* The following skin definition would result in 'skin1' and 'skin2'
524
* being loaded for calendar (if calendar was requested), and
525
* 'sam' for all other skinnable components:
530
* // The default skin, which is automatically applied if not
531
* // overriden by a component-specific skin definition.
532
* // Change this in to apply a different skin globally
533
* defaultSkin: 'sam',
535
* // This is combined with the loader base property to get
536
* // the default root directory for a skin. ex:
537
* // http://yui.yahooapis.com/2.3.0/build/assets/skins/sam/
538
* base: 'assets/skins/',
540
* // Any component-specific overrides can be specified here,
541
* // making it possible to load different skins for different
542
* // components. It is possible to load more than one skin
543
* // for a given component as well.
545
* calendar: ['skin1', 'skin2']
551
self.skin = Y.merge(Y.Env.meta.skin);
554
* Map of conditional modules
557
self.conditions = {};
559
// map of modules with a hash of modules that meet the requirement
560
// self.provides = {};
563
self._internal = true;
566
cache = GLOBAL_ENV._renderedMods;
569
oeach(cache, function modCache(v, k) {
570
//self.moduleInfo[k] = Y.merge(v);
571
self.moduleInfo[k] = v;
574
cache = GLOBAL_ENV._conditions;
576
oeach(cache, function condCache(v, k) {
577
//self.conditions[k] = Y.merge(v);
578
self.conditions[k] = v;
582
oeach(defaults, self.addModule, self);
585
if (!GLOBAL_ENV._renderedMods) {
586
//GLOBAL_ENV._renderedMods = Y.merge(self.moduleInfo);
587
//GLOBAL_ENV._conditions = Y.merge(self.conditions);
588
GLOBAL_ENV._renderedMods = self.moduleInfo;
589
GLOBAL_ENV._conditions = self.conditions;
594
self._internal = false;
598
self.testresults = null;
600
if (Y.config.tests) {
601
self.testresults = Y.config.tests;
605
* List of rollup files found in the library metadata
608
// self.rollups = null;
611
* Whether or not to load optional dependencies for
612
* the requested modules
613
* @property loadOptional
617
// self.loadOptional = false;
620
* All of the derived dependencies in sorted order, which
621
* will be populated when either calculate() or insert()
629
* Set when beginning to compute the dependency tree.
630
* Composed of what YUI reports to be loaded combined
631
* with what has been loaded by any instance on the page
632
* with the version number specified in the metadata.
634
* @type {string: boolean}
636
self.loaded = GLOBAL_LOADED[VERSION];
639
* A list of modules to attach to the YUI instance when complete.
640
* If not supplied, the sorted list of dependencies are applied.
641
* @property attaching
643
// self.attaching = null;
646
* Flag to indicate the dependency tree needs to be recomputed
647
* if insert is called again.
655
* List of modules inserted by the utility
657
* @type {string: boolean}
662
* List of skipped modules during insert() because the module
668
// Y.on('yui:load', self.loadNext, self);
673
* Cached sorted calculate results
681
Y.Loader.prototype = {
685
'searchExp': '-min\\.js',
689
'searchExp': '-min\\.js',
690
'replaceStr': '-debug.js'
694
* Check the pages meta-data and cache the result.
695
* @method _inspectPage
698
_inspectPage: function() {
699
oeach(ON_PAGE, function(v, k) {
701
var m = this.moduleInfo[k],
702
req = v.details.requires,
703
mr = m && m.requires;
705
if (!m._inspected && req && mr.length != req.length) {
706
// console.log('deleting ' + m.name);
707
// m.requres = YObject.keys(Y.merge(YArray.hash(req), YArray.hash(mr)));
709
// delete m.expanded_map;
712
m = this.addModule(v.details, k);
719
* returns true if b is not loaded, and is required directly or by means of modules it supersedes.
722
* @param {String} mod1 The first module to compare
723
* @param {String} mod2 The second module to compare
725
_requires: function(mod1, mod2) {
727
var i, rm, after_map, s,
728
info = this.moduleInfo,
737
after_map = m.after_map;
739
// check if this module should be sorted after the other
740
// do this first to short circut circular deps
741
if (after_map && (mod2 in after_map)) {
745
after_map = other.after_map;
748
if (after_map && (mod1 in after_map)) {
752
// check if this module requires one the other supersedes
753
s = info[mod2] && info[mod2].supersedes;
755
for (i = 0; i < s.length; i++) {
756
if (this._requires(mod1, s[i])) {
762
s = info[mod1] && info[mod1].supersedes;
764
for (i = 0; i < s.length; i++) {
765
if (this._requires(mod2, s[i])) {
771
// check if this module requires the other directly
772
// if (r && YArray.indexOf(r, mod2) > -1) {
773
if (rm && (mod2 in rm)) {
777
// external css files should be sorted below yui css
778
if (m.ext && m.type == CSS && !other.ext && other.type == CSS) {
785
* Apply a new config to the Loader instance
787
* @param {Object} o The new configuration
789
_config: function(o) {
790
var i, j, val, f, group, groupName, self = this;
791
// apply config values
794
if (o.hasOwnProperty(i)) {
796
if (i == 'require') {
798
} else if (i == 'skin') {
799
Y.mix(self.skin, o[i], true);
800
} else if (i == 'groups') {
802
if (val.hasOwnProperty(j)) {
803
// Y.log('group: ' + j);
806
self.addGroup(group, groupName);
810
} else if (i == 'modules') {
811
// add a hash of module definitions
812
oeach(val, self.addModule, self);
813
} else if (i == 'gallery') {
814
this.groups.gallery.update(val);
815
} else if (i == 'yui2' || i == '2in3') {
816
this.groups.yui2.update(o['2in3'], o.yui2);
817
} else if (i == 'maxURLLength') {
818
self[i] = Math.min(MAX_URL_LENGTH, val);
832
self.filter = self.FILTER_DEFS[f];
834
self.require('yui-log', 'dump');
839
self.require('intl-base', 'intl');
845
* Returns the skin module name for the specified skin name. If a
846
* module name is supplied, the returned skin module name is
847
* specific to the module passed in.
849
* @param {string} skin the name of the skin.
850
* @param {string} mod optional: the name of a module to skin.
851
* @return {string} the full skin module name.
853
formatSkin: function(skin, mod) {
854
var s = SKIN_PREFIX + skin;
863
* Adds the skin def to the module info
865
* @param {string} skin the name of the skin.
866
* @param {string} mod the name of the module.
867
* @param {string} parent parent module if this is a skin of a
868
* submodule or plugin.
869
* @return {string} the module name for the skin.
872
_addSkin: function(skin, mod, parent) {
873
var mdef, pkg, name, nmod,
874
info = this.moduleInfo,
876
ext = info[mod] && info[mod].ext;
878
// Add a module definition for the module-specific skin css
880
name = this.formatSkin(skin, mod);
883
pkg = mdef.pkg || mod;
889
path: (parent || pkg) + '/' + sinf.base + skin +
894
nmod.base = mdef.base;
897
nmod.configFn = mdef.configFn;
899
this.addModule(nmod, name);
901
Y.log('adding skin ' + name + ', ' + parent + ', ' + pkg + ', ' + info[name].path);
909
* Add a new module group
911
* <dt>name:</dt> <dd>required, the group name</dd>
912
* <dt>base:</dt> <dd>The base dir for this module group</dd>
913
* <dt>root:</dt> <dd>The root path to add to each combo
915
* <dt>combine:</dt> <dd>combo handle</dd>
916
* <dt>comboBase:</dt> <dd>combo service base path</dd>
917
* <dt>modules:</dt> <dd>the group of modules</dd>
920
* @param {object} o An object containing the module data.
921
* @param {string} name the group name.
923
addGroup: function(o, name) {
924
var mods = o.modules,
926
name = name || o.name;
928
self.groups[name] = o;
931
oeach(o.patterns, function(v, k) {
933
self.patterns[k] = v;
938
oeach(mods, function(v, k) {
940
self.addModule(v, k);
946
* Add a new module to the component metadata.
948
* <dt>name:</dt> <dd>required, the component name</dd>
949
* <dt>type:</dt> <dd>required, the component type (js or css)
951
* <dt>path:</dt> <dd>required, the path to the script from
953
* <dt>requires:</dt> <dd>array of modules required by this
955
* <dt>optional:</dt> <dd>array of optional modules for this
957
* <dt>supersedes:</dt> <dd>array of the modules this component
959
* <dt>after:</dt> <dd>array of modules the components which, if
960
* present, should be sorted above this one</dd>
961
* <dt>after_map:</dt> <dd>faster alternative to 'after' -- supply
962
* a hash instead of an array</dd>
963
* <dt>rollup:</dt> <dd>the number of superseded modules required
964
* for automatic rollup</dd>
965
* <dt>fullpath:</dt> <dd>If fullpath is specified, this is used
966
* instead of the configured base + path</dd>
967
* <dt>skinnable:</dt> <dd>flag to determine if skin assets should
968
* automatically be pulled in</dd>
969
* <dt>submodules:</dt> <dd>a hash of submodules</dd>
970
* <dt>group:</dt> <dd>The group the module belongs to -- this
971
* is set automatically when it is added as part of a group
972
* configuration.</dd>
974
* <dd>array of BCP 47 language tags of languages for which this
975
* module has localized resource bundles,
976
* e.g., ["en-GB","zh-Hans-CN"]</dd>
977
* <dt>condition:</dt>
978
* <dd>Specifies that the module should be loaded automatically if
979
* a condition is met. This is an object with up to three fields:
980
* [trigger] - the name of a module that can trigger the auto-load
981
* [test] - a function that returns true when the module is to be
983
* [when] - specifies the load order of the conditional module
984
* with regard to the position of the trigger module.
985
* This should be one of three values: 'before', 'after', or
986
* 'instead'. The default is 'after'.
988
* <dt>testresults:</dt><dd>a hash of test results from Y.Features.all()</dd>
991
* @param {object} o An object containing the module data.
992
* @param {string} name the module name (optional), required if not
993
* in the module data.
994
* @return {object} the module definition or null if
995
* the object passed in did not provide all required attributes.
997
addModule: function(o, name) {
998
name = name || o.name;
1000
//Only merge this data if the temp flag is set
1001
//from an earlier pass from a pattern or else
1002
//an override module (YUI_config) can not be used to
1003
//replace a default module.
1004
if (this.moduleInfo[name] && this.moduleInfo[name].temp) {
1005
//This catches temp modules loaded via a pattern
1006
// The module will be added twice, once from the pattern and
1007
// Once from the actual add call, this ensures that properties
1008
// that were added to the module the first time around (group: gallery)
1009
// are also added the second time around too.
1010
o = Y.merge(this.moduleInfo[name], o);
1015
if (!o || !o.name) {
1023
if (!o.path && !o.fullpath) {
1024
o.path = _path(name, name, o.type);
1026
o.supersedes = o.supersedes || o.use;
1028
o.ext = ('ext' in o) ? o.ext : (this._internal) ? false : true;
1029
o.requires = this.filterRequires(o.requires) || [];
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
if (!o.langPack && o.lang) {
1041
langs = YArray(o.lang);
1042
for (j = 0; j < langs.length; j++) {
1044
packName = this.getLangPackName(lang, name);
1045
smod = this.moduleInfo[packName];
1047
smod = this._addLangPack(lang, o, packName);
1053
sup = o.supersedes || [];
1057
if (subs.hasOwnProperty(i)) {
1060
s.path = s.path || _path(name, i, o.type);
1065
sup = sup.concat(s.supersedes);
1068
smod = this.addModule(s, i);
1071
if (smod.skinnable) {
1073
overrides = this.skin.overrides;
1074
if (overrides && overrides[i]) {
1075
for (j = 0; j < overrides[i].length; j++) {
1076
skinname = this._addSkin(overrides[i][j],
1081
skinname = this._addSkin(this.skin.defaultSkin,
1086
// looks like we are expected to work out the metadata
1087
// for the parent module language packs from what is
1088
// specified in the child modules.
1089
if (s.lang && s.lang.length) {
1091
langs = YArray(s.lang);
1092
for (j = 0; j < langs.length; j++) {
1094
packName = this.getLangPackName(lang, name);
1095
supName = this.getLangPackName(lang, i);
1096
smod = this.moduleInfo[packName];
1099
smod = this._addLangPack(lang, o, packName);
1102
flatSup = flatSup || YArray.hash(smod.supersedes);
1104
if (!(supName in flatSup)) {
1105
smod.supersedes.push(supName);
1108
o.lang = o.lang || [];
1110
flatLang = flatLang || YArray.hash(o.lang);
1112
if (!(lang in flatLang)) {
1116
// Y.log('pack ' + packName + ' should supersede ' + supName);
1117
// Add rollup file, need to add to supersedes list too
1120
packName = this.getLangPackName(ROOT_LANG, name);
1121
supName = this.getLangPackName(ROOT_LANG, i);
1123
smod = this.moduleInfo[packName];
1126
smod = this._addLangPack(lang, o, packName);
1129
if (!(supName in flatSup)) {
1130
smod.supersedes.push(supName);
1133
// Y.log('pack ' + packName + ' should supersede ' + supName);
1134
// Add rollup file, need to add to supersedes list too
1142
//o.supersedes = YObject.keys(YArray.hash(sup));
1143
o.supersedes = YArray.dedupe(sup);
1144
if (this.allowRollup) {
1145
o.rollup = (l < 4) ? l : Math.min(l - 1, 4);
1149
plugins = o.plugins;
1151
for (i in plugins) {
1152
if (plugins.hasOwnProperty(i)) {
1155
plug.path = plug.path || _path(name, i, o.type);
1156
plug.requires = plug.requires || [];
1157
plug.group = o.group;
1158
this.addModule(plug, i);
1160
this._addSkin(this.skin.defaultSkin, i, name);
1168
t = o.condition.trigger;
1169
if (YUI.Env.aliases[t]) {
1170
t = YUI.Env.aliases[t];
1172
if (!Y.Lang.isArray(t)) {
1176
for (i = 0; i < t.length; i++) {
1178
when = o.condition.when;
1179
conditions[trigger] = conditions[trigger] || {};
1180
conditions[trigger][name] = o.condition;
1181
// the 'when' attribute can be 'before', 'after', or 'instead'
1182
// the default is after.
1183
if (when && when != 'after') {
1184
if (when == 'instead') { // replace the trigger
1185
o.supersedes = o.supersedes || [];
1186
o.supersedes.push(trigger);
1187
} else { // before the trigger
1188
// the trigger requires the conditional mod,
1189
// so it should appear before the conditional
1190
// mod if we do not intersede.
1192
} else { // after the trigger
1193
o.after = o.after || [];
1194
o.after.push(trigger);
1200
o.after_map = YArray.hash(o.after);
1203
// this.dirty = true;
1206
ret = o.configFn(o);
1207
if (ret === false) {
1208
delete this.moduleInfo[name];
1217
* Add a requirement for one or more module
1219
* @param {string[] | string*} what the modules to load.
1221
require: function(what) {
1222
var a = (typeof what === 'string') ? YArray(arguments) : what;
1224
this.required = Y.merge(this.required, YArray.hash(this.filterRequires(a)));
1226
this._explodeRollups();
1229
* Grab all the items that were asked for, check to see if the Loader
1230
* meta-data contains a "use" array. If it doesm remove the asked item and replace it with
1231
* the content of the "use".
1232
* This will make asking for: "dd"
1233
* Actually ask for: "dd-ddm-base,dd-ddm,dd-ddm-drop,dd-drag,dd-proxy,dd-constrain,dd-drop,dd-scroll,dd-drop-plugin"
1235
* @method _explodeRollups
1237
_explodeRollups: function() {
1240
if (!self.allowRollup) {
1241
oeach(r, function(v, name) {
1242
m = self.getModule(name);
1245
YArray.each(m.use, function(v) {
1246
m = self.getModule(v);
1249
YArray.each(m.use, function(v) {
1263
* Explodes the required array to remove aliases and replace them with real modules
1264
* @method filterRequires
1265
* @param {Array} r The original requires array
1266
* @return {Array} The new array of exploded requirements
1268
filterRequires: function(r) {
1270
if (!Y.Lang.isArray(r)) {
1274
var c = [], i, mod, o, m;
1276
for (i = 0; i < r.length; i++) {
1277
mod = this.getModule(r[i]);
1278
if (mod && mod.use) {
1279
for (o = 0; o < mod.use.length; o++) {
1280
//Must walk the other modules in case a module is a rollup of rollups (datatype)
1281
m = this.getModule(mod.use[o]);
1283
c = Y.Array.dedupe([].concat(c, this.filterRequires(m.use)));
1297
* Returns an object containing properties for all modules required
1298
* in order to load the requested module
1299
* @method getRequires
1300
* @param {object} mod The module definition from moduleInfo.
1301
* @return {array} the expanded requirement list.
1303
getRequires: function(mod) {
1305
if (!mod || mod._parsed) {
1306
// Y.log('returning no reqs for ' + mod.name);
1307
return NO_REQUIREMENTS;
1310
var i, m, j, add, packName, lang, testresults = this.testresults,
1311
name = mod.name, cond, go,
1312
adddef = ON_PAGE[name] && ON_PAGE[name].details,
1315
o, skinmod, skindef, skinpar, skinname,
1316
intl = mod.lang || mod.intl,
1317
info = this.moduleInfo,
1318
ftests = Y.Features && Y.Features.tests.load,
1321
// console.log(name);
1323
// pattern match leaves module stub that needs to be filled out
1324
if (mod.temp && adddef) {
1326
mod = this.addModule(adddef, name);
1327
mod.group = old_mod.group;
1328
mod.pkg = old_mod.pkg;
1329
delete mod.expanded;
1332
// console.log('cache: ' + mod.langCache + ' == ' + this.lang);
1334
// if (mod.expanded && (!mod.langCache || mod.langCache == this.lang)) {
1335
if (mod.expanded && (!this.lang || mod.langCache === this.lang)) {
1336
//Y.log('Already expanded ' + name + ', ' + mod.expanded);
1337
return mod.expanded;
1344
r = this.filterRequires(mod.requires);
1346
//If a module has a lang attribute, auto add the intl requirement.
1351
o = this.filterRequires(mod.optional);
1353
// Y.log("getRequires: " + name + " (dirty:" + this.dirty +
1354
// ", expanded:" + mod.expanded + ")");
1357
mod.langCache = this.lang;
1359
for (i = 0; i < r.length; i++) {
1360
//Y.log(name + ' requiring ' + r[i], 'info', 'loader');
1364
m = this.getModule(r[i]);
1366
add = this.getRequires(m);
1367
intl = intl || (m.expanded_map &&
1368
(INTL in m.expanded_map));
1369
for (j = 0; j < add.length; j++) {
1376
// get the requirements from superseded modules, if any
1377
r = this.filterRequires(mod.supersedes);
1379
for (i = 0; i < r.length; i++) {
1381
// if this module has submodules, the requirements list is
1382
// expanded to include the submodules. This is so we can
1383
// prevent dups when a submodule is already loaded and the
1384
// parent is requested.
1385
if (mod.submodules) {
1390
m = this.getModule(r[i]);
1393
add = this.getRequires(m);
1394
intl = intl || (m.expanded_map &&
1395
(INTL in m.expanded_map));
1396
for (j = 0; j < add.length; j++) {
1404
if (o && this.loadOptional) {
1405
for (i = 0; i < o.length; i++) {
1411
add = this.getRequires(m);
1412
intl = intl || (m.expanded_map &&
1413
(INTL in m.expanded_map));
1414
for (j = 0; j < add.length; j++) {
1422
cond = this.conditions[name];
1425
if (testresults && ftests) {
1426
oeach(testresults, function(result, id) {
1427
var condmod = ftests[id].name;
1428
if (!hash[condmod] && ftests[id].trigger == name) {
1429
if (result && ftests[id]) {
1430
hash[condmod] = true;
1436
oeach(cond, function(def, condmod) {
1437
if (!hash[condmod]) {
1438
go = def && ((def.ua && Y.UA[def.ua]) ||
1439
(def.test && def.test(Y, r)));
1441
hash[condmod] = true;
1443
m = this.getModule(condmod);
1444
// Y.log('conditional', m);
1446
add = this.getRequires(m);
1447
for (j = 0; j < add.length; j++) {
1457
// Create skin modules
1458
if (mod.skinnable) {
1459
skindef = this.skin.overrides;
1460
oeach(YUI.Env.aliases, function(o, n) {
1461
if (Y.Array.indexOf(o, name) > -1) {
1465
if (skindef && (skindef[name] || (skinpar && skindef[skinpar]))) {
1467
if (skindef[skinpar]) {
1470
for (i = 0; i < skindef[skinname].length; i++) {
1471
skinmod = this._addSkin(skindef[skinname][i], name);
1475
skinmod = this._addSkin(this.skin.defaultSkin, name);
1480
mod._parsed = false;
1484
if (mod.lang && !mod.langPack && Y.Intl) {
1485
lang = Y.Intl.lookupBestLang(this.lang || ROOT_LANG, mod.lang);
1486
//Y.log('Best lang: ' + lang + ', this.lang: ' + this.lang + ', mod.lang: ' + mod.lang);
1487
packName = this.getLangPackName(lang, name);
1489
d.unshift(packName);
1495
mod.expanded_map = YArray.hash(d);
1497
mod.expanded = YObject.keys(mod.expanded_map);
1499
return mod.expanded;
1504
* Returns a hash of module names the supplied module satisfies.
1505
* @method getProvides
1506
* @param {string} name The name of the module.
1507
* @return {object} what this module provides.
1509
getProvides: function(name) {
1510
var m = this.getModule(name), o, s;
1511
// supmap = this.provides;
1517
if (m && !m.provides) {
1522
YArray.each(s, function(v) {
1523
Y.mix(o, this.getProvides(v));
1536
* Calculates the dependency tree, the result is stored in the sorted
1539
* @param {object} o optional options object.
1540
* @param {string} type optional argument to prune modules.
1542
calculate: function(o, type) {
1543
if (o || type || this.dirty) {
1555
if (this.allowRollup) {
1558
this._explodeRollups();
1565
* Creates a "psuedo" package for languages provided in the lang array
1566
* @method _addLangPack
1567
* @param {String} lang The language to create
1568
* @param {Object} m The module definition to create the language pack around
1569
* @param {String} packName The name of the package (e.g: lang/datatype-date-en-US)
1570
* @return {Object} The module definition
1572
_addLangPack: function(lang, m, packName) {
1575
existing = this.moduleInfo[packName];
1579
packPath = _path((m.pkg || name), packName, JS, true);
1581
this.addModule({ path: packPath,
1586
supersedes: [] }, packName);
1589
Y.Env.lang = Y.Env.lang || {};
1590
Y.Env.lang[lang] = Y.Env.lang[lang] || {};
1591
Y.Env.lang[lang][name] = true;
1595
return this.moduleInfo[packName];
1599
* Investigates the current YUI configuration on the page. By default,
1600
* modules already detected will not be loaded again unless a force
1601
* option is encountered. Called by calculate()
1605
_setup: function() {
1606
var info = this.moduleInfo, name, i, j, m, l,
1609
for (name in info) {
1610
if (info.hasOwnProperty(name)) {
1615
//m.requires = YObject.keys(YArray.hash(m.requires));
1616
m.requires = YArray.dedupe(m.requires);
1618
// Create lang pack modules
1619
if (m.lang && m.lang.length) {
1620
// Setup root package if the module has lang defined,
1621
// it needs to provide a root language pack
1622
packName = this.getLangPackName(ROOT_LANG, name);
1623
this._addLangPack(null, m, packName);
1631
//l = Y.merge(this.inserted);
1634
// available modules
1635
if (!this.ignoreRegistered) {
1636
Y.mix(l, GLOBAL_ENV.mods);
1639
// add the ignore list to the list of loaded packages
1641
Y.mix(l, YArray.hash(this.ignore));
1644
// expand the list to include superseded modules
1646
if (l.hasOwnProperty(j)) {
1647
Y.mix(l, this.getProvides(j));
1651
// remove modules on the force list from the loaded list
1653
for (i = 0; i < this.force.length; i++) {
1654
if (this.force[i] in l) {
1655
delete l[this.force[i]];
1660
Y.mix(this.loaded, l);
1666
* Builds a module name for a language pack
1667
* @method getLangPackName
1668
* @param {string} lang the language code.
1669
* @param {string} mname the module to build it for.
1670
* @return {string} the language pack module name.
1672
getLangPackName: function(lang, mname) {
1673
return ('lang/' + mname + ((lang) ? '_' + lang : ''));
1676
* Inspects the required modules list looking for additional
1677
* dependencies. Expands the required list to include all
1678
* required modules. Called by calculate()
1682
_explode: function() {
1683
var r = this.required, m, reqs, done = {},
1686
// the setup phase is over, all modules have been created
1689
self._explodeRollups();
1692
oeach(r, function(v, name) {
1695
m = self.getModule(name);
1697
var expound = m.expound;
1700
r[expound] = self.getModule(expound);
1701
reqs = self.getRequires(r[expound]);
1702
Y.mix(r, YArray.hash(reqs));
1705
reqs = self.getRequires(m);
1706
Y.mix(r, YArray.hash(reqs));
1711
// Y.log('After explode: ' + YObject.keys(r));
1714
* Get's the loader meta data for the requested module
1716
* @param {String} mname The module name to get
1717
* @return {Object} The module metadata
1719
getModule: function(mname) {
1720
//TODO: Remove name check - it's a quick hack to fix pattern WIP
1725
var p, found, pname,
1726
m = this.moduleInfo[mname],
1727
patterns = this.patterns;
1729
// check the patterns library to see if we should automatically add
1730
// the module with defaults
1732
// Y.log('testing patterns ' + YObject.keys(patterns));
1733
for (pname in patterns) {
1734
if (patterns.hasOwnProperty(pname)) {
1735
// Y.log('testing pattern ' + i);
1736
p = patterns[pname];
1738
// use the metadata supplied for the pattern
1739
// as the module definition.
1740
if (mname.indexOf(pname) > -1) {
1749
// Y.log('executing pattern action: ' + pname);
1750
p.action.call(this, mname, pname);
1752
Y.log('Undefined module: ' + mname + ', matched a pattern: ' +
1753
pname, 'info', 'loader');
1754
// ext true or false?
1755
m = this.addModule(Y.merge(found), mname);
1764
// impl in rollup submodule
1765
_rollup: function() { },
1768
* Remove superceded modules and loaded modules. Called by
1769
* calculate() after we have the mega list of all dependencies
1771
* @return {object} the reduced dependency hash.
1774
_reduce: function(r) {
1776
r = r || this.required;
1778
var i, j, s, m, type = this.loadType,
1779
ignore = this.ignore ? YArray.hash(this.ignore) : false;
1782
if (r.hasOwnProperty(i)) {
1783
m = this.getModule(i);
1784
// remove if already loaded
1785
if (((this.loaded[i] || ON_PAGE[i]) &&
1786
!this.forceMap[i] && !this.ignoreRegistered) ||
1787
(type && m && m.type != type)) {
1790
if (ignore && ignore[i]) {
1793
// remove anything this module supersedes
1794
s = m && m.supersedes;
1796
for (j = 0; j < s.length; j++) {
1808
* Handles the queue when a module has been loaded for all cases
1811
* @param {String} msg The message from Loader
1812
* @param {Boolean} success A boolean denoting success or failure
1814
_finish: function(msg, success) {
1815
Y.log('loader finishing: ' + msg + ', ' + Y.id + ', ' +
1816
this.data, 'info', 'loader');
1818
_queue.running = false;
1820
var onEnd = this.onEnd;
1822
onEnd.call(this.context, {
1831
* The default Loader onSuccess handler, calls this.onSuccess with a payload
1832
* @method _onSuccess
1835
_onSuccess: function() {
1836
var self = this, skipped = Y.merge(self.skipped), fn,
1837
failed = [], rreg = self.requireRegistration,
1840
oeach(skipped, function(k) {
1841
delete self.inserted[k];
1846
oeach(self.inserted, function(v, k) {
1847
var mod = self.getModule(k);
1848
if (mod && rreg && mod.type == JS && !(k in YUI.Env.mods)) {
1851
Y.mix(self.loaded, self.getProvides(k));
1855
fn = self.onSuccess;
1856
msg = (failed.length) ? 'notregistered' : 'success';
1857
success = !(failed.length);
1859
fn.call(self.context, {
1867
self._finish(msg, success);
1870
* The default Loader onFailure handler, calls this.onFailure with a payload
1871
* @method _onFailure
1874
_onFailure: function(o) {
1875
Y.log('load error: ' + o.msg + ', ' + Y.id, 'error', 'loader');
1876
var f = this.onFailure, msg = 'failure: ' + o.msg;
1878
f.call(this.context, {
1884
this._finish(msg, false);
1888
* The default Loader onTimeout handler, calls this.onTimeout with a payload
1889
* @method _onTimeout
1892
_onTimeout: function() {
1893
Y.log('loader timeout: ' + Y.id, 'error', 'loader');
1894
var f = this.onTimeout;
1896
f.call(this.context, {
1902
this._finish('timeout', false);
1906
* Sorts the dependency tree. The last step of calculate()
1912
// create an indexed list
1913
var s = YObject.keys(this.required),
1914
// loaded = this.loaded,
1916
p = 0, l, a, b, j, k, moved, doneKey;
1918
// keep going until we make a pass without moving anything
1924
// start the loop after items that are already sorted
1925
for (j = p; j < l; j++) {
1927
// check the next module on the list to see if its
1928
// dependencies have been met
1931
// check everything below current item and move if we
1932
// find a requirement for the current item
1933
for (k = j + 1; k < l; k++) {
1936
if (!done[doneKey] && this._requires(a, s[k])) {
1938
// extract the dependency so we can move it up
1941
// insert the dependency above the item that
1943
s.splice(j, 0, b[0]);
1945
// only swap two dependencies once to short circut
1946
// circular dependencies
1947
done[doneKey] = true;
1956
// jump out of loop if we moved something
1959
// this item is sorted, move our pointer and keep going
1965
// when we make it here and moved is false, we are
1980
partial: function(partial, o, type) {
1981
this.sorted = partial;
1982
this.insert(o, type, true);
1985
* Handles the actual insertion of script/link tags
1987
* @param {Object} source The YUI instance the request came from
1988
* @param {Object} o The metadata to include
1989
* @param {String} type JS or CSS
1990
* @param {Boolean} [skipcalc=false] Do a Loader.calculate on the meta
1992
_insert: function(source, o, type, skipcalc) {
1994
// Y.log('private _insert() ' + (type || '') + ', ' + Y.id, "info", "loader");
1996
// restore the state at the time of the request
1998
this._config(source);
2001
// build the dependency list
2002
// don't include type so we can process CSS and script in
2003
// one pass when the type is not specified.
2008
this.loadType = type;
2014
// Y.log("trying to load css first");
2015
this._internalCallback = function() {
2017
var f = self.onCSS, n, p, sib;
2019
// IE hack for style overrides that are not being applied
2020
if (this.insertBefore && Y.UA.ie) {
2021
n = Y.config.doc.getElementById(this.insertBefore);
2023
sib = n.nextSibling;
2026
p.insertBefore(n, sib);
2033
f.call(self.context, Y);
2035
self._internalCallback = null;
2037
self._insert(null, null, JS);
2040
this._insert(null, null, CSS);
2045
// set a flag to indicate the load has started
2046
this._loading = true;
2048
// flag to indicate we are done with the combo service
2049
// and any additional files will need to be loaded
2051
this._combineComplete = {};
2058
* Once a loader operation is completely finished, process any additional queued items.
2062
_continue: function() {
2063
if (!(_queue.running) && _queue.size() > 0) {
2064
_queue.running = true;
2070
* inserts the requested modules and their dependencies.
2071
* <code>type</code> can be "js" or "css". Both script and
2072
* css are inserted if type is not provided.
2074
* @param {object} o optional options object.
2075
* @param {string} type the type of dependency to insert.
2077
insert: function(o, type, skipsort) {
2078
// Y.log('public insert() ' + (type || '') + ', ' +
2079
// Y.Object.keys(this.required), "info", "loader");
2080
var self = this, copy = Y.merge(this);
2081
delete copy.require;
2083
_queue.add(function() {
2084
self._insert(copy, o, type, skipsort);
2090
* Executed every time a module is loaded, and if we are in a load
2091
* cycle, we attempt to load the next script. Public so that it
2092
* is possible to call this if using a method other than
2093
* Y.register to determine when scripts are fully loaded
2095
* @param {string} mname optional the name of the module that has
2096
* been loaded (which is usually why it is time to load the next
2099
loadNext: function(mname) {
2100
// It is possible that this function is executed due to something
2101
// else on the page loading a YUI module. Only react when we
2102
// are actively loading something
2103
if (!this._loading) {
2107
var s, len, i, m, url, fn, msg, attr, group, groupName, j, frag,
2108
comboSource, comboSources, mods, combining, urls, comboBase,
2110
type = self.loadType,
2111
handleSuccess = function(o) {
2112
self.loadNext(o.data);
2114
handleCombo = function(o) {
2115
self._combineComplete[type] = true;
2116
var i, len = combining.length;
2118
for (i = 0; i < len; i++) {
2119
self.inserted[combining[i]] = true;
2125
if (self.combine && (!self._combineComplete[type])) {
2129
self._combining = combining;
2133
// the default combo base
2134
comboBase = self.comboBase;
2141
for (i = 0; i < len; i++) {
2142
comboSource = comboBase;
2143
m = self.getModule(s[i]);
2144
groupName = m && m.group;
2147
group = self.groups[groupName];
2149
if (!group.combine) {
2154
if (group.comboBase) {
2155
comboSource = group.comboBase;
2158
if ("root" in group && L.isValue(group.root)) {
2159
m.root = group.root;
2164
comboSources[comboSource] = comboSources[comboSource] || [];
2165
comboSources[comboSource].push(m);
2168
for (j in comboSources) {
2169
if (comboSources.hasOwnProperty(j)) {
2171
mods = comboSources[j];
2174
for (i = 0; i < len; i++) {
2175
// m = self.getModule(s[i]);
2178
// Do not try to combine non-yui JS unless combo def
2180
if (m && (m.type === type) && (m.combine || !m.ext)) {
2182
frag = ((L.isValue(m.root)) ? m.root : self.root) + m.path;
2183
frag = self._filter(frag, m.name);
2184
if ((url !== j) && (i <= (len - 1)) &&
2185
((frag.length + url.length) > self.maxURLLength)) {
2186
//Hack until this is rewritten to use an array and not string concat:
2187
if (url.substr(url.length - 1, 1) === self.comboSep) {
2188
url = url.substr(0, (url.length - 1));
2190
urls.push(self._filter(url));
2195
if (i < (len - 1)) {
2196
url += self.comboSep;
2199
combining.push(m.name);
2204
if (combining.length && (url != j)) {
2205
//Hack until this is rewritten to use an array and not string concat:
2206
if (url.substr(url.length - 1, 1) === self.comboSep) {
2207
url = url.substr(0, (url.length - 1));
2209
urls.push(self._filter(url));
2214
if (combining.length) {
2216
Y.log('Attempting to use combo: ' + combining, 'info', 'loader');
2218
// if (m.type === CSS) {
2221
attr = self.cssAttributes;
2224
attr = self.jsAttributes;
2228
data: self._loading,
2229
onSuccess: handleCombo,
2230
onFailure: self._onFailure,
2231
onTimeout: self._onTimeout,
2232
insertBefore: self.insertBefore,
2233
charset: self.charset,
2235
timeout: self.timeout,
2243
self._combineComplete[type] = true;
2249
// if the module that was just loaded isn't what we were expecting,
2251
if (mname !== self._loading) {
2255
// Y.log("loadNext executing, just loaded " + mname + ", " +
2256
// Y.id, "info", "loader");
2258
// The global handler that is called when each module is loaded
2259
// will pass that module name to this function. Storing this
2260
// data to avoid loading the same module multiple times
2261
// centralize this in the callback
2262
self.inserted[mname] = true;
2263
// self.loaded[mname] = true;
2265
// provided = self.getProvides(mname);
2266
// Y.mix(self.loaded, provided);
2267
// Y.mix(self.inserted, provided);
2269
if (self.onProgress) {
2270
self.onProgress.call(self.context, {
2280
for (i = 0; i < len; i = i + 1) {
2281
// this.inserted keeps track of what the loader has loaded.
2282
// move on if this item is done.
2283
if (s[i] in self.inserted) {
2287
// Because rollups will cause multiple load notifications
2288
// from Y, loadNext may be called multiple times for
2289
// the same module when loading a rollup. We can safely
2290
// skip the subsequent requests
2291
if (s[i] === self._loading) {
2292
Y.log('still loading ' + s[i] + ', waiting', 'info', 'loader');
2296
// log("inserting " + s[i]);
2297
m = self.getModule(s[i]);
2300
if (!self.skipped[s[i]]) {
2301
msg = 'Undefined module ' + s[i] + ' skipped';
2302
Y.log(msg, 'warn', 'loader');
2303
// self.inserted[s[i]] = true;
2304
self.skipped[s[i]] = true;
2310
group = (m.group && self.groups[m.group]) || NOT_FOUND;
2312
// The load type is stored to offer the possibility to load
2313
// the css separately from the script.
2314
if (!type || type === m.type) {
2315
self._loading = s[i];
2316
Y.log('attempting to load ' + s[i] + ', ' + self.base, 'info', 'loader');
2318
if (m.type === CSS) {
2320
attr = self.cssAttributes;
2323
attr = self.jsAttributes;
2326
url = (m.fullpath) ? self._filter(m.fullpath, s[i]) :
2327
self._url(m.path, s[i], group.base || m.base);
2331
onSuccess: handleSuccess,
2332
insertBefore: self.insertBefore,
2333
charset: self.charset,
2335
onFailure: self._onFailure,
2336
onTimeout: self._onTimeout,
2337
timeout: self.timeout,
2347
self._loading = null;
2349
fn = self._internalCallback;
2351
// internal callback for loading css first
2353
// Y.log('loader internal');
2354
self._internalCallback = null;
2357
// Y.log('loader complete');
2363
* Apply filter defined for this instance to a url/path
2365
* @param {string} u the string to filter.
2366
* @param {string} name the name of the module, if we are processing
2367
* a single module as opposed to a combined url.
2368
* @return {string} the filtered string.
2371
_filter: function(u, name) {
2372
var f = this.filter,
2373
hasFilter = name && (name in this.filters),
2374
modFilter = hasFilter && this.filters[name],
2375
groupName = this.moduleInfo[name] ? this.moduleInfo[name].group:null;
2376
if (groupName && this.groups[groupName].filter) {
2377
modFilter = this.groups[groupName].filter;
2383
f = (L.isString(modFilter)) ?
2384
this.FILTER_DEFS[modFilter.toUpperCase()] || null :
2388
u = u.replace(new RegExp(f.searchExp, 'g'), f.replaceStr);
2396
* Generates the full url for a module
2398
* @param {string} path the path fragment.
2399
* @param {String} name The name of the module
2400
* @pamra {String} [base=self.base] The base url to use
2401
* @return {string} the full url.
2404
_url: function(path, name, base) {
2405
return this._filter((base || this.base || '') + path, name);
2408
* Returns an Object hash of file arrays built from `loader.sorted` or from an arbitrary list of sorted modules.
2410
* @param {Boolean} [calc=false] Perform a loader.calculate() before anything else
2411
* @param {Array} [s=loader.sorted] An override for the loader.sorted array
2412
* @return {Object} Object hash (js and css) of two arrays of file lists
2413
* @example This method can be used as an off-line dep calculator
2416
* var loader = new Y.Loader({
2421
* require: ['node', 'dd', 'console']
2423
* var out = loader.resolve(true);
2426
resolve: function(calc, s) {
2427
var self = this, i, m, url, out = { js: [], css: [] };
2432
s = s || self.sorted;
2434
for (i = 0; i < s.length; i++) {
2435
m = self.getModule(s[i]);
2438
url = self._filter((self.root + m.path), m.name, self.root);
2440
url = self._filter(m.fullpath, m.name, '') || self._url(m.path, m.name);
2442
out[m.type].push(url);
2446
out.js = [self.comboBase + out.js.join(self.comboSep)];
2447
out.css = [self.comboBase + out.css.join(self.comboSep)];
2453
* Returns an Object hash of hashes built from `loader.sorted` or from an arbitrary list of sorted modules.
2456
* @param {Boolean} [calc=false] Perform a loader.calculate() before anything else
2457
* @param {Array} [s=loader.sorted] An override for the loader.sorted array
2458
* @return {Object} Object hash (js and css) of two object hashes of file lists, with the module name as the key
2459
* @example This method can be used as an off-line dep calculator
2462
* var loader = new Y.Loader({
2467
* require: ['node', 'dd', 'console']
2469
* var out = loader.hash(true);
2472
hash: function(calc, s) {
2473
var self = this, i, m, url, out = { js: {}, css: {} };
2478
s = s || self.sorted;
2480
for (i = 0; i < s.length; i++) {
2481
m = self.getModule(s[i]);
2483
url = self._filter(m.fullpath, m.name, '') || self._url(m.path, m.name);
2484
out[m.type][m.name] = url;
2494
}, '3.4.1' ,{requires:['get']});