yui-base.js revision 7f42f69d1fb2e4ea5f1635fc635d3a6c70860c50
998276643802ff9fb197fe220cbd9552da00a624Luke Smith/**
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * The YUI module contains the components required for building the YUI seed
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * file. This includes the script loading mechanism, a simple queue, and
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * the core utilities for the library.
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @module yui
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @submodule yui-base
998276643802ff9fb197fe220cbd9552da00a624Luke Smith */
998276643802ff9fb197fe220cbd9552da00a624Luke Smith
998276643802ff9fb197fe220cbd9552da00a624Luke Smithif (typeof YUI != 'undefined') {
998276643802ff9fb197fe220cbd9552da00a624Luke Smith YUI._YUI = YUI;
998276643802ff9fb197fe220cbd9552da00a624Luke Smith}
998276643802ff9fb197fe220cbd9552da00a624Luke Smith
998276643802ff9fb197fe220cbd9552da00a624Luke Smith/**
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * The YUI global namespace object. If YUI is already defined, the
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * existing YUI object will not be overwritten so that defined
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * namespaces are preserved. It is the constructor for the object
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * the end user interacts with. As indicated below, each instance
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * has full custom event support, but only if the event system
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * is available. This is a self-instantiable factory function. You
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * can invoke it directly like this:
998276643802ff9fb197fe220cbd9552da00a624Luke Smith *
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * YUI().use('*', function(Y) {
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * // ready
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * });
998276643802ff9fb197fe220cbd9552da00a624Luke Smith *
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * But it also works like this:
998276643802ff9fb197fe220cbd9552da00a624Luke Smith *
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * var Y = YUI();
998276643802ff9fb197fe220cbd9552da00a624Luke Smith *
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @class YUI
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @constructor
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @global
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @uses EventTarget
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @param o* {object} 0..n optional configuration objects. these values
64436761af23a95069579e643c4ef13a252e330dLuke Smith * are store in Y.config. See config for the list of supported
64436761af23a95069579e643c4ef13a252e330dLuke Smith * properties.
64436761af23a95069579e643c4ef13a252e330dLuke Smith */
64436761af23a95069579e643c4ef13a252e330dLuke Smith /*global YUI*/
64436761af23a95069579e643c4ef13a252e330dLuke Smith /*global YUI_config*/
64436761af23a95069579e643c4ef13a252e330dLuke Smith var YUI = function() {
64436761af23a95069579e643c4ef13a252e330dLuke Smith var i = 0,
64436761af23a95069579e643c4ef13a252e330dLuke Smith Y = this,
64436761af23a95069579e643c4ef13a252e330dLuke Smith args = arguments,
64436761af23a95069579e643c4ef13a252e330dLuke Smith l = args.length,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith instanceOf = function(o, type) {
64436761af23a95069579e643c4ef13a252e330dLuke Smith return (o && o.hasOwnProperty && (o instanceof type));
64436761af23a95069579e643c4ef13a252e330dLuke Smith },
64436761af23a95069579e643c4ef13a252e330dLuke Smith gconf = (typeof YUI_config !== 'undefined') && YUI_config;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!(instanceOf(Y, YUI))) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y = new YUI();
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith } else {
64436761af23a95069579e643c4ef13a252e330dLuke Smith // set up the core environment
64436761af23a95069579e643c4ef13a252e330dLuke Smith Y._init();
64436761af23a95069579e643c4ef13a252e330dLuke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith // YUI.GlobalConfig is a master configuration that might span
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith // multiple contexts in a non-browser environment. It is applied
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith // first to all instances in all contexts.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (YUI.GlobalConfig) {
64436761af23a95069579e643c4ef13a252e330dLuke Smith Y.applyConfig(YUI.GlobalConfig);
64436761af23a95069579e643c4ef13a252e330dLuke Smith }
64436761af23a95069579e643c4ef13a252e330dLuke Smith
64436761af23a95069579e643c4ef13a252e330dLuke Smith // YUI_Config is a page-level config. It is applied to all
998276643802ff9fb197fe220cbd9552da00a624Luke Smith // instances created on the page. This is applied after
998276643802ff9fb197fe220cbd9552da00a624Luke Smith // YUI.GlobalConfig, and before the instance level configuration
998276643802ff9fb197fe220cbd9552da00a624Luke Smith // objects.
998276643802ff9fb197fe220cbd9552da00a624Luke Smith if (gconf) {
998276643802ff9fb197fe220cbd9552da00a624Luke Smith Y.applyConfig(gconf);
998276643802ff9fb197fe220cbd9552da00a624Luke Smith }
998276643802ff9fb197fe220cbd9552da00a624Luke Smith
998276643802ff9fb197fe220cbd9552da00a624Luke Smith // bind the specified additional modules for this instance
998276643802ff9fb197fe220cbd9552da00a624Luke Smith if (!l) {
998276643802ff9fb197fe220cbd9552da00a624Luke Smith Y._setup();
64436761af23a95069579e643c4ef13a252e330dLuke Smith }
64436761af23a95069579e643c4ef13a252e330dLuke Smith }
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith if (l) {
64436761af23a95069579e643c4ef13a252e330dLuke Smith // Each instance can accept one or more configuration objects.
64436761af23a95069579e643c4ef13a252e330dLuke Smith // These are applied after YUI.GlobalConfig and YUI_Config,
64436761af23a95069579e643c4ef13a252e330dLuke Smith // overriding values set in those config files if there is a '
64436761af23a95069579e643c4ef13a252e330dLuke Smith // matching property.
64436761af23a95069579e643c4ef13a252e330dLuke Smith for (; i < l; i++) {
64436761af23a95069579e643c4ef13a252e330dLuke Smith Y.applyConfig(args[i]);
64436761af23a95069579e643c4ef13a252e330dLuke Smith }
64436761af23a95069579e643c4ef13a252e330dLuke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith Y._setup();
64436761af23a95069579e643c4ef13a252e330dLuke Smith }
64436761af23a95069579e643c4ef13a252e330dLuke Smith
64436761af23a95069579e643c4ef13a252e330dLuke Smith Y.instanceOf = instanceOf;
64436761af23a95069579e643c4ef13a252e330dLuke Smith
64436761af23a95069579e643c4ef13a252e330dLuke Smith return Y;
64436761af23a95069579e643c4ef13a252e330dLuke Smith };
64436761af23a95069579e643c4ef13a252e330dLuke Smith
64436761af23a95069579e643c4ef13a252e330dLuke Smith(function() {
64436761af23a95069579e643c4ef13a252e330dLuke Smith
64436761af23a95069579e643c4ef13a252e330dLuke Smith var proto, prop,
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith VERSION = '@VERSION@',
64436761af23a95069579e643c4ef13a252e330dLuke Smith PERIOD = '.',
64436761af23a95069579e643c4ef13a252e330dLuke Smith BASE = 'http://yui.yahooapis.com/',
64436761af23a95069579e643c4ef13a252e330dLuke Smith DOC_LABEL = 'yui3-js-enabled',
64436761af23a95069579e643c4ef13a252e330dLuke Smith NOOP = function() {},
64436761af23a95069579e643c4ef13a252e330dLuke Smith SLICE = Array.prototype.slice,
64436761af23a95069579e643c4ef13a252e330dLuke Smith APPLY_TO_AUTH = { 'io.xdrReady': 1, // the functions applyTo
64436761af23a95069579e643c4ef13a252e330dLuke Smith 'io.xdrResponse': 1, // can call. this should
64436761af23a95069579e643c4ef13a252e330dLuke Smith 'SWF.eventHandler': 1 }, // be done at build time
64436761af23a95069579e643c4ef13a252e330dLuke Smith hasWin = (typeof window != 'undefined'),
64436761af23a95069579e643c4ef13a252e330dLuke Smith win = (hasWin) ? window : null,
64436761af23a95069579e643c4ef13a252e330dLuke Smith doc = (hasWin) ? win.document : null,
64436761af23a95069579e643c4ef13a252e330dLuke Smith docEl = doc && doc.documentElement,
64436761af23a95069579e643c4ef13a252e330dLuke Smith docClass = docEl && docEl.className,
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith instances = {},
64436761af23a95069579e643c4ef13a252e330dLuke Smith time = new Date().getTime(),
64436761af23a95069579e643c4ef13a252e330dLuke Smith add = function(el, type, fn, capture) {
64436761af23a95069579e643c4ef13a252e330dLuke Smith if (el && el.addEventListener) {
64436761af23a95069579e643c4ef13a252e330dLuke Smith el.addEventListener(type, fn, capture);
64436761af23a95069579e643c4ef13a252e330dLuke Smith } else if (el && el.attachEvent) {
64436761af23a95069579e643c4ef13a252e330dLuke Smith el.attachEvent('on' + type, fn);
64436761af23a95069579e643c4ef13a252e330dLuke Smith }
64436761af23a95069579e643c4ef13a252e330dLuke Smith },
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith remove = function(el, type, fn, capture) {
64436761af23a95069579e643c4ef13a252e330dLuke Smith if (el && el.removeEventListener) {
64436761af23a95069579e643c4ef13a252e330dLuke Smith // this can throw an uncaught exception in FF
64436761af23a95069579e643c4ef13a252e330dLuke Smith try {
64436761af23a95069579e643c4ef13a252e330dLuke Smith el.removeEventListener(type, fn, capture);
64436761af23a95069579e643c4ef13a252e330dLuke Smith } catch (ex) {}
64436761af23a95069579e643c4ef13a252e330dLuke Smith } else if (el && el.detachEvent) {
64436761af23a95069579e643c4ef13a252e330dLuke Smith el.detachEvent('on' + type, fn);
64436761af23a95069579e643c4ef13a252e330dLuke Smith }
64436761af23a95069579e643c4ef13a252e330dLuke Smith },
64436761af23a95069579e643c4ef13a252e330dLuke Smith handleLoad = function() {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith YUI.Env.windowLoaded = true;
64436761af23a95069579e643c4ef13a252e330dLuke Smith YUI.Env.DOMReady = true;
64436761af23a95069579e643c4ef13a252e330dLuke Smith if (hasWin) {
64436761af23a95069579e643c4ef13a252e330dLuke Smith remove(window, 'load', handleLoad);
64436761af23a95069579e643c4ef13a252e330dLuke Smith }
64436761af23a95069579e643c4ef13a252e330dLuke Smith },
64436761af23a95069579e643c4ef13a252e330dLuke Smith getLoader = function(Y, o) {
64436761af23a95069579e643c4ef13a252e330dLuke Smith var loader = Y.Env._loader;
64436761af23a95069579e643c4ef13a252e330dLuke Smith if (loader) {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith loader.ignoreRegistered = false;
64436761af23a95069579e643c4ef13a252e330dLuke Smith loader.onEnd = null;
64436761af23a95069579e643c4ef13a252e330dLuke Smith loader.data = null;
64436761af23a95069579e643c4ef13a252e330dLuke Smith loader.required = [];
64436761af23a95069579e643c4ef13a252e330dLuke Smith loader.loadType = null;
64436761af23a95069579e643c4ef13a252e330dLuke Smith } else {
64436761af23a95069579e643c4ef13a252e330dLuke Smith loader = new Y.Loader(Y.config);
998276643802ff9fb197fe220cbd9552da00a624Luke Smith Y.Env._loader = loader;
998276643802ff9fb197fe220cbd9552da00a624Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith return loader;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith },
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith clobber = function(r, s) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith for (var i in s) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (s.hasOwnProperty(i)) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith r[i] = s[i];
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith },
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith ALREADY_DONE = { success: true };
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith// Stamp the documentElement (HTML) with a class of "yui-loaded" to
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith// enable styles that need to key off of JS being enabled.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smithif (docEl && docClass.indexOf(DOC_LABEL) == -1) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (docClass) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith docClass += ' ';
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith docClass += DOC_LABEL;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith docEl.className = docClass;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith}
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smithif (VERSION.indexOf('@') > -1) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith VERSION = '3.2.0'; // dev time hack for cdn test
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith}
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smithproto = {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith /**
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * Applies a new configuration object to the YUI instance config.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * This will merge new group/module definitions, and will also
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * update the loader cache if necessary. Updating Y.config directly
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * will not update the cache.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @method applyConfig
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @param {object} the configuration object.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @since 3.2.0
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith */
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith applyConfig: function(o) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith o = o || NOOP;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith var attr,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith name,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith // detail,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith config = this.config,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith mods = config.modules,
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith groups = config.groups,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith rls = config.rls,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith loader = this.Env._loader;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith for (name in o) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (o.hasOwnProperty(name)) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith attr = o[name];
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (mods && name == 'modules') {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith clobber(mods, attr);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith } else if (groups && name == 'groups') {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith clobber(groups, attr);
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith } else if (rls && name == 'rls') {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith clobber(rls, attr);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith } else if (name == 'win') {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith config[name] = attr.contentWindow || attr;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith config.doc = config[name].document;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith } else if (name == '_yuid') {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith // preserve the guid
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith } else {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith config[name] = attr;
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (loader) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith loader._config(o);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith },
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
998276643802ff9fb197fe220cbd9552da00a624Luke Smith _config: function(o) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith this.applyConfig(o);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith },
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith /**
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * Initialize this YUI instance
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @private
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith */
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith _init: function() {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith var filter,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y = this,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith G_ENV = YUI.Env,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Env = Y.Env,
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith prop;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith /**
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * The version number of the YUI instance.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @property version
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @type string
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith */
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y.version = VERSION;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!Env) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y.Env = {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith mods: {}, // flat module map
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith versions: {}, // version module map
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith base: BASE,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith cdn: BASE + VERSION + '/build/',
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith // bootstrapped: false,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith _idx: 0,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith _used: {},
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith _attached: {},
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith _yidx: 0,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith _uidx: 0,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith _guidp: 'y',
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith _loaded: {},
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith serviced: {},
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith getBase: G_ENV && G_ENV.getBase ||
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith function(srcPattern, comboPattern) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith var b, nodes, i, src, match;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith // get from querystring
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith nodes = (doc && doc.getElementsByTagName('script')) || [];
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith for (i = 0; i < nodes.length; i = i + 1) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith src = nodes[i].src;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (src) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith match = src.match(srcPattern);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith b = match && match[1];
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (b) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith // this is to set up the path to the loader. The file
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith // filter for loader should match the yui include.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith filter = match[2];
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (filter) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith match = filter.indexOf('js');
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (match > -1) {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith filter = filter.substr(0, match);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith // extract correct path for mixed combo urls
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith // http://yuilibrary.com/projects/yui3/ticket/2528423
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith match = src.match(comboPattern);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (match && match[3]) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith b = match[1] + match[3];
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith break;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
998276643802ff9fb197fe220cbd9552da00a624Luke Smith // use CDN default
998276643802ff9fb197fe220cbd9552da00a624Luke Smith return b || Env.cdn;
998276643802ff9fb197fe220cbd9552da00a624Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith };
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith Env = Y.Env;
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Env._loaded[VERSION] = {};
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (G_ENV && Y !== YUI) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Env._yidx = ++G_ENV._yidx;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Env._guidp = ('yui_' + VERSION + '_' +
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Env._yidx + '_' + time).replace(/\./g, '_');
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith } else if (YUI._YUI) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith G_ENV = YUI._YUI.Env;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Env._yidx += G_ENV._yidx;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Env._uidx += G_ENV._uidx;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith for (prop in G_ENV) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!(prop in Env)) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Env[prop] = G_ENV[prop];
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith delete YUI._YUI;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y.id = Y.stamp(Y);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith instances[Y.id] = Y;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y.constructor = YUI;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith // configuration defaults
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y.config = Y.config || {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith win: win,
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith doc: doc,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith debug: true,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith useBrowserConsole: true,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith throwFail: true,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith bootstrap: true,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith cacheUse: true,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith fetchCSS: true
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith };
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y.config.base = YUI.config.base ||
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y.Env.getBase(/^(.*)yui\/yui([\.\-].*)js(\?.*)?$/,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith /^(.*\?)(.*\&)(.*)yui\/yui[\.\-].*js(\?.*)?$/);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!filter || (!('-min.-debug.').indexOf(filter))) {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith filter = '-min.';
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y.config.loaderPath = YUI.config.loaderPath ||
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith 'loader/loader' + (filter || '-min.') + 'js';
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith },
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith /**
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * Finishes the instance setup. Attaches whatever modules were defined
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * when the yui modules was registered.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @method _setup
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @private
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith */
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith _setup: function(o) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith var i, Y = this,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith core = [],
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith mods = YUI.Env.mods,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith extras = Y.config.core || ['get',
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith 'rls',
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith 'intl-base',
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith 'loader',
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith 'yui-log',
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith 'yui-later',
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith 'yui-throttle'];
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith for (i = 0; i < extras.length; i++) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (mods[extras[i]]) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith core.push(extras[i]);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y._attach(['yui-base']);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y._attach(core);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith },
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith /**
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * Executes a method on a YUI instance with
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * the specified id if the specified method is whitelisted.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @method applyTo
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @param id {string} the YUI instance id.
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * @param method {string} the name of the method to exectute.
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * Ex: 'Object.keys'.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @param args {Array} the arguments to apply to the method.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @return {object} the return value from the applied method or null.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith */
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith applyTo: function(id, method, args) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!(method in APPLY_TO_AUTH)) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith this.log(method + ': applyTo not allowed', 'warn', 'yui');
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith return null;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith var instance = instances[id], nest, m, i;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (instance) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith nest = method.split('.');
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith m = instance;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith for (i = 0; i < nest.length; i = i + 1) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith m = m[nest[i]];
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!m) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith this.log('applyTo not found: ' + method, 'warn', 'yui');
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith return m.apply(instance, args);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith return null;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith },
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith /**
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * Registers a module with the YUI global. The easiest way to create a
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * first-class YUI module is to use the YUI component build tool.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith *
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * http://yuilibrary.com/projects/builder
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith *
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * The build system will produce the YUI.add wrapper for you module, along
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * with any configuration info required for the module.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @method add
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @param name {string} module name.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @param fn {Function} entry point into the module that
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * is used to bind module to the YUI instance.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @param version {string} version string.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @param details {object} optional config data:
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * requires: features that must be present before this module can be
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * attached.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * optional: optional features that should be present if loadOptional
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * is defined. Note: modules are not often loaded this way in YUI 3,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * but this field is still useful to inform the user that certain
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * features in the component will require additional dependencies.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * use: features that are included within this module which need to
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * be attached automatically when this module is attached. This
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * supports the YUI 3 rollup system -- a module with submodules
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * defined will need to have the submodules listed in the 'use'
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * config. The YUI component build tool does this for you.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @return {YUI} the YUI instance.
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith *
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith */
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith add: function(name, fn, version, details) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith details = details || {};
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith var env = YUI.Env,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith mod = {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith name: name,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith fn: fn,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith version: version,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith details: details
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith },
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith loader,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith i, versions = env.versions;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith env.mods[name] = mod;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith versions[version] = versions[version] || {};
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith versions[version][name] = mod;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith for (i in instances) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (instances.hasOwnProperty(i)) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith loader = instances[i].Env._loader;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (loader) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!loader.moduleInfo[name]) {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith loader.addModule(details, name);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith return this;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith },
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith /**
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * Executes the function associated with each required
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * module, binding the module to the YUI instance.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @method _attach
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @private
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith */
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith _attach: function(r, fromLoader) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith var i, name, mod, details, req, use, after,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith mods = YUI.Env.mods,
998276643802ff9fb197fe220cbd9552da00a624Luke Smith Y = this, j,
998276643802ff9fb197fe220cbd9552da00a624Luke Smith done = Y.Env._attached,
998276643802ff9fb197fe220cbd9552da00a624Luke Smith len = r.length, loader;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith for (i = 0; i < len; i++) {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith if (!done[r[i]]) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith name = r[i];
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith mod = mods[name];
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!mod) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith loader = Y.Env._loader;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!loader || !loader.moduleInfo[name]) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y.message('NOT loaded: ' + name, 'warn', 'yui');
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith } else {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith done[name] = true;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith details = mod.details;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith req = details.requires;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith use = details.use;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith after = details.after;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (req) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith for (j = 0; j < req.length; j++) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!done[req[j]]) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!Y._attach(req)) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith return false;
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith break;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (after) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith for (j = 0; j < after.length; j++) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!done[after[j]]) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!Y._attach(after)) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith return false;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith break;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (mod.fn) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith try {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith mod.fn(Y, name);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith } catch (e) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y.error('Attach error: ' + name, e, name);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith return false;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (use) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith for (j = 0; j < use.length; j++) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!done[use[j]]) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith if (!Y._attach(use)) {
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith return false;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith break;
998276643802ff9fb197fe220cbd9552da00a624Luke Smith }
998276643802ff9fb197fe220cbd9552da00a624Luke Smith }
998276643802ff9fb197fe220cbd9552da00a624Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith }
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith return true;
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith },
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith /**
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * Attaches one or more modules to the YUI instance. When this
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * is executed, the requirements are analyzed, and one of
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * several things can happen:
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith *
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * - All requirements are available on the page -- The modules
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * are attached to the instance. If supplied, the use callback
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * is executed synchronously.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith *
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * - Modules are missing, the Get utility is not available OR
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * the 'bootstrap' config is false -- A warning is issued about
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * the missing modules and all available modules are attached.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith *
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * - Modules are missing, the Loader is not available but the Get
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * utility is and boostrap is not false -- The loader is bootstrapped
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * before doing the following....
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith *
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * - Modules are missing and the Loader is available -- The loader
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * expands the dependency tree and fetches missing modules. When
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * the loader is finshed the callback supplied to use is executed
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * asynchronously.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @param modules* {string} 1-n modules to bind (uses arguments array).
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @param *callback {function} callback function executed when
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * the instance has the required functionality. If included, it
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * must be the last parameter.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * <code>
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * // loads and attaches drag and drop and its dependencies
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * YUI().use('dd', function(Y) &#123;&#125);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * // attaches all modules that are available on the page
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * YUI().use('*', function(Y) &#123;&#125);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * // intrinsic YUI gallery support (since 3.1.0)
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * YUI().use('gallery-yql', function(Y) &#123;&#125);
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * // intrinsic YUI 2in3 support (since 3.1.0)
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * YUI().use('yui2-datatable', function(Y) &#123;&#125);.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * </code>
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith *
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith * @return {YUI} the YUI instance.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith */
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith use: function() {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith var args = SLICE.call(arguments, 0),
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith callback = args[args.length - 1],
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Y = this,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith i = 0,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith info,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith name,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith Env = Y.Env,
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith provisioned = true;
998276643802ff9fb197fe220cbd9552da00a624Luke Smith // key;
998276643802ff9fb197fe220cbd9552da00a624Luke Smith
998276643802ff9fb197fe220cbd9552da00a624Luke Smith // The last argument supplied to use can be a load complete callback
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (Y.Lang.isFunction(callback)) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith args.pop();
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith } else {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith callback = null;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // key = args.join();
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // if (Y.config.cacheUse && Y.Env.serviced[key]) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // Y._notify(callback, ALREADY_DONE, args);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (Y.config.cacheUse) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith while ((name = args[i++])) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith info = Env._loader && Env._loader.moduleInfo[name];
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (!Env._attached[name]) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith provisioned = false;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith break;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (provisioned) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y._notify(callback, ALREADY_DONE, args);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith return Y;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (Y._loading) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y._useQueue = Y._useQueue || new Y.Queue();
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith Y._useQueue.add([args, callback]);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith } else {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y._use(args, function(Y, response) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // if (Y.config.cacheUse) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // Y.Env.serviced[key] = true;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y._notify(callback, response, args);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith });
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith return Y;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith },
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith _notify: function(callback, response, args) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (!response.success && this.config.loadErrorFn) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith this.config.loadErrorFn.call(this, this, callback, response, args);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith } else if (callback) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith try {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith callback(this, response);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith } catch (e) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith this.error('use callback error', e, args);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith },
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith _use: function(args, callback) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith if (!this.Array) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith this._attach(['yui-base']);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith var len, loader, handleBoot,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y = this,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith G_ENV = YUI.Env,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith mods = G_ENV.mods,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Env = Y.Env,
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith used = Env._used,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith queue = G_ENV._loaderQueue,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith firstArg = args[0],
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith YArray = Y.Array,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith config = Y.config,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith boot = config.bootstrap,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith missing = [],
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith r = [],
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith ret = true,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith fetchCSS = config.fetchCSS,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith process = function(names, skip) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith if (!names.length) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith return;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith YArray.each(names, function(name) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // add this module to full list of things to attach
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (!skip) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith r.push(name);
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // only attach a module once
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (used[name]) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith return;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith var m = mods[name], req, use;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (m) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith used[name] = true;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith req = m.details.requires;
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith use = m.details.use;
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith } else {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // CSS files don't register themselves, see if it has
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // been loaded
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (!G_ENV._loaded[VERSION][name]) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith missing.push(name);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith } else {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith used[name] = true; // probably css
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith // make sure requirements are attached
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (req && req.length) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith process(req);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // make sure we grab the submodule dependencies too
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (use && use.length) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith process(use, 1);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith });
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith },
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith handleLoader = function(fromLoader) {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith var response = fromLoader || {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith success: true,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith msg: 'not dynamic'
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith },
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith redo, origMissing,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith ret = true,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith data = response.data;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y._loading = false;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (data) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith origMissing = missing;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith missing = [];
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith r = [];
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith process(data);
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith redo = missing.length;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (redo) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (missing.sort().join() ==
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith origMissing.sort().join()) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith redo = false;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (redo && data) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y._loading = false;
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith Y._use(args, function() {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (Y._attach(data)) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y._notify(callback, response, data);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith });
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith } else {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (data) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith ret = Y._attach(data);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (ret) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y._notify(callback, response, args);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith if (Y._useQueue && Y._useQueue.size() && !Y._loading) {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith Y._use.apply(Y, Y._useQueue.next());
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith };
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // YUI().use('*'); // bind everything available
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (firstArg === '*') {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith ret = Y._attach(Y.Object.keys(mods));
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (ret) {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith handleLoader();
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith return Y;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // use loader to expand dependencies and sort the
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // requirements if it is available.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (boot && Y.Loader && args.length) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith loader = getLoader(Y);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith loader.require(args);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith loader.ignoreRegistered = true;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith loader.calculate(null, (fetchCSS) ? null : 'js');
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith args = loader.sorted;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // process each requirement and any additional requirements
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // the module metadata specifies
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith process(args);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith len = missing.length;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (len) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith missing = Y.Object.keys(YArray.hash(missing));
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith len = missing.length;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // dynamic load
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (boot && len && Y.Loader) {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith Y._loading = true;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith loader = getLoader(Y);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith loader.onEnd = handleLoader;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith loader.context = Y;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith loader.data = args;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith loader.ignoreRegistered = false;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith loader.require(args);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith loader.insert(null, (fetchCSS) ? null : 'js');
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // loader.partial(missing, (fetchCSS) ? null : 'js');
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith } else if (len && Y.config.use_rls) {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // server side loader service
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y.Get.script(Y._rls(args), {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith onEnd: function(o) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith handleLoader(o);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith },
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith data: args
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith });
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
998276643802ff9fb197fe220cbd9552da00a624Luke Smith } else if (boot && len && Y.Get && !Env.bootstrapped) {
998276643802ff9fb197fe220cbd9552da00a624Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y._loading = true;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith handleBoot = function() {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith Y._loading = false;
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith queue.running = false;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Env.bootstrapped = true;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (Y._attach(['loader'])) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y._use(args, callback);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith };
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (G_ENV._bootstrapping) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith queue.add(handleBoot);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith } else {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith G_ENV._bootstrapping = true;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y.Get.script(config.base + config.loaderPath, {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith onEnd: handleBoot
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith });
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith } else {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith ret = Y._attach(args);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (ret) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith handleLoader();
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith return Y;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith },
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith /**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Returns the namespace specified and creates it if it doesn't exist
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * <pre>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * YUI.namespace("property.package");
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * YUI.namespace("YAHOO.property.package");
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * </pre>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Either of the above would create YUI.property, then
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * YUI.property.package (YAHOO is scrubbed out, this is
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * to remain compatible with YUI2)
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Be careful when naming packages. Reserved words may work in some browsers
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * and not others. For instance, the following will fail in Safari:
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * <pre>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * YUI.namespace("really.long.nested.namespace");
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * </pre>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * This fails because "long" is a future reserved word in ECMAScript
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @method namespace
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @param {string*} arguments 1-n namespaces to create.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @return {object} A reference to the last namespace object created.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith namespace: function() {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith var a = arguments, o = this, i = 0, j, d, arg;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith for (; i < a.length; i++) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // d = ('' + a[i]).split('.');
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith arg = a[i];
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (arg.indexOf(PERIOD)) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith d = arg.split(PERIOD);
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith for (j = (d[0] == 'YAHOO') ? 1 : 0; j < d.length; j++) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith o[d[j]] = o[d[j]] || {};
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith o = o[d[j]];
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith } else {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith o[arg] = o[arg] || {};
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith return o;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith },
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith // this is replaced if the log module is included
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith log: NOOP,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith message: NOOP,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith /**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Report an error. The reporting mechanism is controled by
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * the 'throwFail' configuration attribute. If throwFail is
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * not specified, the message is written to the Logger, otherwise
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * a JS error is thrown
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @method error
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @param msg {string} the error message.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @param e {Error|string} Optional JS error that was caught, or an error string.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @param data Optional additional info
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * and throwFail is specified, this error will be re-thrown.
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * @return {YUI} this YUI instance.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith error: function(msg, e, data) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith var Y = this, ret;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (Y.config.errorFn) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith ret = Y.config.errorFn.apply(Y, arguments);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith if (Y.config.throwFail && !ret) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith throw (e || new Error(msg));
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith } else {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y.message(msg, 'error'); // don't scrub this one
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith return Y;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith },
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith /**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Generate an id that is unique among all YUI instances
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @method guid
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @param pre {string} optional guid prefix.
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * @return {string} the guid.
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith guid: function(pre) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith var id = this.Env._guidp + (++this.Env._uidx);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith return (pre) ? (pre + id) : id;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith },
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith /**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Returns a guid associated with an object. If the object
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * does not have one, a new one is created unless readOnly
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * is specified.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @method stamp
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @param o The object to stamp.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @param readOnly {boolean} if true, a valid guid will only
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * be returned if the object has one assigned to it.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @return {string} The object's guid or null.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith stamp: function(o, readOnly) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith var uid;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (!o) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith return o;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // IE generates its own unique ID for dom nodes
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // The uniqueID property of a document node returns a new ID
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (o.uniqueID && o.nodeType && o.nodeType !== 9) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith uid = o.uniqueID;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith } else {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith uid = (typeof o === 'string') ? o : o._yuid;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (!uid) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith uid = this.guid();
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (!readOnly) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith try {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith o._yuid = uid;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith } catch (e) {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith uid = null;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith return uid;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith },
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith /**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Destroys the YUI instance
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @method destroy
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * @since 3.3.0
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith destroy: function() {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith var Y = this;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (Y.Event) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith Y.Event._unload();
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith delete instances[Y.id];
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith delete Y.Env;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith delete Y.config;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith /**
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * instanceof check for objects that works around
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * memory leak in IE when the item tested is
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * window/document
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @method instanceOf
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @since 3.3.0
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith};
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith YUI.prototype = proto;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // inheritance utilities are not available yet
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith for (prop in proto) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (proto.hasOwnProperty(prop)) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith YUI[prop] = proto[prop];
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
998276643802ff9fb197fe220cbd9552da00a624Luke Smith // set up the environment
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith YUI._init();
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith if (hasWin) {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // add a window load event at load time so we can capture
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // the case where it fires before dynamic loading is
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith // complete.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith add(window, 'load', handleLoad);
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith } else {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith handleLoad();
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
998276643802ff9fb197fe220cbd9552da00a624Luke Smith YUI.Env.add = add;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith YUI.Env.remove = remove;
998276643802ff9fb197fe220cbd9552da00a624Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith /*global exports*/
998276643802ff9fb197fe220cbd9552da00a624Luke Smith // Support the CommonJS method for exporting our single global
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith if (typeof exports == 'object') {
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith exports.YUI = YUI;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith}());
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * The config object contains all of the configuration options for
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * the YUI instance. This object is supplied by the implementer
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * when instantiating a YUI instance. Some properties have default
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * values if they are not supplied by the implementer. This should
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * not be updated directly because some values are cached. Use
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * applyConfig() to update the config object on a YUI instance that
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * has already been configured.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @class config
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @static
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
998276643802ff9fb197fe220cbd9552da00a624Luke Smith
998276643802ff9fb197fe220cbd9552da00a624Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Allows the YUI seed file to fetch the loader component and library
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * metadata to dynamically load additional dependencies.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * @property bootstrap
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * @type boolean
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @default true
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Log to the browser console if debug is on and the browser has a
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * supported console.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property useBrowserConsole
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type boolean
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @default true
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * A hash of log sources that should be logged. If specified, only
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * log messages from these sources will be logged.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property logInclude
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type object
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * A hash of log sources that should be not be logged. If specified,
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * all sources are logged if not on this list.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property logExclude
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type object
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Set to true if the yui seed file was dynamically loaded in
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * order to bootstrap components relying on the window load event
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * and the 'domready' custom event.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property injected
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * @type boolean
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @default false
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * If throwFail is set, Y.error will generate or re-throw a JS Error.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Otherwise the failure is logged.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property throwFail
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type boolean
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @default true
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * The window/frame that this instance should operate in.
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property win
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type Window
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @default the window hosting YUI
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * The document associated with the 'win' configuration.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property doc
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * @type Document
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @default the document hosting YUI
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * A list of modules that defines the YUI core (overrides the default).
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property core
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type string[]
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * A list of languages in order of preference. This list is matched against
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * the list of available languages in modules that the YUI instance uses to
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * determine the best possible localization of language sensitive modules.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Languages are represented using BCP 47 language tags, such as "en-GB" for
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * English as used in the United Kingdom, or "zh-Hans-CN" for simplified
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Chinese as used in China. The list can be provided as a comma-separated
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * list or as an array.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property lang
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type string|string[]
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * The default date format
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property dateFormat
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type string
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @deprecated use configuration in DataType.Date.format() instead.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
998276643802ff9fb197fe220cbd9552da00a624Luke Smith/**
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * The default locale
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * @property locale
15ddc967c5d429ed2983719db23b453794ab0338Luke Smith * @type string
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @deprecated use config.lang instead.
998276643802ff9fb197fe220cbd9552da00a624Luke Smith */
998276643802ff9fb197fe220cbd9552da00a624Luke Smith
998276643802ff9fb197fe220cbd9552da00a624Luke Smith/**
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * The default interval when polling in milliseconds.
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @property pollInterval
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @type int
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @default 20
998276643802ff9fb197fe220cbd9552da00a624Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * The number of dynamic nodes to insert by default before
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * automatically removing them. This applies to script nodes
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * because remove the node will not make the evaluated script
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * unavailable. Dynamic CSS is not auto purged, because removing
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * a linked style sheet will also remove the style definitions.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property purgethreshold
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type int
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @default 20
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * The default interval when polling in milliseconds.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property windowResizeDelay
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type int
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @default 40
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * Base directory for dynamic loading
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @property base
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @type string
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/*
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * The secure base dir (not implemented)
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * For dynamic loading.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property secureBase
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type string
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * For dynamic loading.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property comboBase
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type string
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * The root path to prepend to module path for the combo service.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Ex: 3.0.0b1/build/
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * For dynamic loading.
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @property root
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @type string
998276643802ff9fb197fe220cbd9552da00a624Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * A filter to apply to result urls. This filter will modify the default
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * path for all modules. The default path for the YUI library is the
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * minified version of the files (e.g., event-min.js). The filter property
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * can be a predefined filter or a custom filter. The valid predefined
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * filters are:
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * <dl>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * <dt>DEBUG</dt>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * <dd>Selects the debug versions of the library (e.g., event-debug.js).
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * This option will automatically include the Logger widget</dd>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * <dt>RAW</dt>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * <dd>Selects the non-minified version of the library (e.g., event.js).</dd>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * </dl>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * You can also define a custom filter, which must be an object literal
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * containing a search expression and a replace string:
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * <pre>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * myFilter: &#123;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * 'searchExp': "-min\\.js",
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * 'replaceStr': "-debug.js"
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * &#125;
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * </pre>
998276643802ff9fb197fe220cbd9552da00a624Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * For dynamic loading.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property filter
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type string|object
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * The 'skin' config let's you configure application level skin
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * customizations. It contains the following attributes which
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * can be specified to override the defaults:
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * // The default skin, which is automatically applied if not
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * // overriden by a component-specific skin definition.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * // Change this in to apply a different skin globally
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * defaultSkin: 'sam',
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * // This is combined with the loader base property to get
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * // the default root directory for a skin.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * base: 'assets/skins/',
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * // Any component-specific overrides can be specified here,
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * // making it possible to load different skins for different
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * // components. It is possible to load more than one skin
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * // for a given component as well.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * overrides: {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * slider: ['capsule', 'round']
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * For dynamic loading.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * @property skin
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
998276643802ff9fb197fe220cbd9552da00a624Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Hash of per-component filter specification. If specified for a given
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * component, this overrides the filter config.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * For dynamic loading.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property filters
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Use the YUI combo service to reduce the number of http connections
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * required to load your dependencies. Turning this off will
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * disable combo handling for YUI and all module groups configured
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * with a combo service.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * For dynamic loading.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property combine
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type boolean
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @default true if 'base' is not supplied, false if it is.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * A list of modules that should never be dynamically loaded
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property ignore
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type string[]
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * A list of modules that should always be loaded when required, even if already
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * present on the page.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property force
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type string[]
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Node or id for a node that should be used as the insertion point for new
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * nodes. For dynamic loading.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property insertBefore
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type string
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Object literal containing attributes to add to dynamically loaded script
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * nodes.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property jsAttributes
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type string
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Object literal containing attributes to add to dynamically loaded link
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * nodes.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property cssAttributes
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type string
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Number of milliseconds before a timeout occurs when dynamically
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * loading nodes. If not set, there is no timeout.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property timeout
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type int
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * Callback for the 'CSSComplete' event. When dynamically loading YUI
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * components with CSS, this property fires when the CSS is finished
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * loading but script loading is still ongoing. This provides an
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * opportunity to enhance the presentation of a loading page a little
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * bit before the entire loading process is done.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property onCSS
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type function
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * A hash of module definitions to add to the list of YUI components.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * These components can then be dynamically loaded side by side with
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * YUI via the use() method. This is a hash, the key is the module
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * name, and the value is an object literal specifying the metdata
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * for the module. * See Loader.addModule for the supported module
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * metadata fields. Also @see groups, which provides a way to
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * configure the base and combo spec for a set of modules.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * <code>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * modules: {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; mymod1: {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; requires: ['node'],
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; fullpath: 'http://myserver.mydomain.com/mymod1/mymod1.js'
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; },
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; mymod2: {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; requires: ['mymod1'],
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; fullpath: 'http://myserver.mydomain.com/mymod2/mymod2.js'
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * </code>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith *
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property modules
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type object
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith/**
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * A hash of module group definitions. It for each group you
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * can specify a list of modules and the base path and
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * combo spec to use when dynamically loading the modules. @see
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @see modules for the details about the modules part of the
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * group definition.
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * <code>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; groups: {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; yui2: {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; // specify whether or not this group has a combo service
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; combine: true,
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; // the base path for non-combo paths
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; base: 'http://yui.yahooapis.com/2.8.0r4/build/',
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; // the path to the combo service
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; comboBase: 'http://yui.yahooapis.com/combo?',
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; // a fragment to prepend to the path attribute when
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; // when building combo urls
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; root: '2.8.0r4/build/',
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp;
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; // the module definitions
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; modules: {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; yui2_yde: {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; path: "yahoo-dom-event/yahoo-dom-event.js"
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; },
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; yui2_anim: {
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; path: "animation/animation.js",
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; requires: ['yui2_yde']
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * &nbsp; }
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * </code>
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @property modules
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith * @type object
45c60cccb9510ac1984b981c475511ad657f1116Luke Smith */
998276643802ff9fb197fe220cbd9552da00a624Luke Smith
998276643802ff9fb197fe220cbd9552da00a624Luke Smith/**
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * The loader 'path' attribute to the loader itself. This is combined
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * with the 'base' attribute to dynamically load the loader component
998276643802ff9fb197fe220cbd9552da00a624Luke Smith * when boostrapping with the get utility alone.
8c0728da50e402de1837852ea5482ccd74c230f7Luke Smith *
* @property loaderPath
* @type string
* @default loader/loader-min.js
*/
/**
* Specifies whether or not YUI().use(...) will attempt to load CSS
* resources at all. Any truthy value will cause CSS dependencies
* to load when fetching script. The special value 'force' will
* cause CSS dependencies to be loaded even if no script is needed.
*
* @property fetchCSS
* @type boolean|string
* @default true
*/
/**
* The default gallery version to build gallery module urls
* @property gallery
* @type string
* @since 3.1.0
*/
/**
* The default YUI 2 version to build yui2 module urls. This is for
* intrinsic YUI 2 support via the 2in3 project. Also @see the '2in3'
* config for pulling different revisions of the wrapped YUI 2
* modules.
* @since 3.1.0
* @property yui2
* @type string
* @default 2.8.1
*/
/**
* The 2in3 project is a deployment of the various versions of YUI 2
* deployed as first-class YUI 3 modules. Eventually, the wrapper
* for the modules will change (but the underlying YUI 2 code will
* be the same), and you can select a particular version of
* the wrapper modules via this config.
* @since 3.1.0
* @property 2in3
* @type string
* @default 1
*/
/**
* Alternative console log function for use in environments without
* a supported native console. The function is executed in the
* YUI instance context.
* @since 3.1.0
* @property logFn
* @type Function
*/
/**
* A callback to execute when Y.error is called. It receives the
* error message and an javascript error object if Y.error was
* executed because a javascript error was caught. The function
* is executed in the YUI instance context.
*
* @since 3.2.0
* @property errorFn
* @type Function
*/
/**
* A callback to execute when the loader fails to load one or
* more resource. This could be because of a script load
* failure. It can also fail if a javascript module fails
* to register itself, but only when the 'requireRegistration'
* is true. If this function is defined, the use() callback will
* only be called when the loader succeeds, otherwise it always
* executes unless there was a javascript error when attaching
* a module.
*
* @since 3.3.0
* @property loadErrorFn
* @type Function
*/
/**
* When set to true, the YUI loader will expect that all modules
* it is responsible for loading will be first-class YUI modules
* that register themselves with the YUI global. If this is
* set to true, loader will fail if the module registration fails
* to happen after the script is loaded.
*
* @since 3.3.0
* @property requireRegistration
* @type boolean
* @default false
*/
/**
* Cache serviced use() requests.
* @since 3.3.0
* @property cacheUse
* @type boolean
* @default true
*/
/**
* The parameter defaults for the remote loader service.
* Requires the rls submodule. The properties that are
* supported:
* <pre>
* m: comma separated list of module requirements. This
* must be the param name even for custom implemetations.
* v: the version of YUI to load. Defaults to the version
* of YUI that is being used.
* gv: the version of the gallery to load (@see the gallery config)
* env: comma separated list of modules already on the page.
* this must be the param name even for custom implemetations.
* lang: the languages supported on the page (@see the lang config)
* '2in3v': the version of the 2in3 wrapper to use (@see the 2in3 config).
* '2v': the version of yui2 to use in the yui 2in3 wrappers
* (@see the yui2 config)
* filt: a filter def to apply to the urls (@see the filter config).
* filts: a list of custom filters to apply per module
* (@see the filters config).
* tests: this is a map of conditional module test function id keys
* with the values of 1 if the test passes, 0 if not. This must be
* the name of the querystring param in custom templates.
*</pre>
*
* @since 3.2.0
* @property rls
*/
/**
* The base path to the remote loader service
*
* @since 3.2.0
* @property rls_base
*/
/**
* The template to use for building the querystring portion
* of the remote loader service url. The default is determined
* by the rls config -- each property that has a value will be
* represented.
*
* ex: m={m}&v={v}&env={env}&lang={lang}&filt={filt}&tests={tests}
*
*
* @since 3.2.0
* @property rls_tmpl
*/
/**
* Configure the instance to use a remote loader service instead of
* the client loader.
*
* @since 3.2.0
* @property use_rls
*/
YUI.add('yui-base', function(Y) {
/*
* YUI stub
* @module yui
* @submodule yui-base
*/
/**
* The YUI module contains the components required for building the YUI
* seed file. This includes the script loading mechanism, a simple queue,
* and the core utilities for the library.
* @module yui
* @submodule yui-base
*/
/**
* Provides the language utilites and extensions used by the library
* @class Lang
* @static
*/
Y.Lang = Y.Lang || {};
var L = Y.Lang,
ARRAY = 'array',
BOOLEAN = 'boolean',
DATE = 'date',
ERROR = 'error',
FUNCTION = 'function',
NUMBER = 'number',
NULL = 'null',
OBJECT = 'object',
REGEX = 'regexp',
STRING = 'string',
STRING_PROTO = String.prototype,
TOSTRING = Object.prototype.toString,
UNDEFINED = 'undefined',
TYPES = {
'undefined' : UNDEFINED,
'number' : NUMBER,
'boolean' : BOOLEAN,
'string' : STRING,
'[object Function]' : FUNCTION,
'[object RegExp]' : REGEX,
'[object Array]' : ARRAY,
'[object Date]' : DATE,
'[object Error]' : ERROR
},
TRIMREGEX = /^\s+|\s+$/g,
EMPTYSTRING = '',
SUBREGEX = /\{\s*([^\|\}]+?)\s*(?:\|([^\}]*))?\s*\}/g;
/**
* Determines whether or not the provided item is an array.
* Returns false for array-like collections such as the
* function arguments collection or HTMLElement collection
* will return false. Use <code>Y.Array.test</code> if you
* want to test for an array-like collection.
* @method isArray
* @static
* @param o The object to test.
* @return {boolean} true if o is an array.
*/
// L.isArray = Array.isArray || function(o) {
// return L.type(o) === ARRAY;
// };
L.isArray = function(o) {
return L.type(o) === ARRAY;
};
/**
* Determines whether or not the provided item is a boolean.
* @method isBoolean
* @static
* @param o The object to test.
* @return {boolean} true if o is a boolean.
*/
L.isBoolean = function(o) {
return typeof o === BOOLEAN;
};
/**
* <p>
* Determines whether or not the provided item is a function.
* Note: Internet Explorer thinks certain functions are objects:
* </p>
*
* <pre>
* var obj = document.createElement("object");
* Y.Lang.isFunction(obj.getAttribute) // reports false in IE
* &nbsp;
* var input = document.createElement("input"); // append to body
* Y.Lang.isFunction(input.focus) // reports false in IE
* </pre>
*
* <p>
* You will have to implement additional tests if these functions
* matter to you.
* </p>
*
* @method isFunction
* @static
* @param o The object to test.
* @return {boolean} true if o is a function.
*/
L.isFunction = function(o) {
return L.type(o) === FUNCTION;
};
/**
* Determines whether or not the supplied item is a date instance.
* @method isDate
* @static
* @param o The object to test.
* @return {boolean} true if o is a date.
*/
L.isDate = function(o) {
// return o instanceof Date;
return L.type(o) === DATE && o.toString() !== 'Invalid Date' && !isNaN(o);
};
/**
* Determines whether or not the provided item is null.
* @method isNull
* @static
* @param o The object to test.
* @return {boolean} true if o is null.
*/
L.isNull = function(o) {
return o === null;
};
/**
* Determines whether or not the provided item is a legal number.
* @method isNumber
* @static
* @param o The object to test.
* @return {boolean} true if o is a number.
*/
L.isNumber = function(o) {
return typeof o === NUMBER && isFinite(o);
};
/**
* Determines whether or not the provided item is of type object
* or function. Note that arrays are also objects, so
* <code>Y.Lang.isObject([]) === true</code>.
* @method isObject
* @static
* @param o The object to test.
* @param failfn {boolean} fail if the input is a function.
* @return {boolean} true if o is an object.
*/
L.isObject = function(o, failfn) {
var t = typeof o;
return (o && (t === OBJECT ||
(!failfn && (t === FUNCTION || L.isFunction(o))))) || false;
};
/**
* Determines whether or not the provided item is a string.
* @method isString
* @static
* @param o The object to test.
* @return {boolean} true if o is a string.
*/
L.isString = function(o) {
return typeof o === STRING;
};
/**
* Determines whether or not the provided item is undefined.
* @method isUndefined
* @static
* @param o The object to test.
* @return {boolean} true if o is undefined.
*/
L.isUndefined = function(o) {
return typeof o === UNDEFINED;
};
/**
* Returns a string without any leading or trailing whitespace. If
* the input is not a string, the input will be returned untouched.
* @method trim
* @static
* @param s {string} the string to trim.
* @return {string} the trimmed string.
*/
L.trim = STRING_PROTO.trim ? function(s) {
return (s && s.trim) ? s.trim() : s;
} : function (s) {
try {
return s.replace(TRIMREGEX, EMPTYSTRING);
} catch (e) {
return s;
}
};
/**
* Returns a string without any leading whitespace.
* @method trimLeft
* @static
* @param s {string} the string to trim.
* @return {string} the trimmed string.
*/
L.trimLeft = STRING_PROTO.trimLeft ? function (s) {
return s.trimLeft();
} : function (s) {
return s.replace(/^\s+/, '');
};
/**
* Returns a string without any trailing whitespace.
* @method trimRight
* @static
* @param s {string} the string to trim.
* @return {string} the trimmed string.
*/
L.trimRight = STRING_PROTO.trimRight ? function (s) {
return s.trimRight();
} : function (s) {
return s.replace(/\s+$/, '');
};
/**
* A convenience method for detecting a legitimate non-null value.
* Returns false for null/undefined/NaN, true for other values,
* including 0/false/''
* @method isValue
* @static
* @param o The item to test.
* @return {boolean} true if it is not null/undefined/NaN || false.
*/
L.isValue = function(o) {
var t = L.type(o);
switch (t) {
case NUMBER:
return isFinite(o);
case NULL:
case UNDEFINED:
return false;
default:
return !!(t);
}
};
/**
* <p>
* Returns a string representing the type of the item passed in.
* </p>
*
* <p>
* Known issues:
* </p>
*
* <ul>
* <li>
* <code>typeof HTMLElementCollection</code> returns function in Safari, but
* <code>Y.type()</code> reports object, which could be a good thing --
* but it actually caused the logic in <code>Y.Lang.isObject</code> to fail.
* </li>
* </ul>
*
* @method type
* @param o the item to test.
* @return {string} the detected type.
* @static
*/
L.type = function(o) {
return TYPES[typeof o] || TYPES[TOSTRING.call(o)] || (o ? OBJECT : NULL);
};
/**
* Lightweight version of <code>Y.substitute</code>. Uses the same template
* structure as <code>Y.substitute</code>, but doesn't support recursion,
* auto-object coersion, or formats.
* @method sub
* @param {string} s String to be modified.
* @param {object} o Object containing replacement values.
* @return {string} the substitute result.
* @static
* @since 3.2.0
*/
L.sub = function(s, o) {
return ((s.replace) ? s.replace(SUBREGEX, function(match, key) {
return (!L.isUndefined(o[key])) ? o[key] : match;
}) : s);
};
/**
* Returns the current time in milliseconds.
* @method now
* @return {int} the current date
* @since 3.3.0
*/
L.now = Date.now || function () {
return new Date().getTime();
};
/**
* The YUI module contains the components required for building the YUI seed
* file. This includes the script loading mechanism, a simple queue, and the
* core utilities for the library.
* @module yui
* @submodule yui-base
*/
var Native = Array.prototype, LENGTH = 'length',
/**
* Adds the following array utilities to the YUI instance. Additional
* array helpers can be found in the collection component.
* @class Array
*/
/**
* Y.Array(o) returns an array:
* - Arrays are return unmodified unless the start position is specified.
* - "Array-like" collections (@see Array.test) are converted to arrays
* - For everything else, a new array is created with the input as the sole
* item.
* - The start position is used if the input is or is like an array to return
* a subset of the collection.
*
* @todo this will not automatically convert elements that are also
* collections such as forms and selects. Passing true as the third
* param will force a conversion.
*
* @method ()
* @static
* @param {object} o the item to arrayify.
* @param {int} startIdx if an array or array-like, this is the start index.
* @param {boolean} arraylike if true, it forces the array-like fork. This
* can be used to avoid multiple Array.test calls.
* @return {Array} the resulting array.
*/
YArray = function(o, startIdx, arraylike) {
var t = (arraylike) ? 2 : YArray.test(o),
l, a, start = startIdx || 0;
if (t) {
// IE errors when trying to slice HTMLElement collections
try {
return Native.slice.call(o, start);
} catch (e) {
a = [];
l = o.length;
for (; start < l; start++) {
a.push(o[start]);
}
return a;
}
} else {
return [o];
}
};
Y.Array = YArray;
/**
* Evaluates the input to determine if it is an array, array-like, or
* something else. This is used to handle the arguments collection
* available within functions, and HTMLElement collections
*
* @method test
* @static
*
* @todo current implementation (intenionally) will not implicitly
* handle html elements that are array-like (forms, selects, etc).
*
* @param {object} o the object to test.
*
* @return {int} a number indicating the results:
* 0: Not an array or an array-like collection
* 1: A real array.
* 2: array-like collection.
*/
YArray.test = function(o) {
var r = 0;
if (Y.Lang.isObject(o)) {
if (Y.Lang.isArray(o)) {
r = 1;
} else {
try {
// indexed, but no tagName (element) or alert (window),
// or functions without apply/call (Safari
// HTMLElementCollection bug).
if ((LENGTH in o) && !o.tagName && !o.alert && !o.apply) {
r = 2;
}
} catch (e) {}
}
}
return r;
};
/**
* Executes the supplied function on each item in the array.
* @method each
* @param {Array} a the array to iterate.
* @param {Function} f the function to execute on each item. The
* function receives three arguments: the value, the index, the full array.
* @param {object} o Optional context object.
* @static
* @return {YUI} the YUI instance.
*/
YArray.each = (Native.forEach) ?
function(a, f, o) {
Native.forEach.call(a || [], f, o || Y);
return Y;
} :
function(a, f, o) {
var l = (a && a.length) || 0, i;
for (i = 0; i < l; i = i + 1) {
f.call(o || Y, a[i], i, a);
}
return Y;
};
/**
* Returns an object using the first array as keys, and
* the second as values. If the second array is not
* provided the value is set to true for each.
* @method hash
* @static
* @param {Array} k keyset.
* @param {Array} v optional valueset.
* @return {object} the hash.
*/
YArray.hash = function(k, v) {
var o = {}, l = k.length, vl = v && v.length, i;
for (i = 0; i < l; i = i + 1) {
o[k[i]] = (vl && vl > i) ? v[i] : true;
}
return o;
};
/**
* Returns the index of the first item in the array
* that contains the specified value, -1 if the
* value isn't found.
* @method indexOf
* @static
* @param {Array} a the array to search.
* @param {any} val the value to search for.
* @return {int} the index of the item that contains the value or -1.
*/
YArray.indexOf = (Native.indexOf) ?
function(a, val) {
return Native.indexOf.call(a, val);
} :
function(a, val) {
for (var i = 0; i < a.length; i = i + 1) {
if (a[i] === val) {
return i;
}
}
return -1;
};
/**
* Numeric sort convenience function.
* Y.ArrayAssert.itemsAreEqual([1,2,3], [3,1,2].sort(Y.Array.numericSort));
* @method numericSort
* @static
* @param {number} a a number.
* @param {number} b a number.
*/
YArray.numericSort = function(a, b) {
return (a - b);
};
/**
* Executes the supplied function on each item in the array.
* Returning true from the processing function will stop the
* processing of the remaining items.
* @method some
* @param {Array} a the array to iterate.
* @param {Function} f the function to execute on each item. The function
* receives three arguments: the value, the index, the full array.
* @param {object} o Optional context object.
* @static
* @return {boolean} true if the function returns true on
* any of the items in the array.
*/
YArray.some = (Native.some) ?
function(a, f, o) {
return Native.some.call(a, f, o);
} :
function(a, f, o) {
var l = a.length, i;
for (i = 0; i < l; i = i + 1) {
if (f.call(o, a[i], i, a)) {
return true;
}
}
return false;
};
/**
* The YUI module contains the components required for building the YUI
* seed file. This includes the script loading mechanism, a simple queue,
* and the core utilities for the library.
* @module yui
* @submodule yui-base
*/
/**
* A simple FIFO queue. Items are added to the Queue with add(1..n items) and
* removed using next().
*
* @class Queue
* @constructor
* @param {MIXED} item* 0..n items to seed the queue.
*/
function Queue() {
this._init();
this.add.apply(this, arguments);
}
Queue.prototype = {
/**
* Initialize the queue
*
* @method _init
* @protected
*/
_init: function() {
/**
* The collection of enqueued items
*
* @property _q
* @type Array
* @protected
*/
this._q = [];
},
/**
* Get the next item in the queue. FIFO support
*
* @method next
* @return {MIXED} the next item in the queue.
*/
next: function() {
return this._q.shift();
},
/**
* Get the last in the queue. LIFO support.
*
* @method last
* @return {MIXED} the last item in the queue.
*/
last: function() {
return this._q.pop();
},
/**
* Add 0..n items to the end of the queue.
*
* @method add
* @param {MIXED} item* 0..n items.
* @return {object} this queue.
*/
add: function() {
this._q.push.apply(this._q, arguments);
return this;
},
/**
* Returns the current number of queued items.
*
* @method size
* @return {Number} The size.
*/
size: function() {
return this._q.length;
}
};
Y.Queue = Queue;
YUI.Env._loaderQueue = YUI.Env._loaderQueue || new Queue();
/**
* The YUI module contains the components required for building the YUI
* seed file. This includes the script loading mechanism, a simple queue,
* and the core utilities for the library.
* @module yui
* @submodule yui-base
*/
var CACHED_DELIMITER = '__',
NOT_ENUMERATED = ['toString', 'valueOf'],
/*
* IE will not enumerate native functions in a derived object even if the
* function was overridden. This is a workaround for specific functions
* we care about on the Object prototype.
* @property _iefix
* @for YUI
* @param {Function} r the object to receive the augmentation
* @param {Function} s the object that supplies the properties to augment
* @private
*/
_iefix = function(r, s) {
var i, fname, fn;
for (i = 0; i < NOT_ENUMERATED.length; i++) {
fname = NOT_ENUMERATED[i];
fn = s[fname];
if (L.isFunction(fn) && fn != Object.prototype[fname]) {
r[fname] = fn;
}
}
};
/**
* Returns a new object containing all of the properties of
* all the supplied objects. The properties from later objects
* will overwrite those in earlier objects. Passing in a
* single object will create a shallow copy of it. For a deep
* copy, use clone.
* @method merge
* @for YUI
* @param arguments {Object*} the objects to merge.
* @return {object} the new merged object.
*/
Y.merge = function() {
var a = arguments, o = {}, i, l = a.length;
for (i = 0; i < l; i = i + 1) {
Y.mix(o, a[i], true);
}
return o;
};
/**
* Applies the supplier's properties to the receiver. By default
* all prototype and static propertes on the supplier are applied
* to the corresponding spot on the receiver. By default all
* properties are applied, and a property that is already on the
* reciever will not be overwritten. The default behavior can
* be modified by supplying the appropriate parameters.
*
* @todo add constants for the modes
*
* @method mix
* @param {Function} r the object to receive the augmentation.
* @param {Function} s the object that supplies the properties to augment.
* @param ov {boolean} if true, properties already on the receiver
* will be overwritten if found on the supplier.
* @param wl {string[]} a whitelist. If supplied, only properties in
* this list will be applied to the receiver.
* @param {int} mode what should be copies, and to where
* default(0): object to object
* 1: prototype to prototype (old augment)
* 2: prototype to prototype and object props (new augment)
* 3: prototype to object
* 4: object to prototype.
* @param merge {boolean/int} merge objects instead of overwriting/ignoring.
* A value of 2 will skip array merge
* Used by Y.aggregate.
* @return {object} the augmented object.
*/
Y.mix = function(r, s, ov, wl, mode, merge) {
if (!s || !r) {
return r || Y;
}
if (mode) {
switch (mode) {
case 1: // proto to proto
return Y.mix(r.prototype, s.prototype, ov, wl, 0, merge);
case 2: // object to object and proto to proto
Y.mix(r.prototype, s.prototype, ov, wl, 0, merge);
break; // pass through
case 3: // proto to static
return Y.mix(r, s.prototype, ov, wl, 0, merge);
case 4: // static to proto
return Y.mix(r.prototype, s, ov, wl, 0, merge);
default: // object to object is what happens below
}
}
// Maybe don't even need this wl && wl.length check anymore??
var i, l, p, type;
if (wl && wl.length) {
for (i = 0, l = wl.length; i < l; ++i) {
p = wl[i];
type = Y.Lang.type(r[p]);
if (s.hasOwnProperty(p)) {
if (merge && type == 'object') {
Y.mix(r[p], s[p]);
} else if (ov || !(p in r)) {
r[p] = s[p];
}
}
}
} else {
for (i in s) {
// if (s.hasOwnProperty(i) && !(i in FROZEN)) {
if (s.hasOwnProperty(i)) {
// check white list if it was supplied
// if the receiver has this property, it is an object,
// and merge is specified, merge the two objects.
if (merge && Y.Lang.isObject(r[i], true)) {
Y.mix(r[i], s[i], ov, wl, 0, true); // recursive
// otherwise apply the property only if overwrite
// is specified or the receiver doesn't have one.
} else if (ov || !(i in r)) {
r[i] = s[i];
}
// if merge is specified and the receiver is an array,
// append the array item
// } else if (arr) {
// r.push(s[i]);
// }
}
}
if (Y.UA.ie) {
_iefix(r, s);
}
}
return r;
};
/**
* Returns a wrapper for a function which caches the
* return value of that function, keyed off of the combined
* argument values.
* @method cached
* @param source {function} the function to memoize.
* @param cache an optional cache seed.
* @param refetch if supplied, this value is tested against the cached
* value. If the values are equal, the wrapped function is executed again.
* @return {Function} the wrapped function.
*/
Y.cached = function(source, cache, refetch) {
cache = cache || {};
return function(arg1) {
var k = (arguments.length > 1) ?
Array.prototype.join.call(arguments, CACHED_DELIMITER) : arg1;
if (!(k in cache) || (refetch && cache[k] == refetch)) {
cache[k] = source.apply(source, arguments);
}
return cache[k];
};
};
/**
* The YUI module contains the components required for building the YUI
* seed file. This includes the script loading mechanism, a simple queue,
* and the core utilities for the library.
* @module yui
* @submodule yui-base
*/
/**
* Adds the following Object utilities to the YUI instance
* @class Object
*/
/**
* Y.Object(o) returns a new object based upon the supplied object.
* @method ()
* @static
* @param o the supplier object.
* @return {Object} the new object.
*/
var F = function() {},
// O = Object.create || function(o) {
// F.prototype = o;
// return new F();
// },
O = function(o) {
F.prototype = o;
return new F();
},
owns = function(o, k) {
return o && o.hasOwnProperty && o.hasOwnProperty(k);
// return Object.prototype.hasOwnProperty.call(o, k);
},
UNDEF,
/**
* Extracts the keys, values, or size from an object
*
* @method _extract
* @param o the object.
* @param what what to extract (0: keys, 1: values, 2: size).
* @return {boolean|Array} the extracted info.
* @static
* @private
*/
_extract = function(o, what) {
var count = (what === 2), out = (count) ? 0 : [], i;
for (i in o) {
if (owns(o, i)) {
if (count) {
out++;
} else {
out.push((what) ? o[i] : i);
}
}
}
return out;
};
Y.Object = O;
/**
* Returns an array containing the object's keys
* @method keys
* @static
* @param o an object.
* @return {string[]} the keys.
*/
// O.keys = Object.keys || function(o) {
// return _extract(o);
// };
O.keys = function(o) {
return _extract(o);
};
/**
* Returns an array containing the object's values
* @method values
* @static
* @param o an object.
* @return {Array} the values.
*/
// O.values = Object.values || function(o) {
// return _extract(o, 1);
// };
O.values = function(o) {
return _extract(o, 1);
};
/**
* Returns the size of an object
* @method size
* @static
* @param o an object.
* @return {int} the size.
*/
O.size = Object.size || function(o) {
return _extract(o, 2);
};
/**
* Returns true if the object contains a given key
* @method hasKey
* @static
* @param o an object.
* @param k the key to query.
* @return {boolean} true if the object contains the key.
*/
O.hasKey = owns;
/**
* Returns true if the object contains a given value
* @method hasValue
* @static
* @param o an object.
* @param v the value to query.
* @return {boolean} true if the object contains the value.
*/
O.hasValue = function(o, v) {
return (Y.Array.indexOf(O.values(o), v) > -1);
};
/**
* Determines whether or not the property was added
* to the object instance. Returns false if the property is not present
* in the object, or was inherited from the prototype.
*
* @method owns
* @static
* @param o {any} The object being testing.
* @param p {string} the property to look for.
* @return {boolean} true if the object has the property on the instance.
*/
O.owns = owns;
/**
* Executes a function on each item. The function
* receives the value, the key, and the object
* as parameters (in that order).
* @method each
* @static
* @param o the object to iterate.
* @param f {Function} the function to execute on each item. The function
* receives three arguments: the value, the the key, the full object.
* @param c the execution context.
* @param proto {boolean} include proto.
* @return {YUI} the YUI instance.
*/
O.each = function(o, f, c, proto) {
var s = c || Y, i;
for (i in o) {
if (proto || owns(o, i)) {
f.call(s, o[i], i, o);
}
}
return Y;
};
/**
* Executes a function on each item, but halts if the
* function returns true. The function
* receives the value, the key, and the object
* as paramters (in that order).
* @method some
* @static
* @param o the object to iterate.
* @param f {Function} the function to execute on each item. The function
* receives three arguments: the value, the the key, the full object.
* @param c the execution context.
* @param proto {boolean} include proto.
* @return {boolean} true if any execution of the function returns true,
* false otherwise.
*/
O.some = function(o, f, c, proto) {
var s = c || Y, i;
for (i in o) {
if (proto || owns(o, i)) {
if (f.call(s, o[i], i, o)) {
return true;
}
}
}
return false;
};
/**
* Retrieves the sub value at the provided path,
* from the value object provided.
*
* @method getValue
* @static
* @param o The object from which to extract the property value.
* @param path {Array} A path array, specifying the object traversal path
* from which to obtain the sub value.
* @return {Any} The value stored in the path, undefined if not found,
* undefined if the source is not an object. Returns the source object
* if an empty path is provided.
*/
O.getValue = function(o, path) {
if (!Y.Lang.isObject(o)) {
return UNDEF;
}
var i,
p = Y.Array(path),
l = p.length;
for (i = 0; o !== UNDEF && i < l; i++) {
o = o[p[i]];
}
return o;
};
/**
* Sets the sub-attribute value at the provided path on the
* value object. Returns the modified value object, or
* undefined if the path is invalid.
*
* @method setValue
* @static
* @param o The object on which to set the sub value.
* @param path {Array} A path array, specifying the object traversal path
* at which to set the sub value.
* @param val {Any} The new value for the sub-attribute.
* @return {Object} The modified object, with the new sub value set, or
* undefined, if the path was invalid.
*/
O.setValue = function(o, path, val) {
var i,
p = Y.Array(path),
leafIdx = p.length - 1,
ref = o;
if (leafIdx >= 0) {
for (i = 0; ref !== UNDEF && i < leafIdx; i++) {
ref = ref[p[i]];
}
if (ref !== UNDEF) {
ref[p[i]] = val;
} else {
return UNDEF;
}
}
return o;
};
/**
* Returns true if the object has no properties of its own
* @method isEmpty
* @static
* @return {boolean} true if the object is empty.
* @since 3.2.0
*/
O.isEmpty = function(o) {
for (var i in o) {
if (owns(o, i)) {
return false;
}
}
return true;
};
/**
* The YUI module contains the components required for building the YUI seed
* file. This includes the script loading mechanism, a simple queue, and the
* core utilities for the library.
* @module yui
* @submodule yui-base
*/
/**
* YUI user agent detection.
* Do not fork for a browser if it can be avoided. Use feature detection when
* you can. Use the user agent as a last resort. For all fields listed
* as @type float, UA stores a version number for the browser engine,
* 0 otherwise. This value may or may not map to the version number of
* the browser using the engine. The value is presented as a float so
* that it can easily be used for boolean evaluation as well as for
* looking for a particular range of versions. Because of this,
* some of the granularity of the version info may be lost. The fields that
* are @type string default to null. The API docs list the values that
* these fields can have.
* @class UA
* @static
*/
/**
* Static method for parsing the UA string. Defaults to assigning it's value to Y.UA
* @static
* @method Env.parseUA
* @param {String} subUA Parse this UA string instead of navigator.userAgent
* @returns {Object} The Y.UA object
*/
YUI.Env.parseUA = function(subUA) {
var numberify = function(s) {
var c = 0;
return parseFloat(s.replace(/\./g, function() {
return (c++ == 1) ? '' : '.';
}));
},
win = Y.config.win,
nav = win && win.navigator,
o = {
/**
* Internet Explorer version number or 0. Example: 6
* @property ie
* @type float
* @static
*/
ie: 0,
/**
* Opera version number or 0. Example: 9.2
* @property opera
* @type float
* @static
*/
opera: 0,
/**
* Gecko engine revision number. Will evaluate to 1 if Gecko
* is detected but the revision could not be found. Other browsers
* will be 0. Example: 1.8
* <pre>
* Firefox 1.0.0.4: 1.7.8 <-- Reports 1.7
* Firefox 1.5.0.9: 1.8.0.9 <-- 1.8
* Firefox 2.0.0.3: 1.8.1.3 <-- 1.81
* Firefox 3.0 <-- 1.9
* Firefox 3.5 <-- 1.91
* </pre>
* @property gecko
* @type float
* @static
*/
gecko: 0,
/**
* AppleWebKit version. KHTML browsers that are not WebKit browsers
* will evaluate to 1, other browsers 0. Example: 418.9
* <pre>
* Safari 1.3.2 (312.6): 312.8.1 <-- Reports 312.8 -- currently the
* latest available for Mac OSX 10.3.
* Safari 2.0.2: 416 <-- hasOwnProperty introduced
* Safari 2.0.4: 418 <-- preventDefault fixed
* Safari 2.0.4 (419.3): 418.9.1 <-- One version of Safari may run
* different versions of webkit
* Safari 2.0.4 (419.3): 419 <-- Tiger installations that have been
* updated, but not updated
* to the latest patch.
* Webkit 212 nightly: 522+ <-- Safari 3.0 precursor (with native
* SVG and many major issues fixed).
* Safari 3.0.4 (523.12) 523.12 <-- First Tiger release - automatic
* update from 2.x via the 10.4.11 OS patch.
* Webkit nightly 1/2008:525+ <-- Supports DOMContentLoaded event.
* yahoo.com user agent hack removed.
* </pre>
* http://en.wikipedia.org/wiki/Safari_version_history
* @property webkit
* @type float
* @static
*/
webkit: 0,
/**
* Chrome will be detected as webkit, but this property will also
* be populated with the Chrome version number
* @property chrome
* @type float
* @static
*/
chrome: 0,
/**
* The mobile property will be set to a string containing any relevant
* user agent information when a modern mobile browser is detected.
* Currently limited to Safari on the iPhone/iPod Touch, Nokia N-series
* devices with the WebKit-based browser, and Opera Mini.
* @property mobile
* @type string
* @default null
* @static
*/
mobile: null,
/**
* Adobe AIR version number or 0. Only populated if webkit is detected.
* Example: 1.0
* @property air
* @type float
*/
air: 0,
/**
* Detects Apple iPad's OS version
* @property ipad
* @type float
* @static
*/
ipad: 0,
/**
* Detects Apple iPhone's OS version
* @property iphone
* @type float
* @static
*/
iphone: 0,
/**
* Detects Apples iPod's OS version
* @property ipod
* @type float
* @static
*/
ipod: 0,
/**
* General truthy check for iPad, iPhone or iPod
* @property ios
* @type float
* @default null
* @static
*/
ios: null,
/**
* Detects Googles Android OS version
* @property android
* @type float
* @static
*/
android: 0,
/**
* Detects Palms WebOS version
* @property webos
* @type float
* @static
*/
webos: 0,
/**
* Google Caja version number or 0.
* @property caja
* @type float
*/
caja: nav && nav.cajaVersion,
/**
* Set to true if the page appears to be in SSL
* @property secure
* @type boolean
* @static
*/
secure: false,
/**
* The operating system. Currently only detecting windows or macintosh
* @property os
* @type string
* @default null
* @static
*/
os: null
},
ua = subUA || nav && nav.userAgent,
loc = win && win.location,
href = loc && loc.href,
m;
o.secure = href && (href.toLowerCase().indexOf('https') === 0);
if (ua) {
if ((/windows|win32/i).test(ua)) {
o.os = 'windows';
} else if ((/macintosh/i).test(ua)) {
o.os = 'macintosh';
} else if ((/rhino/i).test(ua)) {
o.os = 'rhino';
}
// Modern KHTML browsers should qualify as Safari X-Grade
if ((/KHTML/).test(ua)) {
o.webkit = 1;
}
// Modern WebKit browsers are at least X-Grade
m = ua.match(/AppleWebKit\/([^\s]*)/);
if (m && m[1]) {
o.webkit = numberify(m[1]);
// Mobile browser check
if (/ Mobile\//.test(ua)) {
o.mobile = 'Apple'; // iPhone or iPod Touch
m = ua.match(/OS ([^\s]*)/);
if (m && m[1]) {
m = numberify(m[1].replace('_', '.'));
}
o.ios = m;
o.ipad = o.ipod = o.iphone = 0;
m = ua.match(/iPad|iPod|iPhone/);
if (m && m[0]) {
o[m[0].toLowerCase()] = o.ios;
}
} else {
m = ua.match(/NokiaN[^\/]*|Android \d\.\d|webOS\/\d\.\d/);
if (m) {
// Nokia N-series, Android, webOS, ex: NokiaN95
o.mobile = m[0];
}
if (/webOS/.test(ua)) {
o.mobile = 'WebOS';
m = ua.match(/webOS\/([^\s]*);/);
if (m && m[1]) {
o.webos = numberify(m[1]);
}
}
if (/ Android/.test(ua)) {
o.mobile = 'Android';
m = ua.match(/Android ([^\s]*);/);
if (m && m[1]) {
o.android = numberify(m[1]);
}
}
}
m = ua.match(/Chrome\/([^\s]*)/);
if (m && m[1]) {
o.chrome = numberify(m[1]); // Chrome
} else {
m = ua.match(/AdobeAIR\/([^\s]*)/);
if (m) {
o.air = m[0]; // Adobe AIR 1.0 or better
}
}
}
if (!o.webkit) { // not webkit
// @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr)
m = ua.match(/Opera[\s\/]([^\s]*)/);
if (m && m[1]) {
o.opera = numberify(m[1]);
m = ua.match(/Opera Mini[^;]*/);
if (m) {
o.mobile = m[0]; // ex: Opera Mini/2.0.4509/1316
}
} else { // not opera or webkit
m = ua.match(/MSIE\s([^;]*)/);
if (m && m[1]) {
o.ie = numberify(m[1]);
} else { // not opera, webkit, or ie
m = ua.match(/Gecko\/([^\s]*)/);
if (m) {
o.gecko = 1; // Gecko detected, look for revision
m = ua.match(/rv:([^\s\)]*)/);
if (m && m[1]) {
o.gecko = numberify(m[1]);
}
}
}
}
}
}
YUI.Env.UA = o;
return o;
};
Y.UA = YUI.Env.UA || YUI.Env.parseUA();
}, '@VERSION@' );