yui.js revision 466e89e60fbad15b099068ee771d408bc06f14c1
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * The YUI module contains the components required for building the YUI seed
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * file. This includes the script loading mechanism, a simple queue, and
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * the core utilities for the library.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @module yui
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @submodule yui-base
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * The YUI global namespace object. If YUI is already defined, the
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * existing YUI object will not be overwritten so that defined
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * namespaces are preserved. It is the constructor for the object
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * the end user interacts with. As indicated below, each instance
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * has full custom event support, but only if the event system
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * is available. This is a self-instantiable factory function. You
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * can invoke it directly like this:
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * YUI().use('*', function(Y) {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * But it also works like this:
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * var Y = YUI();
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @class YUI
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @constructor
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @uses EventTarget
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @param o* {object} 0..n optional configuration objects. these values
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * are store in Y.config. See config for the list of supported
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * properties.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /*global YUI*/
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /*global YUI_config*/
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass var YUI = function() {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass return (o && o.hasOwnProperty && (o instanceof type));
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass gconf = (typeof YUI_config !== 'undefined') && YUI_config;
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass // set up the core environment
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass // YUI.GlobalConfig is a master configuration that might span
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass // multiple contexts in a non-browser environment. It is applied
905f59668fbc4df1a3acb1e28f2629ae57fd216cDav Glass // first to all instances in all contexts.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass // YUI_Config is a page-level config. It is applied to all
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass // instances created on the page. This is applied after
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass // YUI.GlobalConfig, and before the instance level configuration
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass // bind the specified additional modules for this instance
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass // Each instance can accept one or more configuration objects.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass // These are applied after YUI.GlobalConfig and YUI_Config,
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass // overriding values set in those config files if there is a '
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass // matching property.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass for (; i < l; i++) {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass(function() {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass NOOP = function() {},
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass APPLY_TO_AUTH = { 'io.xdrReady': 1, // the functions applyTo
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass // this can throw an uncaught exception in FF
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass } catch (ex) {}
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass handleLoad = function() {
d0bccce76452becc96b65acaaa684aa6fabaf386Dav Glass getLoader = function(Y, o) {
d0bccce76452becc96b65acaaa684aa6fabaf386Dav Glass clobber = function(r, s) {
d0bccce76452becc96b65acaaa684aa6fabaf386Dav Glass for (var i in s) {
d0bccce76452becc96b65acaaa684aa6fabaf386Dav Glass r[i] = s[i];
9002d9b85f99bb503c702f12a20f829f732d22f8Dav Glass// Stamp the documentElement (HTML) with a class of "yui-loaded" to
9002d9b85f99bb503c702f12a20f829f732d22f8Dav Glass// enable styles that need to key off of JS being enabled.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Applies a new configuration object to the YUI instance config.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * This will merge new group/module definitions, and will also
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * update the loader cache if necessary. Updating Y.config directly
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * will not update the cache.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @method applyConfig
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @param {object} the configuration object.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @since 3.2.0
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass applyConfig: function(o) {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass for (name in o) {
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass // preserve the guid
58b0694c5cd8077e8c1f73624a56c8880927375fDav Glass _config: function(o) {
d0bccce76452becc96b65acaaa684aa6fabaf386Dav Glass * Initialize this YUI instance
d0bccce76452becc96b65acaaa684aa6fabaf386Dav Glass _init: function() {
58b0694c5cd8077e8c1f73624a56c8880927375fDav Glass * The version number of the YUI instance.
58b0694c5cd8077e8c1f73624a56c8880927375fDav Glass * @property version
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * @type string
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass // bootstrapped: false,
d0bccce76452becc96b65acaaa684aa6fabaf386Dav Glass // get from querystring
d0bccce76452becc96b65acaaa684aa6fabaf386Dav Glass nodes = (doc && doc.getElementsByTagName('script')) || [];
6dcd63a9962ebe13f3b428d1f71c51a93c1700cfDav Glass // this is to set up the path to the loader. The file
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass // filter for loader should match the yui include.
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass // extract correct path for mixed combo urls
bc7d05651658bd1302a26ba8015c432c8b4a1519Dav Glass // http://yuilibrary.com/projects/yui3/ticket/2528423
20ce20f1b8ee0bcb928f97d3725e77889d5b27aeDav Glass // use CDN default
e04e9b42ef212618f77fd4b0f9a71cab4c55d8a0Dav Glass // configuration defaults
_setup: function(o) {
core = [],
if (instance) {
m = instance;
m = m[nest[i]];
mod = {
for (i in instances) {
if (loader) {
if (!done[r[i]]) {
name = r[i];
if (!mod) {
if (req) {
if (after) {
if (use) {
use: function() {
key;
callback = null;
if (Y._loading) {
if (callback) {
YArray = Y.Array,
missing = [],
ret = true,
if (!skip) {
success: true,
ret = true,
Y._loading = false;
if (data) {
missing = [];
if (redo) {
redo = false;
Y._loading = false;
if (data) {
if (ret) {
if (ret) {
handleLoader();
if (len) {
Y._loading = true;
onEnd: function(o) {
handleLoader(o);
Y._loading = true;
handleBoot = function() {
Y._loading = false;
if (ret) {
handleLoader();
namespace: function() {
for (; i < a.length; i++) {
arg = a[i];
var Y = this, ret;
var uid;
if (!uid) {
if (!readOnly) {
uid = null;
return uid;
destroy: function() {
if (Y.Event) {
delete Y.Env;
delete Y.config;
if (hasWin) {
handleLoad();
* The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?
* 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"
* fullpath: 'http://myserver.mydomain.com/mymod1/mymod1.js'
* fullpath: 'http://myserver.mydomain.com/mymod2/mymod2.js'
* base: 'http://yui.yahooapis.com/2.8.0r4/build/',
* comboBase: 'http://yui.yahooapis.com/combo?',
* path: "yahoo-dom-event/yahoo-dom-event.js"
* path: "animation/animation.js",
* @default loader/loader-min.js
var L = Y.Lang,
TYPES = {
TRIMREGEX = /^\s+|\s+$/g,
SUBREGEX = /\{\s*([^\|\}]+?)\s*(?:\|([^\}]*))?\s*\}/g;
L.isBoolean = function(o) {
return typeof o === BOOLEAN;
L.isFunction = function(o) {
L.isDate = function(o) {
L.isNull = function(o) {
L.isNumber = function(o) {
return (o && (t === OBJECT ||
L.isString = function(o) {
return typeof o === STRING;
L.isUndefined = function(o) {
return typeof o === UNDEFINED;
return s.trimLeft();
return s.trimRight();
L.isValue = function(o) {
var t = L.type(o);
case NUMBER:
return isFinite(o);
case NULL:
case UNDEFINED:
L.type = function(o) {
L.sub = function(s, o) {
return new Date().getTime();
l = o.length;
Y.Array = YArray;
f.call(o || Y, a[i], i, a);
function(a, val) {
function(a, val) {
if (a[i] === val) {
var l = a.length, i;
if (f.call(o, a[i], i, a)) {
function Queue() {
this._init();
_init: function() {
this._q = [];
next: function() {
last: function() {
add: function() {
size: function() {
_iefix = function(r, s) {
Y.merge = function() {
Y.mix(o, a[i], true);
* @param merge {boolean/int} merge objects instead of overwriting/ignoring.
if (mode) {
switch (mode) {
var i, l, p, type;
p = wl[i];
if (s.hasOwnProperty(p)) {
Y.mix(r[p], s[p]);
} else if (ov || !(p in r)) {
if (s.hasOwnProperty(i)) {
} else if (ov || !(i in r)) {
_iefix(r, s);
return function(arg1) {
return cache[k];
O = Object.create || function(o) {
F.prototype = o;
owns = function(o, k) {
if (owns(o, i)) {
if (count) {
out++;
return out;
return _extract(o);
O.hasValue = function(o, v) {
f.call(s, o[i], i, o);
if (f.call(s, o[i], i, o)) {
return UNDEF;
p = Y.Array(path),
l = p.length;
p = Y.Array(path),
ref = o;
return UNDEF;
O.isEmpty = function(o) {
if (owns(o, i)) {
var numberify = function(s) {
mobile: null,
ios: null,
secure: false,
os: null
if (ua) {
o.ios = m;
L = Y.Lang,
Y.Get = function() {
queues = {},
d = w.document,
for (i in attr) {
if (attributes) {
if (attributes) {
purge: function() {
if (q && q.onEnd) {
if (q.timer) {
if (q.onFailure) {
if (q.timer) {
q.finished = true;
if (q.aborted) {
if (q.onSuccess) {
if (q.onTimeout) {
if (q.timer) {
if (q.aborted) {
if (loaded) {
if (q.varName) {
if (q.varName) {
w = q.win;
d = w.document;
if (!url) {
if (q.timeout) {
}, q.timeout);
if (insertBefore) {
h.appendChild(n);
_autoPurge = function() {
if (purging) {
purging = true;
for (i in queues) {
q = queues[i];
delete queues[i];
purging = false;
_autoPurge();
finished: false,
nodes: []
n.onreadystatechange = function() {
n.onreadystatechange = null;
n.onload = function() {
n.onerror = function(e) {
n = q.nodes;
l = n.length;
if (insertBefore) {
h = s.parentNode;
node = n[i];
q.nodes = [];
setTimeout(function() {
abort: function(o) {
q.aborted = true;
* Y.Get.css("http://localhost/css/menu.css");
* ["http://localhost/css/menu.css",
var feature_tests = {};
if (cat_o) {
return result;
if (!feature) {
if (ua) {
return result;
/* This file is auto-generated by src/loader/meta_join.py */
ret = false;
test: function() {
test: function() {
return ret;
v: Y.version,
url;
return url;
var SPLIT_REGEX = /[, ]/;
return availableLanguages[i];
if (result) {
return result;
var INSTANCE = Y,
Y = INSTANCE,
c = Y.config,
if (c.debug) {
if (src) {
if (!bail) {
if (c.useBrowserConsole) {
console[f](m);
* Provides a setTimeout/setInterval wrapper
m = o[fn];
m.call(o);
cancel: function() {
if (this.interval) {
/*! Based on work by Simon Willison: http://gist.github.com/292562 */
* Can set globally with Y.config.throttleTime or by call. Passing a -1 will