yui.js revision 1629abfab16a010ce64a057b1d3b3dfeaec3cc1f
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith(function() {
3cefe5340bfed84038e5816dbfbe7cec44f0df31Luke Smith add = function () {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return function(){};
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith remove = function() {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith return function(){};
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith globalListener = function() {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith// @TODO: this needs to be created at build time from module metadata
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith// reduce to one or the other
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * The YUI global namespace object. If YUI is already defined, the
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * existing YUI object will not be overwritten so that defined
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * namespaces are preserved.
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @class YUI
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @constructor
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @uses EventTarget
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param o* Up to five optional configuration objects. This object is stored
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * in YUI.config. See config for the list of supported properties.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith /*global YUI*/
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith // Make a function, disallow direct instantiation
abf34f3b3d65331ec654c9980a6d60d7f9701bfeLuke Smith // Allow instantiation without the new operator
abf34f3b3d65331ec654c9980a6d60d7f9701bfeLuke Smith if (!(Y instanceof YUI)) {
abf34f3b3d65331ec654c9980a6d60d7f9701bfeLuke Smith // set up the core environment
abf34f3b3d65331ec654c9980a6d60d7f9701bfeLuke Smith for (i=0; i<l; i++) {
abf34f3b3d65331ec654c9980a6d60d7f9701bfeLuke Smith // bind the specified additional modules for this instance
9327ef7ad1fee11b0e494b97cc07386565326c03Luke Smith// The prototype contains the functions that are required to allow the external
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith// modules to be registered and for the instance to be initialized.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _config: function(o) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith o = o || {};
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith for (i in o) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith for (j in m) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith } else if (i == 'win') {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith c[i] = o[i].contentWindow || o[i];
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith c[i] = o[i];
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Initialize this YUI instance
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param o config options
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _init: function(o) {
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith // find targeted window/frame
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // @TODO create facades
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith var v = '@VERSION@', Y = this;
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith // @todo expand the new module metadata
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith cdn: 'http://yui.yahooapis.com/' + v + '/build/',
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith Y.Env._guidp = ('yui_' + v + '-' + Y.Env._yidx + '-' + _startTime).replace(/\./g, '_');
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // configuration defaults
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith base: function() {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // get from querystring
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith match = nodes[i].src.match(/^(.*)yui\/yui[\.\-].*js(\?.*)?$/);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // use CDN default
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Finishes the instance setup. Attaches whatever modules were defined
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * when the yui modules was registered.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method _setup
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith _setup: function(o) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Executes a method on a YUI instance with
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * the specified id if the specified method is whitelisted.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method applyTo
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param id {string} the YUI instance id
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param method {string} the name of the method to exectute.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Ex: 'Object.keys'
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith * @param args {Array} the arguments to apply to the method
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith * @return {object} the return value from the applied method or null
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return null;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return null;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Register a module
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method add
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param name {string} module name
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param fn {Function} entry point into the module that
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * is used to bind module to the YUI instance
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param version {string} version string
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param details optional config data:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * requires - features that should be present before loading
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * optional - optional features that should be present if load optional defined
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * use - features that should be attached automatically
0cd29719d36de1f7e3d0043f5d6fafb990a7b9e0Luke Smith * skinnable -
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * omit - features that should not be loaded if this module is present
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return {YUI} the YUI instance
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // this.log('Adding a new component ' + name);
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith // @todo expand this to include version mapping
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith // @todo may want to restore the build property
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // @todo fire moduleAvailable event
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return this; // chain support
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // this.log('attaching ' + name, 'info', 'yui');
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Bind a module to a YUI instance
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param modules* {string} 1-n modules to bind (uses arguments array)
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param *callback {function} callback function executed when
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * the instance has the required functionality. If included, it
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * must be the last parameter.
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * Implement versioning? loader can load different versions?
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * Should sub-modules/plugins be normal modules, or do
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * we add syntax for specifying these?
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * YUI().use('dragdrop')
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * YUI().use('dragdrop:2.4.0'); // specific version
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * YUI().use('dragdrop:2.4.0-'); // at least this version
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * YUI().use('dragdrop:2.4.0-2.9999.9999'); // version range
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * YUI().use('*'); // use all available modules
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * YUI().use('lang+dump+substitute'); // use lang and some plugins
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * YUI().use('lang+*'); // use lang and all known plugins
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @return {YUI} the YUI instance
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith use: function() {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith this._useQueue = this._useQueue || new this.Queue();
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return this;
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith var Y = this,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith k, i, l, missing = [],
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith f = function(name) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith // only attach a module once
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // CSS files don't register themselves, see if it has been loaded
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith // probably css
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // make sure requirements are attached
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // add this module to full list of things to attach
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // process queued use requests as long until done
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // or dynamic load happens again.
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith while (Y._useQueue && Y._useQueue.size() && !Y._loading) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // The last argument supplied to use can be a load complete callback
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // YUI().use('*'); // bind everything available
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith for (k in mods) {
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith // use loader to expand dependencies and sort the
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith // requirements if it is available.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // process each requirement and any additional requirements
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // the module metadata specifies
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // dynamic load
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith } else if (Y.Get && missing.length && !Y.Env.bootstrapped) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // a.unshift('loader');
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith Y.Get.script(Y.config.base + Y.config.loaderPath, {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith onEnd: function() {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return Y; // chain support var yui = YUI().use('dragdrop');
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Returns the namespace specified and creates it if it doesn't exist
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * YUI.namespace("property.package");
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * YUI.namespace("YAHOO.property.package");
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Either of the above would create YUI.property, then
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * YUI.property.package (YAHOO is scrubbed out, this is
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * to remain compatible with YUI2)
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Be careful when naming packages. Reserved words may work in some browsers
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * and not others. For instance, the following will fail in Safari:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * YUI.namespace("really.long.nested.namespace");
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * This fails because "long" is a future reserved word in ECMAScript
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @method namespace
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @param {string*} arguments 1-n namespaces to create
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @return {object} A reference to the last namespace object created
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith namespace: function() {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith var a=arguments, o=null, i, j, d;
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith for (j=(d[0] == "YAHOO") ? 1 : 0; j<d.length; j=j+1) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith o[d[j]] = o[d[j]] || {};
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith o = o[d[j]];
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith // this is replaced if the log module is included
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith log: function() {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * Report an error. The reporting mechanism is controled by
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * the 'throwFail' configuration attribute. If throwFail is
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * not specified, the message is written to the Logger, otherwise
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * a JS error is thrown
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @method error
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith * @param msg {string} the error message
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @param e {Error} Optional JS error that was caught. If supplied
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * and throwFail is specified, this error will be re-thrown.
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @return {YUI} this YUI instance
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith this.message(msg, "error"); // don't scrub this one
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return this;
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * Generate an id that is unique among all YUI instances
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @method guid
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @param pre {string} optional guid prefix
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @return {string} the guid
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith * Returns a guid associated with an object. If the object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * does not have one, a new one is created unless readOnly
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * is specified.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method stamp
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param o The object to stamp
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param readOnly {boolean} if true, a valid guid will only
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * be returned if the object has one assigned to it.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return {string} The object's guid or null
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith } catch(e) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith// Give the YUI global the same properties as an instance.
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith// This makes it so that the YUI global can be used like the YAHOO
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith// global was used prior to 3.x. More importantly, the YUI global
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith// provides global metadata, so env needs to be configured.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith// @TODO review
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // inheritance utilities are not available yet
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith for (i in p) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // if (1) { // intenionally ignoring hasOwnProperty check
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // set up the environment
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // add a window load event at load time so we can capture
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // the case where it fires before dynamic loading is
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // complete.
5800f4bbed853824dd8797caae32f78bcc9ef09bLuke Smith * Subscribe to an event. The signature differs depending on the
5800f4bbed853824dd8797caae32f78bcc9ef09bLuke Smith * type of event you are attaching to.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method on
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param type {string|function|object} The type of the event. If
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * this is a function, this is dispatched to the aop system. If an
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * object, it is parsed for multiple subsription definitions
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param fn {Function} The callback
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param elspec {any} DOM element(s), selector string(s), and or
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Node ref(s) to attach DOM related events to (only applies to
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * DOM events).
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return the event target or a detach handle per 'chain' config
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * The config object contains all of the configuration options for
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * the YUI instance. This object is supplied by the implementer
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * when instantiating a YUI instance. Some properties have default
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * values if they are not supplied by the implementer.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @class config
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Turn debug statements on or off.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property debug
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type boolean
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default true
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * Log to the browser console if debug is on and the browser has a
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * supported console.
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @property useBrowserConsole
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @type boolean
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @default true
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * A hash of log sources that should be logged. If specified, only log messages from these sources will be logged.
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith * @property logInclude
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @type object
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * A hash of log sources that should be not be logged. If specified, all sources are logged if not on this list.
5800f4bbed853824dd8797caae32f78bcc9ef09bLuke Smith * @property logExclude
5800f4bbed853824dd8797caae32f78bcc9ef09bLuke Smith * @type object
3cefe5340bfed84038e5816dbfbe7cec44f0df31Luke Smith * Set to true if the yui seed file was dynamically loaded in
3cefe5340bfed84038e5816dbfbe7cec44f0df31Luke Smith * order to bootstrap components relying on the window load event
3cefe5340bfed84038e5816dbfbe7cec44f0df31Luke Smith * and the 'domready' custom event.
3cefe5340bfed84038e5816dbfbe7cec44f0df31Luke Smith * @property injected
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * If throwFail is set, Y.fail will generate or re-throw a JS Error. Otherwise the failure is logged.
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith * @property throwFail
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith * @type boolean
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith * @default true
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith * The window/frame that this instance should operate in.
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith * @property win
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith * @type Window
d7a66fe2de41baa56b41e8b7b254d1f6a50a5135Luke Smith * @default the window hosting YUI
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * The document associated with the 'win' configuration.
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @property doc
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type Document
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default the document hosting YUI
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith * A list of modules that defines the YUI core (overrides the default).
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith * @property core
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type string[]
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith * The default date format
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith * @property dateFormat
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith * @type string
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * The default locale
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @property locale
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type string
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * The default interval when polling in milliseconds.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property pollInterval
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default 20
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * The number of dynamic nodes to insert by default before
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * automatically removing them. This applies to script nodes
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * because remove the node will not make the evaluated script
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * unavailable. Dynamic CSS is not auto purged, because removing
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * a linked style sheet will also remove the style definitions.
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @property purgethreshold
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default 20
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * The default interval when polling in milliseconds.
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith * @property windowResizeDelay
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @default 40
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Base directory for dynamic loading
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property base
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type string
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * The secure base dir (not implemented)
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * For dynamic loading.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property secureBase
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type string
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith * For dynamic loading.
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith * @property comboBase
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith * @type string
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * The root path to prepend to module names for the combo service. Ex: 3.0.0b1/build/
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith * For dynamic loading.
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @property root
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @type string
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * A filter to apply to result urls. This filter will modify the default
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * path for all modules. The default path for the YUI library is the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * minified version of the files (e.g., event-min.js). The filter property
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * can be a predefined filter or a custom filter. The valid predefined
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * filters are:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <dt>DEBUG</dt>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <dd>Selects the debug versions of the library (e.g., event-debug.js).
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * This option will automatically include the Logger widget</dd>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * <dt>RAW</dt>
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * <dd>Selects the non-minified version of the library (e.g., event.js).</dd>
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * You can also define a custom filter, which must be an object literal
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * containing a search expression and a replace string:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * myFilter: {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * 'searchExp': "-min\\.js",
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * 'replaceStr': "-debug.js"
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * For dynamic loading.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property filter
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type string|object
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Hash of per-component filter specification. If specified for a given component,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * this overrides the filter config
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * For dynamic loading.
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @property filters
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @type object
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * Use the YUI combo service to reduce the number of http connections
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * required to load your dependencies.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * For dynamic loading.
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @property combine
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @type boolean
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * @default true if 'base' is not supplied, false if it is.
16479f9c396537f36d0d9c5633b24df618eee1e6Luke Smith * A list of modules that should never be dynamically loaded
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property ignore
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type string[]
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * A list of modules that should always be loaded when required, even if already
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * present on the page.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property force
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type string[]
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Node or id for a node that should be used as the insertion point for new nodes
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * For dynamic loading.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property insertBefore
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type string
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * charset for dynamic nodes
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property charset
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @type string
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @deprecated use jsAttributes cssAttributes
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Object literal containing attributes to add to dynamically loaded script nodes.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property jsAttributes
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type string
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Object literal containing attributes to add to dynamically loaded link nodes.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property cssAttributes
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type string
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Number of milliseconds before a timeout occurs when dynamically
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * loading nodes. If not set, there is no timeout.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property timeout
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Callback for the 'CSSComplete' event. When dynamically loading YUI
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * components with CSS, this property fires when the CSS is finished
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * loading but script loading is still ongoing. This provides an
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * opportunity to enhance the presentation of a loading page a little
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * bit before the entire loading process is done.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @property onCSS
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @type function
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * A list of module definitions to add to the list of YUI components.
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * These components can then be dynamically loaded side by side with
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * YUI via the use() method.See Loader.addModule for the supported
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * module metadata.
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * @property modules
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * @type function
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * The loader 'path' attribute to the loader itself. This is combined
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * with the 'base' attribute to dynamically load the loader component
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * when boostrapping with the get utility alone.
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * @property loaderPath
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @module yui
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * @submodule yui-base
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith(function() {
4db02d4b38afe802ad625f6c389e106fdc7c26faLuke Smith * If the 'debug' config is true, a 'yui:log' event will be
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * dispatched, which the Console widget and anything else
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * can consume. If the 'useBrowserConsole' config is true, it will
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * write to the browser console if available. YUI-specific log
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore * messages will only be present in the -debug versions of the
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore * JS files. The build system is supposed to remove log statements
4db02d4b38afe802ad625f6c389e106fdc7c26faLuke Smith * from the raw and minified versions of the files.
4db02d4b38afe802ad625f6c389e106fdc7c26faLuke Smith * @method log
4db02d4b38afe802ad625f6c389e106fdc7c26faLuke Smith * @param {String} msg The message to log.
4db02d4b38afe802ad625f6c389e106fdc7c26faLuke Smith * @param {String} cat The log category for the message. Default
4db02d4b38afe802ad625f6c389e106fdc7c26faLuke Smith * categories are "info", "warn", "error", time".
4db02d4b38afe802ad625f6c389e106fdc7c26faLuke Smith * Custom categories can be used as well. (opt)
4db02d4b38afe802ad625f6c389e106fdc7c26faLuke Smith * @param {String} src The source of the the message (opt)
4db02d4b38afe802ad625f6c389e106fdc7c26faLuke Smith * @param {boolean} silent If true, the log event won't fire
4db02d4b38afe802ad625f6c389e106fdc7c26faLuke Smith * @return {YUI} YUI instance
4db02d4b38afe802ad625f6c389e106fdc7c26faLuke Smith // suppress log message if the config is off or the event stack
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // or the event call stack contains a consumer of the yui:log event
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // apply source filters
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith * Write a system message. This message will be preserved in the
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith * minified and raw versions of the YUI files, unlike log statements.
12193f069c735c9fa68aa22d6b4a8ff1fc5b83f1Luke Smith * @method message
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param {String} msg The message to log.
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @param {String} cat The log category for the message. Default
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * categories are "info", "warn", "error", time".
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * Custom categories can be used as well. (opt)
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @param {String} src The source of the the message (opt)
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @param {boolean} silent If true, the log event won't fire
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @return {YUI} YUI instance
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith(function() {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Provides the language utilites and extensions used by the library
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @class Lang
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke SmithTRIMREGEX = /^\s+|\s+$/g,
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * Determines whether or not the provided item is an array.
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith * Returns false for array-like collections such as the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * function arguments collection or HTMLElement collection
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith * will return false. You can use @see Array.test if you
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @method isArray
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param o The object to test
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @return {boolean} true if o is an array
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke SmithL.isArray = function(o) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * Determines whether or not the provided item is a boolean
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @method isBoolean
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param o The object to test
c31ae0e3c3d2726907b1876b5fe81cfd94527d5dLuke Smith * @return {boolean} true if o is a boolean
b32d148b0052e1f874e9bc9803bef729bf859d97Luke SmithL.isBoolean = function(o) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith return typeof o === BOOLEAN;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Determines whether or not the provided item is a function
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Note: Internet Explorer thinks certain functions are objects:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * var obj = document.createElement("object");
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Y.Lang.isFunction(obj.getAttribute) // reports false in IE
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * var input = document.createElement("input"); // append to body
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Y.Lang.isFunction(input.focus) // reports false in IE
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * You will have to implement additional tests if these functions
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * matter to you.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method isFunction
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param o The object to test
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return {boolean} true if o is a function
b32d148b0052e1f874e9bc9803bef729bf859d97Luke SmithL.isFunction = function(o) {
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith * Determines whether or not the supplied item is a date instance
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method isDate
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith * @param o The object to test
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith * @return {boolean} true if o is a date
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke SmithL.isDate = function(o) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // return o instanceof Date;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Determines whether or not the provided item is null
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method isNull
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param o The object to test
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return {boolean} true if o is null
b32d148b0052e1f874e9bc9803bef729bf859d97Luke SmithL.isNull = function(o) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith return o === null;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Determines whether or not the provided item is a legal number
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method isNumber
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param o The object to test
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return {boolean} true if o is a number
b32d148b0052e1f874e9bc9803bef729bf859d97Luke SmithL.isNumber = function(o) {
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * Determines whether or not the provided item is of type object
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * or function
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith * @method isObject
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith * @param o The object to test
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @param failfn {boolean} fail if the input is a function
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @return {boolean} true if o is an object
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smithreturn (o && (typeof o === OBJECT || (!failfn && L.isFunction(o)))) || false;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Determines whether or not the provided item is a string
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method isString
c36390194c43d30adc1059a74fdf9f51a235b8a9Luke Smith * @param o The object to test
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return {boolean} true if o is a string
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke SmithL.isString = function(o) {
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith return typeof o === STRING;
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * Determines whether or not the provided item is undefined
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * @method isUndefined
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * @param o The object to test
8652e2d20f8ea9c9bfe21217ba427cf0d85ada9aLuke Smith * @return {boolean} true if o is undefined
b32d148b0052e1f874e9bc9803bef729bf859d97Luke SmithL.isUndefined = function(o) {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith return typeof o === UNDEFINED;
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * Returns a string without any leading or trailing whitespace. If
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * the input is not a string, the input will be returned untouched.
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @method trim
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @param s {string} the string to trim
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @return {string} the trimmed string
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke SmithL.trim = function(s){
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith } catch(e) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * A convenience method for detecting a legitimate non-null value.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Returns false for null/undefined/NaN, true for other values,
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * including 0/false/''
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method isValue
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param o The item to test
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return {boolean} true if it is not null/undefined/NaN || false
b32d148b0052e1f874e9bc9803bef729bf859d97Luke SmithL.isValue = function(o) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith var t = L.type(o);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith switch (t) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return false;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return !!(t);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Returns a string representing the type of the item passed in.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method type
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param o the item to test
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return {string} the detected type
b32d148b0052e1f874e9bc9803bef729bf859d97Luke SmithL.type = function (o) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith return TYPES[typeof o] || TYPES[TOSTRING.call(o)] || (o ? OBJECT : NULL);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Provides information about the environment hosting YUI
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @module yui
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @submodule Array
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith(function() {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Adds the following array utilities to the YUI instance. Additional
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * array helpers can be found in the collection component.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @class Array
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Y.Array(o) returns an array:
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * - Arrays are return unmodified unless the start position is specified.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * - "Array-like" collections (@see Array.test) are converted to arrays
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith * - For everything else, a new array is created with the input as the sole item
35eeab4975a1c9e62cf466455a59e80ba5e00fb0Luke Smith * - The start position is used if the input is or is like an array to return
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * a subset of the collection.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @TODO this will not automatically convert elements that are also collections
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * such as forms and selects. Passing true as the third param will
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * force a conversion.
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @method ()
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @param o the item to arrayify
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @param i {int} if an array or array-like, this is the start index
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @param al {boolean} if true, it forces the array-like fork. This
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * can be used to avoid multiple array.test calls.
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @return {Array} the resulting array
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith // switch (t) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // // return (startIdx) ? o.slice(startIdx) : o;
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // return Native.slice.call(o, startIdx || 0);
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // return [o];
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith // IE errors when trying to slice element collections
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith } catch(e) {
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * Evaluates the input to determine if it is an array, array-like, or
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * something else. This is used to handle the arguments collection
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * available within functions, and HTMLElement collections
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @method test
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @todo current implementation (intenionally) will not implicitly
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * handle html elements that are array-like (forms, selects, etc).
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * @return {int} a number indicating the results:
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * 0: Not an array or an array-like collection
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * 1: A real array.
ed51daad3a3ab15255ca10edef69d5f703d69adbLuke Smith * 2: array-like collection.
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith // indexed, but no tagName (element) or alert (window)
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith if ("length" in o && !("tagName" in o) && !("alert" in o) &&
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith } catch(e) {}
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * Executes the supplied function on each item in the array.
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @method each
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @param a {Array} the array to iterate
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @param f {Function} the function to execute on each item
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @param o Optional context object
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith * @return {YUI} the YUI instance
d463aba91a07cde67f9ec9382bce464db5bcc9d3Luke Smith function (a, f, o) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith function (a, f, o) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith f.call(o || Y, a[i], i, a);
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore * Returns an object using the first array as keys, and
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * the second as values. If the second array is not
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore * provided the value is set to true for each.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method hash
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore * @param k {Array} keyset
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore * @param v {Array} optional valueset
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return {object} the hash
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Returns the index of the first item in the array
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * that contains the specified value, -1 if the
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * value isn't found.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method indexOf
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param a {Array} the array to search
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @param val the value to search for
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @return {int} the index of the item that contains the value or -1
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith function(a, val) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith function(a, val) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith if (a[i] === val) {
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Numeric sort convenience function.
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * Y.ArrayAssert.itemsAreEqual([1, 2, 3], [3, 1, 2].sort(Y.Array.numericSort));
b32d148b0052e1f874e9bc9803bef729bf859d97Luke Smith * @method numericSort
var l = a.length, i;
if (f.call(o, a[i], i, a)) {
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];
Y.mix(r[p], s[p]);
} else if (arr) {
r.push(s[p]);
} else if (arr) {
r.push(s[i]);
_iefix(r, s);
v = cache[k];
return cache[k];
F.prototype = o;
if (count) {
out++;
if (o.hasOwnProperty(i)) {
return out;
O.keys = function(o) {
return _extract(o);
O.values = function(o) {
O.size = function(o) {
O.hasKey = function(o, k) {
O.hasValue = function(o, v) {
O.owns = function(o, k) {
return (o.hasOwnProperty(k));
f.call(s, o[i], i, o);
return UNDEFINED;
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) {
var L = Y.Lang,
m = o[fn];
if (!L.isArray(d)) {
d = [data];
m.apply(o, d);
id: r,
cancel: function() {
if (this.interval) {
clearInterval(r);
clearTimeout(r);
// var min = ['yui-base', 'log', 'lang', 'array', 'core'], core, C = Y.config;
if (C.core) {
function Queue() {
this._init();
_init : function () {
this._q = [];
next : function () {
add : function () {
size : function () {
L = Y.Lang,
Y.Get = function() {
var queues={},
purging=false,
for (i in attr) {
if (attributes) {
if (attributes) {
n = q.nodes;
l = n.length;
if (q.insertBefore) {
h = s.parentNode;
node = n[i];
q.nodes = [];
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) {
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",