2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.com/yui/license.html
8
YUI.add('loader-base', function(Y) {
13
* @submodule loader-base
16
if (!YUI.Env[Y.version]) {
19
var VERSION = Y.version,
22
ROOT = VERSION + BUILD,
23
CDN_BASE = Y.Env.base,
24
GALLERY_VERSION = 'gallery-2010.09.01-19-12',
25
// GALLERY_ROOT = GALLERY_VERSION + BUILD,
28
YUI2_VERSION = '2.8.1',
29
// YUI2_ROOT = TNT + '.' + TNT_VERSION + '/' + YUI2_VERSION + BUILD,
30
COMBO_BASE = CDN_BASE + 'combo?',
31
META = { version: VERSION,
34
comboBase: COMBO_BASE,
35
skin: { defaultSkin: 'sam',
36
base: 'assets/skins/',
43
'cssfonts-context' ] },
45
// modules: { / METAGEN / },
48
yui2Update = function(tnt, yui2) {
49
var root = TNT + '.' +
50
(tnt || TNT_VERSION) + '/' + (yui2 || YUI2_VERSION) + BUILD;
51
groups.yui2.base = CDN_BASE + root;
52
groups.yui2.root = root;
54
galleryUpdate = function(tag) {
55
var root = (tag || GALLERY_VERSION) + BUILD;
56
groups.gallery.base = CDN_BASE + root;
57
groups.gallery.root = root;
63
// base: CDN_BASE + GALLERY_ROOT,
66
// root: GALLERY_ROOT,
67
comboBase: COMBO_BASE,
68
update: galleryUpdate,
69
patterns: { 'gallery-': { },
70
'gallerycss-': { type: 'css' } }
74
// base: CDN_BASE + YUI2_ROOT,
78
comboBase: COMBO_BASE,
82
configFn: function(me) {
83
if(/-skin|reset|fonts|grids|base/.test(me.name)) {
85
me.path = me.path.replace(/\.js/, '.css');
86
// this makes skins in builds earlier than 2.6.0 work as long as combine is false
87
me.path = me.path.replace(/\/yui2-skin/, '/assets/skins/sam/yui2-skin');
97
YUI.Env[VERSION] = META;
103
* Loader dynamically loads script and css files. It includes the dependency
104
* info for the version of the library in use, and will automatically pull in
105
* dependencies for the modules requested. It supports rollup files and will
106
* automatically use these when appropriate in order to minimize the number of
107
* http connections required to load all of the dependencies. It can load the
108
* files from the Yahoo! CDN, and it can utilize the combo service provided on
109
* this network to reduce the number of http connections required to download
113
* @submodule loader-base
117
* Loader dynamically loads script and css files. It includes the dependency
118
* info for the version of the library in use, and will automatically pull in
119
* dependencies for the modules requested. It supports rollup files and will
120
* automatically use these when appropriate in order to minimize the number of
121
* http connections required to load all of the dependencies. It can load the
122
* files from the Yahoo! CDN, and it can utilize the combo service provided on
123
* this network to reduce the number of http connections required to download
126
* While the loader can be instantiated by the end user, it normally is not.
127
* @see YUI.use for the normal use case. The use function automatically will
128
* pull in missing dependencies.
132
* @param o an optional set of configuration options. Valid options:
137
* The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?</li>
139
* The root path to prepend to module names for the combo service. Ex: 2.5.2/build/</li>
142
* A filter to apply to result urls. This filter will modify the default
143
* path for all modules. The default path for the YUI library is the
144
* minified version of the files (e.g., event-min.js). The filter property
145
* can be a predefined filter or a custom filter. The valid predefined
149
* <dd>Selects the debug versions of the library (e.g., event-debug.js).
150
* This option will automatically include the Logger widget</dd>
152
* <dd>Selects the non-minified version of the library (e.g., event.js).</dd>
154
* You can also define a custom filter, which must be an object literal
155
* containing a search expression and a replace string:
158
* 'searchExp': "-min\\.js",
159
* 'replaceStr': "-debug.js"
164
* <li>filters: per-component filter specification. If specified for a given component, this overrides the filter config</li>
166
* Use the YUI combo service to reduce the number of http connections required to load your dependencies</li>
168
* A list of modules that should never be dynamically loaded</li>
170
* A list of modules that should always be loaded when required, even if already present on the page</li>
172
* Node or id for a node that should be used as the insertion point for new nodes</li>
174
* charset for dynamic nodes (deprecated, use jsAttributes or cssAttributes)</li>
175
* <li>jsAttributes: object literal containing attributes to add to script nodes</li>
176
* <li>cssAttributes: object literal containing attributes to add to link nodes</li>
178
* The number of milliseconds before a timeout occurs when dynamically loading nodes. If
179
* not set, there is no timeout</li>
181
* execution context for all callbacks</li>
183
* callback for the 'success' event</li>
184
* <li>onFailure: callback for the 'failure' event</li>
185
* <li>onCSS: callback for the 'CSSComplete' event. When loading YUI components with CSS
186
* the CSS is loaded first, then the script. This provides a moment you can tie into to improve
187
* the presentation of the page while the script is loading.</li>
189
* callback for the 'timeout' event</li>
191
* callback executed each time a script or css file is loaded</li>
193
* A list of module definitions. See Loader.addModule for the supported module metadata</li>
195
* A list of group definitions. Each group can contain specific definitions for base, comboBase,
196
* combine, and accepts a list of modules. See above for the description of these properties.</li>
197
* <li>2in3: the version of the YUI 2 in 3 wrapper to use. The intrinsic support for YUI 2 modules
198
* in YUI 3 relies on versions of the YUI 2 components inside YUI 3 module wrappers. These wrappers
199
* change over time to accomodate the issues that arise from running YUI 2 in a YUI 3 sandbox.</li>
200
* <li>yui2: when using the 2in3 project, you can select the version of YUI 2 to use. Valid values
201
* are 2.2.2, 2.3.1, 2.4.1, 2.5.2, 2.6.0, 2.7.0, 2.8.0, and 2.8.1 [default] -- plus all versions
202
* of YUI 2 going forward.</li>
207
NO_REQUIREMENTS = [],
208
MAX_URL_LENGTH = (Y.UA.ie) ? 2048 : 8192,
209
GLOBAL_ENV = YUI.Env,
210
GLOBAL_LOADED = GLOBAL_ENV._loaded,
217
oeach = YObject.each,
219
_queue = GLOBAL_ENV._loaderQueue,
220
META = GLOBAL_ENV[VERSION],
221
SKIN_PREFIX = "skin-",
223
ON_PAGE = GLOBAL_ENV.mods,
226
_path = function(dir, file, type, nomin) {
227
var path = dir + '/' + file;
231
path += '.' + (type || CSS);
238
Y.Loader = function(o) {
240
var defaults = META.modules,
243
modulekey = META.md5;
246
* Internal callback to handle multiple internal insert() calls
247
* so that css is inserted prior to js
248
* @property _internalCallback
251
// self._internalCallback = null;
254
* Callback that will be executed when the loader is finished
259
// self.onSuccess = null;
262
* Callback that will be executed if there is a failure
266
// self.onFailure = null;
269
* Callback for the 'CSSComplete' event. When loading YUI components with CSS
270
* the CSS is loaded first, then the script. This provides a moment you can tie into to improve
271
* the presentation of the page while the script is loading.
275
// self.onCSS = null;
278
* Callback executed each time a script or css file is loaded
282
// self.onProgress = null;
285
* Callback that will be executed if a timeout occurs
289
// self.onTimeout = null;
292
* The execution context for all callbacks
294
* @default {YUI} the YUI instance
299
* Data that is passed to all callbacks
305
* Node reference or id where new nodes should be inserted before
306
* @property insertBefore
307
* @type string|HTMLElement
309
// self.insertBefore = null;
312
* The charset attribute for inserted nodes
315
* @deprecated, use cssAttributes or jsAttributes
317
// self.charset = null;
320
* An object literal containing attributes to add to link nodes
321
* @property cssAttributes
324
// self.cssAttributes = null;
327
* An object literal containing attributes to add to script nodes
328
* @property jsAttributes
331
// self.jsAttributes = null;
334
* The base directory.
337
* @default http://yui.yahooapis.com/[YUI VERSION]/build/
339
self.base = Y.Env.meta.base;
342
* Base path for the combo service
343
* @property comboBase
345
* @default http://yui.yahooapis.com/combo?
347
self.comboBase = Y.Env.meta.comboBase;
350
* Base path for language packs.
352
// self.langBase = Y.Env.meta.langBase;
356
* If configured, the loader will attempt to use the combo
357
* service for YUI resources and configured external resources.
360
* @default true if a base dir isn't in the config
362
self.combine = o.base && (o.base.indexOf( self.comboBase.substr(0, 20)) > -1);
365
* Max url length for combo urls. The default is 2048 for
366
* internet explorer, and 8192 otherwise. This is the URL
367
* limit for the Yahoo! hosted combo servers. If consuming
368
* a different combo service that has a different URL limit
369
* it is possible to override this default by supplying
370
* the maxURLLength config option. The config option will
371
* only take effect if lower than the default.
375
* Other A-Grade Browsers: Higher that what is typically supported
376
* 'capable' mobile browsers: @TODO
381
* @property maxURLLength
384
self.maxURLLength = MAX_URL_LENGTH;
387
* Ignore modules registered on the YUI global
388
* @property ignoreRegistered
391
// self.ignoreRegistered = false;
394
* Root path to prepend to module path for the combo
398
* @default [YUI VERSION]/build/
400
self.root = Y.Env.meta.root;
403
* Timeout value in milliseconds. If set, self value will be used by
404
* the get utility. the timeout event will fire if
412
* A list of modules that should not be loaded, even if
413
* they turn up in the dependency tree
417
// self.ignore = null;
420
* A list of modules that should always be loaded, even
421
* if they have already been inserted into the page.
425
// self.force = null;
430
* Should we allow rollups
431
* @property allowRollup
435
self.allowRollup = true;
438
* A filter to apply to result urls. This filter will modify the default
439
* path for all modules. The default path for the YUI library is the
440
* minified version of the files (e.g., event-min.js). The filter property
441
* can be a predefined filter or a custom filter. The valid predefined
445
* <dd>Selects the debug versions of the library (e.g., event-debug.js).
446
* This option will automatically include the Logger widget</dd>
448
* <dd>Selects the non-minified version of the library (e.g., event.js).</dd>
450
* You can also define a custom filter, which must be an object literal
451
* containing a search expression and a replace string:
454
* 'searchExp': "-min\\.js",
455
* 'replaceStr': "-debug.js"
459
* @type string|{searchExp: string, replaceStr: string}
461
// self.filter = null;
464
* per-component filter specification. If specified for a given component, this
465
* overrides the filter config.
472
* The list of requested modules
474
* @type {string: boolean}
479
* If a module name is predefined when requested, it is checked againsts
480
* the patterns provided in this property. If there is a match, the
481
* module is added with the default configuration.
483
* At the moment only supporting module prefixes, but anticipate supporting
484
* at least regular expressions.
488
// self.patterns = Y.merge(Y.Env.meta.patterns);
492
* The library metadata
493
* @property moduleInfo
495
// self.moduleInfo = Y.merge(Y.Env.meta.moduleInfo);
496
self.moduleInfo = {};
498
self.groups = Y.merge(Y.Env.meta.groups);
501
* Provides the information used to skin the skinnable components.
502
* The following skin definition would result in 'skin1' and 'skin2'
503
* being loaded for calendar (if calendar was requested), and
504
* 'sam' for all other skinnable components:
509
* // The default skin, which is automatically applied if not
510
* // overriden by a component-specific skin definition.
511
* // Change this in to apply a different skin globally
512
* defaultSkin: 'sam',
514
* // This is combined with the loader base property to get
515
* // the default root directory for a skin. ex:
516
* // http://yui.yahooapis.com/2.3.0/build/assets/skins/sam/
517
* base: 'assets/skins/',
519
* // Any component-specific overrides can be specified here,
520
* // making it possible to load different skins for different
521
* // components. It is possible to load more than one skin
522
* // for a given component as well.
524
* calendar: ['skin1', 'skin2']
530
self.skin = Y.merge(Y.Env.meta.skin);
533
* Map of conditional modules
536
self.conditions = {};
538
// map of modules with a hash of modules that meet the requirement
539
// self.provides = {};
542
self._internal = true;
545
cache = GLOBAL_ENV._renderedMods;
548
oeach(cache, function(v, k) {
549
self.moduleInfo[k] = Y.merge(v);
552
cache = GLOBAL_ENV._conditions;
554
oeach(cache, function(v, k) {
555
self.conditions[k] = Y.merge(v);
559
oeach(defaults, self.addModule, self);
562
if (!GLOBAL_ENV._renderedMods) {
563
GLOBAL_ENV._renderedMods = Y.merge(self.moduleInfo);
564
GLOBAL_ENV._conditions = Y.merge(self.conditions);
569
self._internal = false;
574
* List of rollup files found in the library metadata
577
// self.rollups = null;
580
* Whether or not to load optional dependencies for
581
* the requested modules
582
* @property loadOptional
586
// self.loadOptional = false;
589
* All of the derived dependencies in sorted order, which
590
* will be populated when either calculate() or insert()
598
* Set when beginning to compute the dependency tree.
599
* Composed of what YUI reports to be loaded combined
600
* with what has been loaded by any instance on the page
601
* with the version number specified in the metadata.
603
* @type {string: boolean}
605
self.loaded = GLOBAL_LOADED[VERSION];
608
* A list of modules to attach to the YUI instance when complete.
609
* If not supplied, the sorted list of dependencies are applied.
610
* @property attaching
612
// self.attaching = null;
615
* Flag to indicate the dependency tree needs to be recomputed
616
* if insert is called again.
624
* List of modules inserted by the utility
626
* @type {string: boolean}
631
* List of skipped modules during insert() because the module
637
// Y.on('yui:load', self.loadNext, self);
641
* Cached sorted calculate results
649
Y.Loader.prototype = {
653
'searchExp': "-min\\.js",
657
'searchExp': "-min\\.js",
658
'replaceStr': "-debug.js"
662
_inspectPage: function() {
663
oeach(ON_PAGE, function(v, k) {
665
var m = this.moduleInfo[k],
666
req = v.details.requires,
667
mr = m && m.requires;
669
if (!m._inspected && req && mr.length != req.length) {
673
m = this.addModule(v.details, k);
680
// returns true if b is not loaded, and is required
681
// directly or by means of modules it supersedes.
682
_requires: function(mod1, mod2) {
684
var i, rm, after, after_map, s,
685
info = this.moduleInfo,
689
// if (loaded[mod2] || !m || !other) {
696
after_map = m.after_map;
698
// check if this module requires the other directly
699
// if (r && YArray.indexOf(r, mod2) > -1) {
700
if (rm && (mod2 in rm)) {
704
// check if this module should be sorted after the other
705
if (after_map && (mod2 in after_map)) {
707
} else if (after && YArray.indexOf(after, mod2) > -1) {
711
// check if this module requires one the other supersedes
712
s = info[mod2] && info[mod2].supersedes;
714
for (i=0; i<s.length; i++) {
715
if (this._requires(mod1, s[i])) {
721
// external css files should be sorted below yui css
722
if (m.ext && m.type == CSS && !other.ext && other.type == CSS) {
729
_config: function(o) {
730
var i, j, val, f, group, groupName, self = this;
731
// apply config values
734
if (o.hasOwnProperty(i)) {
736
if (i == 'require') {
738
} else if (i == 'skin') {
739
Y.mix(self.skin, o[i], true);
740
} else if (i == 'groups') {
742
if (val.hasOwnProperty(j)) {
743
// Y.log('group: ' + j);
746
self.addGroup(group, groupName);
750
} else if (i == 'modules') {
751
// add a hash of module definitions
752
oeach(val, self.addModule, self);
753
} else if (i == 'gallery') {
754
this.groups.gallery.update(val);
755
} else if (i == 'yui2' || i == '2in3') {
756
this.groups.yui2.update(o['2in3'], o.yui2);
757
} else if (i == 'maxURLLength') {
758
self[i] = Math.min(MAX_URL_LENGTH, val);
772
self.filter = self.FILTER_DEFS[f];
774
self.require('yui-log', 'dump');
781
* Returns the skin module name for the specified skin name. If a
782
* module name is supplied, the returned skin module name is
783
* specific to the module passed in.
785
* @param skin {string} the name of the skin
786
* @param mod {string} optional: the name of a module to skin
787
* @return {string} the full skin module name
789
formatSkin: function(skin, mod) {
790
var s = SKIN_PREFIX + skin;
799
* Adds the skin def to the module info
801
* @param skin {string} the name of the skin
802
* @param mod {string} the name of the module
803
* @param parent {string} parent module if this is a skin of a
804
* submodule or plugin
805
* @return {string} the module name for the skin
808
_addSkin: function(skin, mod, parent) {
810
info = this.moduleInfo,
812
ext = info[mod] && info[mod].ext;
814
// Add a module definition for the module-specific skin css
816
name = this.formatSkin(skin, mod);
819
pkg = mdef.pkg || mod;
825
after_map: YArray.hash(sinf.after),
826
path: (parent || pkg) + '/' + sinf.base + skin + '/' + mod + '.css',
830
// Y.log('adding skin ' + name + ', ' + parent + ', ' + pkg + ', ' + info[name].path);
837
/** Add a new module group
839
* <dt>name:</dt> <dd>required, the group name</dd>
840
* <dt>base:</dt> <dd>The base dir for this module group</dd>
841
* <dt>root:</dt> <dd>The root path to add to each combo resource path</dd>
842
* <dt>combine:</dt> <dd>combo handle</dd>
843
* <dt>comboBase:</dt> <dd>combo service base path</dd>
844
* <dt>modules:</dt> <dd>the group of modules</dd>
847
* @param o An object containing the module data
848
* @param name the module name (optional), required if not in the module data
849
* @return {boolean} true if the module was added, false if
850
* the object passed in did not provide all required attributes
852
addGroup: function(o, name) {
853
var mods = o.modules,
855
name = name || o.name;
857
self.groups[name] = o;
860
oeach(o.patterns, function(v, k) {
862
self.patterns[k] = v;
867
oeach(mods, function(v, k) {
869
self.addModule(v, k);
874
/** Add a new module to the component metadata.
876
* <dt>name:</dt> <dd>required, the component name</dd>
877
* <dt>type:</dt> <dd>required, the component type (js or css)</dd>
878
* <dt>path:</dt> <dd>required, the path to the script from "base"</dd>
879
* <dt>requires:</dt> <dd>array of modules required by this component</dd>
880
* <dt>optional:</dt> <dd>array of optional modules for this component</dd>
881
* <dt>supersedes:</dt> <dd>array of the modules this component replaces</dd>
882
* <dt>after:</dt> <dd>array of modules the components which, if present, should be sorted above this one</dd>
883
* <dt>after_map:</dt> <dd>faster alternative to 'after' -- supply a hash instead of an array</dd>
884
* <dt>rollup:</dt> <dd>the number of superseded modules required for automatic rollup</dd>
885
* <dt>fullpath:</dt> <dd>If fullpath is specified, this is used instead of the configured base + path</dd>
886
* <dt>skinnable:</dt> <dd>flag to determine if skin assets should automatically be pulled in</dd>
887
* <dt>submodules:</dt> <dd>a hash of submodules</dd>
888
* <dt>group:</dt> <dd>The group the module belongs to -- this is set automatically when
889
* it is added as part of a group configuration.</dd>
890
* <dt>lang:</dt> <dd>array of BCP 47 language tags of
891
* languages for which this module has localized resource bundles,
892
* e.g., ["en-GB","zh-Hans-CN"]</dd>
893
* <dt>condition:</dt> <dd>Specifies that the module should be loaded automatically if
894
* a condition is met. This is an object with two fields:
895
* [trigger] - the name of a module that can trigger the auto-load
896
* [test] - a function that returns true when the module is to be loaded
900
* @param o An object containing the module data
901
* @param name the module name (optional), required if not in the module data
902
* @return the module definition or null if
903
* the object passed in did not provide all required attributes
905
addModule: function(o, name) {
907
name = name || o.name;
918
if (!o.path && !o.fullpath) {
919
o.path = _path(name, name, o.type);
922
o.ext = ('ext' in o) ? o.ext : (this._internal) ? false : true;
923
o.requires = o.requires || [];
925
// Handle submodule logic
926
var subs = o.submodules, i, l, sup, s, smod, plugins, plug,
927
j, langs, packName, supName, flatSup, flatLang, lang, ret,
929
conditions = this.conditions, condmod;
930
// , existing = this.moduleInfo[name], newr;
932
this.moduleInfo[name] = o;
934
if (!o.langPack && o.lang) {
935
langs = YArray(o.lang);
936
for (j=0; j < langs.length; j++) {
938
packName = this.getLangPackName(lang, name);
939
smod = this.moduleInfo[packName];
941
smod = this._addLangPack(lang, o, packName);
947
sup = o.supersedes || [];
951
if (subs.hasOwnProperty(i)) {
954
s.path = s.path || _path(name, i, o.type);
959
sup = sup.concat(s.supersedes);
962
smod = this.addModule(s, i);
965
if (smod.skinnable) {
967
overrides = this.skin.overrides;
968
if (overrides && overrides[i]) {
969
for (j=0; j<overrides[i].length; j++) {
970
skinname = this._addSkin(overrides[i][j], i, name);
974
skinname = this._addSkin(this.skin.defaultSkin, i, name);
978
// looks like we are expected to work out the metadata
979
// for the parent module language packs from what is
980
// specified in the child modules.
981
if (s.lang && s.lang.length) {
983
langs = YArray(s.lang);
984
for (j=0; j < langs.length; j++) {
986
packName = this.getLangPackName(lang, name);
987
supName = this.getLangPackName(lang, i);
988
smod = this.moduleInfo[packName];
991
smod = this._addLangPack(lang, o, packName);
994
flatSup = flatSup || YArray.hash(smod.supersedes);
996
if (!(supName in flatSup)) {
997
smod.supersedes.push(supName);
1000
o.lang = o.lang || [];
1002
flatLang = flatLang || YArray.hash(o.lang);
1004
if (!(lang in flatLang)) {
1008
// Y.log('pack ' + packName + ' should supersede ' + supName);
1009
// Add rollup file, need to add to supersedes list too
1016
o.supersedes = YObject.keys(YArray.hash(sup));
1017
o.rollup = (l<4) ? l : Math.min(l-1, 4);
1020
plugins = o.plugins;
1022
for (i in plugins) {
1023
if (plugins.hasOwnProperty(i)) {
1026
plug.path = plug.path || _path(name, i, o.type);
1027
plug.requires = plug.requires || [];
1028
plug.group = o.group;
1029
// plug.requires.push(name);
1030
this.addModule(plug, i);
1032
this._addSkin(this.skin.defaultSkin, i, name);
1040
condmod = o.condition.trigger;
1041
conditions[condmod] = conditions[condmod] || {};
1042
conditions[condmod][name] = o.condition;
1045
// this.dirty = true;
1048
ret = o.configFn(o);
1049
if (ret === false) {
1050
delete this.moduleInfo[name];
1059
* Add a requirement for one or more module
1061
* @param what {string[] | string*} the modules to load
1063
require: function(what) {
1064
var a = (typeof what === "string") ? arguments : what;
1066
Y.mix(this.required, YArray.hash(a));
1070
* Returns an object containing properties for all modules required
1071
* in order to load the requested module
1072
* @method getRequires
1073
* @param mod The module definition from moduleInfo
1075
getRequires: function(mod) {
1076
if (!mod || mod._parsed) {
1077
return NO_REQUIREMENTS;
1080
var i, m, j, add, packName, lang,
1081
name = mod.name, cond, go,
1082
adddef = ON_PAGE[name] && ON_PAGE[name].details,
1085
o, skinmod, skindef,
1086
intl = mod.lang || mod.intl,
1087
info = this.moduleInfo,
1090
// pattern match leaves module stub that needs to be filled out
1091
if (mod.temp && adddef) {
1095
mod = this.addModule(adddef, name);
1096
mod.group = old_mod.group;
1097
mod.pkg = old_mod.pkg;
1098
delete mod.expanded;
1099
// console.log('TEMP MOD: ' + name + ', ' + mod.requires);
1100
// console.log(Y.dump(mod));
1103
// if (!this.dirty && mod.expanded && (!mod.langCache || mod.langCache == this.lang)) {
1104
if (mod.expanded && (!mod.langCache || mod.langCache == this.lang)) {
1105
// Y.log('already expanded ' + name + ', ' + mod.expanded);
1106
return mod.expanded;
1112
// Y.log("getRequires: " + name + " (dirty:" + this.dirty + ", expanded:" + mod.expanded + ")");
1116
// Create skin modules
1117
if (mod.skinnable) {
1118
skindef = this.skin.overrides;
1119
if (skindef && skindef[name]) {
1120
for (i=0; i<skindef[name].length; i++) {
1121
skinmod = this._addSkin(skindef[name][i], name);
1125
skinmod = this._addSkin(this.skin.defaultSkin, name);
1130
for (i=0; i<r.length; i++) {
1131
// Y.log(name + ' requiring ' + r[i]);
1135
m = this.getModule(r[i]);
1137
add = this.getRequires(m);
1138
intl = intl || (m.expanded_map && (INTL in m.expanded_map));
1139
for (j=0; j<add.length; j++) {
1146
// get the requirements from superseded modules, if any
1149
for (i=0; i<r.length; i++) {
1152
// if this module has submodules, the requirements list is
1153
// expanded to include the submodules. This is so we can
1154
// prevent dups when a submodule is already loaded and the
1155
// parent is requested.
1156
if (mod.submodules) {
1161
m = this.getModule(r[i]);
1164
add = this.getRequires(m);
1165
intl = intl || (m.expanded_map && (INTL in m.expanded_map));
1166
for (j=0; j<add.length; j++) {
1174
if (o && this.loadOptional) {
1175
for (i=0; i<o.length; i++) {
1181
add = this.getRequires(m);
1182
intl = intl || (m.expanded_map && (INTL in m.expanded_map));
1183
for (j=0; j<add.length; j++) {
1191
cond = this.conditions[name];
1194
oeach(cond, function(def, condmod) {
1196
if (!hash[condmod]) {
1197
go = def && ((def.ua && Y.UA[def.ua]) ||
1198
(def.test && def.test(Y, r)));
1200
hash[condmod] = true;
1202
m = this.getModule(condmod);
1204
add = this.getRequires(m);
1205
for (j=0; j<add.length; j++) {
1214
mod._parsed = false;
1218
if (mod.lang && !mod.langPack && Y.Intl) {
1219
lang = Y.Intl.lookupBestLang(this.lang || ROOT_LANG, mod.lang);
1220
// Y.log('Best lang: ' + lang + ', this.lang: ' + this.lang + ', mod.lang: ' + mod.lang);
1221
mod.langCache = this.lang;
1222
packName = this.getLangPackName(lang, name);
1224
d.unshift(packName);
1231
mod.expanded_map = YArray.hash(d);
1233
mod.expanded = YObject.keys(mod.expanded_map);
1235
return mod.expanded;
1240
* Returns a hash of module names the supplied module satisfies.
1241
* @method getProvides
1242
* @param name {string} The name of the module
1243
* @return what this module provides
1245
getProvides: function(name) {
1246
var m = this.getModule(name), o, s;
1247
// supmap = this.provides;
1253
if (m && !m.provides) {
1258
YArray.each(s, function(v) {
1259
Y.mix(o, this.getProvides(v));
1272
* Calculates the dependency tree, the result is stored in the sorted
1275
* @param o optional options object
1276
* @param type optional argument to prune modules
1279
calculate: function(o, type) {
1280
if (o || type || this.dirty) {
1291
if (this.allowRollup) {
1299
_addLangPack: function(lang, m, packName) {
1302
existing = this.moduleInfo[packName];
1306
packPath = _path((m.pkg || name), packName, JS, true);
1308
this.addModule({ path: packPath,
1313
supersedes: [] }, packName, true);
1316
Y.Env.lang = Y.Env.lang || {};
1317
Y.Env.lang[lang] = Y.Env.lang[lang] || {};
1318
Y.Env.lang[lang][name] = true;
1322
return this.moduleInfo[packName];
1326
* Investigates the current YUI configuration on the page. By default,
1327
* modules already detected will not be loaded again unless a force
1328
* option is encountered. Called by calculate()
1332
_setup: function() {
1333
var info = this.moduleInfo, name, i, j, m, l,
1336
for (name in info) {
1337
if (info.hasOwnProperty(name)) {
1342
m.requires = YObject.keys(YArray.hash(m.requires));
1344
// Create lang pack modules
1345
if (m.lang && m.lang.length) {
1346
// Setup root package if the module has lang defined,
1347
// it needs to provide a root language pack
1348
packName = this.getLangPackName(ROOT_LANG, name);
1349
this._addLangPack(null, m, packName);
1356
//l = Y.merge(this.inserted);
1359
// available modules
1360
if (!this.ignoreRegistered) {
1361
Y.mix(l, GLOBAL_ENV.mods);
1364
// add the ignore list to the list of loaded packages
1366
Y.mix(l, YArray.hash(this.ignore));
1369
// expand the list to include superseded modules
1371
if (l.hasOwnProperty(j)) {
1372
Y.mix(l, this.getProvides(j));
1376
// remove modules on the force list from the loaded list
1378
for (i=0; i<this.force.length; i++) {
1379
if (this.force[i] in l) {
1380
delete l[this.force[i]];
1385
Y.mix(this.loaded, l);
1391
* Builds a module name for a language pack
1392
* @function getLangPackName
1393
* @param lang {string} the language code
1394
* @param mname {string} the module to build it for
1395
* @return {string} the language pack module name
1397
getLangPackName: function(lang, mname) {
1398
return ('lang/' + mname + ((lang) ? '_' + lang : ''));
1402
* Inspects the required modules list looking for additional
1403
* dependencies. Expands the required list to include all
1404
* required modules. Called by calculate()
1408
_explode: function() {
1409
var r = this.required, m, reqs, done = {},
1412
// the setup phase is over, all modules have been created
1415
oeach(r, function(v, name) {
1418
m = self.getModule(name);
1420
var expound = m.expound;
1423
r[expound] = self.getModule(expound);
1424
reqs = self.getRequires(r[expound]);
1425
Y.mix(r, YArray.hash(reqs));
1428
reqs = self.getRequires(m);
1429
Y.mix(r, YArray.hash(reqs));
1431
// sups = m.supersedes;
1434
// YArray.each(sups, function(sup) {
1435
// if (sup in self.loaded) {
1438
// // if (sup in self.conditions) {
1444
// remove the definition for a rollup with
1445
// submodules -- getRequires() includes the
1446
// submodules. Removing the parent makes
1447
// it possible to prevent submodule duplication
1448
// if the parent is requested after a submodule
1450
// if (m.submodules) {
1457
// Y.log('After explode: ' + YObject.keys(r));
1460
getModule: function(mname) {
1461
//TODO: Remove name check - it's a quick hack to fix pattern WIP
1466
var p, found, pname,
1467
m = this.moduleInfo[mname],
1468
patterns = this.patterns;
1470
// check the patterns library to see if we should automatically add
1471
// the module with defaults
1473
// Y.log('testing patterns ' + YObject.keys(patterns));
1474
for (pname in patterns) {
1475
if (patterns.hasOwnProperty(pname)) {
1476
// Y.log('testing pattern ' + i);
1477
p = patterns[pname];
1479
// use the metadata supplied for the pattern
1480
// as the module definition.
1481
if (mname.indexOf(pname) > -1) {
1490
// Y.log('executing pattern action: ' + pname);
1491
p.action.call(this, mname, pname);
1493
Y.log('Undefined module: ' + mname + ', matched a pattern: ' + pname, 'info', 'loader');
1494
// ext true or false?
1495
m = this.addModule(Y.merge(found), mname);
1504
// impl in rollup submodule
1505
_rollup: function() { },
1508
* Remove superceded modules and loaded modules. Called by
1509
* calculate() after we have the mega list of all dependencies
1513
_reduce: function(r) {
1515
r = r || this.required;
1517
var i, j, s, m, type = this.loadType;
1519
if (r.hasOwnProperty(i)) {
1520
m = this.getModule(i);
1521
// remove if already loaded
1522
if (((this.loaded[i] || ON_PAGE[i]) && !this.forceMap[i] && !this.ignoreRegistered) || (type && m && m.type != type)) {
1525
// remove anything this module supersedes
1526
s = m && m.supersedes;
1528
for (j=0; j<s.length; j++) {
1536
// Y.log('required now: ' + YObject.keys(r));
1541
_finish: function(msg, success) {
1542
Y.log('loader finishing: ' + msg + ', ' + Y.id + ', ' + this.data, "info", "loader");
1544
_queue.running = false;
1546
var onEnd = this.onEnd;
1548
onEnd.call(this.context, {
1557
_onSuccess: function() {
1558
// Y.log('loader _onSuccess, skipping: ' + Y.Object.keys(this.skipped), "info", "loader");
1559
var skipped = Y.merge(this.skipped), fn;
1561
oeach(skipped, function(k) {
1562
delete this.inserted[k];
1567
// Y.mix(this.loaded, this.inserted);
1568
oeach(this.inserted, function(v, k) {
1569
Y.mix(this.loaded, this.getProvides(k));
1572
fn = this.onSuccess;
1574
fn.call(this.context, {
1581
this._finish('success', true);
1584
_onFailure: function(o) {
1585
Y.log('load error: ' + o.msg + ', ' + Y.id, "error", "loader");
1586
var f = this.onFailure, msg = 'failure: ' + o.msg;
1588
f.call(this.context, {
1594
this._finish(msg, false);
1597
_onTimeout: function() {
1598
Y.log('loader timeout: ' + Y.id, "error", "loader");
1599
var f = this.onTimeout;
1601
f.call(this.context, {
1607
this._finish('timeout', false);
1612
* Sorts the dependency tree. The last step of calculate()
1619
// create an indexed list
1620
var s = YObject.keys(this.required),
1621
// loaded = this.loaded,
1623
p=0, l, a, b, j, k, moved, doneKey;
1626
// keep going until we make a pass without moving anything
1632
// start the loop after items that are already sorted
1633
for (j=p; j<l; j++) {
1635
// check the next module on the list to see if its
1636
// dependencies have been met
1639
// check everything below current item and move if we
1640
// find a requirement for the current item
1641
for (k=j+1; k<l; k++) {
1644
if (!done[doneKey] && this._requires(a, s[k])) {
1646
// extract the dependency so we can move it up
1649
// insert the dependency above the item that
1651
s.splice(j, 0, b[0]);
1653
// only swap two dependencies once to short circut
1654
// circular dependencies
1655
done[doneKey] = true;
1664
// jump out of loop if we moved something
1667
// this item is sorted, move our pointer and keep going
1673
// when we make it here and moved is false, we are
1685
_insert: function(source, o, type) {
1687
// Y.log('private _insert() ' + (type || '') + ', ' + Y.id, "info", "loader");
1689
// restore the state at the time of the request
1691
this._config(source);
1694
// build the dependency list
1695
this.calculate(o); // don't include type so we can process CSS and script in
1696
// one pass when the type is not specified.
1697
this.loadType = type;
1703
// Y.log("trying to load css first");
1704
this._internalCallback = function() {
1706
var f = self.onCSS, n, p, sib;
1708
// IE hack for style overrides that are not being applied
1709
if (this.insertBefore && Y.UA.ie) {
1710
n = Y.config.doc.getElementById(this.insertBefore);
1712
sib = n.nextSibling;
1715
p.insertBefore(n, sib);
1722
f.call(self.context, Y);
1724
self._internalCallback = null;
1726
self._insert(null, null, JS);
1729
this._insert(null, null, CSS);
1734
// set a flag to indicate the load has started
1735
this._loading = true;
1737
// flag to indicate we are done with the combo service
1738
// and any additional files will need to be loaded
1740
this._combineComplete = {};
1747
// Once a loader operation is completely finished, process
1748
// any additional queued items.
1749
_continue: function() {
1750
if (!(_queue.running) && _queue.size() > 0) {
1751
_queue.running = true;
1757
* inserts the requested modules and their dependencies.
1758
* <code>type</code> can be "js" or "css". Both script and
1759
* css are inserted if type is not provided.
1761
* @param o optional options object
1762
* @param type {string} the type of dependency to insert
1764
insert: function(o, type) {
1765
// Y.log('public insert() ' + (type || '') + ', ' + Y.Object.keys(this.required), "info", "loader");
1766
var self = this, copy = Y.merge(this, true);
1767
delete copy.require;
1769
_queue.add(function() {
1770
self._insert(copy, o, type);
1776
* Executed every time a module is loaded, and if we are in a load
1777
* cycle, we attempt to load the next script. Public so that it
1778
* is possible to call this if using a method other than
1779
* Y.register to determine when scripts are fully loaded
1781
* @param mname {string} optional the name of the module that has
1782
* been loaded (which is usually why it is time to load the next
1785
loadNext: function(mname) {
1786
// It is possible that this function is executed due to something
1787
// else one the page loading a YUI module. Only react when we
1788
// are actively loading something
1789
if (!this._loading) {
1793
var s, len, i, m, url, fn, msg, attr, group, groupName, j, frag,
1794
comboSource, comboSources, mods, combining, urls, comboBase,
1796
type = this.loadType,
1798
handleSuccess = function(o) {
1799
self.loadNext(o.data);
1801
handleCombo = function(o) {
1802
self._combineComplete[type] = true;
1803
var i, len = combining.length;
1805
for (i=0; i<len; i++) {
1806
// self.loaded[combining[i]] = true;
1807
self.inserted[combining[i]] = true;
1809
// provided = this.getProvides(combining[i]);
1811
// Y.mix(self.loaded, provided);
1812
// Y.mix(self.inserted, provided);
1818
if (this.combine && (!this._combineComplete[type])) {
1822
this._combining = combining;
1826
// the default combo base
1827
comboBase = this.comboBase;
1834
for (i=0; i<len; i++) {
1835
comboSource = comboBase;
1836
m = this.getModule(s[i]);
1837
groupName = m && m.group;
1840
group = this.groups[groupName];
1842
if (!group.combine) {
1847
if (group.comboBase) {
1848
comboSource = group.comboBase;
1852
m.root = group.root;
1857
comboSources[comboSource] = comboSources[comboSource] || [];
1858
comboSources[comboSource].push(m);
1861
for (j in comboSources) {
1862
if (comboSources.hasOwnProperty(j)) {
1864
mods = comboSources[j];
1867
for (i=0; i<len; i++) {
1868
// m = this.getModule(s[i]);
1871
// Do not try to combine non-yui JS unless combo def is found
1872
if (m && (m.type === type) && (m.combine || !m.ext)) {
1874
frag = (m.root || this.root) + m.path;
1876
if ((url !== j) && (i < (len - 1)) && ((frag.length + url.length) > this.maxURLLength)) {
1877
urls.push(this._filter(url));
1882
if (i < (len - 1)) {
1886
combining.push(m.name);
1891
if (combining.length && (url != j)) {
1892
urls.push(this._filter(url));
1897
if (combining.length) {
1899
Y.log('Attempting to use combo: ' + combining, "info", "loader");
1901
// if (m.type === CSS) {
1904
attr = this.cssAttributes;
1907
attr = this.jsAttributes;
1911
data: this._loading,
1912
onSuccess: handleCombo,
1913
onFailure: this._onFailure,
1914
onTimeout: this._onTimeout,
1915
insertBefore: this.insertBefore,
1916
charset: this.charset,
1918
timeout: this.timeout,
1926
this._combineComplete[type] = true;
1932
// if the module that was just loaded isn't what we were expecting,
1934
if (mname !== this._loading) {
1938
// Y.log("loadNext executing, just loaded " + mname + ", " + Y.id, "info", "loader");
1940
// The global handler that is called when each module is loaded
1941
// will pass that module name to this function. Storing this
1942
// data to avoid loading the same module multiple times
1943
// centralize this in the callback
1944
this.inserted[mname] = true;
1945
// this.loaded[mname] = true;
1947
// provided = this.getProvides(mname);
1948
// Y.mix(this.loaded, provided);
1949
// Y.mix(this.inserted, provided);
1951
if (this.onProgress) {
1952
this.onProgress.call(this.context, {
1962
for (i=0; i<len; i=i+1) {
1963
// this.inserted keeps track of what the loader has loaded.
1964
// move on if this item is done.
1965
if (s[i] in this.inserted) {
1969
// Because rollups will cause multiple load notifications
1970
// from Y, loadNext may be called multiple times for
1971
// the same module when loading a rollup. We can safely
1972
// skip the subsequent requests
1973
if (s[i] === this._loading) {
1974
Y.log("still loading " + s[i] + ", waiting", "info", "loader");
1978
// log("inserting " + s[i]);
1979
m = this.getModule(s[i]);
1982
msg = "Undefined module " + s[i] + " skipped";
1983
Y.log(msg, 'warn', 'loader');
1984
// this.inserted[s[i]] = true;
1985
this.skipped[s[i]] = true;
1990
group = (m.group && this.groups[m.group]) || NOT_FOUND;
1992
// The load type is stored to offer the possibility to load
1993
// the css separately from the script.
1994
if (!type || type === m.type) {
1995
this._loading = s[i];
1996
Y.log("attempting to load " + s[i] + ", " + this.base, "info", "loader");
1998
if (m.type === CSS) {
2000
attr = this.cssAttributes;
2003
attr = this.jsAttributes;
2006
url = (m.fullpath) ? this._filter(m.fullpath, s[i]) : this._url(m.path, s[i], group.base || m.base);
2010
onSuccess: handleSuccess,
2011
insertBefore: this.insertBefore,
2012
charset: this.charset,
2014
onFailure: this._onFailure,
2015
onTimeout: this._onTimeout,
2016
timeout: this.timeout,
2026
this._loading = null;
2028
fn = this._internalCallback;
2030
// internal callback for loading css first
2032
// Y.log('loader internal');
2033
this._internalCallback = null;
2036
// Y.log('loader complete');
2042
* Apply filter defined for this instance to a url/path
2044
* @param u {string} the string to filter
2045
* @param name {string} the name of the module, if we are processing
2046
* a single module as opposed to a combined url
2047
* @return {string} the filtered string
2050
_filter: function(u, name) {
2051
var f = this.filter,
2052
hasFilter = name && (name in this.filters),
2053
modFilter = hasFilter && this.filters[name];
2057
f = (L.isString(modFilter)) ?
2058
this.FILTER_DEFS[modFilter.toUpperCase()] || null :
2062
u = u.replace(new RegExp(f.searchExp, 'g'), f.replaceStr);
2070
* Generates the full url for a module
2072
* @param path {string} the path fragment
2073
* @return {string} the full url
2076
_url: function(path, name, base) {
2077
return this._filter((base || this.base || "") + path, name);
2083
}, '3.2.0' ,{requires:['get']});