yui-core-debug.js revision 8e9916f9f941d449c02f791f310cc77f63582a6d
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The YUI module contains the components required for building the YUI seed
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * file. This includes the script loading mechanism, a simple queue, and
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the core utilities for the library.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @module yui
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @submodule yui-base
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassif (typeof YUI != 'undefined') {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass YUI._YUI = YUI;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass}
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The YUI global namespace object. If YUI is already defined, the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * existing YUI object will not be overwritten so that defined
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * namespaces are preserved. It is the constructor for the object
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the end user interacts with. As indicated below, each instance
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * has full custom event support, but only if the event system
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * is available. This is a self-instantiable factory function. You
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * can invoke it directly like this:
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * YUI().use('*', function(Y) {
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * // ready
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * });
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * But it also works like this:
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * var Y = YUI();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @class YUI
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @constructor
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @global
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @uses EventTarget
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param o* {object} 0..n optional configuration objects. these values
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * are store in Y.config. See <a href="config.html">Config</a> for the list of supported
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * properties.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /*global YUI*/
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /*global YUI_config*/
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var YUI = function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var i = 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y = this,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass args = arguments,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass l = args.length,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass instanceOf = function(o, type) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return (o && o.hasOwnProperty && (o instanceof type));
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass gconf = (typeof YUI_config !== 'undefined') && YUI_config;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!(instanceOf(Y, YUI))) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y = new YUI();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // set up the core environment
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._init();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // YUI.GlobalConfig is a master configuration that might span
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // multiple contexts in a non-browser environment. It is applied
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // first to all instances in all contexts.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (YUI.GlobalConfig) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.applyConfig(YUI.GlobalConfig);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // YUI_Config is a page-level config. It is applied to all
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // instances created on the page. This is applied after
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // YUI.GlobalConfig, and before the instance level configuration
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // objects.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (gconf) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.applyConfig(gconf);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // bind the specified additional modules for this instance
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!l) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._setup();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (l) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Each instance can accept one or more configuration objects.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // These are applied after YUI.GlobalConfig and YUI_Config,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // overriding values set in those config files if there is a '
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // matching property.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (; i < l; i++) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.applyConfig(args[i]);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._setup();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.instanceOf = instanceOf;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Y;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass };
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass(function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var proto, prop,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass VERSION = '@VERSION@',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass PERIOD = '.',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass BASE = 'http://yui.yahooapis.com/',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass DOC_LABEL = 'yui3-js-enabled',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass NOOP = function() {},
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass SLICE = Array.prototype.slice,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass APPLY_TO_AUTH = { 'io.xdrReady': 1, // the functions applyTo
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass 'io.xdrResponse': 1, // can call. this should
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass 'SWF.eventHandler': 1 }, // be done at build time
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass hasWin = (typeof window != 'undefined'),
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass win = (hasWin) ? window : null,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass doc = (hasWin) ? win.document : null,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass docEl = doc && doc.documentElement,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass docClass = docEl && docEl.className,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass instances = {},
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass time = new Date().getTime(),
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass add = function(el, type, fn, capture) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (el && el.addEventListener) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass el.addEventListener(type, fn, capture);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if (el && el.attachEvent) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass el.attachEvent('on' + type, fn);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass remove = function(el, type, fn, capture) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (el && el.removeEventListener) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // this can throw an uncaught exception in FF
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass try {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass el.removeEventListener(type, fn, capture);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } catch (ex) {}
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if (el && el.detachEvent) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass el.detachEvent('on' + type, fn);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass handleLoad = function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass YUI.Env.windowLoaded = true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass YUI.Env.DOMReady = true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (hasWin) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass remove(window, 'load', handleLoad);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass getLoader = function(Y, o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var loader = Y.Env._loader;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (loader) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass //loader._config(Y.config);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.ignoreRegistered = false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.onEnd = null;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.data = null;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.required = [];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.loadType = null;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader = new Y.Loader(Y.config);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.Env._loader = loader;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return loader;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass clobber = function(r, s) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (var i in s) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (s.hasOwnProperty(i)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass r[i] = s[i];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ALREADY_DONE = { success: true };
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass// Stamp the documentElement (HTML) with a class of "yui-loaded" to
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass// enable styles that need to key off of JS being enabled.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassif (docEl && docClass.indexOf(DOC_LABEL) == -1) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (docClass) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass docClass += ' ';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass docClass += DOC_LABEL;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass docEl.className = docClass;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass}
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassif (VERSION.indexOf('@') > -1) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass VERSION = '3.3.0'; // dev time hack for cdn test
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass}
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassproto = {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Applies a new configuration object to the YUI instance config.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * This will merge new group/module definitions, and will also
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * update the loader cache if necessary. Updating Y.config directly
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * will not update the cache.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method applyConfig
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {object} the configuration object.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.2.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass applyConfig: function(o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o = o || NOOP;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var attr,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass name,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // detail,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass config = this.config,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass mods = config.modules,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass groups = config.groups,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass rls = config.rls,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader = this.Env._loader;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (name in o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (o.hasOwnProperty(name)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass attr = o[name];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (mods && name == 'modules') {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass clobber(mods, attr);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if (groups && name == 'groups') {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass clobber(groups, attr);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if (rls && name == 'rls') {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass clobber(rls, attr);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if (name == 'win') {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass config[name] = attr.contentWindow || attr;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass config.doc = config[name].document;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if (name == '_yuid') {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // preserve the guid
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass config[name] = attr;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (loader) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader._config(o);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
fcdb79161199cde3840a5b9779ece302b3b4c9ffDav Glass /**
fcdb79161199cde3840a5b9779ece302b3b4c9ffDav Glass * Old way to apply a config to the instance (calls `applyConfig` under the hood)
fcdb79161199cde3840a5b9779ece302b3b4c9ffDav Glass * @private
fcdb79161199cde3840a5b9779ece302b3b4c9ffDav Glass * @method _config
fcdb79161199cde3840a5b9779ece302b3b4c9ffDav Glass * @param {Object} o The config to apply
fcdb79161199cde3840a5b9779ece302b3b4c9ffDav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _config: function(o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass this.applyConfig(o);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Initialize this YUI instance
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @private
fcdb79161199cde3840a5b9779ece302b3b4c9ffDav Glass * @method _init
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _init: function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var filter,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y = this,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass G_ENV = YUI.Env,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Env = Y.Env,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass prop;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The version number of the YUI instance.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property version
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.version = VERSION;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!Env) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.Env = {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass mods: {}, // flat module map
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass versions: {}, // version module map
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass base: BASE,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass cdn: BASE + VERSION + '/build/',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // bootstrapped: false,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _idx: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _used: {},
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _attached: {},
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _missed: [],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _yidx: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _uidx: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _guidp: 'y',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _loaded: {},
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // serviced: {},
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Regex in English:
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // I'll start at the \b(simpleyui).
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // 1. Look in the test string for "simpleyui" or "yui" or
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // "yui-base" or "yui-rls" or "yui-foobar" that comes after a word break. That is, it
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // can't match "foyui" or "i_heart_simpleyui". This can be anywhere in the string.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // 2. After #1 must come a forward slash followed by the string matched in #1, so
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // "yui-base/yui-base" or "simpleyui/simpleyui" or "yui-pants/yui-pants".
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // 3. The second occurence of the #1 token can optionally be followed by "-debug" or "-min",
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // so "yui/yui-min", "yui/yui-debug", "yui-base/yui-base-debug". NOT "yui/yui-tshirt".
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // 4. This is followed by ".js", so "yui/yui.js", "simpleyui/simpleyui-min.js"
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // 0. Going back to the beginning, now. If all that stuff in 1-4 comes after a "?" in the string,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // then capture the junk between the LAST "&" and the string in 1-4. So
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // "blah?foo/yui/yui.js" will capture "foo/" and "blah?some/thing.js&3.3.0/build/yui-rls/yui-rls.js"
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // will capture "3.3.0/build/"
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass //
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Regex Exploded:
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // (?:\? Find a ?
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // (?:[^&]*&) followed by 0..n characters followed by an &
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // * in fact, find as many sets of characters followed by a & as you can
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // ([^&]*) capture the stuff after the last & in \1
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // )? but it's ok if all this ?junk&more_junk stuff isn't even there
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // \b(simpleyui| after a word break find either the string "simpleyui" or
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // yui(?:-\w+)? the string "yui" optionally followed by a -, then more characters
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // ) and store the simpleyui or yui-* string in \2
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // \/\2 then comes a / followed by the simpleyui or yui-* string in \2
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // (?:-(min|debug))? optionally followed by "-min" or "-debug"
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // .js and ending in ".js"
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _BASE_RE: /(?:\?(?:[^&]*&)*([^&]*))?\b(simpleyui|yui(?:-\w+)?)\/\2(?:-(min|debug))?\.js/,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass parseBasePath: function(src, pattern) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var match = src.match(pattern),
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass path, filter;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (match) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass path = RegExp.leftContext || src.slice(0, src.indexOf(match[0]));
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // this is to set up the path to the loader. The file
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // filter for loader should match the yui include.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass filter = match[3];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // extract correct path for mixed combo urls
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // http://yuilibrary.com/projects/yui3/ticket/2528423
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (match[1]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass path += '?' + match[1];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass path = {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass filter: filter,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass path: path
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return path;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass getBase: G_ENV && G_ENV.getBase ||
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass function(pattern) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var nodes = (doc && doc.getElementsByTagName('script')) || [],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass path = Env.cdn, parsed,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass i, len, src;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (i = 0, len = nodes.length; i < len; ++i) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass src = nodes[i].src;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (src) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass parsed = Y.Env.parseBasePath(src, pattern);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (parsed) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass filter = parsed.filter;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass path = parsed.path;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass break;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // use CDN default
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return path;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass };
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Env = Y.Env;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Env._loaded[VERSION] = {};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (G_ENV && Y !== YUI) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Env._yidx = ++G_ENV._yidx;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Env._guidp = ('yui_' + VERSION + '_' +
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Env._yidx + '_' + time).replace(/\./g, '_');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if (YUI._YUI) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass G_ENV = YUI._YUI.Env;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Env._yidx += G_ENV._yidx;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Env._uidx += G_ENV._uidx;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (prop in G_ENV) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!(prop in Env)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Env[prop] = G_ENV[prop];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass delete YUI._YUI;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.id = Y.stamp(Y);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass instances[Y.id] = Y;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.constructor = YUI;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // configuration defaults
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.config = Y.config || {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass win: win,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass doc: doc,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass debug: true,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass useBrowserConsole: true,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass throwFail: true,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass bootstrap: true,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass cacheUse: true,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass fetchCSS: true,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass use_rls: false
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass };
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.config.lang = Y.config.lang || 'en-US';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.config.base = YUI.config.base || Y.Env.getBase(Y.Env._BASE_RE);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!filter || (!('mindebug').indexOf(filter))) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass filter = 'min';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass filter = (filter) ? '-' + filter : filter;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.config.loaderPath = YUI.config.loaderPath || 'loader/loader' + filter + '.js';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Finishes the instance setup. Attaches whatever modules were defined
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * when the yui modules was registered.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method _setup
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @private
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _setup: function(o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var i, Y = this,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass core = [],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass mods = YUI.Env.mods,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass extras = Y.config.core || ['get','intl-base'];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (i = 0; i < extras.length; i++) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (mods[extras[i]]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass core.push(extras[i]);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._attach(['yui-base']);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._attach(core);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Y.log(Y.id + ' initialized', 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Executes a method on a YUI instance with
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the specified id if the specified method is whitelisted.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method applyTo
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param id {String} the YUI instance id.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param method {String} the name of the method to exectute.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Ex: 'Object.keys'.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param args {Array} the arguments to apply to the method.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @return {Object} the return value from the applied method or null.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass applyTo: function(id, method, args) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!(method in APPLY_TO_AUTH)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass this.log(method + ': applyTo not allowed', 'warn', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return null;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var instance = instances[id], nest, m, i;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (instance) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass nest = method.split('.');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = instance;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (i = 0; i < nest.length; i = i + 1) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = m[nest[i]];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!m) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass this.log('applyTo not found: ' + method, 'warn', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return m.apply(instance, args);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return null;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Registers a module with the YUI global. The easiest way to create a
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * first-class YUI module is to use the YUI component build tool.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * http://yuilibrary.com/projects/builder
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * The build system will produce the `YUI.add` wrapper for you module, along
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * with any configuration info required for the module.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method add
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param name {String} module name.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param fn {Function} entry point into the module that
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * is used to bind module to the YUI instance.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param version {String} version string.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param details {Object} optional config data:
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param details.requires {Array} features that must be present before this module can be attached.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param details.optional {Array} optional features that should be present if loadOptional
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * is defined. Note: modules are not often loaded this way in YUI 3,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * but this field is still useful to inform the user that certain
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * features in the component will require additional dependencies.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param details.use {Array} features that are included within this module which need to
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * be attached automatically when this module is attached. This
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * supports the YUI 3 rollup system -- a module with submodules
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * defined will need to have the submodules listed in the 'use'
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * config. The YUI component build tool does this for you.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {YUI} the YUI instance.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass add: function(name, fn, version, details) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass details = details || {};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var env = YUI.Env,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass mod = {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass name: name,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass fn: fn,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass version: version,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass details: details
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass i, versions = env.versions;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass env.mods[name] = mod;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass versions[version] = versions[version] || {};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass versions[version][name] = mod;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (i in instances) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (instances.hasOwnProperty(i)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader = instances[i].Env._loader;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (loader) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!loader.moduleInfo[name]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.addModule(details, name);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return this;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Executes the function associated with each required
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * module, binding the module to the YUI instance.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method _attach
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @private
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _attach: function(r, moot) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var i, name, mod, details, req, use, after,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass mods = YUI.Env.mods,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass aliases = YUI.Env.aliases,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y = this, j,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass done = Y.Env._attached,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass len = r.length, loader;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass //console.info('attaching: ' + r, 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (i = 0; i < len; i++) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!done[r[i]]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass name = r[i];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass mod = mods[name];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (aliases && aliases[name]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._attach(aliases[name]);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass continue;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!mod) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader = Y.Env._loader;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (loader && loader.moduleInfo[name]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass mod = loader.moduleInfo[name];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (mod.use) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass moot = true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Y.log('no js def for: ' + name, 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass //if (!loader || !loader.moduleInfo[name]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass //if ((!loader || !loader.moduleInfo[name]) && !moot) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!moot) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (name.indexOf('skin-') === -1) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.Env._missed.push(name);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.message('NOT loaded: ' + name, 'warn', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass done[name] = true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass //Don't like this, but in case a mod was asked for once, then we fetch it
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass //We need to remove it from the missed list
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (j = 0; j < Y.Env._missed.length; j++) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (Y.Env._missed[j] === name) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.message('Found: ' + name + ' (was reported as missing earlier)', 'warn', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.Env._missed.splice(j, 1);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass details = mod.details;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass req = details.requires;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass use = details.use;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass after = details.after;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (req) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (j = 0; j < req.length; j++) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!done[req[j]]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!Y._attach(req)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass break;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (after) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (j = 0; j < after.length; j++) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!done[after[j]]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!Y._attach(after, true)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass break;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (mod.fn) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass try {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass mod.fn(Y, name);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } catch (e) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.error('Attach error: ' + name, e, name);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (use) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (j = 0; j < use.length; j++) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!done[use[j]]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!Y._attach(use)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass break;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Attaches one or more modules to the YUI instance. When this
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * is executed, the requirements are analyzed, and one of
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * several things can happen:
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * All requirements are available on the page -- The modules
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * are attached to the instance. If supplied, the use callback
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * is executed synchronously.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * Modules are missing, the Get utility is not available OR
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the 'bootstrap' config is false -- A warning is issued about
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the missing modules and all available modules are attached.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * Modules are missing, the Loader is not available but the Get
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * utility is and boostrap is not false -- The loader is bootstrapped
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * before doing the following....
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * Modules are missing and the Loader is available -- The loader
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * expands the dependency tree and fetches missing modules. When
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the loader is finshed the callback supplied to use is executed
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * asynchronously.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @method use
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param modules* {String} 1-n modules to bind (uses arguments array).
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param *callback {Function} callback function executed when
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the instance has the required functionality. If included, it
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * must be the last parameter.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @example
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * // loads and attaches dd and its dependencies
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * YUI().use('dd', function(Y) {});
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * // loads and attaches dd and node as well as all of their dependencies (since 3.4.0)
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * YUI().use(['dd', 'node'], function(Y) {});
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * // attaches all modules that are available on the page
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * YUI().use('*', function(Y) {});
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * // intrinsic YUI gallery support (since 3.1.0)
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * YUI().use('gallery-yql', function(Y) {});
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * // intrinsic YUI 2in3 support (since 3.1.0)
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * YUI().use('yui2-datatable', function(Y) {});
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {YUI} the YUI instance.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass use: function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var args = SLICE.call(arguments, 0),
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass callback = args[args.length - 1],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y = this,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass i = 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass name,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Env = Y.Env,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass provisioned = true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // The last argument supplied to use can be a load complete callback
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (Y.Lang.isFunction(callback)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass args.pop();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass callback = null;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (Y.Lang.isArray(args[0])) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass args = args[0];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (Y.config.cacheUse) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass while ((name = args[i++])) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!Env._attached[name]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass provisioned = false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass break;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (provisioned) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (args.length) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.log('already provisioned: ' + args, 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._notify(callback, ALREADY_DONE, args);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Y;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (Y.config.cacheUse) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass while ((name = args[i++])) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!Env._attached[name]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass provisioned = false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass break;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (provisioned) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (args.length) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.log('already provisioned: ' + args, 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._notify(callback, ALREADY_DONE, args);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Y;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (Y._loading) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._useQueue = Y._useQueue || new Y.Queue();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._useQueue.add([args, callback]);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._use(args, function(Y, response) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._notify(callback, response, args);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass });
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Y;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass /**
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * Notify handler from Loader for attachment/load errors
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @method _notify
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param callback {Function} The callback to pass to the `Y.config.loadErrorFn`
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param response {Object} The response returned from Loader
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param args {Array} The aruments passed from Loader
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @private
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _notify: function(callback, response, args) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!response.success && this.config.loadErrorFn) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass this.config.loadErrorFn.call(this, this, callback, response, args);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if (callback) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass try {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass callback(this, response);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } catch (e) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass this.error('use callback error', e, args);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass /**
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * This private method is called from the `use` method queue. To ensure that only one set of loading
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * logic is performed at a time.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @method _use
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @private
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param args* {String} 1-n modules to bind (uses arguments array).
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param *callback {Function} callback function executed when
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * the instance has the required functionality. If included, it
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * must be the last parameter.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _use: function(args, callback) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!this.Array) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass this._attach(['yui-base']);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var len, loader, handleBoot, handleRLS,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y = this,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass G_ENV = YUI.Env,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass mods = G_ENV.mods,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Env = Y.Env,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass used = Env._used,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass queue = G_ENV._loaderQueue,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass firstArg = args[0],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass YArray = Y.Array,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass config = Y.config,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass boot = config.bootstrap,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass missing = [],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass r = [],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ret = true,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass fetchCSS = config.fetchCSS,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass process = function(names, skip) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!names.length) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass YArray.each(names, function(name) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // add this module to full list of things to attach
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!skip) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass r.push(name);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // only attach a module once
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (used[name]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var m = mods[name], req, use;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass used[name] = true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass req = m.details.requires;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass use = m.details.use;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // CSS files don't register themselves, see if it has
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // been loaded
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!G_ENV._loaded[VERSION][name]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass missing.push(name);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass used[name] = true; // probably css
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // make sure requirements are attached
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (req && req.length) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass process(req);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // make sure we grab the submodule dependencies too
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (use && use.length) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass process(use, 1);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass });
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass handleLoader = function(fromLoader) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var response = fromLoader || {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass success: true,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass msg: 'not dynamic'
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass redo, origMissing,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ret = true,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass data = response.data;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._loading = false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (data) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass origMissing = missing;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass missing = [];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass r = [];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass process(data);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass redo = missing.length;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (redo) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (missing.sort().join() ==
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass origMissing.sort().join()) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass redo = false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (redo && data) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._loading = false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._use(args, function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.log('Nested use callback: ' + data, 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (Y._attach(data)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._notify(callback, response, data);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass });
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (data) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Y.log('attaching from loader: ' + data, 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ret = Y._attach(data);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (ret) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._notify(callback, response, args);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (Y._useQueue && Y._useQueue.size() && !Y._loading) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._use.apply(Y, Y._useQueue.next());
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass };
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass// Y.log(Y.id + ': use called: ' + a + ' :: ' + callback, 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // YUI().use('*'); // bind everything available
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (firstArg === '*') {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ret = Y._attach(Y.Object.keys(mods));
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (ret) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass handleLoader();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Y;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Y.log('before loader requirements: ' + args, 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // use loader to expand dependencies and sort the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // requirements if it is available.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (boot && Y.Loader && args.length) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader = getLoader(Y);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.require(args);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.ignoreRegistered = true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.calculate(null, (fetchCSS) ? null : 'js');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass args = loader.sorted;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // process each requirement and any additional requirements
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // the module metadata specifies
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass process(args);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass len = missing.length;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (len) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass missing = Y.Object.keys(YArray.hash(missing));
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass len = missing.length;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassY.log('Modules missing: ' + missing + ', ' + missing.length, 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // dynamic load
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (boot && len && Y.Loader) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass// Y.log('Using loader to fetch missing deps: ' + missing, 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.log('Using Loader', 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._loading = true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader = getLoader(Y);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.onEnd = handleLoader;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.context = Y;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.data = args;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.ignoreRegistered = false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.require(args);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.insert(null, (fetchCSS) ? null : 'js');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // loader.partial(missing, (fetchCSS) ? null : 'js');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if (len && Y.config.use_rls) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass G_ENV._rls_queue = G_ENV._rls_queue || new Y.Queue();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // server side loader service
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass handleRLS = function(instance, argz) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var rls_end = function(o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass handleLoader(o);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass G_ENV._rls_in_progress = false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (G_ENV._rls_queue.size()) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass G_ENV._rls_queue.next()();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass rls_url = instance._rls(argz);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (rls_url) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.log('Fetching RLS url', 'info', 'rls');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass instance.rls_oncomplete(function(o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass rls_end(o);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass });
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass instance.Get.script(rls_url, {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass data: argz
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass });
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass rls_end({
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass data: argz
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass });
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass };
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass G_ENV._rls_queue.add(function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.log('executing queued rls request', 'info', 'rls');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass G_ENV._rls_in_progress = true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.rls_locals(Y, args, handleRLS);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass });
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!G_ENV._rls_in_progress && G_ENV._rls_queue.size()) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass G_ENV._rls_queue.next()();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if (boot && len && Y.Get && !Env.bootstrapped) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._loading = true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass handleBoot = function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._loading = false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass queue.running = false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Env.bootstrapped = true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (Y._attach(['loader'])) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._use(args, callback);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass };
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (G_ENV._bootstrapping) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassY.log('Waiting for loader', 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass queue.add(handleBoot);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass G_ENV._bootstrapping = true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassY.log('Fetching loader: ' + config.base + config.loaderPath, 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.Get.script(config.base + config.loaderPath, {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass onEnd: handleBoot
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass });
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.log('Attaching available dependencies: ' + args, 'info', 'yui');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ret = Y._attach(args);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (ret) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass handleLoader();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Y;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns the namespace specified and creates it if it doesn't exist
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * YUI.namespace("property.package");
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * YUI.namespace("YAHOO.property.package");
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * Either of the above would create `YUI.property`, then
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * `YUI.property.package` (`YAHOO` is scrubbed out, this is
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * to remain compatible with YUI2)
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Be careful when naming packages. Reserved words may work in some browsers
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * and not others. For instance, the following will fail in Safari:
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * YUI.namespace("really.long.nested.namespace");
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * This fails because "long" is a future reserved word in ECMAScript
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method namespace
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {string*} arguments 1-n namespaces to create.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {object} A reference to the last namespace object created.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass namespace: function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var a = arguments, o = this, i = 0, j, d, arg;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (; i < a.length; i++) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // d = ('' + a[i]).split('.');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass arg = a[i];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (arg.indexOf(PERIOD)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass d = arg.split(PERIOD);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (j = (d[0] == 'YAHOO') ? 1 : 0; j < d.length; j++) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o[d[j]] = o[d[j]] || {};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o = o[d[j]];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o[arg] = o[arg] || {};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return o;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // this is replaced if the log module is included
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass log: NOOP,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass message: NOOP,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // this is replaced if the dump module is included
8e9916f9f941d449c02f791f310cc77f63582a6dLuke Smith dump: function (o) { return ''+o; },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Report an error. The reporting mechanism is controled by
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * the `throwFail` configuration attribute. If throwFail is
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * not specified, the message is written to the Logger, otherwise
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * a JS error is thrown
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method error
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param msg {String} the error message.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param e {Error|String} Optional JS error that was caught, or an error string.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param data Optional additional info
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * and `throwFail` is specified, this error will be re-thrown.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {YUI} this YUI instance.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass error: function(msg, e, data) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var Y = this, ret;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (Y.config.errorFn) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ret = Y.config.errorFn.apply(Y, arguments);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (Y.config.throwFail && !ret) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass throw (e || new Error(msg));
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.message(msg, 'error'); // don't scrub this one
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Y;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Generate an id that is unique among all YUI instances
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method guid
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param pre {String} optional guid prefix.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @return {String} the guid.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass guid: function(pre) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var id = this.Env._guidp + '_' + (++this.Env._uidx);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return (pre) ? (pre + id) : id;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * Returns a `guid` associated with an object. If the object
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * does not have one, a new one is created unless `readOnly`
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * is specified.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method stamp
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param o {Object} The object to stamp.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @param readOnly {Boolean} if `true`, a valid guid will only
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * be returned if the object has one assigned to it.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @return {String} The object's guid or null.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass stamp: function(o, readOnly) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var uid;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return o;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // IE generates its own unique ID for dom nodes
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // The uniqueID property of a document node returns a new ID
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (o.uniqueID && o.nodeType && o.nodeType !== 9) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass uid = o.uniqueID;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass uid = (typeof o === 'string') ? o : o._yuid;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!uid) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass uid = this.guid();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!readOnly) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass try {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o._yuid = uid;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } catch (e) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass uid = null;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return uid;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Destroys the YUI instance
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method destroy
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.3.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass destroy: function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var Y = this;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (Y.Event) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.Event._unload();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass delete instances[Y.id];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass delete Y.Env;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass delete Y.config;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * instanceof check for objects that works around
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * memory leak in IE when the item tested is
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * window/document
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method instanceOf
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.3.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass YUI.prototype = proto;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // inheritance utilities are not available yet
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (prop in proto) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (proto.hasOwnProperty(prop)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass YUI[prop] = proto[prop];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // set up the environment
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass YUI._init();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (hasWin) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // add a window load event at load time so we can capture
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // the case where it fires before dynamic loading is
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // complete.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass add(window, 'load', handleLoad);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass handleLoad();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass YUI.Env.add = add;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass YUI.Env.remove = remove;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /*global exports*/
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Support the CommonJS method for exporting our single global
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (typeof exports == 'object') {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass exports.YUI = YUI;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass}());
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The config object contains all of the configuration options for
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * the `YUI` instance. This object is supplied by the implementer
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * when instantiating a `YUI` instance. Some properties have default
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * values if they are not supplied by the implementer. This should
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * not be updated directly because some values are cached. Use
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * `applyConfig()` to update the config object on a YUI instance that
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * has already been configured.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @class config
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Allows the YUI seed file to fetch the loader component and library
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * metadata to dynamically load additional dependencies.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property bootstrap
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type boolean
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default true
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Log to the browser console if debug is on and the browser has a
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * supported console.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property useBrowserConsole
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type boolean
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default true
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * A hash of log sources that should be logged. If specified, only
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * log messages from these sources will be logged.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property logInclude
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type object
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * A hash of log sources that should be not be logged. If specified,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * all sources are logged if not on this list.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property logExclude
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type object
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Set to true if the yui seed file was dynamically loaded in
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * order to bootstrap components relying on the window load event
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * and the `domready` custom event.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property injected
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type boolean
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default false
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * If `throwFail` is set, `Y.error` will generate or re-throw a JS Error.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Otherwise the failure is logged.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property throwFail
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type boolean
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default true
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The window/frame that this instance should operate in.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property win
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type Window
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default the window hosting YUI
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The document associated with the 'win' configuration.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property doc
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type Document
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default the document hosting YUI
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * A list of modules that defines the YUI core (overrides the default).
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property core
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string[]
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * A list of languages in order of preference. This list is matched against
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the list of available languages in modules that the YUI instance uses to
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * determine the best possible localization of language sensitive modules.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Languages are represented using BCP 47 language tags, such as "en-GB" for
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * English as used in the United Kingdom, or "zh-Hans-CN" for simplified
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Chinese as used in China. The list can be provided as a comma-separated
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * list or as an array.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property lang
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string|string[]
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The default date format
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property dateFormat
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @deprecated use configuration in `DataType.Date.format()` instead.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The default locale
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property locale
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @deprecated use `config.lang` instead.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The default interval when polling in milliseconds.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property pollInterval
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type int
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default 20
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The number of dynamic nodes to insert by default before
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * automatically removing them. This applies to script nodes
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * because removing the node will not make the evaluated script
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * unavailable. Dynamic CSS is not auto purged, because removing
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * a linked style sheet will also remove the style definitions.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property purgethreshold
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type int
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default 20
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The default interval when polling in milliseconds.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property windowResizeDelay
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type int
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default 40
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Base directory for dynamic loading
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property base
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/*
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The secure base dir (not implemented)
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * For dynamic loading.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property secureBase
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * The YUI combo service base dir. Ex: `http://yui.yahooapis.com/combo?`
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * For dynamic loading.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property comboBase
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The root path to prepend to module path for the combo service.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Ex: 3.0.0b1/build/
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * For dynamic loading.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property root
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * A filter to apply to result urls. This filter will modify the default
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * path for all modules. The default path for the YUI library is the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * minified version of the files (e.g., event-min.js). The filter property
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * can be a predefined filter or a custom filter. The valid predefined
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * filters are:
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <dl>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <dt>DEBUG</dt>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <dd>Selects the debug versions of the library (e.g., event-debug.js).
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * This option will automatically include the Logger widget</dd>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <dt>RAW</dt>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <dd>Selects the non-minified version of the library (e.g., event.js).</dd>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * </dl>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * You can also define a custom filter, which must be an object literal
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * containing a search expression and a replace string:
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * myFilter: {
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * 'searchExp': "-min\\.js",
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * 'replaceStr': "-debug.js"
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * For dynamic loading.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property filter
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string|object
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * The `skin` config let's you configure application level skin
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * customizations. It contains the following attributes which
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * can be specified to override the defaults:
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * // The default skin, which is automatically applied if not
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * // overriden by a component-specific skin definition.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * // Change this in to apply a different skin globally
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * defaultSkin: 'sam',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * // This is combined with the loader base property to get
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * // the default root directory for a skin.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * base: 'assets/skins/',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * // Any component-specific overrides can be specified here,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * // making it possible to load different skins for different
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * // components. It is possible to load more than one skin
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * // for a given component as well.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * overrides: {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * slider: ['capsule', 'round']
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * For dynamic loading.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property skin
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Hash of per-component filter specification. If specified for a given
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * component, this overrides the filter config.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * For dynamic loading.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property filters
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Use the YUI combo service to reduce the number of http connections
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * required to load your dependencies. Turning this off will
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * disable combo handling for YUI and all module groups configured
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * with a combo service.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * For dynamic loading.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property combine
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type boolean
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default true if 'base' is not supplied, false if it is.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * A list of modules that should never be dynamically loaded
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property ignore
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string[]
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * A list of modules that should always be loaded when required, even if already
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * present on the page.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property force
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string[]
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Node or id for a node that should be used as the insertion point for new
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * nodes. For dynamic loading.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property insertBefore
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Object literal containing attributes to add to dynamically loaded script
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * nodes.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property jsAttributes
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Object literal containing attributes to add to dynamically loaded link
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * nodes.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property cssAttributes
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Number of milliseconds before a timeout occurs when dynamically
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * loading nodes. If not set, there is no timeout.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property timeout
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type int
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Callback for the 'CSSComplete' event. When dynamically loading YUI
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * components with CSS, this property fires when the CSS is finished
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * loading but script loading is still ongoing. This provides an
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * opportunity to enhance the presentation of a loading page a little
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * bit before the entire loading process is done.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property onCSS
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type function
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * A hash of module definitions to add to the list of YUI components.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * These components can then be dynamically loaded side by side with
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * YUI via the `use()` method. This is a hash, the key is the module
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * name, and the value is an object literal specifying the metdata
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * for the module. See `Loader.addModule` for the supported module
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * metadata fields. Also see groups, which provides a way to
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * configure the base and combo spec for a set of modules.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * modules: {
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * mymod1: {
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * requires: ['node'],
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * fullpath: 'http://myserver.mydomain.com/mymod1/mymod1.js'
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * },
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * mymod2: {
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * requires: ['mymod1'],
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * fullpath: 'http://myserver.mydomain.com/mymod2/mymod2.js'
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * }
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property modules
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type object
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * A hash of module group definitions. It for each group you
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * can specify a list of modules and the base path and
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * combo spec to use when dynamically loading the modules.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * groups: {
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * yui2: {
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * // specify whether or not this group has a combo service
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * combine: true,
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * // the base path for non-combo paths
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * base: 'http://yui.yahooapis.com/2.8.0r4/build/',
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * // the path to the combo service
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * comboBase: 'http://yui.yahooapis.com/combo?',
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * // a fragment to prepend to the path attribute when
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * // when building combo urls
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * root: '2.8.0r4/build/',
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * // the module definitions
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * modules: {
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * yui2_yde: {
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * path: "yahoo-dom-event/yahoo-dom-event.js"
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * },
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * yui2_anim: {
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * path: "animation/animation.js",
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * requires: ['yui2_yde']
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * }
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * }
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * }
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * }
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @property groups
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type object
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The loader 'path' attribute to the loader itself. This is combined
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * with the 'base' attribute to dynamically load the loader component
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * when boostrapping with the get utility alone.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property loaderPath
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default loader/loader-min.js
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Specifies whether or not YUI().use(...) will attempt to load CSS
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * resources at all. Any truthy value will cause CSS dependencies
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * to load when fetching script. The special value 'force' will
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * cause CSS dependencies to be loaded even if no script is needed.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property fetchCSS
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type boolean|string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default true
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The default gallery version to build gallery module urls
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property gallery
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.1.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The default YUI 2 version to build yui2 module urls. This is for
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * intrinsic YUI 2 support via the 2in3 project. Also see the '2in3'
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * config for pulling different revisions of the wrapped YUI 2
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * modules.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.1.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property yui2
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default 2.8.1
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The 2in3 project is a deployment of the various versions of YUI 2
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * deployed as first-class YUI 3 modules. Eventually, the wrapper
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * for the modules will change (but the underlying YUI 2 code will
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * be the same), and you can select a particular version of
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the wrapper modules via this config.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.1.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property 2in3
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default 1
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Alternative console log function for use in environments without
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * a supported native console. The function is executed in the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * YUI instance context.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.1.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property logFn
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type Function
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * A callback to execute when Y.error is called. It receives the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * error message and an javascript error object if Y.error was
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * executed because a javascript error was caught. The function
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * is executed in the YUI instance context.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.2.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property errorFn
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type Function
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * A callback to execute when the loader fails to load one or
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * more resource. This could be because of a script load
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * failure. It can also fail if a javascript module fails
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * to register itself, but only when the 'requireRegistration'
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * is true. If this function is defined, the use() callback will
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * only be called when the loader succeeds, otherwise it always
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * executes unless there was a javascript error when attaching
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * a module.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.3.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property loadErrorFn
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type Function
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * When set to true, the YUI loader will expect that all modules
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * it is responsible for loading will be first-class YUI modules
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * that register themselves with the YUI global. If this is
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * set to true, loader will fail if the module registration fails
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * to happen after the script is loaded.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.3.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property requireRegistration
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type boolean
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default false
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Cache serviced use() requests.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.3.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property cacheUse
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type boolean
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default true
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @deprecated no longer used
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The parameter defaults for the remote loader service.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Requires the rls submodule. The properties that are
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * supported:
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * `m`: comma separated list of module requirements. This
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * must be the param name even for custom implemetations.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * `v`: the version of YUI to load. Defaults to the version
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * of YUI that is being used.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * `gv`: the version of the gallery to load (see the gallery config)
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * `env`: comma separated list of modules already on the page.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * this must be the param name even for custom implemetations.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * `lang`: the languages supported on the page (see the lang config)
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * `'2in3v'`: the version of the 2in3 wrapper to use (see the 2in3 config).
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * `'2v'`: the version of yui2 to use in the yui 2in3 wrappers
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * `filt`: a filter def to apply to the urls (see the filter config).
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * `filts`: a list of custom filters to apply per module
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * `tests`: this is a map of conditional module test function id keys
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * with the values of 1 if the test passes, 0 if not. This must be
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the name of the querystring param in custom templates.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.2.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property rls
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The base path to the remote loader service
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.2.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property rls_base
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The template to use for building the querystring portion
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * of the remote loader service url. The default is determined
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * by the rls config -- each property that has a value will be
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * represented.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.2.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property rls_tmpl
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * @example
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * m={m}&v={v}&env={env}&lang={lang}&filt={filt}&tests={tests}
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Configure the instance to use a remote loader service instead of
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the client loader.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.2.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property use_rls
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassYUI.add('yui-base', function(Y) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/*
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * YUI stub
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @module yui
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @submodule yui-base
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The YUI module contains the components required for building the YUI
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * seed file. This includes the script loading mechanism, a simple queue,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * and the core utilities for the library.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @module yui
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @submodule yui-base
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Provides core language utilites and extensions used throughout YUI.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @class Lang
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassvar L = Y.Lang || (Y.Lang = {}),
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassSTRING_PROTO = String.prototype,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassTOSTRING = Object.prototype.toString,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassTYPES = {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass 'undefined' : 'undefined',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass 'number' : 'number',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass 'boolean' : 'boolean',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass 'string' : 'string',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass '[object Function]': 'function',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass '[object RegExp]' : 'regexp',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass '[object Array]' : 'array',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass '[object Date]' : 'date',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass '[object Error]' : 'error'
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass},
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassSUBREGEX = /\{\s*([^|}]+?)\s*(?:\|([^}]*))?\s*\}/g,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassTRIMREGEX = /^\s+|\s+$/g,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass// If either MooTools or Prototype is on the page, then there's a chance that we
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass// can't trust "native" language features to actually be native. When this is
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass// the case, we take the safe route and fall back to our own non-native
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass// implementation.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glasswin = Y.config.win,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassunsafeNatives = win && !!(win.MooTools || win.Prototype);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Determines whether or not the provided item is an array.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns `false` for array-like collections such as the function `arguments`
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * collection or `HTMLElement` collections. Use `Y.Array.test()` if you want to
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * test for an array-like collection.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method isArray
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param o The object to test.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {boolean} true if o is an array.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.isArray = (!unsafeNatives && Array.isArray) || function (o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return L.type(o) === 'array';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Determines whether or not the provided item is a boolean.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method isBoolean
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param o The object to test.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {boolean} true if o is a boolean.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.isBoolean = function(o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return typeof o === 'boolean';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <p>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Determines whether or not the provided item is a function.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Note: Internet Explorer thinks certain functions are objects:
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * </p>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <pre>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * var obj = document.createElement("object");
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Y.Lang.isFunction(obj.getAttribute) // reports false in IE
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * &nbsp;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * var input = document.createElement("input"); // append to body
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Y.Lang.isFunction(input.focus) // reports false in IE
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * </pre>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <p>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * You will have to implement additional tests if these functions
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * matter to you.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * </p>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method isFunction
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param o The object to test.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {boolean} true if o is a function.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.isFunction = function(o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return L.type(o) === 'function';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Determines whether or not the supplied item is a date instance.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method isDate
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param o The object to test.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {boolean} true if o is a date.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.isDate = function(o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return L.type(o) === 'date' && o.toString() !== 'Invalid Date' && !isNaN(o);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Determines whether or not the provided item is null.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method isNull
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param o The object to test.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {boolean} true if o is null.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.isNull = function(o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return o === null;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Determines whether or not the provided item is a legal number.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method isNumber
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param o The object to test.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {boolean} true if o is a number.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.isNumber = function(o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return typeof o === 'number' && isFinite(o);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Determines whether or not the provided item is of type object
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * or function. Note that arrays are also objects, so
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <code>Y.Lang.isObject([]) === true</code>.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method isObject
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param o The object to test.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param failfn {boolean} fail if the input is a function.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {boolean} true if o is an object.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @see isPlainObject
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.isObject = function(o, failfn) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var t = typeof o;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return (o && (t === 'object' ||
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass (!failfn && (t === 'function' || L.isFunction(o))))) || false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Determines whether or not the provided item is a string.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method isString
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param o The object to test.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {boolean} true if o is a string.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.isString = function(o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return typeof o === 'string';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Determines whether or not the provided item is undefined.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method isUndefined
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param o The object to test.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {boolean} true if o is undefined.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.isUndefined = function(o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return typeof o === 'undefined';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns a string without any leading or trailing whitespace. If
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the input is not a string, the input will be returned untouched.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method trim
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param s {string} the string to trim.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {string} the trimmed string.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.trim = STRING_PROTO.trim ? function(s) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return s && s.trim ? s.trim() : s;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass} : function (s) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass try {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return s.replace(TRIMREGEX, '');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } catch (e) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return s;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns a string without any leading whitespace.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method trimLeft
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param s {string} the string to trim.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {string} the trimmed string.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.trimLeft = STRING_PROTO.trimLeft ? function (s) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return s.trimLeft();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass} : function (s) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return s.replace(/^\s+/, '');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns a string without any trailing whitespace.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method trimRight
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param s {string} the string to trim.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {string} the trimmed string.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.trimRight = STRING_PROTO.trimRight ? function (s) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return s.trimRight();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass} : function (s) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return s.replace(/\s+$/, '');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * A convenience method for detecting a legitimate non-null value.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns false for null/undefined/NaN, true for other values,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * including 0/false/''
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method isValue
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param o The item to test.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {boolean} true if it is not null/undefined/NaN || false.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.isValue = function(o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var t = L.type(o);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass switch (t) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass case 'number':
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return isFinite(o);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass case 'null': // fallthru
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass case 'undefined':
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass default:
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return !!t;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <p>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns a string representing the type of the item passed in.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * </p>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <p>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Known issues:
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * </p>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <ul>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <li>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <code>typeof HTMLElementCollection</code> returns function in Safari, but
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <code>Y.type()</code> reports object, which could be a good thing --
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * but it actually caused the logic in <code>Y.Lang.isObject</code> to fail.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * </li>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * </ul>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method type
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param o the item to test.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {string} the detected type.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.type = function(o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return TYPES[typeof o] || TYPES[TOSTRING.call(o)] || (o ? 'object' : 'null');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Lightweight version of <code>Y.substitute</code>. Uses the same template
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * structure as <code>Y.substitute</code>, but doesn't support recursion,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * auto-object coersion, or formats.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method sub
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {string} s String to be modified.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {object} o Object containing replacement values.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {string} the substitute result.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.2.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.sub = function(s, o) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return s.replace ? s.replace(SUBREGEX, function (match, key) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return L.isUndefined(o[key]) ? match : o[key];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }) : s;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns the current time in milliseconds.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method now
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {int} Current time in milliseconds.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.3.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassL.now = Date.now || function () {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return new Date().getTime();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The YUI module contains the components required for building the YUI seed
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * file. This includes the script loading mechanism, a simple queue, and the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * core utilities for the library.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @module yui
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @submodule yui-base
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassvar Lang = Y.Lang,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Native = Array.prototype,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass hasOwn = Object.prototype.hasOwnProperty;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Adds utilities to the YUI instance for working with arrays. Additional array
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * helpers can be found in the `collection` module.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @class Array
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * `Y.Array(thing)` returns an array created from _thing_. Depending on
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * _thing_'s type, one of the following will happen:
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * Arrays are returned unmodified unless a non-zero _startIndex_ is
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * specified.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * Array-like collections (see `Array.test()`) are converted to arrays.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * For everything else, a new array is created with _thing_ as the sole
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * item.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Note: elements that are also collections, such as `<form>` and `<select>`
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * elements, are not automatically converted to arrays. To force a conversion,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * pass `true` as the value of the _force_ parameter.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method ()
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {mixed} thing The thing to arrayify.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {int} [startIndex=0] If non-zero and _thing_ is an array or array-like
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * collection, a subset of items starting at the specified index will be
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * returned.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {boolean} [force=false] If `true`, _thing_ will be treated as an
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * array-like collection no matter what.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Array}
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassfunction YArray(thing, startIndex, force) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var len, result;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass startIndex || (startIndex = 0);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (force || YArray.test(thing)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // IE throws when trying to slice HTMLElement collections.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass try {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Native.slice.call(thing, startIndex);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } catch (ex) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass result = [];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (len = thing.length; startIndex < len; ++startIndex) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass result.push(thing[startIndex]);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return result;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return [thing];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass}
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassY.Array = YArray;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Evaluates _obj_ to determine if it's an array, an array-like collection, or
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * something else. This is useful when working with the function `arguments`
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * collection and `HTMLElement` collections.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Note: This implementation doesn't consider elements that are also
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * collections, such as `<form>` and `<select>`, to be array-like.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method test
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {object} obj Object to test.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {int} A number indicating the results of the test:
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass *
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * 0: Neither an array nor an array-like collection.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * 1: Real array.
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * * 2: Array-like collection.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassYArray.test = function (obj) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var result = 0;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (Lang.isArray(obj)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass result = 1;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if (Lang.isObject(obj)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass try {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // indexed, but no tagName (element) or alert (window),
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // or functions without apply/call (Safari
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // HTMLElementCollection bug).
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if ('length' in obj && !obj.tagName && !obj.alert && !obj.apply) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass result = 2;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } catch (ex) {}
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return result;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Dedupes an array of strings, returning an array that's guaranteed to contain
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * only one copy of a given string.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * This method differs from `Y.Array.unique` in that it's optimized for use only
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * with strings, whereas `unique` may be used with other types (but is slower).
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Using `dedupe` with non-string values may result in unexpected behavior.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method dedupe
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {String[]} array Array of strings to dedupe.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Array} Deduped copy of _array_.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.4.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassYArray.dedupe = function (array) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var hash = {},
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass results = [],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass i, item, len;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (i = 0, len = array.length; i < len; ++i) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass item = array[i];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!hasOwn.call(hash, item)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass hash[item] = 1;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass results.push(item);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return results;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Executes the supplied function on each item in the array. This method wraps
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the native ES5 `Array.forEach()` method if available.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method each
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Array} array Array to iterate.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Function} fn Function to execute on each item in the array.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {mixed} fn.item Current array item.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Number} fn.index Current array index.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Array} fn.array Array being iterated.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} [thisObj] `this` object to use when calling _fn_.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {YUI} The YUI instance.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @chainable
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassYArray.each = YArray.forEach = Native.forEach ? function (array, fn, thisObj) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Native.forEach.call(array || [], fn, thisObj || Y);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Y;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass} : function (array, fn, thisObj) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (var i = 0, len = (array && array.length) || 0; i < len; ++i) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (i in array) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass fn.call(thisObj || Y, array[i], i, array);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Y;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Alias for `each`.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method forEach
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns an object using the first array as keys and the second as values. If
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the second array is not provided, or if it doesn't contain the same number of
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * values as the first array, then `true` will be used in place of the missing
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * values.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @example
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Y.Array.hash(['a', 'b', 'c'], ['foo', 'bar']);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * // => {a: 'foo', b: 'bar', c: true}
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method hash
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Array} keys Array to use as keys.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Array} [values] Array to use as values.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Object}
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassYArray.hash = function (keys, values) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var hash = {},
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass vlen = (values && values.length) || 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass i, len;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (i = 0, len = keys.length; i < len; ++i) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (i in keys) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass hash[keys[i]] = vlen > i && i in values ? values[i] : true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return hash;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns the index of the first item in the array that's equal (using a strict
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * equality check) to the specified _value_, or `-1` if the value isn't found.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * This method wraps the native ES5 `Array.indexOf()` method if available.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method indexOf
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Array} array Array to search.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {any} value Value to search for.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Number} Index of the item strictly equal to _value_, or `-1` if not
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * found.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassYArray.indexOf = Native.indexOf ? function (array, value) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // TODO: support fromIndex
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Native.indexOf.call(array, value);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass} : function (array, value) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (var i = 0, len = array.length; i < len; ++i) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (array[i] === value) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return i;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return -1;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Numeric sort convenience function.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The native `Array.prototype.sort()` function converts values to strings and
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * sorts them in lexicographic order, which is unsuitable for sorting numeric
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * values. Provide `Y.Array.numericSort` as a custom sort function when you want
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * to sort values in numeric order.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @example
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * [42, 23, 8, 16, 4, 15].sort(Y.Array.numericSort);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * // => [4, 8, 15, 16, 23, 42]
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method numericSort
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Number} a First value to compare.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Number} b Second value to compare.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Number} Difference between _a_ and _b_.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassYArray.numericSort = function (a, b) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return a - b;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Executes the supplied function on each item in the array. Returning a truthy
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * value from the function will stop the processing of remaining items.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method some
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Array} array Array to iterate.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Function} fn Function to execute on each item.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {mixed} fn.value Current array item.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Number} fn.index Current array index.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Array} fn.array Array being iterated.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} [thisObj] `this` object to use when calling _fn_.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Boolean} `true` if the function returns a truthy value on any of the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * items in the array; `false` otherwise.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassYArray.some = Native.some ? function (array, fn, thisObj) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Native.some.call(array, fn, thisObj);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass} : function (array, fn, thisObj) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (var i = 0, len = array.length; i < len; ++i) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (i in array && fn.call(thisObj, array[i], i, array)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The YUI module contains the components required for building the YUI
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * seed file. This includes the script loading mechanism, a simple queue,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * and the core utilities for the library.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @module yui
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @submodule yui-base
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * A simple FIFO queue. Items are added to the Queue with add(1..n items) and
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * removed using next().
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @class Queue
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @constructor
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {MIXED} item* 0..n items to seed the queue.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassfunction Queue() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass this._init();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass this.add.apply(this, arguments);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass}
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassQueue.prototype = {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Initialize the queue
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method _init
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @protected
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass _init: function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The collection of enqueued items
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property _q
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type Array
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @protected
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass this._q = [];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Get the next item in the queue. FIFO support
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method next
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {MIXED} the next item in the queue.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass next: function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return this._q.shift();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Get the last in the queue. LIFO support.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method last
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {MIXED} the last item in the queue.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass last: function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return this._q.pop();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Add 0..n items to the end of the queue.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method add
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {MIXED} item* 0..n items.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {object} this queue.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass add: function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass this._q.push.apply(this._q, arguments);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return this;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns the current number of queued items.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method size
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Number} The size.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass size: function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return this._q.length;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassY.Queue = Queue;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassYUI.Env._loaderQueue = YUI.Env._loaderQueue || new Queue();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassThe YUI module contains the components required for building the YUI seed file.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassThis includes the script loading mechanism, a simple queue, and the core
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassutilities for the library.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@module yui
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@submodule yui-base
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass**/
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassvar CACHED_DELIMITER = '__',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass hasOwn = Object.prototype.hasOwnProperty,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass isObject = Y.Lang.isObject;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassReturns a wrapper for a function which caches the return value of that function,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glasskeyed off of the combined string representation of the argument values provided
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glasswhen the wrapper is called.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassCalling this function again with the same arguments will return the cached value
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassrather than executing the wrapped function.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassNote that since the cache is keyed off of the string representation of arguments
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glasspassed to the wrapper function, arguments that aren't strings and don't provide
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassa meaningful `toString()` method may result in unexpected caching behavior. For
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassexample, the objects `{}` and `{foo: 'bar'}` would both be converted to the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassstring `[object Object]` when used as a cache key.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@method cached
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@param {Function} source The function to memoize.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@param {Object} [cache={}] Object in which to store cached values. You may seed
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass this object with pre-existing cached values if desired.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@param {any} [refetch] If supplied, this value is compared with the cached value
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass using a `==` comparison. If the values are equal, the wrapped function is
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass executed again even though a cached value exists.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@return {Function} Wrapped function.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@for YUI
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass**/
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassY.cached = function (source, cache, refetch) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass cache || (cache = {});
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return function (arg) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var key = arguments.length > 1 ?
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Array.prototype.join.call(arguments, CACHED_DELIMITER) :
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass arg.toString();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!(key in cache) || (refetch && cache[key] == refetch)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass cache[key] = source.apply(source, arguments);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return cache[key];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass };
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassReturns a new object containing all of the properties of all the supplied
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassobjects. The properties from later objects will overwrite those in earlier
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassobjects.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassPassing in a single object will create a shallow copy of it. For a deep copy,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassuse `clone()`.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@method merge
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@param {Object} objects* One or more objects to merge.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@return {Object} A new merged object.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass**/
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassY.merge = function () {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var args = arguments,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass i = 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass len = args.length,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass result = {};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (; i < len; ++i) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.mix(result, args[i], true);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return result;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassMixes _supplier_'s properties into _receiver_. Properties will not be
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassoverwritten or merged unless the _overwrite_ or _merge_ parameters are `true`,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassrespectively.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassIn the default mode (0), only properties the supplier owns are copied (prototype
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassproperties are not copied). The following copying modes are available:
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * `0`: _Default_. Object to object.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * `1`: Prototype to prototype.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * `2`: Prototype to prototype and object to object.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * `3`: Prototype to object.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * `4`: Object to prototype.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@method mix
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@param {Function|Object} receiver The object or function to receive the mixed
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass properties.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@param {Function|Object} supplier The object or function supplying the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass properties to be mixed.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@param {Boolean} [overwrite=false] If `true`, properties that already exist
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass on the receiver will be overwritten with properties from the supplier.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@param {String[]} [whitelist] An array of property names to copy. If
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass specified, only the whitelisted properties will be copied, and all others
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass will be ignored.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@param {Int} [mode=0] Mix mode to use. See above for available modes.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@param {Boolean} [merge=false] If `true`, objects and arrays that already
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass exist on the receiver will have the corresponding object/array from the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass supplier merged into them, rather than being skipped or overwritten. When
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass both _overwrite_ and _merge_ are `true`, _merge_ takes precedence.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass@return {Function|Object|YUI} The receiver, or the YUI instance if the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass specified receiver is falsy.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass**/
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassY.mix = function(receiver, supplier, overwrite, whitelist, mode, merge) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var alwaysOverwrite, exists, from, i, key, len, to;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // If no supplier is given, we return the receiver. If no receiver is given,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // we return Y. Returning Y doesn't make much sense to me, but it's
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // grandfathered in for backcompat reasons.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!receiver || !supplier) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return receiver || Y;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (mode) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // In mode 2 (prototype to prototype and object to object), we recurse
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // once to do the proto to proto mix. The object to object mix will be
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // handled later on.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (mode === 2) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.mix(receiver.prototype, supplier.prototype, overwrite,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass whitelist, 0, merge);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Depending on which mode is specified, we may be copying from or to
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // the prototypes of the supplier and receiver.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass from = mode === 1 || mode === 3 ? supplier.prototype : supplier;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass to = mode === 1 || mode === 4 ? receiver.prototype : receiver;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // If either the supplier or receiver doesn't actually have a
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // prototype property, then we could end up with an undefined `from`
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // or `to`. If that happens, we abort and return the receiver.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!from || !to) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return receiver;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass from = supplier;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass to = receiver;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // If `overwrite` is truthy and `merge` is falsy, then we can skip a call
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // to `hasOwnProperty` on each iteration and save some time.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass alwaysOverwrite = overwrite && !merge;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (whitelist) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (i = 0, len = whitelist.length; i < len; ++i) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass key = whitelist[i];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // We call `Object.prototype.hasOwnProperty` instead of calling
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // `hasOwnProperty` on the object itself, since the object's
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // `hasOwnProperty` method may have been overridden or removed.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Also, some native objects don't implement a `hasOwnProperty`
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // method.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!hasOwn.call(from, key)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass continue;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass exists = alwaysOverwrite ? false : hasOwn.call(to, key);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (merge && exists && isObject(to[key], true)
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass && isObject(from[key], true)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // If we're in merge mode, and the key is present on both
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // objects, and the value on both objects is either an object or
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // an array (but not a function), then we recurse to merge the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // `from` value into the `to` value instead of overwriting it.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass //
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Note: It's intentional that the whitelist isn't passed to the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // recursive call here. This is legacy behavior that lots of
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // code still depends on.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.mix(to[key], from[key], overwrite, null, 0, merge);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if (overwrite || !exists) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // We're not in merge mode, so we'll only copy the `from` value
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // to the `to` value if we're in overwrite mode or if the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // current key doesn't exist on the `to` object.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass to[key] = from[key];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (key in from) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // The code duplication here is for runtime performance reasons.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Combining whitelist and non-whitelist operations into a single
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // loop or breaking the shared logic out into a function both result
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // in worse performance, and Y.mix is critical enough that the byte
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // tradeoff is worth it.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!hasOwn.call(from, key)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass continue;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass exists = alwaysOverwrite ? false : hasOwn.call(to, key);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (merge && exists && isObject(to[key], true)
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass && isObject(from[key], true)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.mix(to[key], from[key], overwrite, null, 0, merge);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if (overwrite || !exists) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass to[key] = from[key];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // If this is an IE browser with the JScript enumeration bug, force
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // enumeration of the buggy properties by making a recursive call with
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // the buggy properties as the whitelist.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (Y.Object._hasEnumBug) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.mix(to, from, overwrite, Y.Object._forceEnum, mode, merge);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return receiver;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The YUI module contains the components required for building the YUI
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * seed file. This includes the script loading mechanism, a simple queue,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * and the core utilities for the library.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @module yui
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @submodule yui-base
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Adds utilities to the YUI instance for working with objects.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @class Object
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassvar hasOwn = Object.prototype.hasOwnProperty,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass// If either MooTools or Prototype is on the page, then there's a chance that we
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass// can't trust "native" language features to actually be native. When this is
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass// the case, we take the safe route and fall back to our own non-native
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass// implementations.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glasswin = Y.config.win,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassunsafeNatives = win && !!(win.MooTools || win.Prototype),
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassUNDEFINED, // <-- Note the comma. We're still declaring vars.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns a new object that uses _obj_ as its prototype. This method wraps the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * native ES5 `Object.create()` method if available, but doesn't currently
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * pass through `Object.create()`'s second argument (properties) in order to
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * ensure compatibility with older browsers.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method ()
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} obj Prototype object.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Object} New object using _obj_ as its prototype.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassO = Y.Object = (!unsafeNatives && Object.create) ? function (obj) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // We currently wrap the native Object.create instead of simply aliasing it
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // to ensure consistency with our fallback shim, which currently doesn't
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // support Object.create()'s second argument (properties). Once we have a
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // safe fallback for the properties arg, we can stop wrapping
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Object.create().
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Object.create(obj);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass} : (function () {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Reusable constructor function for the Object.create() shim.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass function F() {}
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // The actual shim.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return function (obj) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass F.prototype = obj;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return new F();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass };
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass}()),
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Property names that IE doesn't enumerate in for..in loops, even when they
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * should be enumerable. When `_hasEnumBug` is `true`, it's necessary to
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * manually enumerate these properties.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property _forceEnum
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type String[]
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @protected
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassforceEnum = O._forceEnum = [
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass 'hasOwnProperty',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass 'isPrototypeOf',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass 'propertyIsEnumerable',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass 'toString',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass 'toLocaleString',
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass 'valueOf'
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * `true` if this browser has the JScript enumeration bug that prevents
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * enumeration of the properties named in the `_forceEnum` array, `false`
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * otherwise.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * See:
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * - <https://developer.mozilla.org/en/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * - <http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property _hasEnumBug
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type {Boolean}
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @protected
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlasshasEnumBug = O._hasEnumBug = !{valueOf: 0}.propertyIsEnumerable('valueOf'),
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns `true` if _key_ exists on _obj_, `false` if _key_ doesn't exist or
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * exists only on _obj_'s prototype. This is essentially a safer version of
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * `obj.hasOwnProperty()`.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method owns
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} obj Object to test.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {String} key Property name to look for.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Boolean} `true` if _key_ exists on _obj_, `false` otherwise.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassowns = O.owns = function (obj, key) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return !!obj && hasOwn.call(obj, key);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass}; // <-- End of var declarations.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Alias for `owns()`.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method hasKey
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} obj Object to test.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {String} key Property name to look for.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Boolean} `true` if _key_ exists on _obj_, `false` otherwise.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassO.hasKey = owns;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns an array containing the object's enumerable keys. Does not include
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * prototype keys or non-enumerable keys.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Note that keys are returned in enumeration order (that is, in the same order
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * that they would be enumerated by a `for-in` loop), which may not be the same
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * as the order in which they were defined.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * This method is an alias for the native ES5 `Object.keys()` method if
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * available.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @example
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Y.Object.keys({a: 'foo', b: 'bar', c: 'baz'});
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * // => ['a', 'b', 'c']
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method keys
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} obj An object.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {String[]} Array of keys.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassO.keys = (!unsafeNatives && Object.keys) || function (obj) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!Y.Lang.isObject(obj)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass throw new TypeError('Object.keys called on a non-object');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var keys = [],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass i, key, len;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (key in obj) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (owns(obj, key)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass keys.push(key);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (hasEnumBug) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (i = 0, len = forceEnum.length; i < len; ++i) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass key = forceEnum[i];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (owns(obj, key)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass keys.push(key);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return keys;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns an array containing the values of the object's enumerable keys.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Note that values are returned in enumeration order (that is, in the same
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * order that they would be enumerated by a `for-in` loop), which may not be the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * same as the order in which they were defined.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @example
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Y.Object.values({a: 'foo', b: 'bar', c: 'baz'});
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * // => ['foo', 'bar', 'baz']
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method values
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} obj An object.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Array} Array of values.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassO.values = function (obj) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var keys = O.keys(obj),
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass i = 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass len = keys.length,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass values = [];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (; i < len; ++i) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass values.push(obj[keys[i]]);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return values;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns the number of enumerable keys owned by an object.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method size
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} obj An object.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Number} The object's size.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassO.size = function (obj) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return O.keys(obj).length;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns `true` if the object owns an enumerable property with the specified
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * value.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method hasValue
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} obj An object.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {any} value The value to search for.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Boolean} `true` if _obj_ contains _value_, `false` otherwise.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassO.hasValue = function (obj, value) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Y.Array.indexOf(O.values(obj), value) > -1;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Executes a function on each enumerable property in _obj_. The function
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * receives the value, the key, and the object itself as parameters (in that
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * order).
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * By default, only properties owned by _obj_ are enumerated. To include
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * prototype properties, set the _proto_ parameter to `true`.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method each
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} obj Object to enumerate.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Function} fn Function to execute on each enumerable property.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {mixed} fn.value Value of the current property.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {String} fn.key Key of the current property.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} fn.obj Object being enumerated.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} [thisObj] `this` object to use when calling _fn_.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Boolean} [proto=false] Include prototype properties.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {YUI} the YUI instance.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @chainable
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassO.each = function (obj, fn, thisObj, proto) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var key;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (key in obj) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (proto || owns(obj, key)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass fn.call(thisObj || Y, obj[key], key, obj);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return Y;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Executes a function on each enumerable property in _obj_, but halts if the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * function returns a truthy value. The function receives the value, the key,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * and the object itself as paramters (in that order).
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * By default, only properties owned by _obj_ are enumerated. To include
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * prototype properties, set the _proto_ parameter to `true`.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method some
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} obj Object to enumerate.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Function} fn Function to execute on each enumerable property.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {mixed} fn.value Value of the current property.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {String} fn.key Key of the current property.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} fn.obj Object being enumerated.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} [thisObj] `this` object to use when calling _fn_.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Boolean} [proto=false] Include prototype properties.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Boolean} `true` if any execution of _fn_ returns a truthy value,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * `false` otherwise.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassO.some = function (obj, fn, thisObj, proto) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var key;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (key in obj) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (proto || owns(obj, key)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (fn.call(thisObj || Y, obj[key], key, obj)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return false;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Retrieves the sub value at the provided path,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * from the value object provided.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method getValue
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param o The object from which to extract the property value.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param path {Array} A path array, specifying the object traversal path
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * from which to obtain the sub value.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Any} The value stored in the path, undefined if not found,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * undefined if the source is not an object. Returns the source object
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * if an empty path is provided.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassO.getValue = function(o, path) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!Y.Lang.isObject(o)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return UNDEFINED;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var i,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass p = Y.Array(path),
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass l = p.length;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (i = 0; o !== UNDEFINED && i < l; i++) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o = o[p[i]];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return o;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Sets the sub-attribute value at the provided path on the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * value object. Returns the modified value object, or
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * undefined if the path is invalid.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method setValue
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param o The object on which to set the sub value.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param path {Array} A path array, specifying the object traversal path
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * at which to set the sub value.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param val {Any} The new value for the sub-attribute.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Object} The modified object, with the new sub value set, or
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * undefined, if the path was invalid.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassO.setValue = function(o, path, val) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var i,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass p = Y.Array(path),
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass leafIdx = p.length - 1,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ref = o;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (leafIdx >= 0) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (i = 0; ref !== UNDEFINED && i < leafIdx; i++) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ref = ref[p[i]];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (ref !== UNDEFINED) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ref[p[i]] = val;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return UNDEFINED;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return o;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Returns `true` if the object has no enumerable properties of its own.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @method isEmpty
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @param {Object} obj An object.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {Boolean} `true` if the object is empty.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.2.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassO.isEmpty = function (obj) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return !O.keys(obj).length;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The YUI module contains the components required for building the YUI seed
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * file. This includes the script loading mechanism, a simple queue, and the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * core utilities for the library.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @module yui
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @submodule yui-base
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * YUI user agent detection.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Do not fork for a browser if it can be avoided. Use feature detection when
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * you can. Use the user agent as a last resort. For all fields listed
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * as @type float, UA stores a version number for the browser engine,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * 0 otherwise. This value may or may not map to the version number of
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * the browser using the engine. The value is presented as a float so
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * that it can easily be used for boolean evaluation as well as for
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * looking for a particular range of versions. Because of this,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * some of the granularity of the version info may be lost. The fields that
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * are @type string default to null. The API docs list the values that
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * these fields can have.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @class UA
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass* Static method for parsing the UA string. Defaults to assigning it's value to Y.UA
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass* @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass* @method Env.parseUA
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass* @param {String} subUA Parse this UA string instead of navigator.userAgent
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass* @returns {Object} The Y.UA object
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass*/
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassYUI.Env.parseUA = function(subUA) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var numberify = function(s) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass var c = 0;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return parseFloat(s.replace(/\./g, function() {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return (c++ == 1) ? '' : '.';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }));
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass win = Y.config.win,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass nav = win && win.navigator,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o = {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Internet Explorer version number or 0. Example: 6
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property ie
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type float
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ie: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Opera version number or 0. Example: 9.2
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property opera
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type float
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass opera: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Gecko engine revision number. Will evaluate to 1 if Gecko
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * is detected but the revision could not be found. Other browsers
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * will be 0. Example: 1.8
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <pre>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Firefox 1.0.0.4: 1.7.8 <-- Reports 1.7
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Firefox 1.5.0.9: 1.8.0.9 <-- 1.8
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Firefox 2.0.0.3: 1.8.1.3 <-- 1.81
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Firefox 3.0 <-- 1.9
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Firefox 3.5 <-- 1.91
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * </pre>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property gecko
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type float
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass gecko: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * AppleWebKit version. KHTML browsers that are not WebKit browsers
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * will evaluate to 1, other browsers 0. Example: 418.9
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * <pre>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Safari 1.3.2 (312.6): 312.8.1 <-- Reports 312.8 -- currently the
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * latest available for Mac OSX 10.3.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Safari 2.0.2: 416 <-- hasOwnProperty introduced
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Safari 2.0.4: 418 <-- preventDefault fixed
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Safari 2.0.4 (419.3): 418.9.1 <-- One version of Safari may run
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * different versions of webkit
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Safari 2.0.4 (419.3): 419 <-- Tiger installations that have been
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * updated, but not updated
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * to the latest patch.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Webkit 212 nightly: 522+ <-- Safari 3.0 precursor (with native
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * SVG and many major issues fixed).
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Safari 3.0.4 (523.12) 523.12 <-- First Tiger release - automatic
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * update from 2.x via the 10.4.11 OS patch.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Webkit nightly 1/2008:525+ <-- Supports DOMContentLoaded event.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * yahoo.com user agent hack removed.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * </pre>
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * http://en.wikipedia.org/wiki/Safari_version_history
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property webkit
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type float
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass webkit: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Safari will be detected as webkit, but this property will also
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * be populated with the Safari version number
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property safari
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type float
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass safari: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Chrome will be detected as webkit, but this property will also
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * be populated with the Chrome version number
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property chrome
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type float
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass chrome: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The mobile property will be set to a string containing any relevant
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * user agent information when a modern mobile browser is detected.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Currently limited to Safari on the iPhone/iPod Touch, Nokia N-series
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * devices with the WebKit-based browser, and Opera Mini.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property mobile
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default null
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass mobile: null,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Adobe AIR version number or 0. Only populated if webkit is detected.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Example: 1.0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property air
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type float
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass air: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Detects Apple iPad's OS version
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property ipad
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type float
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ipad: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Detects Apple iPhone's OS version
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property iphone
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type float
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass iphone: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Detects Apples iPod's OS version
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property ipod
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type float
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ipod: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * General truthy check for iPad, iPhone or iPod
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property ios
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type float
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default null
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ios: null,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Detects Googles Android OS version
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property android
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type float
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass android: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Detects Palms WebOS version
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property webos
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type float
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass webos: 0,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Google Caja version number or 0.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property caja
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type float
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass caja: nav && nav.cajaVersion,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * Set to true if the page appears to be in SSL
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property secure
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type boolean
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass secure: false,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass /**
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * The operating system. Currently only detecting windows or macintosh
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property os
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @type string
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @default null
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass os: null
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass ua = subUA || nav && nav.userAgent,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loc = win && win.location,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass href = loc && loc.href,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.secure = href && (href.toLowerCase().indexOf('https') === 0);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (ua) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if ((/windows|win32/i).test(ua)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.os = 'windows';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if ((/macintosh/i).test(ua)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.os = 'macintosh';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else if ((/rhino/i).test(ua)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.os = 'rhino';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Modern KHTML browsers should qualify as Safari X-Grade
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if ((/KHTML/).test(ua)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.webkit = 1;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Modern WebKit browsers are at least X-Grade
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = ua.match(/AppleWebKit\/([^\s]*)/);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m && m[1]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.webkit = numberify(m[1]);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.safari = o.webkit;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Mobile browser check
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (/ Mobile\//.test(ua)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.mobile = 'Apple'; // iPhone or iPod Touch
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = ua.match(/OS ([^\s]*)/);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m && m[1]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = numberify(m[1].replace('_', '.'));
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.ios = m;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.ipad = o.ipod = o.iphone = 0;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = ua.match(/iPad|iPod|iPhone/);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m && m[0]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o[m[0].toLowerCase()] = o.ios;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = ua.match(/NokiaN[^\/]*|webOS\/\d\.\d/);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass // Nokia N-series, webOS, ex: NokiaN95
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.mobile = m[0];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (/webOS/.test(ua)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.mobile = 'WebOS';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = ua.match(/webOS\/([^\s]*);/);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m && m[1]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.webos = numberify(m[1]);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (/ Android/.test(ua)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (/Mobile/.test(ua)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.mobile = 'Android';
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = ua.match(/Android ([^\s]*);/);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m && m[1]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.android = numberify(m[1]);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = ua.match(/Chrome\/([^\s]*)/);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m && m[1]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.chrome = numberify(m[1]); // Chrome
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.safari = 0; //Reset safari back to 0
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = ua.match(/AdobeAIR\/([^\s]*)/);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.air = m[0]; // Adobe AIR 1.0 or better
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!o.webkit) { // not webkit
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass// @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr)
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = ua.match(/Opera[\s\/]([^\s]*)/);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m && m[1]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.opera = numberify(m[1]);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = ua.match(/Version\/([^\s]*)/);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m && m[1]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.opera = numberify(m[1]); // opera 10+
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = ua.match(/Opera Mini[^;]*/);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.mobile = m[0]; // ex: Opera Mini/2.0.4509/1316
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else { // not opera or webkit
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = ua.match(/MSIE\s([^;]*)/);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m && m[1]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.ie = numberify(m[1]);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass } else { // not opera, webkit, or ie
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = ua.match(/Gecko\/([^\s]*)/);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.gecko = 1; // Gecko detected, look for revision
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass m = ua.match(/rv:([^\s\)]*)/);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (m && m[1]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.gecko = numberify(m[1]);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass YUI.Env.UA = o;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return o;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassY.UA = YUI.Env.UA || YUI.Env.parseUA();
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassYUI.Env.aliases = {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "anim": ["anim-base","anim-color","anim-curve","anim-easing","anim-node-plugin","anim-scroll","anim-xy"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "app": ["controller","model","model-list","view"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "attribute": ["attribute-base","attribute-complex"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "autocomplete": ["autocomplete-base","autocomplete-sources","autocomplete-list","autocomplete-plugin"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "base": ["base-base","base-pluginhost","base-build"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "cache": ["cache-base","cache-offline","cache-plugin"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "collection": ["array-extras","arraylist","arraylist-add","arraylist-filter","array-invoke"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "dataschema": ["dataschema-base","dataschema-json","dataschema-xml","dataschema-array","dataschema-text"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "datasource": ["datasource-local","datasource-io","datasource-get","datasource-function","datasource-cache","datasource-jsonschema","datasource-xmlschema","datasource-arrayschema","datasource-textschema","datasource-polling"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "datatable": ["datatable-base","datatable-datasource","datatable-sort","datatable-scroll"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "datatype": ["datatype-number","datatype-date","datatype-xml"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "datatype-date": ["datatype-date-parse","datatype-date-format"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "datatype-number": ["datatype-number-parse","datatype-number-format"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "datatype-xml": ["datatype-xml-parse","datatype-xml-format"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "dd": ["dd-ddm-base","dd-ddm","dd-ddm-drop","dd-drag","dd-proxy","dd-constrain","dd-drop","dd-scroll","dd-delegate"],
04b64da9f66b8791f4519ebf215ca4ee5771dfe3Matt Sweeney "dom": ["dom-base","dom-screen","dom-style","selector-native","selector"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "editor": ["frame","selection","exec-command","editor-base","editor-para","editor-br","editor-bidi","editor-tab","createlink-base"],
a958fdd529761b111fb3d448b732519434c5d4afLuke Smith "event": ["event-base","event-delegate","event-synthetic","event-mousewheel","event-mouseenter","event-key","event-focus","event-resize","event-hover","event-outside"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "event-custom": ["event-custom-base","event-custom-complex"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "event-gestures": ["event-flick","event-move"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "highlight": ["highlight-base","highlight-accentfold"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "history": ["history-base","history-hash","history-hash-ie","history-html5"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "io": ["io-base","io-xdr","io-form","io-upload-iframe","io-queue"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "json": ["json-parse","json-stringify"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "loader": ["loader-base","loader-rollup","loader-yui3"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "node": ["node-base","node-event-delegate","node-pluginhost","node-screen","node-style"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "pluginhost": ["pluginhost-base","pluginhost-config"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "querystring": ["querystring-parse","querystring-stringify"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "recordset": ["recordset-base","recordset-sort","recordset-filter","recordset-indexer"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "resize": ["resize-base","resize-proxy","resize-constrain"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "slider": ["slider-base","slider-value-range","clickable-rail","range-slider"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "text": ["text-accentfold","text-wordbreak"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "widget": ["widget-base","widget-htmlparser","widget-uievents","widget-skin"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "yui-rls": ["yui-base","get","features","intl-base","rls","yui-log","yui-later"]
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass}, '@VERSION@' );