yui-base.js revision d1f171a81a8b50c0f694f3dd1ea7ccc08e86cf55
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp/**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * The YUI module contains the components required for building the YUI seed file.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * This includes the script loading mechanism, a simple queue, and the core utilities for the library.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @module yui
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @submodule yui-base
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippif (typeof YUI === 'undefined') {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp/**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * The YUI global namespace object. If YUI is already defined, the
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * existing YUI object will not be overwritten so that defined
87a49173dbc22a145cb87e605cca83fd42524377Tripp * namespaces are preserved. It is the constructor for the object
87a49173dbc22a145cb87e605cca83fd42524377Tripp * the end user interacts with. As indicated below, each instance
87a49173dbc22a145cb87e605cca83fd42524377Tripp * has full custom event support, but only if the event system
87a49173dbc22a145cb87e605cca83fd42524377Tripp * is available.
87a49173dbc22a145cb87e605cca83fd42524377Tripp *
87a49173dbc22a145cb87e605cca83fd42524377Tripp * @class YUI
87a49173dbc22a145cb87e605cca83fd42524377Tripp * @constructor
87a49173dbc22a145cb87e605cca83fd42524377Tripp * @global
87a49173dbc22a145cb87e605cca83fd42524377Tripp * @uses EventTarget
87a49173dbc22a145cb87e605cca83fd42524377Tripp * @param o* Up to five optional configuration objects. This object is stored
87a49173dbc22a145cb87e605cca83fd42524377Tripp * in YUI.config. See config for the list of supported properties.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp /*global YUI*/
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp /*global YUI_config*/
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var YUI = function(o1, o2, o3, o4, o5) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var Y = this, a = arguments, i, l = a.length,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp globalConfig = (typeof YUI_config !== 'undefined') && YUI_config;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // Allow instantiation without the new operator
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (!(Y instanceof YUI)) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return new YUI(o1, o2, o3, o4, o5);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp } else {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp // set up the core environment
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp Y._init();
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if (globalConfig) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp Y._config(globalConfig);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
f69d245bb21be88752420e834a6b6be37e9b525fTripp for (i=0; i<l; i++) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp Y._config(a[i]);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp // bind the specified additional modules for this instance
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp Y._setup();
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp return Y;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp };
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp}
87a49173dbc22a145cb87e605cca83fd42524377Tripp
87a49173dbc22a145cb87e605cca83fd42524377Tripp(function() {
87a49173dbc22a145cb87e605cca83fd42524377Tripp var p, i,
87a49173dbc22a145cb87e605cca83fd42524377Tripp VERSION = '@VERSION@',
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp DOC_LABEL = 'yui3-js-enabled',
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp NOOP = function() {},
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp SLICE = Array.prototype.slice,
f69d245bb21be88752420e834a6b6be37e9b525fTripp APPLY_TO_AUTH = { 'io.xdrReady': 1, // the functions applyTo
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp 'io.xdrResponse': 1, // can call. this should
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp 'SWF.eventHandler': 1 }, // be done at build time
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp hasWin = (typeof window != 'undefined'),
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp win = (hasWin) ? window : null,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp doc = (hasWin) ? win.document : null,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp docEl = doc && doc.documentElement,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp docClass = docEl && docEl.className,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp instances = {},
87a49173dbc22a145cb87e605cca83fd42524377Tripp time = new Date().getTime(),
87a49173dbc22a145cb87e605cca83fd42524377Tripp add = function(el, type, fn, capture) {
87a49173dbc22a145cb87e605cca83fd42524377Tripp if (el && el.addEventListener) {
87a49173dbc22a145cb87e605cca83fd42524377Tripp el.addEventListener(type, fn, capture);
87a49173dbc22a145cb87e605cca83fd42524377Tripp } else if (el && el.attachEvent) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp el.attachEvent("on" + type, fn);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp },
f69d245bb21be88752420e834a6b6be37e9b525fTripp remove = function (el, type, fn, capture) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (el && el.removeEventListener) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp el.removeEventListener(type, fn, capture);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp } else if (el && el.detachEvent) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp el.detachEvent("on" + type, fn);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp handleLoad = function() {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp YUI.Env.windowLoaded = true;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp YUI.Env.DOMReady = true;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if (hasWin) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp remove(window, 'load', handleLoad);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp };
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp// Stamp the documentElement (HTML) with a class of "yui-loaded" to
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp// enable styles that need to key off of JS being enabled.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippif (docEl && docClass.indexOf(DOC_LABEL) == -1) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if (docClass) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp docClass += ' ';
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp docClass += DOC_LABEL;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp docEl.className = docClass;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp}
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTrippif (VERSION.indexOf('@') > -1) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp VERSION = '3.0.0';
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp}
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippYUI.prototype = {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp _config: function(o) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp o = o || {};
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp var config = this.config, i, j, m, mods = config.modules;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp for (i in o) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if (mods && i == 'modules') {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp m = o[i];
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp for (j in m) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if (m.hasOwnProperty(j)) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp mods[j] = m[j];
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp } else if (i == 'win') {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp config[i] = o[i].contentWindow || o[i];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp config.doc = config[i].document;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp } else {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp config[i] = o[i];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Initialize this YUI instance
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @private
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _init: function() {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var filter,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y = this,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp G_ENV = YUI.Env,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Env = Y.Env;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y.version = VERSION;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y.gallery = 'gallery-2010.02.22-22'; // @TODO build time
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if (!Env) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp Y.Env = {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp mods: {},
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp cdn: 'http://yui.yahooapis.com/' + VERSION + '/build/',
f69d245bb21be88752420e834a6b6be37e9b525fTripp bootstrapped: false,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _idx: 0,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _used: {},
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _attached: {},
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _yidx: 0,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _uidx: 0,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _guidp: 'y',
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _loaded: {},
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp getBase: function(srcPattern, comboPattern) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var b, nodes, i, src, match;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // get from querystring
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp nodes = (doc && doc.getElementsByTagName('script')) || [];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp for (i=0; i<nodes.length; i=i+1) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp src = nodes[i].src;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (src) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp //src = "http://yui.yahooapis.com/combo?2.8.0r4/b
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp //uild/yuiloader-dom-event/yuiloader-dom-event.js
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp //&3.0.0/build/yui/yui-min.js"; // debug url
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp match = src.match(srcPattern);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp b = match && match[1];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (b) {
f69d245bb21be88752420e834a6b6be37e9b525fTripp // this is to set up the path to the loader. The file
f69d245bb21be88752420e834a6b6be37e9b525fTripp // filter for loader should match the yui include.
f69d245bb21be88752420e834a6b6be37e9b525fTripp filter = match[2];
f69d245bb21be88752420e834a6b6be37e9b525fTripp // extract correct path for mixed combo urls
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp // http://yuilibrary.com/projects/yui3/ticket/2528423
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp match = src.match(comboPattern);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if (match && match[3]) {
f69d245bb21be88752420e834a6b6be37e9b525fTripp b = match[1] + match[3];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp break;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // use CDN default
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return b || Env.cdn;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp };
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Env = Y.Env;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp Env._loaded[VERSION] = {};
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
f69d245bb21be88752420e834a6b6be37e9b525fTripp if (G_ENV && Y !== YUI) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Env._yidx = ++G_ENV._yidx;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Env._guidp = ('yui_' + VERSION + '_' +
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Env._yidx + '_' + time).replace(/\./g, '_');
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y.id = Y.stamp(Y);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp instances[Y.id] = Y;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y.constructor = YUI;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // configuration defaults
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y.config = Y.config || {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp win: win,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp doc: doc,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp debug: true,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp useBrowserConsole: true,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp throwFail: true,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp bootstrap: true,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp fetchCSS: true
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp };
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y.config.base = YUI.config.base ||
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y.Env.getBase(/^(.*)yui\/yui([\.\-].*)js(\?.*)?$/,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /^(.*\?)(.*\&)(.*)yui\/yui[\.\-].*js(\?.*)?$/);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y.config.loaderPath = YUI.config.loaderPath ||
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp 'loader/loader' + (filter || '-min.') + 'js';
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Finishes the instance setup. Attaches whatever modules were defined
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * when the yui modules was registered.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method _setup
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @private
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _setup: function(o) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var Y = this,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp core = [],
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp mods = YUI.Env.mods,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp extras = Y.config.core || ['get', 'intl-base', 'loader', 'yui-log', 'yui-later', 'yui-throttle'];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp for (i=0; i<extras.length; i++) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (mods[extras[i]]) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp core.push(extras[i]);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y.use('yui-base');
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y.use.apply(Y, core);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Executes a method on a YUI instance with
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * the specified id if the specified method is whitelisted.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method applyTo
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param id {string} the YUI instance id
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param method {string} the name of the method to exectute.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Ex: 'Object.keys'
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param args {Array} the arguments to apply to the method
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @return {object} the return value from the applied method or null
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp applyTo: function(id, method, args) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (!(method in APPLY_TO_AUTH)) {
f69d245bb21be88752420e834a6b6be37e9b525fTripp this.log(method + ': applyTo not allowed', 'warn', 'yui');
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return null;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var instance = instances[id], nest, m, i;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (instance) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp nest = method.split('.');
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp m = instance;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp for (i=0; i<nest.length; i=i+1) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp m = m[nest[i]];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (!m) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.log('applyTo not found: ' + method, 'warn', 'yui');
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return m.apply(instance, args);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return null;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Register a module
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method add
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param name {string} module name
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param fn {Function} entry point into the module that
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * is used to bind module to the YUI instance
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param version {string} version string
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param details optional config data:
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * requires - features that should be present before loading
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * optional - optional features that should be present if load optional defined
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * use - features that should be attached automatically
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * skinnable -
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * rollup
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * omit - features that should not be loaded if this module is present
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @return {YUI} the YUI instance
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp add: function(name, fn, version, details) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // this.log('Adding a new component ' + name);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp // @todo expand this to include version mapping
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // @todo may want to restore the build property
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // @todo fire moduleAvailable event
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp details = details || {};
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp YUI.Env.mods[name] = {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp name: name,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp fn: fn,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp version: version,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp details: details
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp };
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return this;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp },
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp _attach: function(r, fromLoader) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp var i, name, mod, details, req, use,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp mods = YUI.Env.mods,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp done = this.Env._attached,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp len = r.length;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp for (i=0; i<len; i++) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp name = r[i];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp mod = mods[name];
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if (!done[name] && mod) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp done[name] = true;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp details = mod.details;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp req = details.requires;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp use = details.use;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if (req) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this._attach(this.Array(req));
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp // this.log('attaching ' + name, 'info', 'yui');
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if (mod.fn) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp mod.fn(this, name);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if (use) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this._attach(this.Array(use));
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp },
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp /**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Bind a module to a YUI instance
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param modules* {string} 1-n modules to bind (uses arguments array)
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param *callback {function} callback function executed when
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * the instance has the required functionality. If included, it
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * must be the last parameter.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @TODO
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Implement versioning? loader can load different versions?
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Should sub-modules/plugins be normal modules, or do
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * we add syntax for specifying these?
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * YUI().use('dragdrop')
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * YUI().use('dragdrop:2.4.0'); // specific version
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * YUI().use('dragdrop:2.4.0-'); // at least this version
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * YUI().use('dragdrop:2.4.0-2.9999.9999'); // version range
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * YUI().use('*'); // use all available modules
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * YUI().use('lang+dump+substitute'); // use lang and some plugins
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * YUI().use('lang+*'); // use lang and all known plugins
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @return {YUI} the YUI instance
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp use: function() {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (!this.Array) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._attach(['yui-base']);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var len, loader, handleBoot,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y = this,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp G_ENV = YUI.Env,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp args = SLICE.call(arguments, 0),
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp mods = G_ENV.mods,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp Env = Y.Env,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp used = Env._used,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp queue = G_ENV._loaderQueue,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp firstArg = args[0],
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp callback = args[args.length - 1],
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp YArray = Y.Array,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp config = Y.config,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp boot = config.bootstrap,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp missing = [],
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp r = [],
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp fetchCSS = config.fetchCSS,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp process = function(name) {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp // only attach a module once
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if (used[name]) {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp return;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp var m = mods[name], req, use;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if (m) {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp used[name] = true;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp req = m.details.requires;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp use = m.details.use;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp } else {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp // CSS files don't register themselves, see if it has been loaded
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if (!G_ENV._loaded[VERSION][name]) {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp missing.push(name);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp } else {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp used[name] = true; // probably css
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if (req) { // make sure requirements are attached
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp YArray.each(YArray(req), process);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if (use) { // make sure we grab the submodule dependencies too
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp YArray.each(YArray(use), process);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp // add this module to full list of things to attach
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp r.push(name);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp },
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp handleLoader = function(fromLoader) {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp var response = fromLoader || {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp success: true,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp msg: 'not dynamic'
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp },
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp newData, redo, origMissing,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp data = response.data;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp Y._loading = false;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if (data) {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp origMissing = missing.concat();
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp missing = [];
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp Y.Array.each(data, process);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp redo = missing.length;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if (redo) {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if (missing.sort().join() == origMissing.sort().join()) {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp redo = false;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if (redo && data) {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp newData = data.concat();
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp newData.push(function() {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp Y._attach(data);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if (callback) {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp callback(Y, response);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp });
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp Y._loading = false;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp Y.use.apply(Y, newData);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp } else {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if (data) {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp Y._attach(data);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if (callback) {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp callback(Y, response);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if (Y._useQueue && Y._useQueue.size() && !Y._loading) {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp Y.use.apply(Y, Y._useQueue.next());
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp };
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if (Y._loading) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp Y._useQueue = Y._useQueue || new Y.Queue();
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y._useQueue.add(args);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return Y;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // The last argument supplied to use can be a load complete callback
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (typeof callback === 'function') {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp args.pop();
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp } else {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp callback = null;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // YUI().use('*'); // bind everything available
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (firstArg === "*") {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp args = Y.Object.keys(mods);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // use loader to expand dependencies and sort the
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp // requirements if it is available.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if (Y.Loader) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp loader = new Y.Loader(config);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp loader.require(args);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp loader.ignoreRegistered = true;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp // loader.allowRollup = false;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp loader.calculate(null, (fetchCSS) ? null : 'js');
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp args = loader.sorted;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp // process each requirement and any additional requirements
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp // the module metadata specifies
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp YArray.each(args, process);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp len = missing.length;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if (len) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp missing = Y.Object.keys(YArray.hash(missing));
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp len = missing.length;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // dynamic load
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (boot && len && Y.Loader) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y._loading = true;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp loader = new Y.Loader(config);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp loader.onEnd = handleLoader;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp loader.context = Y;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp loader.attaching = args;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp loader.data = args;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp loader.require((fetchCSS) ? missing : args);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp loader.insert(null, (fetchCSS) ? null : 'js');
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp } else if (boot && len && Y.Get && !Env.bootstrapped) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y._loading = true;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp args = YArray(arguments, 0, true);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp handleBoot = function() {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y._loading = false;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp queue.running = false;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Env.bootstrapped = true;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y._attach(['loader']);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y.use.apply(Y, args);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp };
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (G_ENV._bootstrapping) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp queue.add(handleBoot);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp } else {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp G_ENV._bootstrapping = true;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp Y.Get.script(config.base + config.loaderPath, {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp onEnd: handleBoot
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp });
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp } else {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (len) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp Y.message('Requirement NOT loaded: ' + missing, 'warn', 'yui');
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp Y._attach(r);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp handleLoader();
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp return Y;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Returns the namespace specified and creates it if it doesn't exist
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * <pre>
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * YUI.namespace("property.package");
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * YUI.namespace("YAHOO.property.package");
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * </pre>
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Either of the above would create YUI.property, then
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * YUI.property.package (YAHOO is scrubbed out, this is
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * to remain compatible with YUI2)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Be careful when naming packages. Reserved words may work in some browsers
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * and not others. For instance, the following will fail in Safari:
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * <pre>
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * YUI.namespace("really.long.nested.namespace");
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * </pre>
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * This fails because "long" is a future reserved word in ECMAScript
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method namespace
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {string*} arguments 1-n namespaces to create
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @return {object} A reference to the last namespace object created
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
1941f59d88c42b5449ef1353ec4336805bff6ac9Tripp namespace: function() {
1941f59d88c42b5449ef1353ec4336805bff6ac9Tripp var a=arguments, o=null, i, j, d;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp for (i=0; i<a.length; i=i+1) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp d = ("" + a[i]).split(".");
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp o = this;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp for (j=(d[0] == "YAHOO") ? 1 : 0; j<d.length; j=j+1) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp o[d[j]] = o[d[j]] || {};
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp o = o[d[j]];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return o;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // this is replaced if the log module is included
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp log: NOOP,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp message: NOOP,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Report an error. The reporting mechanism is controled by
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * the 'throwFail' configuration attribute. If throwFail is
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * not specified, the message is written to the Logger, otherwise
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * a JS error is thrown
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method error
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param msg {string} the error message
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param e {Error} Optional JS error that was caught. If supplied
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * and throwFail is specified, this error will be re-thrown.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @return {YUI} this YUI instance
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp error: function(msg, e) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (this.config.throwFail) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp throw (e || new Error(msg));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp } else {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.message(msg, "error"); // don't scrub this one
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
16178708ecddc36b034aea99e129ceffa009ac05Tripp
16178708ecddc36b034aea99e129ceffa009ac05Tripp return this;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp },
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp /**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Generate an id that is unique among all YUI instances
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method guid
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param pre {string} optional guid prefix
16178708ecddc36b034aea99e129ceffa009ac05Tripp * @return {string} the guid
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp guid: function(pre) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp var id = this.Env._guidp + (++this.Env._uidx);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp return (pre) ? (pre + id) : id;
16178708ecddc36b034aea99e129ceffa009ac05Tripp },
16178708ecddc36b034aea99e129ceffa009ac05Tripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp /**
16178708ecddc36b034aea99e129ceffa009ac05Tripp * Returns a guid associated with an object. If the object
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * does not have one, a new one is created unless readOnly
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * is specified.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method stamp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param o The object to stamp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param readOnly {boolean} if true, a valid guid will only
c8497af565e3869417da55c16f0afc9fafb7d79aTripp * be returned if the object has one assigned to it.
c8497af565e3869417da55c16f0afc9fafb7d79aTripp * @return {string} The object's guid or null
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp stamp: function(o, readOnly) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (!o) {
c8497af565e3869417da55c16f0afc9fafb7d79aTripp return o;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
c8497af565e3869417da55c16f0afc9fafb7d79aTripp var uid = (typeof o === 'string') ? o : o._yuid;
c8497af565e3869417da55c16f0afc9fafb7d79aTripp if (!uid) {
91d40744967aabc3e1c105820a22e279fdecc689Tripp uid = this.guid();
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (!readOnly) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp try {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp o._yuid = uid;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp } catch(e) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp uid = null;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
16178708ecddc36b034aea99e129ceffa009ac05Tripp return uid;
16178708ecddc36b034aea99e129ceffa009ac05Tripp }
16178708ecddc36b034aea99e129ceffa009ac05Tripp};
16178708ecddc36b034aea99e129ceffa009ac05Tripp
16178708ecddc36b034aea99e129ceffa009ac05Tripp// Give the YUI global the same properties as an instance.
16178708ecddc36b034aea99e129ceffa009ac05Tripp// This makes it so that the YUI global can be used like the YAHOO
16178708ecddc36b034aea99e129ceffa009ac05Tripp// global was used prior to 3.x. More importantly, the YUI global
16178708ecddc36b034aea99e129ceffa009ac05Tripp// provides global metadata, so env needs to be configured.
16178708ecddc36b034aea99e129ceffa009ac05Tripp// @TODO review
16178708ecddc36b034aea99e129ceffa009ac05Tripp
16178708ecddc36b034aea99e129ceffa009ac05Tripp p = YUI.prototype;
16178708ecddc36b034aea99e129ceffa009ac05Tripp
16178708ecddc36b034aea99e129ceffa009ac05Tripp // inheritance utilities are not available yet
16178708ecddc36b034aea99e129ceffa009ac05Tripp for (i in p) {
16178708ecddc36b034aea99e129ceffa009ac05Tripp if (1) { // intenionally ignoring hasOwnProperty check
16178708ecddc36b034aea99e129ceffa009ac05Tripp YUI[i] = p[i];
16178708ecddc36b034aea99e129ceffa009ac05Tripp }
16178708ecddc36b034aea99e129ceffa009ac05Tripp }
16178708ecddc36b034aea99e129ceffa009ac05Tripp
16178708ecddc36b034aea99e129ceffa009ac05Tripp // set up the environment
16178708ecddc36b034aea99e129ceffa009ac05Tripp YUI._init();
16178708ecddc36b034aea99e129ceffa009ac05Tripp
16178708ecddc36b034aea99e129ceffa009ac05Tripp // setTimeout(function() { YUI._attach(['yui-base']); }, 0);
16178708ecddc36b034aea99e129ceffa009ac05Tripp
16178708ecddc36b034aea99e129ceffa009ac05Tripp if (hasWin) {
16178708ecddc36b034aea99e129ceffa009ac05Tripp // add a window load event at load time so we can capture
16178708ecddc36b034aea99e129ceffa009ac05Tripp // the case where it fires before dynamic loading is
16178708ecddc36b034aea99e129ceffa009ac05Tripp // complete.
16178708ecddc36b034aea99e129ceffa009ac05Tripp add(window, 'load', handleLoad);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp } else {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp handleLoad();
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp YUI.Env.add = add;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp YUI.Env.remove = remove;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /*global exports*/
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // Support the CommonJS method for exporting our single global
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if (typeof exports == 'object') {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp exports.YUI = YUI;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp})();
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp/**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * The config object contains all of the configuration options for
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * the YUI instance. This object is supplied by the implementer
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * when instantiating a YUI instance. Some properties have default
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * values if they are not supplied by the implementer.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @class config
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @static
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp/**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Allows the YUI seed file to fetch the loader component and library
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * metadata to dynamically load additional dependencies.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @property bootstrap
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @type boolean
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @default true
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
/**
* Log to the browser console if debug is on and the browser has a
* supported console.
*
* @property useBrowserConsole
* @type boolean
* @default true
*/
/**
* A hash of log sources that should be logged. If specified, only log messages from these sources will be logged.
*
* @property logInclude
* @type object
*/
/**
* A hash of log sources that should be not be logged. If specified, all sources are logged if not on this list.
*
* @property logExclude
* @type object
*/
/**
* Set to true if the yui seed file was dynamically loaded in
* order to bootstrap components relying on the window load event
* and the 'domready' custom event.
*
* @property injected
* @type boolean
* @default false
*/
/**
* If throwFail is set, Y.fail will generate or re-throw a JS Error. Otherwise the failure is logged.
*
* @property throwFail
* @type boolean
* @default true
*/
/**
* The window/frame that this instance should operate in.
*
* @property win
* @type Window
* @default the window hosting YUI
*/
/**
* The document associated with the 'win' configuration.
*
* @property doc
* @type Document
* @default the document hosting YUI
*/
/**
* A list of modules that defines the YUI core (overrides the default).
*
* @property core
* @type string[]
*/
/**
* A list of languages in order of preference. This list is matched against
* the list of available languages in modules that the YUI instance uses to
* determine the best possible localization of language sensitive modules.
* Languages are represented using BCP 47 language tags, such as "en-GB" for
* English as used in the United Kingdom, or "zh-Hans-CN" for simplified
* Chinese as used in China. The list can be provided as a comma-separated
* list or as an array.
*
* @property lang
* @type string|string[]
*/
/**
* The default date format
* @property dateFormat
* @type string
* @deprecated use configuration in DataType.Date.format() instead
*/
/**
* The default locale
* @property locale
* @type string
* @deprecated use config.lang instead
*/
/**
* The default interval when polling in milliseconds.
* @property pollInterval
* @type int
* @default 20
*/
/**
* The number of dynamic nodes to insert by default before
* automatically removing them. This applies to script nodes
* because remove the node will not make the evaluated script
* unavailable. Dynamic CSS is not auto purged, because removing
* a linked style sheet will also remove the style definitions.
* @property purgethreshold
* @type int
* @default 20
*/
/**
* The default interval when polling in milliseconds.
* @property windowResizeDelay
* @type int
* @default 40
*/
/**
* Base directory for dynamic loading
* @property base
* @type string
*/
/**
* The secure base dir (not implemented)
* For dynamic loading.
* @property secureBase
* @type string
*/
/**
* The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?
* For dynamic loading.
* @property comboBase
* @type string
*/
/**
* The root path to prepend to module path for the combo service. Ex: 3.0.0b1/build/
* For dynamic loading.
* @property root
* @type string
*/
/**
* A filter to apply to result urls. This filter will modify the default
* path for all modules. The default path for the YUI library is the
* minified version of the files (e.g., event-min.js). The filter property
* can be a predefined filter or a custom filter. The valid predefined
* filters are:
* <dl>
* <dt>DEBUG</dt>
* <dd>Selects the debug versions of the library (e.g., event-debug.js).
* This option will automatically include the Logger widget</dd>
* <dt>RAW</dt>
* <dd>Selects the non-minified version of the library (e.g., event.js).</dd>
* </dl>
* You can also define a custom filter, which must be an object literal
* containing a search expression and a replace string:
* <pre>
* myFilter: &#123;
* 'searchExp': "-min\\.js",
* 'replaceStr': "-debug.js"
* &#125;
* </pre>
*
* For dynamic loading.
*
* @property filter
* @type string|object
*/
/**
* Hash of per-component filter specification. If specified for a given component,
* this overrides the filter config
*
* For dynamic loading.
*
* @property filters
* @type object
*/
/**
* Use the YUI combo service to reduce the number of http connections
* required to load your dependencies. Turning this off will
* disable combo handling for YUI and all module groups configured
* with a combo service.
*
* For dynamic loading.
*
* @property combine
* @type boolean
* @default true if 'base' is not supplied, false if it is.
*/
/**
* A list of modules that should never be dynamically loaded
*
* @property ignore
* @type string[]
*/
/**
* A list of modules that should always be loaded when required, even if already
* present on the page.
*
* @property force
* @type string[]
*/
/**
* Node or id for a node that should be used as the insertion point for new nodes
* For dynamic loading.
*
* @property insertBefore
* @type string
*/
/**
* charset for dynamic nodes
* @property charset
* @type string
* @deprecated use jsAttributes cssAttributes
*/
/**
* Object literal containing attributes to add to dynamically loaded script nodes.
* @property jsAttributes
* @type string
*/
/**
* Object literal containing attributes to add to dynamically loaded link nodes.
* @property cssAttributes
* @type string
*/
/**
* Number of milliseconds before a timeout occurs when dynamically
* loading nodes. If not set, there is no timeout.
* @property timeout
* @type int
*/
/**
* Callback for the 'CSSComplete' event. When dynamically loading YUI
* components with CSS, this property fires when the CSS is finished
* loading but script loading is still ongoing. This provides an
* opportunity to enhance the presentation of a loading page a little
* bit before the entire loading process is done.
*
* @property onCSS
* @type function
*/
/**
* A hash of module definitions to add to the list of YUI components.
* These components can then be dynamically loaded side by side with
* YUI via the use() method. This is a hash, the key is the module
* name, and the value is an object literal specifying the metdata
* for the module. * See Loader.addModule for the supported module
* metadata fields. Also @see groups, which provides a way to
* configure the base and combo spec for a
* <code>
* modules: {
* &nbsp; mymod1: {
* &nbsp; requires: ['node'],
* &nbsp; fullpath: 'http://myserver.mydomain.com/mymod1/mymod1.js'
* &nbsp; },
* &nbsp; mymod2: {
* &nbsp; requires: ['mymod1'],
* &nbsp; fullpath: 'http://myserver.mydomain.com/mymod2/mymod2.js'
* &nbsp; }
* }
* </code>
*
* @property modules
* @type object
*/
/**
* A hash of module group definitions. It for each group you
* can specify a list of modules and the base path and
* combo spec to use when dynamically loading the modules. @see
* @see modules for the details about the modules part of the
* group definition.
* <code>
* &nbsp; groups: {
* &nbsp; yui2: {
* &nbsp; // specify whether or not this group has a combo service
* &nbsp; combine: true,
* &nbsp;
* &nbsp; // the base path for non-combo paths
* &nbsp; base: 'http://yui.yahooapis.com/2.8.0r4/build/',
* &nbsp;
* &nbsp; // the path to the combo service
* &nbsp; comboBase: 'http://yui.yahooapis.com/combo?',
* &nbsp;
* &nbsp; // a fragment to prepend to the path attribute when
* &nbsp; // when building combo urls
* &nbsp; root: '2.8.0r4/build/',
* &nbsp;
* &nbsp; // the module definitions
* &nbsp; modules: {
* &nbsp; yui2_yde: {
* &nbsp; path: "yahoo-dom-event/yahoo-dom-event.js"
* &nbsp; },
* &nbsp; yui2_anim: {
* &nbsp; path: "animation/animation.js",
* &nbsp; requires: ['yui2_yde']
* &nbsp; }
* &nbsp; }
* &nbsp; }
* &nbsp; }
* </code>
* @property modules
* @type object
*/
/**
* The loader 'path' attribute to the loader itself. This is combined
* with the 'base' attribute to dynamically load the loader component
* when boostrapping with the get utility alone.
*
* @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 create gallery module urls
* @property gallery
* @type string
*/
/**
* Alternative console log function for use in environments without
* a supported native console
* @property logFn
* @type Function
*/
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
*/
(function() {
/**
* 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',
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 = '';
/**
* 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. You can use @see Array.test if you
* want to
* @method isArray
* @static
* @param o The object to test
* @return {boolean} true if o is an 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;
};
/**
* Determines whether or not the provided item is a function
* Note: Internet Explorer thinks certain functions are objects:
*
* var obj = document.createElement("object");
* Y.Lang.isFunction(obj.getAttribute) // reports false in IE
*
* var input = document.createElement("input"); // append to body
* Y.Lang.isFunction(input.focus) // reports false in IE
*
* You will have to implement additional tests if these functions
* matter to you.
*
* @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
* @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 = function(s){
try {
return s.replace(TRIMREGEX, EMPTYSTRING);
} catch(e) {
return 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);
}
};
/**
* Returns a string representing the type of the item passed in.
* Known issues:
* typeof HTMLElementCollection returns function in Safari, but
* Y.type() reports object, which could be a good thing --
* but it actually caused the logic in Y.Lang.isObject to fail.
* @method type
* @param o the item to test
* @return {string} the detected type
*/
L.type = function (o) {
return TYPES[typeof o] || TYPES[TOSTRING.call(o)] || (o ? OBJECT : NULL);
};
})();
/**
* 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
*/
(function() {
var L = Y.Lang, 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 o the item to arrayify
* @param i {int} if an array or array-like, this is the start index
* @param arraylike {boolean} 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).
*
* @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 (L.isObject(o)) {
if (L.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 a {Array} the array to iterate
* @param f {Function} the function to execute on each item. The
* function receives three arguments: the value, the index, the full array.
* @param 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 k {Array} keyset
* @param v {Array} 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) {
if (k[i]) {
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 a {Array} the array to search
* @param 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
*/
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 a {Array} the array to iterate
* @param f {Function} the function to execute on each item. The function
* receives three arguments: the value, the index, the full array.
* @param 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
* @param item* {MIXED} 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 item* {MIXED} 0..n items
*/
add: function () {
Y.Array.each(Y.Array(arguments,0,true),function (fn) {
this._q.push(fn);
},this);
return this;
},
/**
* Returns the current number of queued items
*
* @method size
* @return {Number}
*/
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
*/
(function() {
var L = Y.Lang,
DELIMITER = '__',
// FROZEN = {
// 'prototype': 1,
// '_yuid': 1
// },
/*
* 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 fn = s.toString;
if (L.isFunction(fn) && fn != Object.prototype.toString) {
r.toString = 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} merge objects instead of overwriting/ignoring
* 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 arr = merge && L.isArray(r), i, l, p;
if (wl && wl.length) {
for (i = 0, l = wl.length; i < l; ++i) {
p = wl[i];
// if (p in s) {
if (s.hasOwnProperty(p)) {
if (merge && L.isObject(r[p], true)) {
Y.mix(r[p], s[p]);
} else if (!arr && (ov || !(p in r))) {
r[p] = s[p];
} else if (arr) {
r.push(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 && L.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 (!arr && (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.
* @function 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, arg2) {
var k = (arg2) ? Array.prototype.join.call(arguments, 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
*/
(function() {
/**
* Adds the following Object utilities to the YUI instance
* @class Object
*/
/**
* Y.Object(o) returns a new object based upon the supplied object.
* @TODO Use native Object.create() when available
* @method ()
* @static
* @param o the supplier object
* @return {Object} the new object
*/
Y.Object = function(o) {
var F = function() {};
F.prototype = o;
return new F();
};
var O = Y.Object,
owns = function(o, k) {
return o && o.hasOwnProperty && o.hasOwnProperty(k);
},
UNDEFINED = undefined,
/**
* 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;
};
/**
* Returns an array containing the object's keys
* @TODO use native Object.keys() if available
* @method keys
* @static
* @param o an object
* @return {string[]} the keys
*/
O.keys = function(o) {
return _extract(o);
};
/**
* Returns an array containing the object's values
* @TODO use native Object.values() if available
* @method values
* @static
* @param o an object
* @return {Array} the values
*/
O.values = function(o) {
return _extract(o, 1);
};
/**
* Returns the size of an object
* @TODO use native Object.size() if available
* @method size
* @static
* @param o an object
* @return {int} the size
*/
O.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 paramters (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
* @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 UNDEFINED;
}
var i,
p = Y.Array(path),
l = p.length;
for (i=0; o !== UNDEFINED && 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
* @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 !== UNDEFINED && i < leafIdx; i++) {
ref = ref[p[i]];
}
if (ref !== UNDEFINED) {
ref[p[i]] = val;
} else {
return UNDEFINED;
}
}
return o;
};
})();
/**
* 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. 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 (e.g., Gecko 1.8.0.9
* reports 1.8).
* @class UA
* @static
*/
Y.UA = function() {
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_(web_browser)#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
* @static
*/
mobile: null,
/**
* Adobe AIR version number or 0. Only populated if webkit is detected.
* Example: 1.0
* @property air
* @type float
*/
air: 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
* @static
*/
os: null
},
ua = 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
} else {
m=ua.match(/NokiaN[^\/]*|Android \d\.\d|webOS\/\d\.\d/);
if (m) {
o.mobile = m[0]; // Nokia N-series, Android, webOS, ex: NokiaN95
}
}
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]);
}
}
}
}
}
}
return o;
}();
}, '@VERSION@' );