yui.js revision bdd47f2da58d4a47f193431dd9c903369d65853a
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The YUI module contains the components required for building the YUI seed file.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * This includes the script loading mechanism, a simple queue, and the core utilities for the library.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @module yui
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @submodule yui-base
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass(function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass NOOP = function() {},
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // YUI.log('could not attach DOM event listener: ' + type + ' to ' + el);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass globalListener = function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// @TODO: this needs to be created at build time from module metadata
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// Stamp the documentElement (HTML) with a class of "yui-loaded" to
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// enable styles that need to key off of JS being enabled.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glassif (docEl && docElClass.indexOf(DOCUMENT_CLASS) == -1) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// reduce to one or the other
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The YUI global namespace object. If YUI is already defined, the
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * existing YUI object will not be overwritten so that defined
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * namespaces are preserved.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @class YUI
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @constructor
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @uses EventTarget
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param o* Up to five optional configuration objects. This object is stored
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * in YUI.config. See config for the list of supported properties.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /*global YUI*/
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass /*global YUI_config*/
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // @TODO Advice was to make a function, disallow direct instantiation.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass globalConfig = (typeof YUI_config !== 'undefined') && YUI_config;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Allow instantiation without the new operator
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (!(Y instanceof YUI)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // set up the core environment
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass for (i=0; i<l; i++) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // bind the specified additional modules for this instance
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// The prototype contains the functions that are required to allow the external
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// modules to be registered and for the instance to be initialized.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _config: function(o) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass o = o || {};
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass for (i in o) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass for (j in m) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else if (i == 'win') {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass c[i] = o[i].contentWindow || o[i];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass c[i] = o[i];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Initialize this YUI instance
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _init: function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // find targeted window/frame
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // @TODO create facades
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.gallery = 'gallery-2010.02.10-01'; // @TODO build time
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // @todo expand the new module metadata
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.Env._guidp = ('yui_' + v + '_' + Y.Env._yidx + '_' + _startTime).replace(/\./g, '_');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // configuration defaults
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // base: (Y === YUI) ? Y.Env.cdn : function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass base: (YUI.config && YUI.config.base) || function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // get from querystring
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass nodes = (doc && doc.getElementsByTagName('script')) || [];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass//src = "http://yui.yahooapis.com/combo?2.8.0r4/build/yuiloader-dom-event/yuiloader-dom-event.js&3.0.0/build/yui/yui-min.js";
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass//console.log('src) ' + src);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass match = src.match(/^(.*)yui\/yui([\.\-].*)js(\?.*)?$/);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // this is to set up the path to the loader. The file filter for loader should match
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // the yui include.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// extract correct path for mixed combo urls
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// http://yuilibrary.com/projects/yui3/ticket/2528423
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// http://yui.yahooapis.com/combo?2.8.0r4/build/yuiloader-dom-event/yuiloader-dom-event.js&3.0.0/build/yui/yui-min.js
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass match = src.match(/^(.*\?)(.*\&)(.*)yui\/yui[\.\-].*js(\?.*)?$/);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // use CDN default
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass loaderPath: (YUI.config && YUI.config.loaderPath) || 'loader/loader' + (filter || '-min.') + 'js'
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Finishes the instance setup. Attaches whatever modules were defined
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * when the yui modules was registered.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _setup
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass _setup: function(o) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var Y = this,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass extras = Y.config.core || ['get', 'intl-load', 'loader', 'yui-log', 'yui-later', 'yui-throttle'];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Executes a method on a YUI instance with
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * the specified id if the specified method is whitelisted.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method applyTo
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param id {string} the YUI instance id
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param method {string} the name of the method to exectute.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Ex: 'Object.keys'
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param args {Array} the arguments to apply to the method
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {object} the return value from the applied method or null
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this.log(method + ': applyTo not allowed', 'warn', 'yui');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return null;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this.log('applyTo not found: ' + method, 'warn', 'yui');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return null;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Register a module
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method add
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param name {string} module name
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param fn {Function} entry point into the module that
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * is used to bind module to the YUI instance
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param version {string} version string
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param details optional config data:
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * requires - features that should be present before loading
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * optional - optional features that should be present if load optional defined
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * use - features that should be attached automatically
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * skinnable -
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * omit - features that should not be loaded if this module is present
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {YUI} the YUI instance
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // this.log('Adding a new component ' + name);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // @todo expand this to include version mapping
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // @todo may want to restore the build property
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // @todo fire moduleAvailable event
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this; // chain support
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // console.log(name + '::' + m);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // if (!m) { }
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // console.log(req);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // console.log(use);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // this.log('attaching ' + name, 'info', 'yui');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Bind a module to a YUI instance
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param modules* {string} 1-n modules to bind (uses arguments array)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param *callback {function} callback function executed when
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * the instance has the required functionality. If included, it
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * must be the last parameter.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Implement versioning? loader can load different versions?
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Should sub-modules/plugins be normal modules, or do
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * we add syntax for specifying these?
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * YUI().use('dragdrop')
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * YUI().use('dragdrop:2.4.0'); // specific version
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * YUI().use('dragdrop:2.4.0-'); // at least this version
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * YUI().use('dragdrop:2.4.0-2.9999.9999'); // version range
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * YUI().use('*'); // use all available modules
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * YUI().use('lang+dump+substitute'); // use lang and some plugins
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * YUI().use('lang+*'); // use lang and all known plugins
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {YUI} the YUI instance
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass use: function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this._useQueue = this._useQueue || new this.Queue();
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var Y = this,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass k, i, l, missing = [],
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass f = function(name) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // only attach a module once
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // CSS files don't register themselves, see if it has been loaded
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // probably css
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // make sure requirements are attached
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // if (Y.Lang.isString(req)) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // add this module to full list of things to attach
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // The last argument supplied to use can be a load complete callback
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // process queued use requests as long until done
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // or dynamic load happens again.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (Y._useQueue && Y._useQueue.size() && !Y._loading) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // YUI().use('*'); // bind everything available
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass for (k in mods) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // use loader to expand dependencies and sort the
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // requirements if it is available.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // loader.calculate(null, (css && css == 'force') ? null : 'js');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // loader.calculate();
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // loader.calculate(null, (css) ? null : 'js');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // process each requirement and any additional requirements
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // the module metadata specifies
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // dynamic load
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // loader.require(missing);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } else if (boot && l && Y.Get && !Y.Env.bootstrapped) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass onEnd = function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass Y.message('Requirement NOT loaded: ' + missing, 'warn', 'yui');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return Y; // chain support var yui = YUI().use('dragdrop');
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Returns the namespace specified and creates it if it doesn't exist
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * YUI.namespace("property.package");
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * YUI.namespace("YAHOO.property.package");
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Either of the above would create YUI.property, then
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * YUI.property.package (YAHOO is scrubbed out, this is
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * to remain compatible with YUI2)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Be careful when naming packages. Reserved words may work in some browsers
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * and not others. For instance, the following will fail in Safari:
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * YUI.namespace("really.long.nested.namespace");
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * This fails because "long" is a future reserved word in ECMAScript
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method namespace
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param {string*} arguments 1-n namespaces to create
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {object} A reference to the last namespace object created
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass namespace: function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var a=arguments, o=null, i, j, d;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass for (j=(d[0] == "YAHOO") ? 1 : 0; j<d.length; j=j+1) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass o[d[j]] = o[d[j]] || {};
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass o = o[d[j]];
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // this is replaced if the log module is included
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Report an error. The reporting mechanism is controled by
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * the 'throwFail' configuration attribute. If throwFail is
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * not specified, the message is written to the Logger, otherwise
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * a JS error is thrown
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method error
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param msg {string} the error message
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param e {Error} Optional JS error that was caught. If supplied
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * and throwFail is specified, this error will be re-thrown.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {YUI} this YUI instance
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this.message(msg, "error"); // don't scrub this one
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return this;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Generate an id that is unique among all YUI instances
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method guid
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param pre {string} optional guid prefix
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {string} the guid
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Returns a guid associated with an object. If the object
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * does not have one, a new one is created unless readOnly
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * is specified.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method stamp
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param o The object to stamp
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param readOnly {boolean} if true, a valid guid will only
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * be returned if the object has one assigned to it.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @return {string} The object's guid or null
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass } catch(e) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// Give the YUI global the same properties as an instance.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// This makes it so that the YUI global can be used like the YAHOO
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// global was used prior to 3.x. More importantly, the YUI global
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// provides global metadata, so env needs to be configured.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass// @TODO review
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // inheritance utilities are not available yet
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass for (i in p) {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass if (1) { // intenionally ignoring hasOwnProperty check
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // set up the environment
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // add a window load event at load time so we can capture
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // the case where it fires before dynamic loading is
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // complete.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The config object contains all of the configuration options for
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * the YUI instance. This object is supplied by the implementer
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * when instantiating a YUI instance. Some properties have default
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * values if they are not supplied by the implementer.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @class config
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Allows the YUI seed file to fetch the loader component and library
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * metadata to dynamically load additional dependencies.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property bootstrap
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type boolean
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @default true
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Log to the browser console if debug is on and the browser has a
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * supported console.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property useBrowserConsole
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type boolean
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @default true
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * A hash of log sources that should be logged. If specified, only log messages from these sources will be logged.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property logInclude
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type object
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * A hash of log sources that should be not be logged. If specified, all sources are logged if not on this list.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property logExclude
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type object
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Set to true if the yui seed file was dynamically loaded in
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * order to bootstrap components relying on the window load event
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * and the 'domready' custom event.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property injected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type boolean
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @default false
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * If throwFail is set, Y.fail will generate or re-throw a JS Error. Otherwise the failure is logged.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property throwFail
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type boolean
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @default true
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The window/frame that this instance should operate in.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property win
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type Window
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @default the window hosting YUI
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The document associated with the 'win' configuration.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property doc
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type Document
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @default the document hosting YUI
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * A list of modules that defines the YUI core (overrides the default).
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property core
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type string[]
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * A list of languages in order of preference. This list is matched against
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * the list of available languages in modules that the YUI instance uses to
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * determine the best possible localization of language sensitive modules.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Languages are represented using BCP 47 language tags, such as "en-GB" for
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * English as used in the United Kingdom, or "zh-Hans-CN" for simplified
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Chinese as used in China. The list can be provided as a comma-separated
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * list or as an array.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property lang
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type string|string[]
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The default date format
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property dateFormat
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type string
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @deprecated use configuration in DataType.Date.format() instead
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The default locale
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property locale
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type string
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @deprecated use config.lang instead
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The default interval when polling in milliseconds.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property pollInterval
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @default 20
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The number of dynamic nodes to insert by default before
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * automatically removing them. This applies to script nodes
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * because remove the node will not make the evaluated script
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * unavailable. Dynamic CSS is not auto purged, because removing
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * a linked style sheet will also remove the style definitions.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property purgethreshold
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @default 20
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The default interval when polling in milliseconds.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property windowResizeDelay
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @default 40
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Base directory for dynamic loading
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property base
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type string
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The secure base dir (not implemented)
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * For dynamic loading.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property secureBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type string
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * For dynamic loading.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property comboBase
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type string
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The root path to prepend to module names for the combo service. Ex: 3.0.0b1/build/
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * For dynamic loading.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property root
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type string
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * A filter to apply to result urls. This filter will modify the default
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * path for all modules. The default path for the YUI library is the
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * minified version of the files (e.g., event-min.js). The filter property
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * can be a predefined filter or a custom filter. The valid predefined
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * filters are:
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>DEBUG</dt>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dd>Selects the debug versions of the library (e.g., event-debug.js).
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * This option will automatically include the Logger widget</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>RAW</dt>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dd>Selects the non-minified version of the library (e.g., event.js).</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * You can also define a custom filter, which must be an object literal
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * containing a search expression and a replace string:
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * myFilter: {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * 'searchExp': "-min\\.js",
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * 'replaceStr': "-debug.js"
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * For dynamic loading.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property filter
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type string|object
* fullpath: 'http://myserver.mydomain.com/mymod1/mymod1.js'
* fullpath: 'http://myserver.mydomain.com/mymod2/mymod2.js'
* @default loader/loader-min.js
* This includes the script loading mechanism, a simple queue, and the core utilities for the library.
var L = Y.Lang,
TYPES = {
TRIMREGEX = /^\s+|\s+$/g,
L.isArray = function(o) {
L.isBoolean = function(o) {
return typeof o === BOOLEAN;
L.isFunction = function(o) {
L.isDate = function(o) {
L.isNull = function(o) {
L.isNumber = function(o) {
L.isString = function(o) {
return typeof o === STRING;
L.isUndefined = function(o) {
return typeof o === UNDEFINED;
L.trim = function(s){
L.isValue = function(o) {
var t = L.type(o);
case NUMBER:
return isFinite(o);
case NULL:
case UNDEFINED:
L.type = function (o) {
* This includes the script loading mechanism, a simple queue, and the core utilities for the library.
l = o.length;
Y.Array = YArray;
if (L.isObject(o)) {
if (L.isArray(o)) {
// indexed, but no tagName (element) or alert (window), or functions without apply/call (Safari HTMLElementCollection bug)
f.call(o || Y, a[i], i, a);
function(a, val) {
function(a, val) {
if (a[i] === val) {
var l = a.length, i;
if (f.call(o, a[i], i, a)) {
* This includes the script loading mechanism, a simple queue, and the core utilities for the library.
function Queue() {
this._init();
_init: function () {
this._q = [];
next: function () {
last: function () {
add: function () {
size: function () {
* This includes the script loading mechanism, a simple queue, and the core utilities for the library.
var L = Y.Lang,
_iefix = function(r, s) {
Y.merge = function() {
Y.mix(o, a[i], true);
* @param merge {boolean} merge objects instead of overwriting/ignoring
if (mode) {
switch (mode) {
p = wl[i];
if (s.hasOwnProperty(p)) {
Y.mix(r[p], s[p]);
} else if (arr) {
r.push(s[p]);
if (s.hasOwnProperty(i)) {
} else if (arr) {
r.push(s[i]);
_iefix(r, s);
return cache[k];
* This includes the script loading mechanism, a simple queue, and the core utilities for the library.
F.prototype = o;
owns = function(o, k) {
if (owns(o, i)) {
if (count) {
out++;
return out;
O.keys = function(o) {
return _extract(o);
O.values = function(o) {
O.size = function(o) {
O.hasValue = function(o, v) {
f.call(s, o[i], i, o);
if (f.call(s, o[i], i, o)) {
return UNDEFINED;
return UNDEFINED;
* This includes the script loading mechanism, a simple queue, and the core utilities for the library.
Y.UA = function() {
var numberfy = function(s) {
* http://en.wikipedia.org/wiki/Safari_(web_browser)#Version_history
mobile: null,
secure: false,
os: null
if (ua) {
L = Y.Lang,
Y.Get = function() {
var queues={},
_get,
purging=false,
for (i in attr) {
if (attributes) {
if (attributes) {
purge: function() {
if (q && q.onEnd) {
if (q.timer) {
if (q.onFailure) {
if (q.timer) {
q.finished = true;
if (q.aborted) {
if (q.onSuccess) {
if (q.onTimeout) {
if (q.timer) {
if (q.aborted) {
if (loaded) {
if (q.varName) {
if (q.varName) {
w = q.win;
d = w.document;
if (!url) {
if (q.timeout) {
}, q.timeout);
if (q.insertBefore) {
h.appendChild(n);
_autoPurge = function() {
if (purging) {
purging = true;
for (i in queues) {
q = queues[i];
delete queues[i];
purging = false;
_autoPurge();
finished: false,
nodes: []
setTimeout(function() {
n.onreadystatechange = function() {
n.onreadystatechange = null;
n.onload = function() {
n.onerror = function(e) {
n = q.nodes;
l = n.length;
if (q.insertBefore) {
h = s.parentNode;
node = n[i];
q.nodes = [];
setTimeout(function() {
abort: function(o) {
q.aborted = true;
* ["http://yui.yahooapis.com/2.5.2/build/yahoo/yahoo-min.js",
* "http://yui.yahooapis.com/2.5.2/build/event/event-min.js"], {
* ["http://yui.yahooapis.com/2.3.1/build/menu/assets/skins/sam/menu.css",
* insertBefore: 'custom-styles' // nodes will be inserted before the specified node
var INSTANCE = Y,
if (c.debug) {
if (src) {
if (!bail) {
if (c.useBrowserConsole) {
console[f](m);
if (!_published) {
* Provides a setTimeout/setInterval wrapper
var L = Y.Lang,
m = o[fn];
m.apply(o, d);
id: r,
cancel: function() {
if (this.interval) {
clearInterval(r);
clearTimeout(r);
* globally with Y.config.throttleTime or by call. Passing a -1 will disable the throttle. Defaults to 150
/*! Based on work by Simon Willison: http://gist.github.com/292562 */