yui.js revision 82c2b86968ca03bd7f27803809a28f05799ff06f
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp(function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp add = function () {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return function(){};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp remove = function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return function(){};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp globalListener = function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp// @TODO: this needs to be created at build time from module metadata
a89ad754cce3cfc8aee71760e10217b54020360dTripp// reduce to one or the other
a89ad754cce3cfc8aee71760e10217b54020360dTripp * The YUI global namespace object. If YUI is already defined, the
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * existing YUI object will not be overwritten so that defined
a89ad754cce3cfc8aee71760e10217b54020360dTripp * namespaces are preserved.
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * @class YUI
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @constructor
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @uses EventTarget
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param o Optional configuration object. This object is stored
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * in YUI.config. See config for the list of supported properties.
a89ad754cce3cfc8aee71760e10217b54020360dTripp /*global YUI*/
a89ad754cce3cfc8aee71760e10217b54020360dTripp // Make a function, disallow direct instantiation
a89ad754cce3cfc8aee71760e10217b54020360dTripp YUI = function(o) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var Y = this;
a89ad754cce3cfc8aee71760e10217b54020360dTripp // Allow instantiation without the new operator
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (!(Y instanceof YUI)) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp return new YUI(o);
a89ad754cce3cfc8aee71760e10217b54020360dTripp // set up the core environment
a89ad754cce3cfc8aee71760e10217b54020360dTripp // bind the specified additional modules for this instance
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp// The prototype contains the functions that are required to allow the external
a89ad754cce3cfc8aee71760e10217b54020360dTripp// modules to be registered and for the instance to be initialized.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Initialize this YUI instance
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param o config options
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _init: function(o) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o = o || {};
a89ad754cce3cfc8aee71760e10217b54020360dTripp // find targeted window/frame
a89ad754cce3cfc8aee71760e10217b54020360dTripp // @TODO create facades
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var v = '@VERSION@', Y = this;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp v = 'test';
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // @todo expand the new module metadata
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o.useBrowserConsole = ('useBrowserConsole' in o) ? o.useBrowserConsole : true;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o.throwFail = ('throwFail' in o) ? o.throwFail : true;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // get from querystring
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp match = nodes[i].src.match(/^(.*)yui\/yui[\.\-].*js(\?.*)?$/);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // use CDN default
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o.loaderPath = o.loaderPath || 'loader/loader-min.js';
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // add a reference to o for anything that needs it
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // before _setup is called.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.Env._guidp = ('yui_' + v + '-' + Y.Env._yidx + '-' + _startTime).replace(/\./g, '_');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // this.log(this.id + ') init ');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Finishes the instance setup. Attaches whatever modules were defined
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * when the yui modules was registered.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method _setup
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _setup: function(o) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // @TODO eval the need to copy the config
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Executes a method on a YUI instance with
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * the specified id if the specified method is whitelisted.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method applyTo
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param id {string} the YUI instance id
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param method {string} the name of the method to exectute.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Ex: 'Object.keys'
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param args {Array} the arguments to apply to the method
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return {object} the return value from the applied method or null
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return null;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return null;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Register a module
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method add
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param name {string} module name
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param fn {Function} entry point into the module that
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * is used to bind module to the YUI instance
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param version {string} version string
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param details optional config data:
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * requires - features that should be present before loading
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * optional - optional features that should be present if load optional defined
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * use - features that should be attached automatically
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * skinnable -
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * omit - features that should not be loaded if this module is present
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return {YUI} the YUI instance
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // this.log('Adding a new component ' + name);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // @todo expand this to include version mapping
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // @todo may want to restore the build property
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // @todo fire moduleAvailable event
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // if (this.Lang.isFunction(fn)) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // } else {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // var c = Y.config;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // c.modules = c.modules || {};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // c.modules[name] = c.modules[name] || fn;
a89ad754cce3cfc8aee71760e10217b54020360dTripp return this; // chain support
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // this.log('attaching ' + name, 'info', 'yui');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Bind a module to a YUI instance
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param modules* {string} 1-n modules to bind (uses arguments array)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param *callback {function} callback function executed when
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * the instance has the required functionality. If included, it
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * must be the last parameter.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Implement versioning? loader can load different versions?
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Should sub-modules/plugins be normal modules, or do
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * we add syntax for specifying these?
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * YUI().use('dragdrop')
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * YUI().use('dragdrop:2.4.0'); // specific version
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * YUI().use('dragdrop:2.4.0-'); // at least this version
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * YUI().use('dragdrop:2.4.0-2.9999.9999'); // version range
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * YUI().use('*'); // use all available modules
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * YUI().use('lang+dump+substitute'); // use lang and some plugins
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * YUI().use('lang+*'); // use lang and all known plugins
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return {YUI} the YUI instance
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp use: function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var Y = this,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp k, i, l, missing = [],
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp f = function(name) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // only attach a module once
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // Y.log(name + ' already used', 'info', 'yui');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // Y.log('USING ' + name, 'info', 'yui');
a89ad754cce3cfc8aee71760e10217b54020360dTripp // CSS files don't register themselves, see if it has been loaded
a89ad754cce3cfc8aee71760e10217b54020360dTripp // probably css
a89ad754cce3cfc8aee71760e10217b54020360dTripp // Y.log('module not found BUT HAS BEEN LOADED: ' + name, 'info', 'yui');
a89ad754cce3cfc8aee71760e10217b54020360dTripp // make sure requirements are attached
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // Y.log('using module\'s requirements: ' + name, 'info', 'yui');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // add this module to full list of things to attach
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // Y.log('adding to requires list: ' + name);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // Y.log('Use complete');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // process queued use requests as long until done
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // or dynamic load happens again.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._loading = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp while (this._useQueue && this._useQueue.size() && !this._loading) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // Y.log(Y.id + ': use called: ' + a + ' :: ' + callback);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // The last argument supplied to use can be a load complete callback
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // YUI().use('*'); // bind everything available
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for (k in mods) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // Y.log('Use *: ' + a);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // Y.log('loader before: ' + a.join(','));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // use loader to expand dependencies and sort the
a89ad754cce3cfc8aee71760e10217b54020360dTripp // requirements if it is available.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // Y.log('loader after: ' + a.join(','));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // process each requirement and any additional requirements
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // the module metadata specifies
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // Y.log('all reqs: ' + r + ' --- missing: ' + missing + ', l: ' + l + ', ' + r[0]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // dynamic load
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.log('Attempting to dynamically load the missing modules ' + missing, 'info', 'yui');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._loading = true;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp } else if (Y.Get && missing.length && !Y.Env.bootstrapped) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.log('fetching loader: ' + Y.config.base + Y.config.loaderPath);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // a.unshift('loader');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp onEnd: function() {
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp return Y; // chain support var yui = YUI().use('dragdrop');
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * Returns the namespace specified and creates it if it doesn't exist
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * YUI.namespace("property.package");
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * YUI.namespace("YAHOO.property.package");
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * Either of the above would create YUI.property, then
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * YUI.property.package (YAHOO is scrubbed out, this is
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * to remain compatible with YUI2)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Be careful when naming packages. Reserved words may work in some browsers
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * and not others. For instance, the following will fail in Safari:
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * YUI.namespace("really.long.nested.namespace");
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * This fails because "long" is a future reserved word in ECMAScript
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp * @method namespace
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {string*} arguments 1-n namespaces to create
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return {object} A reference to the last namespace object created
9eaaa502227248d304ac9170902697d02158c1d9Tripp namespace: function() {
9eaaa502227248d304ac9170902697d02158c1d9Tripp var a=arguments, o=null, i, j, d;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for (j=(d[0] == "YAHOO") ? 1 : 0; j<d.length; j=j+1) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp o[d[j]] = o[d[j]] || {};
4ef2f7e4cb7c7d255be077c47d542199f7bf8607Tripp o = o[d[j]];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // this is replaced if the log module is included
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp log: function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Report an error. The reporting mechanism is controled by
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * the 'throwFail' configuration attribute. If throwFail is
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * not specified, the message is written to the Logger, otherwise
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * a JS error is thrown
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method error
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param msg {string} the error message
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param e {Error} Optional JS error that was caught. If supplied
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * and throwFail is specified, this error will be re-thrown.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return {YUI} this YUI instance
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Generate an id that is unique among all YUI instances
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method guid
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param pre {string} optional guid prefix
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return {string} the guid
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Returns a guid associated with an object. If the object
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * does not have one, a new one is created unless readOnly
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * is specified.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method stamp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param o The object to stamp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param readOnly {boolean} if true, a valid guid will only
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * be returned if the object has one assigned to it.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return {string} The object's guid or null
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } catch(e) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp// Give the YUI global the same properties as an instance.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp// This makes it so that the YUI global can be used like the YAHOO
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp// global was used prior to 3.x. More importantly, the YUI global
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp// provides global metadata, so env needs to be configured.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp// @TODO review
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // inheritance utilities are not available yet
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp for (i in p) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // if (1) { // intenionally ignoring hasOwnProperty check
a89ad754cce3cfc8aee71760e10217b54020360dTripp YUI[i] = p[i];
* A hash of log sources that should be logged. If specified, only log messages from these sources will be logged.
* A hash of log sources that should be not be logged. If specified, all sources are logged if not on this list.
* If throwFail is set, Y.fail will generate or re-throw a JS Error. Otherwise the failure is logged.
* The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?
* minified version of the files (e.g., event-min.js). The filter property
* <dd>Selects the debug versions of the library (e.g., event-debug.js).
* <dd>Selects the non-minified version of the library (e.g., event.js).</dd>
* 'replaceStr': "-debug.js"
* @default loader/loader-min.js