yui-core-debug.js revision 5c71d16540fb2a8cd79c36ed7c11e6805421451e
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/**
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan GroveThe YUI global namespace object. If YUI is already defined, the
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Groveexisting YUI object will not be overwritten so that defined
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grovenamespaces are preserved. It is the constructor for the object
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grovethe end user interacts with. As indicated below, each instance
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grovehas full custom event support, but only if the event system
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Groveis available. This is a self-instantiable factory function. You
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grovecan invoke it directly like this:
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove YUI().use('*', function(Y) {
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove // ready
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove });
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan GroveBut it also works like this:
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove var Y = YUI();
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav GlassConfiguring the YUI object:
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass YUI({
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass debug: true,
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass combine: false
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass }).use('node', function(Y) {
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass //Node is ready to use
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass });
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav GlassSee the API docs for the <a href="config.html">Config</a> class
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glassfor the complete list of supported configuration properties accepted
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glassby the YUI constuctor.
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove@class YUI
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove@constructor
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove@global
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove@uses EventTarget
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith@param o* {Object} 0..n optional configuration objects. these values
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Groveare store in Y.config. See <a href="config.html">Config</a> for the list of supported
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Groveproperties.
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove*/
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
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove /**
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove YUI.GlobalConfig is a master configuration that might span
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove multiple contexts in a non-browser environment. It is applied
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove first to all instances in all contexts.
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith @property GlobalConfig
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove @type {Object}
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove @global
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith @static
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove @example
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove YUI.GlobalConfig = {
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove filter: 'debug'
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove };
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove YUI().use('node', function(Y) {
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove //debug files used here
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove });
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove YUI({
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove filter: 'min'
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove }).use('node', function(Y) {
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove //min files used here
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove });
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (YUI.GlobalConfig) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.applyConfig(YUI.GlobalConfig);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove /**
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove YUI_config is a page-level config. It is applied to all
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove instances created on the page. This is applied after
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove YUI.GlobalConfig, and before the instance level configuration
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove objects.
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove @global
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove @property YUI_config
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove @type {Object}
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove @example
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove //Single global var to include before YUI seed file
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove YUI_config = {
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove filter: 'debug'
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove };
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove YUI().use('node', function(Y) {
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove //debug files used here
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove });
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove YUI({
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove filter: 'min'
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove }).use('node', function(Y) {
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove //min files used here
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove });
71651656e38f39cf8f088e75166fb0bf51c52eb1Ryan Grove */
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',
72c672b04102e2744ccbc6652c9d726308c55685Dav Glass CSS_STAMP_EL = 'yui3-css-stamp',
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 }
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass YUI.Env.core = Y.Array.dedupe([].concat(YUI.Env.core, [ 'loader-base', 'loader-rollup', 'loader-yui3' ]));
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
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith * @param {Object} o 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 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 (name == 'win') {
1702fd8ca80cc30781373ff0ddf0227bf7688363Dav Glass config[name] = (attr && attr.contentWindow) || attr;
1702fd8ca80cc30781373ff0ddf0227bf7688363Dav Glass config.doc = config[name] ? config[name].document : null;
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 }
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav 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() {
72c672b04102e2744ccbc6652c9d726308c55685Dav Glass var filter, el,
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 = {
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass core: ['get','intl-base'],
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
bc1109485d3d133cb6432ab3116e13496ef0bf47Dav Glass // "yui-base" or "yui-davglass" 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
bc1109485d3d133cb6432ab3116e13496ef0bf47Dav Glass // "blah?foo/yui/yui.js" will capture "foo/" and "blah?some/thing.js&3.3.0/build/yui-davglass/yui-davglass.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;
72c672b04102e2744ccbc6652c9d726308c55685Dav 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,
bc1109485d3d133cb6432ab3116e13496ef0bf47Dav Glass fetchCSS: true
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass };
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
72c672b04102e2744ccbc6652c9d726308c55685Dav Glass //Register the CSS stamp element
72c672b04102e2744ccbc6652c9d726308c55685Dav Glass if (doc && !doc.getElementById(CSS_STAMP_EL)) {
72c672b04102e2744ccbc6652c9d726308c55685Dav Glass el = doc.createElement('div');
8ce9de750041c2639c529ecd0fd621dd43522847Dav Glass el.innerHTML = '<div id="' + CSS_STAMP_EL + '" style="position: absolute !important; visibility: hidden !important"></div>';
8ce9de750041c2639c529ecd0fd621dd43522847Dav Glass YUI.Env.cssStampEl = el.firstChild;
706cc12cf1dff6e6d5098a26e58c573a5c3fda05Dav Glass docEl.insertBefore(YUI.Env.cssStampEl, docEl.firstChild);
72c672b04102e2744ccbc6652c9d726308c55685Dav Glass }
72c672b04102e2744ccbc6652c9d726308c55685Dav 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,
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass //extras = Y.config.core || ['get','intl-base'];
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass extras = Y.config.core || [].concat(YUI.Env.core); //Clone it..
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
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass if (Y.Loader) {
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass getLoader(Y);
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass }
847ed3bff546872247639b703baa857dc3ea4f36Dav 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 }
4a3beddaa1c8f0224c70172e8887351dfe0f9445Dav Glass return m && m.apply(instance, args);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return null;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass },
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass/**
b06f0506728aa781ea59ef35737b6e965463c7afDav GlassRegisters a module with the YUI global. The easiest way to create a
b06f0506728aa781ea59ef35737b6e965463c7afDav Glassfirst-class YUI module is to use the YUI component build tool.
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass
b06f0506728aa781ea59ef35737b6e965463c7afDav Glasshttp://yuilibrary.com/projects/builder
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass
b06f0506728aa781ea59ef35737b6e965463c7afDav GlassThe build system will produce the `YUI.add` wrapper for you module, along
b06f0506728aa781ea59ef35737b6e965463c7afDav Glasswith any configuration info required for the module.
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass@method add
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass@param name {String} module name.
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass@param fn {Function} entry point into the module that is used to bind module to the YUI instance.
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass@param {YUI} fn.Y The YUI instance this module is executed in.
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass@param {String} fn.name The name of the module
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass@param version {String} version string.
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass@param details {Object} optional config data:
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass@param details.requires {Array} features that must be present before this module can be attached.
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass@param details.optional {Array} optional features that should be present if loadOptional
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass is defined. Note: modules are not often loaded this way in YUI 3,
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass but this field is still useful to inform the user that certain
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass features in the component will require additional dependencies.
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass@param details.use {Array} features that are included within this module which need to
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass be attached automatically when this module is attached. This
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass supports the YUI 3 rollup system -- a module with submodules
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass defined will need to have the submodules listed in the 'use'
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass config. The YUI component build tool does this for you.
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass@return {YUI} the YUI instance.
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass@example
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass YUI.add('davglass', function(Y, name) {
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass Y.davglass = function() {
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass alert('Dav was here!');
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass };
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass }, '3.4.0', { requires: ['yui-base', 'harley-davidson', 'mt-dew'] });
b06f0506728aa781ea59ef35737b6e965463c7afDav Glass
b06f0506728aa781ea59ef35737b6e965463c7afDav 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.
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass * @param {Array} r The array of modules to attach
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass * @param {Boolean} [moot=false] Don't throw a warning if the module is not attached
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,
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass loader = Y.Env._loader,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass done = Y.Env._attached,
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass len = r.length, loader,
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass c = [];
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass //Check for conditional modules (in a second+ instance) and add their requirements
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass //TODO I hate this entire method, it needs to be fixed ASAP (3.5.0) ^davglass
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass for (i = 0; i < len; i++) {
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass name = r[i];
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass mod = mods[name];
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass c.push(name);
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass if (loader && loader.conditions[name]) {
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass Y.Object.each(loader.conditions[name], function(def) {
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass var go = def && ((def.ua && Y.UA[def.ua]) || (def.test && def.test(Y)));
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass if (go) {
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass c.push(def.name);
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass }
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass });
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass }
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass }
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass r = c;
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass len = r.length;
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];
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (aliases && aliases[name]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y._attach(aliases[name]);
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass continue;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!mod) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (loader && loader.moduleInfo[name]) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass mod = loader.moduleInfo[name];
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass moot = true;
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) {
bc05981e4a74b0d3280120fc184dc8a2b6e5e9a1Dav Glass if (!moot && name) {
b0ab788daf32aca249320825ecbdcef36aa0c052Dav Glass if ((name.indexOf('skin-') === -1) && (name.indexOf('css') === -1)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Y.Env._missed.push(name);
b0ab788daf32aca249320825ecbdcef36aa0c052Dav Glass Y.Env._missed = Y.Array.dedupe(Y.Env._missed);
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
847ed3bff546872247639b703baa857dc3ea4f36Dav Glass //We need to remove it from the missed list ^davglass
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,
cf7632d230c20fcded115f244fe6bdefd90b024fDav Glass a = [],
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._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,
cf7632d230c20fcded115f244fe6bdefd90b024fDav Glass aliases = G_ENV.aliases,
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
cf7632d230c20fcded115f244fe6bdefd90b024fDav Glass var i = 0, a = [];
cf7632d230c20fcded115f244fe6bdefd90b024fDav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass if (!names.length) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cf7632d230c20fcded115f244fe6bdefd90b024fDav Glass if (aliases) {
cf7632d230c20fcded115f244fe6bdefd90b024fDav Glass for (i = 0; i < names.length; i++) {
cf7632d230c20fcded115f244fe6bdefd90b024fDav Glass if (aliases[names[i]]) {
cf7632d230c20fcded115f244fe6bdefd90b024fDav Glass a = [].concat(a, aliases[names[i]]);
cf7632d230c20fcded115f244fe6bdefd90b024fDav Glass } else {
cf7632d230c20fcded115f244fe6bdefd90b024fDav Glass a.push(names[i]);
cf7632d230c20fcded115f244fe6bdefd90b024fDav Glass }
cf7632d230c20fcded115f244fe6bdefd90b024fDav Glass }
cf7632d230c20fcded115f244fe6bdefd90b024fDav Glass names = a;
cf7632d230c20fcded115f244fe6bdefd90b024fDav Glass }
cf7632d230c20fcded115f244fe6bdefd90b024fDav 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
2ce82ed9bd6af0513d92452be4aab3829a472c8cDav Glass if (mods['loader'] && !Y.Loader) {
2ce82ed9bd6af0513d92452be4aab3829a472c8cDav Glass Y.log('Loader was found in meta, but it is not attached. Attaching..', 'info', 'yui');
2ce82ed9bd6af0513d92452be4aab3829a472c8cDav Glass Y._attach(['loader']);
2ce82ed9bd6af0513d92452be4aab3829a472c8cDav Glass }
2ce82ed9bd6af0513d92452be4aab3829a472c8cDav 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;
8fdf8de0d93e4ab132d572139b31adbf2386ba6fDav Glass loader._boot = true;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass loader.calculate(null, (fetchCSS) ? null : 'js');
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass args = loader.sorted;
8fdf8de0d93e4ab132d572139b31adbf2386ba6fDav Glass loader._boot = false;
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
847ed3bff546872247639b703baa857dc3ea4f36Dav 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
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;
e94e3f2ab78d38f63e97045370fae4a1e6b076beDav Glass G_ENV._bootstrapping = false;
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 /**
2f78fd70583b1cebc3226803c36d82456d8a4319Luke Smith Adds a namespace object onto the YUI global if called statically.
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith // creates YUI.your.namespace.here as nested objects
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith YUI.namespace("your.namespace.here");
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith
2f78fd70583b1cebc3226803c36d82456d8a4319Luke Smith If called as a method on a YUI <em>instance</em>, it creates the
2f78fd70583b1cebc3226803c36d82456d8a4319Luke Smith namespace on the instance.
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith // creates Y.property.package
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith Y.namespace("property.package");
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith Dots in the input string cause `namespace` to create nested objects for
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith each token. If any part of the requested namespace already exists, the
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith current object will be left in place. This allows multiple calls to
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith `namespace` to preserve existing namespaced properties.
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith If the first token in the namespace string is "YAHOO", the token is
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith discarded.
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith
2f78fd70583b1cebc3226803c36d82456d8a4319Luke Smith Be careful with namespace tokens. Reserved words may work in some browsers
2f78fd70583b1cebc3226803c36d82456d8a4319Luke Smith and not others. For instance, the following will fail in some browsers
2f78fd70583b1cebc3226803c36d82456d8a4319Luke Smith because the supported version of JavaScript reserves the word "long":
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith Y.namespace("really.long.nested.namespace");
fd6e0c106ef55f46bcc11b2161d7c6fa24110fdaDav Glass
fd6e0c106ef55f46bcc11b2161d7c6fa24110fdaDav Glass <em>Note: If you pass multiple arguments to create multiple namespaces, only
fd6e0c106ef55f46bcc11b2161d7c6fa24110fdaDav Glass the last one created is returned from this function.</em>
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith @method namespace
2f78fd70583b1cebc3226803c36d82456d8a4319Luke Smith @param {String} namespace* namespaces to create.
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith @return {Object} A reference to the last namespace object created.
cac1e07e6c1588f45e78548aef28059dbf56d6c9Luke Smith **/
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass namespace: function() {
fd6e0c106ef55f46bcc11b2161d7c6fa24110fdaDav Glass var a = arguments, o, i = 0, j, d, arg;
fd6e0c106ef55f46bcc11b2161d7c6fa24110fdaDav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass for (; i < a.length; i++) {
fd6e0c106ef55f46bcc11b2161d7c6fa24110fdaDav Glass o = this; //Reset base object per argument or it will get reused from the last
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass arg = a[i];
fd6e0c106ef55f46bcc11b2161d7c6fa24110fdaDav Glass if (arg.indexOf(PERIOD) > -1) { //Skip this if no "." is present
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] || {};
fd6e0c106ef55f46bcc11b2161d7c6fa24110fdaDav Glass o = o[arg]; //Reset base object to the new object so it's returned
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 /**
1bef166cff922ad4cbe32f0c8346e403606f98b4Dav Glass * Report an error. The reporting mechanism is controlled by
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * the `throwFail` configuration attribute. If throwFail is
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * not specified, the message is written to the Logger, otherwise
5ad07c5fcb6a87187345f23b26e30ba472743f8aDav Glass * a JS error is thrown. If an `errorFn` is specified in the config
5ad07c5fcb6a87187345f23b26e30ba472743f8aDav Glass * it must return `true` to keep the error from being 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.
1bef166cff922ad4cbe32f0c8346e403606f98b4Dav Glass * @param src Optional additional info (passed to `Y.config.errorFn` and `Y.message`)
b43ba5ec2311e6f856ff2434c79b5b43f226dd73Dav Glass * and `throwFail` is specified, this error will be re-thrown.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @return {YUI} this YUI instance.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
1bef166cff922ad4cbe32f0c8346e403606f98b4Dav Glass error: function(msg, e, src) {
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass //TODO Add check for window.onerror here
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 {
1bef166cff922ad4cbe32f0c8346e403606f98b4Dav Glass Y.message(msg, 'error', ''+src); // 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
1d01372aa06d46fcbeeae1718c35cf404f412a85Dav Glass * @param o {Object} The object to check.
1d01372aa06d46fcbeeae1718c35cf404f412a85Dav Glass * @param type {Object} The class to check against.
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @since 3.3.0
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 }
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass /**
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav GlassStatic method on the Global YUI object to apply a config to all YUI instances.
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav GlassIt's main use case is "mashups" where several third party scripts are trying to write to
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glassa global YUI config at the same time. This way they can all call `YUI.applyConfig({})` instead of
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glassoverwriting other scripts configs.
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass@static
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass@since 3.5.0
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass@method applyConfig
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass@param {Object} o the configuration object.
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass@example
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass YUI.applyConfig({
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass modules: {
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass davglass: {
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass fullpath: './davglass.js'
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass }
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass }
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass });
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass YUI.applyConfig({
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass modules: {
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass foo: {
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass fullpath: './foo.js'
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass }
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass }
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass });
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass YUI().use('davglass', function(Y) {
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass //Module davglass will be available here..
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass });
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass */
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass YUI.applyConfig = function(o) {
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass if (!o) {
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass return;
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass }
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass //If there is a GlobalConfig, apply it first to set the defaults
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass if (YUI.GlobalConfig) {
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass this.prototype.applyConfig.call(this, YUI.GlobalConfig);
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass }
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass //Apply this config to it
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass this.prototype.applyConfig.call(this, o);
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass //Reset GlobalConfig to the combined config
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav Glass YUI.GlobalConfig = this.config;
a2e8d3ada9281ad6d3c49b9318315d37452ffc39Dav 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
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass/**
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass * Turns on writing Ylog messages to the browser console.
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass *
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass * @property debug
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass * @type boolean
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass * @default true
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass */
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav 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/**
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass * A list of modules that defines the YUI core (overrides the default list).
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass *
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @property core
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass * @type Array
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass * @default [ get,features,intl-base,yui-log,yui-later,loader-base, loader-rollup, loader-yui3 ]
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,
92dea7aa514637d3813c504c6aa0f92d4c67b6e9Dav Glass *
92dea7aa514637d3813c504c6aa0f92d4c67b6e9Dav Glass * // The comboSeperator to use with this group's combo handler
92dea7aa514637d3813c504c6aa0f92d4c67b6e9Dav Glass * comboSep: ';',
92dea7aa514637d3813c504c6aa0f92d4c67b6e9Dav Glass *
92dea7aa514637d3813c504c6aa0f92d4c67b6e9Dav Glass * // The maxURLLength for this server
92dea7aa514637d3813c504c6aa0f92d4c67b6e9Dav Glass * maxURLLength: 500,
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
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass * @default 2.9.0
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
8c3dc62e775bd2e2d8a0d8ea5a1d34cb7fe8bfc3Dav Glass * @default 4
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
5ad07c5fcb6a87187345f23b26e30ba472743f8aDav Glass * is executed in the YUI instance context. Returning `true` from this
5ad07c5fcb6a87187345f23b26e30ba472743f8aDav Glass * function will stop the Error from being thrown.
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 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
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveSUBREGEX = /\{\s*([^|}]+?)\s*(?:\|([^}]*))?\s*\}/g,
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveTRIMREGEX = /^\s+|\s+$/g,
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveNATIVE_FN_REGEX = /\{\s*\[(?:native code|function)\]\s*\}/i;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove// -- Protected Methods --------------------------------------------------------
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove/**
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveReturns _true_ if the given function appears to be implemented in native code,
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove_false_ otherwise. This isn't guaranteed to be 100% accurate and won't work for
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Groveanything other than functions, but it can be useful for determining whether
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grovea function like `Array.prototype.forEach` is native or a JS shim provided by
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Groveanother library.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveThere's a great article by @kangax discussing the flaws with this technique:
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove<http://perfectionkills.com/detecting-built-in-host-methods/>
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveWhile his points are valid, it's still possible to benefit from this function
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Groveas long as it's used carefully and sparingly, and in such a way that false
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grovenegatives have minimal consequences. It's used internally to avoid using
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grovepotentially broken non-native ES5 shims that have been added to the page by
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Groveother libraries.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove@method _isNative
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove@param {Function} fn Function to test.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove@return {Boolean} _true_ if _fn_ appears to be native, _false_ otherwise.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove@static
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove@protected
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove@since 3.5.0
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove**/
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveL._isNative = function (fn) {
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove return !!(fn && NATIVE_FN_REGEX.test(fn));
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove};
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove// -- Public Methods -----------------------------------------------------------
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 */
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveL.isArray = L._isNative(Array.isArray) ? 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
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove/**
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * Determines whether or not the supplied item is a date instance.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @method isDate
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @static
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @param o The object to test.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @return {boolean} true if o is a date.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove */
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveL.isDate = function(o) {
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove return L.type(o) === 'date' && o.toString() !== 'Invalid Date' && !isNaN(o);
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove};
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove
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 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
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove/**
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * A convenience method for detecting a legitimate non-null value.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * Returns false for null/undefined/NaN, true for other values,
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * including 0/false/''
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @method isValue
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @static
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @param o The item to test.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @return {boolean} true if it is not null/undefined/NaN || false.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove */
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveL.isValue = function(o) {
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove var t = L.type(o);
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove switch (t) {
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove case 'number':
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove return isFinite(o);
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove case 'null': // fallthru
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove case 'undefined':
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove return false;
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove default:
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove return !!t;
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove }
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove};
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove/**
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * Returns the current time in milliseconds.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove *
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @method now
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @return {Number} Current time in milliseconds.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @static
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @since 3.3.0
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove */
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveL.now = Date.now || function () {
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove return new Date().getTime();
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove};
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove/**
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * Lightweight version of <code>Y.substitute</code>. Uses the same template
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * structure as <code>Y.substitute</code>, but doesn't support recursion,
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * auto-object coersion, or formats.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @method sub
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @param {string} s String to be modified.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @param {object} o Object containing replacement values.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @return {string} the substitute result.
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @static
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove * @since 3.2.0
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove */
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveL.sub = function(s, o) {
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove return s.replace ? s.replace(SUBREGEX, function (match, key) {
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove return L.isUndefined(o[key]) ? match : o[key];
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove }) : s;
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove};
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove
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 * <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/**
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove@module yui
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove@submodule yui-base
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove*/
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glassvar Lang = Y.Lang,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass Native = Array.prototype,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass hasOwn = Object.prototype.hasOwnProperty;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan GroveProvides utility methods for working with arrays. Additional array helpers can
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grovebe found in the `collection` and `array-extras` modules.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove`Y.Array(thing)` returns a native array created from _thing_. Depending on
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove_thing_'s type, one of the following will happen:
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove * Arrays are returned unmodified unless a non-zero _startIndex_ is
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove specified.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove * Array-like collections (see `Array.test()`) are converted to arrays.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove * For everything else, a new array is created with _thing_ as the sole
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove item.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan GroveNote: elements that are also collections, such as `<form>` and `<select>`
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Groveelements, are not automatically converted to arrays. To force a conversion,
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grovepass `true` as the value of the _force_ parameter.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@class Array
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@constructor
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {Any} thing The thing to arrayify.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {Number} [startIndex=0] If non-zero and _thing_ is an array or array-like
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove collection, a subset of items starting at the specified index will be
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove returned.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {Boolean} [force=false] If `true`, _thing_ will be treated as an
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove array-like collection no matter what.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@return {Array} A native array created from _thing_, according to the rules
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove described above.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove**/
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/**
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan GroveDedupes an array of strings, returning an array that's guaranteed to contain
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Groveonly one copy of a given string.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan GroveThis method differs from `Array.unique()` in that it's optimized for use only
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grovewith strings, whereas `unique` may be used with other types (but is slower).
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan GroveUsing `dedupe()` with non-string values may result in unexpected behavior.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@method dedupe
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {String[]} array Array of strings to dedupe.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@return {Array} Deduped copy of _array_.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@static
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@since 3.4.0
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove**/
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/**
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan GroveExecutes the supplied function on each item in the array. This method wraps
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grovethe native ES5 `Array.forEach()` method if available.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@method each
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {Array} array Array to iterate.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {Function} fn Function to execute on each item in the array. The function
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove will receive the following arguments:
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove @param {Any} fn.item Current array item.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove @param {Number} fn.index Current array index.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove @param {Array} fn.array Array being iterated.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {Object} [thisObj] `this` object to use when calling _fn_.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@return {YUI} The YUI instance.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@static
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove**/
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveYArray.each = YArray.forEach = Lang._isNative(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/**
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan GroveAlias for `each()`.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@method forEach
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@static
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove**/
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan GroveReturns an object using the first array as keys and the second as values. If
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grovethe second array is not provided, or if it doesn't contain the same number of
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grovevalues as the first array, then `true` will be used in place of the missing
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grovevalues.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@example
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove Y.Array.hash(['a', 'b', 'c'], ['foo', 'bar']);
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove // => {a: 'foo', b: 'bar', c: true}
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@method hash
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {String[]} keys Array of strings to use as keys.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {Array} [values] Array to use as values.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@return {Object} Hash using the first array as keys and the second as values.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@static
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove**/
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/**
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan GroveReturns the index of the first item in the array that's equal (using a strict
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Groveequality check) to the specified _value_, or `-1` if the value isn't found.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan GroveThis method wraps the native ES5 `Array.indexOf()` method if available.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@method indexOf
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {Array} array Array to search.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {Any} value Value to search for.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@return {Number} Index of the item strictly equal to _value_, or `-1` if not
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove found.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@static
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove**/
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveYArray.indexOf = Lang._isNative(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) {
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove if (i in array && array[i] === value) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return i;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass }
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return -1;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan GroveNumeric sort convenience function.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan GroveThe native `Array.prototype.sort()` function converts values to strings and
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grovesorts them in lexicographic order, which is unsuitable for sorting numeric
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grovevalues. Provide `Array.numericSort` as a custom sort function when you want
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Groveto sort values in numeric order.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@example
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove [42, 23, 8, 16, 4, 15].sort(Y.Array.numericSort);
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove // => [4, 8, 15, 16, 23, 42]
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@method numericSort
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {Number} a First value to compare.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {Number} b Second value to compare.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@return {Number} Difference between _a_ and _b_.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@static
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove**/
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlassYArray.numericSort = function (a, b) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass return a - b;
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan GroveExecutes the supplied function on each item in the array. Returning a truthy
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grovevalue from the function will stop the processing of remaining items.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@method some
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {Array} array Array to iterate over.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {Function} fn Function to execute on each item. The function will receive
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove the following arguments:
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove @param {Any} fn.value Current array item.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove @param {Number} fn.index Current array index.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove @param {Array} fn.array Array being iterated over.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@param {Object} [thisObj] `this` object to use when calling _fn_.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@return {Boolean} `true` if the function returns a truthy value on any of the
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove items in the array; `false` otherwise.
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove@static
a7bf61fe73568ec8f3615c238acbe69d5986e21dRyan Grove**/
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveYArray.some = Lang._isNative(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};
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove/**
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan GroveEvaluates _obj_ to determine if it's an array, an array-like collection, or
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grovesomething else. This is useful when working with the function `arguments`
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grovecollection and `HTMLElement` collections.
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan GroveNote: This implementation doesn't consider elements that are also
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grovecollections, such as `<form>` and `<select>`, to be array-like.
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove@method test
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove@param {Object} obj Object to test.
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove@return {Number} A number indicating the results of the test:
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove * 0: Neither an array nor an array-like collection.
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove * 1: Real array.
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove * 2: Array-like collection.
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove@static
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove**/
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan GroveYArray.test = function (obj) {
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove var result = 0;
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove if (Lang.isArray(obj)) {
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove result = 1;
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove } else if (Lang.isObject(obj)) {
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove try {
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove // indexed, but no tagName (element) or alert (window),
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove // or functions without apply/call (Safari
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove // HTMLElementCollection bug).
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove if ('length' in obj && !obj.tagName && !obj.alert && !obj.apply) {
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove result = 2;
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove }
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove } catch (ex) {}
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove }
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove return result;
ca485dc641537729d8e1b87e5b982e6a6b35b49aRyan Grove};
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,
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo isObject = Y.Lang.isObject,
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo win = Y.config.win;
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) :
db31545ac9f368e3fd39e367ae7a12cab1bc18eaDav Glass String(arg);
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
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo/**
4106577eb9389768607e9d9a51f614faa6bdb8bcEric FerraiuoloReturns the `location` object from the window/frame in which this YUI instance
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolooperates, or `undefined` when executing in a non-browser environment
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo(e.g. Node.js).
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo
4106577eb9389768607e9d9a51f614faa6bdb8bcEric FerraiuoloIt is _not_ recommended to hold references to the `window.location` object
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolooutside of the scope of a function in which its properties are being accessed or
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuoloits methods are being called. This is because of a nasty bug/issue that exists
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuoloin both Safari and MobileSafari browsers:
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo[WebKit Bug 34679](https://bugs.webkit.org/show_bug.cgi?id=34679).
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo@method getLocation
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo@return {location} The `location` object from the window/frame in which this YUI
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo instance operates.
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo@since 3.5.0
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo**/
4106577eb9389768607e9d9a51f614faa6bdb8bcEric FerraiuoloY.getLocation = function () {
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo // The reference to the `window` object created outside this function's
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo // scope is safe to hold on to, but it is not safe to do so with the
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo // `location` object. The WebKit engine used in Safari and MobileSafari will
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo // "disconnect" the `location` object from the `window` when a page is
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo // restored from back/forward history cache.
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo return win && win.location;
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo};
4106577eb9389768607e9d9a51f614faa6bdb8bcEric Ferraiuolo
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/**
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan GroveMixes _supplier_'s properties into _receiver_.
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan Grove
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan GroveProperties on _receiver_ or _receiver_'s prototype will not be overwritten or
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan Groveshadowed unless the _overwrite_ parameter is `true`, and will not be merged
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan Groveunless the _merge_ parameter is `true`.
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.
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan Grove@param {Number} [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
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan Grove // If `overwrite` is truthy and `merge` is falsy, then we can skip a
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan Grove // property existence check 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
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan Grove // The `key in to` check here is (sadly) intentional for backwards
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan Grove // compatibility reasons. It prevents undesired shadowing of
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan Grove // prototype members on `to`.
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan Grove exists = alwaysOverwrite ? false : key in to;
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
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan Grove // The `key in to` check here is (sadly) intentional for backwards
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan Grove // compatibility reasons. It prevents undesired shadowing of
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan Grove // prototype members on `to`.
0e0b1aea8a2b10793017ac8c04119623792bd96fRyan Grove exists = alwaysOverwrite ? false : key in to;
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
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grovevar Lang = Y.Lang,
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove hasOwn = Object.prototype.hasOwnProperty,
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove UNDEFINED, // <-- 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 */
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveO = Y.Object = Lang._isNative(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
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove * @type Boolean
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @protected
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass * @static
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass */
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav GlasshasEnumBug = O._hasEnumBug = !{valueOf: 0}.propertyIsEnumerable('valueOf'),
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove/**
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove * `true` if this browser incorrectly considers the `prototype` property of
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove * functions to be enumerable. Currently known to affect Opera 11.50.
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove *
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove * @property _hasProtoEnumBug
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove * @type Boolean
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove * @protected
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove * @static
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove */
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan GrovehasProtoEnumBug = O._hasProtoEnumBug = (function () {}).propertyIsEnumerable('prototype'),
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove
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 */
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan GroveO.keys = Lang._isNative(Object.keys) ? Object.keys : function (obj) {
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove if (!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
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove if (hasProtoEnumBug && typeof obj === 'function') {
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove for (key in obj) {
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove if (owns(obj, key) && key !== 'prototype') {
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove keys.push(key);
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove }
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove }
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove } else {
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove for (key in obj) {
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove if (owns(obj, key)) {
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove keys.push(key);
10bc435f4f69ce3ae4b6b3a55d032e158f7ee04fRyan Grove }
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) {
aa3eb862908fbaa7fe237987a5937e6f93351dceRyan Grove try {
aa3eb862908fbaa7fe237987a5937e6f93351dceRyan Grove return O.keys(obj).length;
aa3eb862908fbaa7fe237987a5937e6f93351dceRyan Grove } catch (ex) {
aa3eb862908fbaa7fe237987a5937e6f93351dceRyan Grove return 0; // Legacy behavior for non-objects.
aa3eb862908fbaa7fe237987a5937e6f93351dceRyan Grove }
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) {
cae4d2ed6ca80fad6273efe302e3f7888512674aRyan Grove if (!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) {
aa5f38e24e68d77ed92110e43dbaa7a91bd7c36aRyan Grove return !O.keys(Object(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 */
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass/**
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith* Static method on `YUI.Env` for parsing a UA string. Called at instantiation
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith* to populate `Y.UA`.
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith*
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass* @static
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith* @method parseUA
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith* @param {String} [subUA=navigator.userAgent] UA string to parse
c18c3cd2fd8eeacf413ae627850f59082866ff8dDav Glass* @return {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,
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass /**
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass * Detects Kindle Silk
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass * @property silk
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass * @type float
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass * @static
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass */
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass silk: 0,
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass /**
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass * Detects Kindle Silk Acceleration
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass * @property accel
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass * @type Boolean
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass * @static
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass */
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass accel: false,
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 */
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass os: null,
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass /**
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass * The Nodejs Version
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass * @property nodejs
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass * @type float
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass * @default 0
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass * @static
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass */
18ece86180354a04882023128233ef8e226105c9Ryan Grove nodejs: 0
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
31ec578faf84a19206019b9e99a5ba8a71df16a5Dav Glass /**
31ec578faf84a19206019b9e99a5ba8a71df16a5Dav Glass * The User Agent string that was parsed
31ec578faf84a19206019b9e99a5ba8a71df16a5Dav Glass * @property userAgent
31ec578faf84a19206019b9e99a5ba8a71df16a5Dav Glass * @type String
31ec578faf84a19206019b9e99a5ba8a71df16a5Dav Glass * @static
31ec578faf84a19206019b9e99a5ba8a71df16a5Dav Glass */
d70d9a880191e4db866518d070be4d6a3cab676aDav Glass o.userAgent = ua;
d70d9a880191e4db866518d070be4d6a3cab676aDav Glass
31ec578faf84a19206019b9e99a5ba8a71df16a5Dav 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';
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass } else if ((/macintosh/i).test(ua) || (/mac_powerpc/i).test(ua)) {
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass o.os = 'macintosh';
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass } else if ((/android/i).test(ua)) {
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass o.os = 'android';
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass } else if ((/symbos/i).test(ua)) {
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass o.os = 'symbos';
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass } else if ((/linux/i).test(ua)) {
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass o.os = 'linux';
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 }
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass if ((/IEMobile/).test(ua) || (/XBLWP7/).test(ua)) {
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass o.mobile = 'windows';
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass }
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass if ((/Fennec/).test(ua)) {
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass o.mobile = 'gecko';
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav 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
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass if (/ Mobile\//.test(ua) || (/iPad|iPod|iPhone/).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;
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass o.os = 'ios';
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 }
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass if (/Silk/.test(ua)) {
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass m = ua.match(/Silk\/([^\s]*)\)/);
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass if (m && m[1]) {
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass o.silk = numberify(m[1]);
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass }
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass if (!o.android) {
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass o.android = 2.34; //Hack for desktop mode in Kindle
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass o.os = 'Android';
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass }
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass if (/Accelerated=true/.test(ua)) {
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass o.accel = true;
31c041fdc24c571a504ebcb97db93c2114626df6Dav Glass }
31c041fdc24c571a504ebcb97db93c2114626df6Dav 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)
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass if (/Opera/.test(ua)) {
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass m = ua.match(/Opera[\s\/]([^\s]*)/);
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass if (m && m[1]) {
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass o.opera = numberify(m[1]);
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass }
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
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass if (/Opera Mobi/.test(ua)) {
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass o.mobile = 'opera';
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass m = ua.replace('Opera Mobi', '').match(/Opera ([^\s]*)/);
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass if (m && m[1]) {
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass o.opera = numberify(m[1]);
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav Glass }
5c71d16540fb2a8cd79c36ed7c11e6805421451eDav 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
d70d9a880191e4db866518d070be4d6a3cab676aDav Glass //It was a parsed UA, do not assign the global value.
d70d9a880191e4db866518d070be4d6a3cab676aDav Glass if (!subUA) {
18ece86180354a04882023128233ef8e226105c9Ryan Grove
e50f934937df79b50c89540b19144762829a301cDav Glass if (typeof process == 'object') {
e50f934937df79b50c89540b19144762829a301cDav Glass
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass if (process.versions && process.versions.node) {
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass //NodeJS
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass o.os = process.platform;
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass o.nodejs = process.versions.node;
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass }
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass }
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass
d70d9a880191e4db866518d070be4d6a3cab676aDav Glass YUI.Env.UA = o;
2b7903ae0f8e77339133aac32cf37c4ced6b195dDav Glass
d70d9a880191e4db866518d070be4d6a3cab676aDav Glass }
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"],
55cd25feb35044897d3d4796b26b58d79f4ddb02Eric Ferraiuolo "app": ["app-base","model","model-list","router","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"],
03e121b4917d1868932bdbafcb42c8a278d70bdbDerek Gathright "button": ["button-base","button-group","cssbutton"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "cache": ["cache-base","cache-offline","cache-plugin"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "collection": ["array-extras","arraylist","arraylist-add","arraylist-filter","array-invoke"],
de9a0f1f71ba0f9cdfb1cbe7f0590557fd1a4fe7Ryan Grove "controller": ["router"],
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"],
820d7f2eab2a78412c9803335bb10a2974e7fbf5Luke Smith "datatable": ["datatable-core","datatable-head","datatable-body","datatable-base","datatable-column-widths","datatable-mutable","datatable-scroll","datatable-datasource","datatable-sort"],
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"],
1d01372aa06d46fcbeeae1718c35cf404f412a85Dav Glass "editor": ["frame","editor-selection","exec-command","editor-base","editor-para","editor-br","editor-bidi","editor-tab","createlink-base"],
cae6c3e5f419ce0ccc48676357b4fb70b31f1642Luke Smith "event": ["event-base","event-delegate","event-synthetic","event-mousewheel","event-mouseenter","event-key","event-focus","event-resize","event-hover","event-outside","event-touch","event-move","event-flick","event-valuechange"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "event-custom": ["event-custom-base","event-custom-complex"],
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass "event-gestures": ["event-flick","event-move"],
b4095a6cbe3647b2e09b018401145e7cec26b07aRyan Grove "handlebars": ["handlebars-compiler"],
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"],
9fe828490d8f0a4ebaa725655a93f54040acc332Dav Glass "widget": ["widget-base","widget-htmlparser","widget-uievents","widget-skin"]
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass};
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass
cfb5c556e841b63b73ea6328df5fd730963e0c44Dav Glass}, '@VERSION@' );