loader.js revision 16a523a00015233b8508de0e296d2a69bbdd2722
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein(function() {
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * Loader dynamically loads script and css files. It includes the dependency
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * info for the version of the library in use, and will automatically pull in
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * dependencies for the modules requested. It supports rollup files and will
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * automatically use these when appropriate in order to minimize the number of
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * http connections required to load all of the dependencies. It can load the
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * files from the Yahoo! CDN, and it can utilize the combo service provided on
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * this network to reduce the number of http connections required to download
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * YUI files.
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * @module loader
f5d30e2864e048a42c4dc1134993ae7efdb5d6c3Mark Andrews * Loader dynamically loads script and css files. It includes the dependency
8077efca7d2ec3b9bf0428386a1ec2fcbcdf437bAutomatic Updater * info for the version of the library in use, and will automatically pull in
26440aaebba1acb5c8810f7faa26ad3b7553762eMark Andrews * dependencies for the modules requested. It supports rollup files and will
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * automatically use these when appropriate in order to minimize the number of
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * http connections required to load all of the dependencies. It can load the
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * files from the Yahoo! CDN, and it can utilize the combo service provided on
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * this network to reduce the number of http connections required to download
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * YUI files.
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * While the loader can be instantiated by the end user, it normally is not.
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @see YUI.use for the normal use case. The use function automatically will
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * pull in missing dependencies.
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @class Loader
bff64bf12b58a6f80e740e94f2e42a32df18113aEvan Hunt * @constructor
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @param o an optional set of configuration options. Valid options:
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * The base dir</li>
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * <li>secureBase:
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * The secure base dir (not implemented)</li>
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * <li>comboBase:
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?</li>
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * The root path to prepend to module names for the combo service. Ex: 2.5.2/build/</li>
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * <li>filter:
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * A filter to apply to result urls. This filter will modify the default
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * path for all modules. The default path for the YUI library is the
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * minified version of the files (e.g., event-min.js). The filter property
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * can be a predefined filter or a custom filter. The valid predefined
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * filters are:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>DEBUG</dt>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dd>Selects the debug versions of the library (e.g., event-debug.js).
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * This option will automatically include the Logger widget</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>RAW</dt>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dd>Selects the non-minified version of the library (e.g., event.js).</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * You can also define a custom filter, which must be an object literal
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * containing a search expression and a replace string:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * myFilter: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * 'searchExp': "-min\\.js",
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * 'replaceStr': "-debug.js"
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <li>filters: per-component filter specification. If specified for a given component, this overrides the filter config</li>
f5d30e2864e048a42c4dc1134993ae7efdb5d6c3Mark Andrews * <li>combine:
1b06367c345e972a0c719a6e821db3e875f20c3bMark Andrews * Use the YUI combo service to reduce the number of http connections required to load your dependencies</li>
c1a883f2e04d94e99c433b1f6cfd0c0338f4ed85Mark Andrews * <li>ignore:
8077efca7d2ec3b9bf0428386a1ec2fcbcdf437bAutomatic Updater * A list of modules that should never be dynamically loaded</li>
85167bb10f76e71c3c8519e2135e31d249f54805Tinderbox User * A list of modules that should always be loaded when required, even if already present on the page</li>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <li>insertBefore:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Node or id for a node that should be used as the insertion point for new nodes</li>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <li>charset:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * charset for dynamic nodes (deprecated, use jsAttributes or cssAttributes)</li>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <li>jsAttributes: object literal containing attributes to add to script nodes</li>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <li>cssAttributes: object literal containing attributes to add to link nodes</li>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <li>timeout:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * number of milliseconds before a timeout occurs when dynamically loading nodes. in not set, there is no timeout</li>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <li>context:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * execution context for all callbacks</li>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <li>onSuccess:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * callback for the 'success' event</li>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <li>onFailure: callback for the 'failure' event</li>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <li>onCSS: callback for the 'CSSComplete' event. When loading YUI components with CSS
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * the CSS is loaded first, then the script. This provides a moment you can tie into to improve
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * the presentation of the page while the script is loading.</li>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <li>onTimeout:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * callback for the 'timeout' event</li>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <li>onProgress:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * callback executed each time a script or css file is loaded</li>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <li>modules:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * A list of module definitions. See Loader.addModule for the supported module metadata</li>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'cssreset-context', 'cssfonts-context', 'cssgrids-context'],
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein GALLERY_VERSION = 'gallery-2009-10-19', // @TODO build time
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein GALLERY_BASE = 'http://yui.yahooapis.com/' + GALLERY_ROOT,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dom-base': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dom-style': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dom-screen': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'selector-native': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'selector-css2': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'selector': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'selector-css3': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein // expound: EVENT,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'node-base': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'node-style': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'node-screen': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'node-pluginhost': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'node-event-delegate': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'node-event-simulate': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'align-plugin': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'shim-plugin': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'anim-base': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'anim-color': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'anim-easing': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'anim-scroll': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'anim-xy': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'anim-curve': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'anim-node-plugin': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'attribute-base': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'attribute-complex': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'base-base': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'base-build': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'base-pluginhost': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'console-filters': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dataschema-base': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dataschema-array': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dataschema-json': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dataschema-text': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dataschema-xml': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'datasource-local': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'datasource-arrayschema': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein requires: [DATASOURCELOCAL, PLUGIN, 'dataschema-array']
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'datasource-cache': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'datasource-function': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'datasource-jsonschema': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein requires: [DATASOURCELOCAL, PLUGIN, 'dataschema-json']
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'datasource-polling': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'datasource-get': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'datasource-textschema': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein requires: [DATASOURCELOCAL, PLUGIN, 'dataschema-text']
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'datasource-io': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'datasource-xmlschema': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein requires: [DATASOURCELOCAL, PLUGIN, 'dataschema-xml']
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'datatype-date': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'datatype-number': {
8afea636ab0c07399aa3e2410b2cfbd41099df98Mark Andrews 'datatype-xml': {
8afea636ab0c07399aa3e2410b2cfbd41099df98Mark Andrews 'dd-ddm-base': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dd-ddm-drop':{
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dd-proxy':{
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dd-constrain':{
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dd-scroll':{
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dd-plugin':{
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dd-drop-plugin':{
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'dd-delegate': {
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews 'event-base': {
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews 'event-delegate': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'event-focus': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'event-key': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'event-mouseenter': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'event-mousewheel': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'event-resize': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'event-custom': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'event-custom-base': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'event-custom-complex': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'event-simulate': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'node-focusmanager': {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein requires: [ATTRIBUTE, NODE, PLUGIN, 'node-event-simulate', 'event-key', 'event-focus']
history: {
imageloader: {
io:{
submodules: {
json: {
submodules: {
loader: {
skinnable: true
oop: {
overlay: {
skinnable: true
plugin: {
pluginhost: {
profiler: {
submodules: {
slider: {
skinnable: true
sortable: {
stylesheet: {
substitute: {
widget: {
submodules : {
plugins: {
skinnable: true
skinnable: true
yui: {
submodules: {
get: {},
test: {
skinnable: true
patterns: {
filter: {
L = Y.Lang;
Y.Loader = function(o) {
this.context = Y;
// this.jsAttributes = null;
* @default http://yui.yahooapis.com/[YUI VERSION]/build/
* @default http://yui.yahooapis.com/combo?
this.forceMap = {};
this.allowRollup = true;
* minified version of the files (e.g., event-min.js). The filter property
* <dd>Selects the debug versions of the library (e.g., event-debug.js).
* <dd>Selects the non-minified version of the library (e.g., event.js).</dd>
* 'replaceStr': "-debug.js"
this.filters = {};
this.required = {};
this.moduleInfo = {};
this._internal = true;
for (i in defaults) {
for (i in onPage) {
this._internal = false;
this.sorted = [];
this.dirty = true;
this.inserted = {};
this.skipped = {};
this._config(o);
FILTER_DEFS: {
RAW: {
DEBUG: {
_config: function(o) {
var i, j, val, f;
if (o.hasOwnProperty(i)) {
val = o[i];
for (j in val) {
this[i] = val;
f = this.filter;
if (L.isString(f)) {
f = f.toUpperCase();
this.filterName = f;
if (mod) {
if (mod) {
this.addModule({
return name;
* <dt>after:</dt> <dd>array of modules the components which, if present, should be sorted above this one</dd>
* <dt>fullpath:</dt> <dd>If fullpath is specified, this is used instead of the configured base + path</dd>
if (!o || !o.name) {
if (!o.type) {
if (subs) {
sup = [];
for (i in subs) {
s = subs[i];
this.addModule(s, i);
if (o.skinnable) {
if (plugins) {
for (i in plugins) {
if (o.skinnable) {
this.dirty = true;
this.dirty = true;
return NO_REQUIREMENTS;
d.push(r[i]);
m = this.getModule(r[i]);
d.push(r[i]);
m = this.getModule(r[i]);
if (o && this.loadOptional) {
d.push(o[i]);
return NOT_FOUND;
if (m && !m.provides) {
s = m.supersedes;
Y.Array.each(s, function(v) {
o[name] = true;
m.provides = o;
return m.provides;
this._config(o);
this._setup();
this._explode();
if (this.allowRollup) {
this._rollup();
this._reduce();
this._sort();
_setup: function() {
if (m && m.skinnable) {
if (o && o[name]) {
if (!this.ignoreRegistered) {
if (this.ignore) {
if (l.hasOwnProperty(j)) {
if (this.force) {
if (this.force[i] in l) {
delete l[this.force[i]];
_explode: function() {
this.dirty = false;
if (expound) {
if (!name) {
for (i in patterns) {
p = patterns[i];
add = p;
if (add) {
_rollup: function() {
for (i in info) {
m = this.getModule(i);
if (m && m.rollup) {
rollups[i] = m;
rolled = false;
for (i in rollups) {
m = this.getModule(i);
s = m.supersedes || [];
roll = false;
if (!m.rollup) {
roll = false;
if (roll) {
if (roll) {
rolled = true;
this.getRequires(m);
if (!rolled) {
_reduce: function() {
if (r.hasOwnProperty(i)) {
m = this.getModule(i);
if ((this.loaded[i] && (!this.forceMap[i]) && !this.ignoreRegistered) || (type && m && m.type != type)) {
s = m && m.supersedes;
_attach: function() {
if (this.attaching) {
_finish: function() {
this._continue();
_onSuccess: function() {
this._attach();
for (i in skipped) {
delete this.inserted[i];
this.skipped = {};
f = this.onSuccess;
success: true,
this._finish();
_onFailure: function(o) {
this._attach();
var f = this.onFailure;
success: false
this._finish();
_onTimeout: function() {
this._attach();
var f = this.onTimeout;
success: false
this._finish();
_sort: function() {
done = {},
r = m.expanded;
l = s.length;
moved = false;
doneKey = a + s[k];
moved = true;
if (moved) {
if (!moved) {
this.sorted = s;
if (source) {
if (!type) {
var self = this;
this._internalCallback = function() {
this._loading = true;
this._combineComplete = {};
this.loadNext();
_continue: function() {
this._continue();
if (!this._loading) {
callback=function(o) {
onsuccess=function(o) {
combining = [];
s = this.sorted;
urls = [];
m = this.getModule(s[i]);
autopurge: false,
context: this
if (mname) {
if (this.onProgress) {
s=this.sorted;
if (s[i] in this.inserted) {
if (s[i] === this._loading) {
m = this.getModule(s[i]);
this.inserted[s[i]] = true;
this.skipped[s[i]] = true;
this._loading = s[i];
data: s[i],
autopurge: false,
this._loading = null;
if (fn) {
this._internalCallback = null;
this._onSuccess();
var f = this.filter,
if (hasFilter) {