yui-base.js revision eb86457f85638a9eb7c4d5f84eb367d24061abfb
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp/**
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * YUI core
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * @module yui
0fdefaa9ca017edfb76b736c825b34186f33045aTripp */
0fdefaa9ca017edfb76b736c825b34186f33045aTripp(function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp var _instances = {}, _startTime = new Date().getTime(), Y, p, i,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp// @TODO: this needs to be created at build time from module metadata
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp _APPLY_TO_WHITE_LIST = {
a89ad754cce3cfc8aee71760e10217b54020360dTripp 'io.xdrReady': 1,
a89ad754cce3cfc8aee71760e10217b54020360dTripp 'io.start': 1,
a89ad754cce3cfc8aee71760e10217b54020360dTripp 'io.success': 1,
a89ad754cce3cfc8aee71760e10217b54020360dTripp 'io.failure': 1,
a89ad754cce3cfc8aee71760e10217b54020360dTripp 'io.abort': 1
a89ad754cce3cfc8aee71760e10217b54020360dTripp };
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp// reduce to one or the other
c093c1aed867e18aa4778708592e1ceb45d18cffTrippif (typeof YUI === 'undefined' || !YUI) {
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * The YUI global namespace object. If YUI is already defined, the
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * existing YUI object will not be overwritten so that defined
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * namespaces are preserved.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @class YUI
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @constructor
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @global
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @uses Event.Target
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param o Optional configuration object. Options:
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <ul>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <li>------------------------------------------------------------------------</li>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <li>Global:</li>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <li>------------------------------------------------------------------------</li>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <li>debug:
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Turn debug statements on or off</li>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <li>useBrowserConsole:
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Log to the browser console if debug is on and the console is available</li>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <li>logInclude:
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * A hash of log sources that should be logged. If specified, only log messages from these sources will be logged.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * </li>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <li>logExclude:
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * A hash of log sources that should be not be logged. If specified, all sources are logged if not on this list.</li>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <li>throwFail:
a89ad754cce3cfc8aee71760e10217b54020360dTripp * If throwFail is set, Y.fail will generate or re-throw a JS error. Otherwise the failure is logged.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>win:
a89ad754cce3cfc8aee71760e10217b54020360dTripp * The target window/frame</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>core:
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * A list of modules that defines the YUI core (overrides the default)</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>------------------------------------------------------------------------</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>For event and get:</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>------------------------------------------------------------------------</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>pollInterval:
a89ad754cce3cfc8aee71760e10217b54020360dTripp * The default poll interval</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>-------------------------------------------------------------------------</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>For loader:</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>-------------------------------------------------------------------------</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>base:
a89ad754cce3cfc8aee71760e10217b54020360dTripp * The base dir</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>secureBase:
a89ad754cce3cfc8aee71760e10217b54020360dTripp * The secure base dir (not implemented)</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>comboBase:
a89ad754cce3cfc8aee71760e10217b54020360dTripp * The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>root:
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * The root path to prepend to module names for the combo service. Ex: 2.5.2/build/</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>filter:
a89ad754cce3cfc8aee71760e10217b54020360dTripp *
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * A filter to apply to result urls. This filter will modify the default
a89ad754cce3cfc8aee71760e10217b54020360dTripp * path for all modules. The default path for the YUI library is the
a89ad754cce3cfc8aee71760e10217b54020360dTripp * minified version of the files (e.g., event-min.js). The filter property
a89ad754cce3cfc8aee71760e10217b54020360dTripp * can be a predefined filter or a custom filter. The valid predefined
a89ad754cce3cfc8aee71760e10217b54020360dTripp * filters are:
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * <dl>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <dt>DEBUG</dt>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <dd>Selects the debug versions of the library (e.g., event-debug.js).
a89ad754cce3cfc8aee71760e10217b54020360dTripp * This option will automatically include the Logger widget</dd>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <dt>RAW</dt>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <dd>Selects the non-minified version of the library (e.g., event.js).</dd>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * </dl>
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * You can also define a custom filter, which must be an object literal
a89ad754cce3cfc8aee71760e10217b54020360dTripp * containing a search expression and a replace string:
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <pre>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * myFilter: &#123;
a89ad754cce3cfc8aee71760e10217b54020360dTripp * 'searchExp': "-min\\.js",
a89ad754cce3cfc8aee71760e10217b54020360dTripp * 'replaceStr': "-debug.js"
a89ad754cce3cfc8aee71760e10217b54020360dTripp * &#125;
a89ad754cce3cfc8aee71760e10217b54020360dTripp * </pre>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
a89ad754cce3cfc8aee71760e10217b54020360dTripp * </li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>combine:
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Use the YUI combo service to reduce the number of http connections required to load your dependencies</li>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <li>ignore:
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * A list of modules that should never be dynamically loaded</li>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <li>force:
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * A list of modules that should always be loaded when required, even if already present on the page</li>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <li>insertBefore:
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Node or id for a node that should be used as the insertion point for new nodes</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>charset:
a89ad754cce3cfc8aee71760e10217b54020360dTripp * charset for dynamic nodes</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>timeout:
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * number of milliseconds before a timeout occurs when dynamically loading nodes. in not set, there is no timeout</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>context:
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * execution context for all callbacks</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>onSuccess:
a89ad754cce3cfc8aee71760e10217b54020360dTripp * callback for the 'success' event</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>onFailure:
a89ad754cce3cfc8aee71760e10217b54020360dTripp * callback for the 'failure' event</li>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <li>onTimeout:
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * callback for the 'timeout' event</li>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <li>onProgress:
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * callback executed each time a script or css file is loaded</li>
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * <li>modules:
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * A list of module definitions. See Loader.addModule for the supported module metadata</li>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * </ul>
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /*global YUI*/
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // Make a function, disallow direct instantiation
a89ad754cce3cfc8aee71760e10217b54020360dTripp YUI = function(o) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp var Y = this;
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp // Allow instantiation without the new operator
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (!(Y instanceof YUI)) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return new YUI(o);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } else {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // set up the core environment
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y._init(o);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c093c1aed867e18aa4778708592e1ceb45d18cffTripp // bind the specified additional modules for this instance
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y._setup();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return Y;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp}
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp// The prototype contains the functions that are required to allow the external
bf801d6851ecf7ed14742ef3639a077daecb5cf8Tripp// modules to be registered and for the instance to be initialized.
a4d2446149b07f9e5c32947091dcbcf4d2eee765TrippYUI.prototype = {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c093c1aed867e18aa4778708592e1ceb45d18cffTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Initialize this YUI instance
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param o config options
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _init: function(o) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o = o || {};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // find targeted window
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // @TODO create facades
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // @TODO resolve windowless environments
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var w = (o.win) ? (o.win.contentWindow) : o.win || window,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp v = '@VERSION@';
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o.win = w;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o.doc = w.document;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o.debug = ('debug' in o) ? o.debug : true;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o.useBrowserConsole = ('useBrowserConsole' in o) ? o.useBrowserConsole : true;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o.throwFail = ('throwFail' in o) ? o.throwFail : true;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c093c1aed867e18aa4778708592e1ceb45d18cffTripp // add a reference to o for anything that needs it
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // before _setup is called.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.config = o;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.Env = {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // @todo expand the new module metadata
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp mods: {},
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _idx: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _pre: 'yuid',
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _used: {},
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _attached: {},
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _yidx: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _uidx: 0
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (v.indexOf('@') > -1) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp v = 'test';
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.version = v;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (YUI.Env) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.Env._yidx = ++YUI.Env._idx;
c093c1aed867e18aa4778708592e1ceb45d18cffTripp this.id = this.stamp(this);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _instances[this.id] = this;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.constructor = YUI;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.log(this.id + ') init ');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Finishes the instance setup. Attaches whatever modules were defined
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * when the yui modules was registered.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method _setup
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _setup: function(o) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.use("yui-base");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // @TODO eval the need to copy the config
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // this.config = this.merge(this.config);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Executes a method on a YUI instance with
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * the specified id if the specified method is whitelisted.
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @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 */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp applyTo: function(id, method, args) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (!(method in _APPLY_TO_WHITE_LIST)) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.error(method + ': applyTo not allowed');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return null;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var instance = _instances[id], nest, m, i;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (instance) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp nest = method.split('.');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp m = instance;
a89ad754cce3cfc8aee71760e10217b54020360dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp for (i=0; i<nest.length; i=i+1) {
cec703a844d9691646231634fe709f4ea41d278aTripp
cec703a844d9691646231634fe709f4ea41d278aTripp m = m[nest[i]];
cec703a844d9691646231634fe709f4ea41d278aTripp
cec703a844d9691646231634fe709f4ea41d278aTripp if (!m) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.error('applyTo not found: ' + method);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return m.apply(instance, args);
cec703a844d9691646231634fe709f4ea41d278aTripp }
cec703a844d9691646231634fe709f4ea41d278aTripp
cec703a844d9691646231634fe709f4ea41d278aTripp return null;
cec703a844d9691646231634fe709f4ea41d278aTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Register a module
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method add
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param name {string} module name
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param fn {Function} entry point into the module that
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * 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
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * optional - optional features that should be present if load optional defined
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * use - features that should be attached automatically
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * skinnable -
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * rollup
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * omit - features that should not be loaded if this module is present
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return {YUI} the YUI instance
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp add: function(name, fn, version, details) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // this.log('Adding a new component ' + name);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // @todo expand this to include version mapping
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // @todo allow requires/supersedes
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // @todo may want to restore the build property
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // @todo fire moduleAvailable event
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var m = {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp name: name,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp fn: fn,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp version: version,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp details: details || {}
a89ad754cce3cfc8aee71760e10217b54020360dTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp YUI.Env.mods[name] = m;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this; // chain support
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _attach: function(r, fromLoader) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var mods = YUI.Env.mods,
a89ad754cce3cfc8aee71760e10217b54020360dTripp attached = this.Env._attached,
a89ad754cce3cfc8aee71760e10217b54020360dTripp i, l = r.length, name, m, d, req, use;
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp for (i=0; i<l; i=i+1) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp name = r[i];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp m = mods[name];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (!attached[name] && m) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp attached[name] = true;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp d = m.details;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp req = d.requires;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp use = d.use;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (req) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._attach(this.Array(req));
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.log('attaching ' + name, 'info', 'YUI');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (m.fn) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp m.fn(this);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (use) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._attach(this.Array(use));
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Bind a module to a YUI instance
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param modules* {string} 1-n modules to bind (uses arguments array)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param *callback {function} callback function executed when
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * the instance has the required functionality. If included, it
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * must be the last parameter.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @TODO
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Implement versioning? loader can load different versions?
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Should sub-modules/plugins be normal modules, or do
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * we add syntax for specifying these?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * YUI().use('dragdrop')
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * YUI().use('dragdrop:2.4.0'); // specific version
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * YUI().use('dragdrop:2.4.0-'); // at least this version
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * YUI().use('dragdrop:2.4.0-2.9999.9999'); // version range
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * YUI().use('*'); // use all available modules
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * YUI().use('lang+dump+substitute'); // use lang and some plugins
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * YUI().use('lang+*'); // use lang and all known plugins
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @return {YUI} the YUI instance
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp use: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp var Y = this,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp a=Array.prototype.slice.call(arguments, 0),
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp mods = YUI.Env.mods,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp used = Y.Env._used,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp loader,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp firstArg = a[0],
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp dynamic = false,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp callback = a[a.length-1],
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp k, i, l, missing = [], r = [],
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp f = function(name) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // only attach a module once
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (used[name]) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var m = mods[name], j, req, use;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp if (m) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp used[name] = true;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp req = m.details.requires;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp use = m.details.use;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } else {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp missing.push(name);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // make sure requirements are attached
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (req) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (Y.Lang.isString(req)) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp f(req);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } else {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp for (j = 0; j < req.length; j = j + 1) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp f(req[j]);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp // add this module to full list of things to attach
a89ad754cce3cfc8aee71760e10217b54020360dTripp r.push(name);
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp onComplete = function(fromLoader) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp fromLoader = fromLoader || {
a89ad754cce3cfc8aee71760e10217b54020360dTripp success: true,
a89ad754cce3cfc8aee71760e10217b54020360dTripp msg: 'not dynamic'
a89ad754cce3cfc8aee71760e10217b54020360dTripp };
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (Y.Env._callback) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp var cb = Y.Env._callback;
a89ad754cce3cfc8aee71760e10217b54020360dTripp Y.Env._callback = null;
a89ad754cce3cfc8aee71760e10217b54020360dTripp cb(Y, fromLoader);
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (Y.fire) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.fire('yui:load', Y, fromLoader);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp };
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // The last argument supplied to use can be a load complete callback
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (typeof callback === 'function') {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp a.pop();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.Env._callback = callback;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp } else {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp callback = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // YUI().use('*'); // bind everything available
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (firstArg === "*") {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp a = [];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for (k in mods) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (mods.hasOwnProperty(k)) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp a.push(k);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return Y.use.apply(Y, a);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // use loader to expand dependencies and sort the
e188eaea1f0e60d808be8a4f6ccdbbd3c9b5039bTripp // requirements if it is available.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (Y.Loader) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp dynamic = true;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader = new Y.Loader(Y.config);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.require(a);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.ignoreRegistered = true;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.allowRollup = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.calculate();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp a = loader.sorted;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp l = a.length;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // process each requirement and any additional requirements
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // the module metadata specifies
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp for (i=0; i<l; i=i+1) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp f(a[i]);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // dynamic load
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (Y.Loader && missing.length) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp loader = new Y.Loader(Y.config);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.onSuccess = onComplete;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.onFailure = onComplete;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp loader.onTimeout = onComplete;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.attaching = a;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.require(missing);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.insert();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp } else {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y._attach(r);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp onComplete();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return Y; // chain support var yui = YUI().use('dragdrop');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Returns the namespace specified and creates it if it doesn't exist
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <pre>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * YUI.namespace("property.package");
a89ad754cce3cfc8aee71760e10217b54020360dTripp * YUI.namespace("YAHOO.property.package");
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * </pre>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Either of the above would create YUI.property, then
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * YUI.property.package (YAHOO is scrubbed out, this is
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * to remain compatible with YUI2)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
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 * <pre>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * YUI.namespace("really.long.nested.namespace");
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * </pre>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * This fails because "long" is a future reserved word in ECMAScript
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method namespace
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {string*} arguments 1-n namespaces to create
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return {object} A reference to the last namespace object created
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp namespace: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var a=arguments, o=null, i, j, d;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for (i=0; i<a.length; i=i+1) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp d = ("" + a[i]).split(".");
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp o = this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for (j=(d[0] == "YAHOO") ? 1 : 0; j<d.length; j=j+1) {
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp o[d[j]] = o[d[j]] || {};
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp o = o[d[j]];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return o;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // this is replaced if the log module is included
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp log: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Report an error. The reporting mechanism is controled by
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * the 'throwFail' configuration attribute. If throwFail is
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * not specified, the message is written to the Logger, otherwise
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * a JS error is thrown
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp * @method error
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param msg {string} the error message
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param e {Error} Optional JS error that was caught. If supplied
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * and throwFail is specified, this error will be re-thrown.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return {YUI} this YUI instance
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp error: function(msg, e) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (this.config.throwFail) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp throw (e || new Error(msg));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp } else {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.message(msg, "error"); // don't scrub this one
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Generate an id that is unique among all YUI instances
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method guid
cec703a844d9691646231634fe709f4ea41d278aTripp * @param pre {string} optional guid prefix
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @return {string} the guid
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp guid: function(pre) {
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp var e = this.Env, p = (pre) || e._pre;
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp return p + '-' +
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp this.version + '-' +
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp e._yidx + '-' +
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp (e._uidx++) + '-' +
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp _startTime;
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp },
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp /**
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * Returns a guid associated with an object. If the object
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * does not have one, a new one is created unless readOnly
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * is specified.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method stamp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @param o The object to stamp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @param readOnly {boolean} if true, a valid guid will only
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * be returned if the object has one assigned to it.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return {string} The object's guid or null
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp stamp: function(o, readOnly) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (!o) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return o;
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp }
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var uid = (typeof o === 'string') ? o : o._yuid;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (!uid) {
9eaaa502227248d304ac9170902697d02158c1d9Tripp uid = this.guid();
9eaaa502227248d304ac9170902697d02158c1d9Tripp if (!readOnly) {
9eaaa502227248d304ac9170902697d02158c1d9Tripp try {
9eaaa502227248d304ac9170902697d02158c1d9Tripp o._yuid = uid;
9eaaa502227248d304ac9170902697d02158c1d9Tripp } catch(e) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp uid = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
4ef2f7e4cb7c7d255be077c47d542199f7bf8607Tripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return uid;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp// Give the YUI global the same properties as an instance.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp// This makes it so that the YUI global can be used like the YAHOO
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp// global was used prior to 3.x. More importantly, the YUI global
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp// provides global metadata, so env needs to be configured.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp// @TODO review
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp Y = YUI;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp p = Y.prototype;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // inheritance utilities are not available yet
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp for (i in p) {
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp if (true) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y[i] = p[i];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // set up the environment
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y._init();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
0fdefaa9ca017edfb76b736c825b34186f33045aTripp})();
0fdefaa9ca017edfb76b736c825b34186f33045aTrippYUI.add('yui-base', function(Y) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp/**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * YUI stub
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @module yui
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @submodule yui-base
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp(function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTrippvar instance = Y;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp/**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * If the 'debug' config is true, a 'yui:log' event will be
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * dispatched, which the Logger widget and anything else
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * can consume. If the 'useBrowserConsole' config is true, it will
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * write to the browser console if available. YUI-specific log
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * messages will only be present in the -debug versions of the
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * JS files.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method log
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @for YUI
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {String} msg The message to log.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {String} cat The log category for the message. Default
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * categories are "info", "warn", "error", time".
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Custom categories can be used as well. (opt)
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @param {String} src The source of the the message (opt)
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @param {boolean} silent If true, the log event won't fire
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @return {YUI} YUI instance
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTrippinstance.log = function(msg, cat, src, silent) {
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var Y = instance, c = Y.config, bail = false, exc, inc, m, f;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // suppress log message if the config is off or the event stack
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // or the event call stack contains a consumer of the yui:log event
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (c.debug) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // apply source filters
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (src) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp exc = c.logExclude;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp inc = c.logInclude;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // console.log('checking src filter: ' + src + ', inc: ' + inc + ', exc: ' + exc);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp if (inc && !(src in inc)) {
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp // console.log('bail: inc list found, but src is not in list: ' + src);
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp bail = true;
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp } else if (exc && (src in exc)) {
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp // console.log('bail: exc list found, and src is in it: ' + src);
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp bail = true;
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (!bail) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (c.useBrowserConsole) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp m = (src) ? src + ': ' + msg : msg;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (typeof console != 'undefined') {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp f = (cat && console[cat]) ? cat : 'log';
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp console[f](m);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } else if (typeof opera != 'undefined') {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp opera.postError(m);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (Y.fire && !bail && !silent) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.fire('yui:log', msg, cat, src);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return Y;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp};
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp/**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Write a system message. This message will be preserved in the
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * minified and raw versions of the YUI files.
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * @method log
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @for YUI
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param {String} msg The message to log.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param {String} cat The log category for the message. Default
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * categories are "info", "warn", "error", time".
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Custom categories can be used as well. (opt)
* @param {String} src The source of the the message (opt)
* @param {boolean} silent If true, the log event won't fire
* @return {YUI} YUI instance
*/
instance.message = function() {
return instance.log.apply(instance, arguments);
};
})();
(function() {
/**
* Provides the language utilites and extensions used by the library
* @class Lang
* @static
*/
Y.Lang = Y.Lang || {};
var L = Y.Lang,
ARRAY = 'array',
BOOLEAN = 'boolean',
DATE = 'date',
ERROR = 'error',
FUNCTION = 'function',
NUMBER = 'number',
OBJECT = 'object',
REGEX = 'regexp',
STRING = 'string',
TOSTRING = Object.prototype.toString,
UNDEFINED = 'undefined',
TYPES = {
'undefined' : UNDEFINED,
'number' : NUMBER,
'boolean' : BOOLEAN,
'string' : STRING,
'[object Function]' : FUNCTION,
'[object RegExp]' : REGEX,
'[object Array]' : ARRAY,
'[object Date]' : DATE,
'[object Error]' : ERROR
};
/**
* Determines whether or not the provided item is an array.
* Returns false for array-like collections such as the
* function arguments collection or HTMLElement collection
* will return false. You can use @see Array.test if you
* want to
* @method isArray
* @static
* @param o The object to test
* @return {boolean} true if o is an array
*/
L.isArray = function(o) {
return L.type(o) === ARRAY;
};
/**
* Determines whether or not the provided item is a boolean
* @method isBoolean
* @static
* @param o The object to test
* @return {boolean} true if o is a boolean
*/
L.isBoolean = function(o) {
return typeof o === BOOLEAN;
};
/**
* Determines whether or not the provided item is a function
* Note: Internet Explorer thinks certain functions are objects:
*
* var obj = document.createElement("object");
* Y.Lang.isFunction(obj.getAttribute) // reports false in IE
*
* var input = document.createElement("input"); // append to body
* Y.Lang.isFunction(input.focus) // reports false in IE
*
* You will have to implement additional tests if these functions
* matter to you.
*
* @method isFunction
* @static
* @param o The object to test
* @return {boolean} true if o is a function
*/
L.isFunction = function(o) {
return L.type(o) === FUNCTION;
};
/**
* Determines whether or not the supplied item is a date instance
* @method isDate
* @static
* @param o The object to test
* @return {boolean} true if o is a date
*/
L.isDate = function(o) {
return o instanceof Date;
};
/**
* Determines whether or not the provided item is null
* @method isNull
* @static
* @param o The object to test
* @return {boolean} true if o is null
*/
L.isNull = function(o) {
return o === null;
};
/**
* Determines whether or not the provided item is a legal number
* @method isNumber
* @static
* @param o The object to test
* @return {boolean} true if o is a number
*/
L.isNumber = function(o) {
return typeof o === NUMBER && isFinite(o);
};
/**
* Determines whether or not the provided item is of type object
* or function
* @method isObject
* @static
* @param o The object to test
* @param failfn {boolean} fail if the input is a function
* @return {boolean} true if o is an object
*/
L.isObject = function(o, failfn) {
return (o && (typeof o === OBJECT || (!failfn && L.isFunction(o)))) || false;
};
/**
* Determines whether or not the provided item is a string
* @method isString
* @static
* @param o The object to test
* @return {boolean} true if o is a string
*/
L.isString = function(o) {
return typeof o === STRING;
};
/**
* Determines whether or not the provided item is undefined
* @method isUndefined
* @static
* @param o The object to test
* @return {boolean} true if o is undefined
*/
L.isUndefined = function(o) {
return typeof o === UNDEFINED;
};
/**
* Returns a string without any leading or trailing whitespace. If
* the input is not a string, the input will be returned untouched.
* @method trim
* @static
* @param s {string} the string to trim
* @return {string} the trimmed string
*/
L.trim = function(s){
try {
return s.replace(/^\s+|\s+$/g, "");
} catch(e) {
return s;
}
};
/**
* A convenience method for detecting a legitimate non-null value.
* Returns false for null/undefined/NaN, true for other values,
* including 0/false/''
* @method isValue
* @static
* @param o The item to test
* @return {boolean} true if it is not null/undefined/NaN || false
*/
L.isValue = function(o) {
var t = L.type(o);
return (t && t !== UNDEFINED) || false;
};
/**
* Returns a string representing the type of the item passed in.
* @method type
* @param o the item to test
* @return {string} the detected type
*/
L.type = function (o) {
return TYPES[typeof o] || TYPES[TOSTRING.call(o)] || (o ? 'object' : 'null');
};
})();
(function() {
/**
* YUI core
* @module yui
*/
var L = Y.Lang, Native = Array.prototype,
/**
* Adds the following array utilities to the YUI instance
* @class YUI~array
*/
/**
* Y.Array(o) returns an array:
* - Arrays are return unmodified unless the start position is specified.
* - "Array-like" collections (@see Array.test) are converted to arrays
* - For everything else, a new array is created with the input as the sole item
* - The start position is used if the input is or is like an array to return
* a subset of the collection.
*
* @TODO this will not automatically convert elements that are also collections
* such as forms and selects. Passing true as the third param will
* force a conversion.
*
* @method Array
* @static
* @param o the item to arrayify
* @param i {int} if an array or array-like, this is the start index
* @param al {boolean} if true, it forces the array-like fork. This
* can be used to avoid multiple array.test calls.
* @return {Array} the resulting array
*/
A = function(o, i, al) {
var t = (al) ? 2 : Y.Array.test(o);
// switch (t) {
// case 1:
// // return (i) ? o.slice(i) : o;
// case 2:
// return Native.slice.call(o, i || 0);
// default:
// return [o];
// }
if (t) {
return Native.slice.call(o, i || 0);
} else {
return [o];
}
};
Y.Array = A;
/**
* Evaluates the input to determine if it is an array, array-like, or
* something else. This is used to handle the arguments collection
* available within functions, and HTMLElement collections
*
* @method Array.test
* @static
*
* @todo current implementation (intenionally) will not implicitly
* handle html elements that are array-like (forms, selects, etc).
*
* @return {int} a number indicating the results:
* 0: Not an array or an array-like collection
* 1: A real array.
* 2: array-like collection.
*/
A.test = function(o) {
var r = 0;
if (L.isObject(o, true)) {
if (L.isArray(o)) {
r = 1;
} else {
try {
// indexed, but no tagName (element) or alert (window)
if ("length" in o &&
!("tagName" in o) &&
!("alert" in o) &&
(!Y.Lang.isFunction(o.size) || o.size() > 1)) {
r = 2;
}
} catch(ex) {}
}
}
return r;
};
/**
* Executes the supplied function on each item in the array.
* @method Array.each
* @param a {Array} the array to iterate
* @param f {Function} the function to execute on each item
* @param o Optional context object
* @static
* @return {YUI} the YUI instance
*/
A.each = (Native.forEach) ?
function (a, f, o) {
Native.forEach.call(a, f, o || Y);
return Y;
} :
function (a, f, o) {
var l = a.length, i;
for (i = 0; i < l; i=i+1) {
f.call(o || Y, a[i], i, a);
}
return Y;
};
/**
* Returns an object using the first array as keys, and
* the second as values. If the second array is not
* provided the value is set to true for each.
* @method Array.hash
* @static
* @param k {Array} keyset
* @param v {Array} optional valueset
* @return {object} the hash
*/
A.hash = function(k, v) {
var o = {}, l = k.length, vl = v && v.length, i;
for (i=0; i<l; i=i+1) {
o[k[i]] = (vl && vl > i) ? v[i] : true;
}
return o;
};
/**
* Returns the index of the first item in the array
* that contains the specified value, -1 if the
* value isn't found.
* @method Array.indexOf
* @static
* @param a {Array} the array to search
* @param val the value to search for
* @return {int} the index of the item that contains the value or -1
*/
A.indexOf = (Native.indexOf) ?
function(a, val) {
return a.indexOf(val);
} :
function(a, val) {
for (var i=0; i<a.length; i=i+1) {
if (a[i] === val) {
return i;
}
}
return -1;
};
/**
* Numeric sort convenience function.
* Y.ArrayAssert.itemsAreEqual([1, 2, 3], [3, 1, 2].sort(Y.Array.numericSort));
* @method numericSort
*/
A.numericSort = function(a, b) {
return (a - b);
};
})();
(function() {
var L = Y.Lang,
A = Y.Array,
OP = Object.prototype,
IEF = ["toString", "valueOf"],
PROTO = 'prototype',
/**
* IE will not enumerate native functions in a derived object even if the
* function was overridden. This is a workaround for specific functions
* we care about on the Object prototype.
* @property _iefix
* @param {Function} r the object to receive the augmentation
* @param {Function} s the object that supplies the properties to augment
* @param w a whitelist object (the keys are the valid items to reference)
* @private
* @for YUI
*/
_iefix = (Y.UA && Y.UA.ie) ?
function(r, s, w) {
var i, a = IEF, n, f;
for (i=0; i<a.length; i=i+1) {
n = a[i];
f = s[n];
if (L.isFunction(f) && f != OP[n]) {
if (!w || (n in w)) {
r[n]=f;
}
}
}
} : function() {};
/**
* Returns a new object containing all of the properties of
* all the supplied objects. The properties from later objects
* will overwrite those in earlier objects. Passing in a
* single object will create a shallow copy of it. For a deep
* copy, use clone.
* @method merge
* @param arguments {Object*} the objects to merge
* @return {object} the new merged object
*/
Y.merge = function() {
var a = arguments, o = {}, i, l = a.length;
for (i=0; i<l; i=i+1) {
Y.mix(o, a[i], true);
}
return o;
};
/**
* Applies the supplier's properties to the receiver. By default
* all prototype and static propertes on the supplier are applied
* to the corresponding spot on the receiver. By default all
* properties are applied, and a property that is already on the
* reciever will not be overwritten. The default behavior can
* be modified by supplying the appropriate parameters.
*
* @TODO add constants for the modes
*
* @method mix
* @param {Function} r the object to receive the augmentation
* @param {Function} s the object that supplies the properties to augment
* @param ov {boolean} if true, properties already on the receiver
* will be overwritten if found on the supplier.
* @param wl {string[]} a whitelist. If supplied, only properties in
* this list will be applied to the receiver.
* @param {int} mode what should be copies, and to where
* default(0): object to object
* 1: prototype to prototype (old augment)
* 2: prototype to prototype and object props (new augment)
* 3: prototype to object
* 4: object to prototype
* @param merge {boolean} merge objects instead of overwriting/ignoring
* Used by Y.aggregate
* @return {object} the augmented object
* @TODO review for PR2
*/
Y.mix = function(r, s, ov, wl, mode, merge) {
if (!s||!r) {
return Y;
}
var w = (wl && wl.length) ? A.hash(wl) : null, m = merge,
f = function(fr, fs, proto, iwl) {
var arr = m && L.isArray(fr), i;
for (i in fs) {
if (fs.hasOwnProperty(i)) {
// We never want to overwrite the prototype
// if (PROTO === i) {
if (PROTO === i || '_yuid' === i) {
continue;
}
// @TODO deal with the hasownprop issue
// check white list if it was supplied
if (!w || iwl || (i in w)) {
// if the receiver has this property, it is an object,
// and merge is specified, merge the two objects.
if (m && L.isObject(fr[i], true)) {
// console.log('aggregate RECURSE: ' + i);
// @TODO recursive or no?
// Y.mix(fr[i], fs[i]); // not recursive
f(fr[i], fs[i], proto, true); // recursive
// otherwise apply the property only if overwrite
// is specified or the receiver doesn't have one.
// @TODO make sure the 'arr' check isn't desructive
} else if (!arr && (ov || !(i in fr))) {
// console.log('hash: ' + i);
fr[i] = fs[i];
// if merge is specified and the receiver is an array,
// append the array item
} else if (arr) {
// console.log('array: ' + i);
// @TODO probably will need to remove dups
fr.push(fs[i]);
}
}
}
}
_iefix(fr, fs, w);
},
rp = r.prototype,
sp = s.prototype;
switch (mode) {
case 1: // proto to proto
f(rp, sp, true);
break;
case 2: // object to object and proto to proto
f(r, s);
f(rp, sp, true);
break;
case 3: // proto to static
f(r, sp, true);
break;
case 4: // static to proto
f(rp, s);
break;
default: // object to object
f(r, s);
}
return r;
};
})();
(function() {
/**
* Adds the following Object utilities to the YUI instance
* @class YUI~object
*/
/**
* Y.Object(o) returns a new object based upon the supplied object.
* @TODO Use native Object.create() when available
* @method Object
* @static
* @param o the supplier object
* @return {object} the new object
*/
Y.Object = function(o) {
var F = function() {};
F.prototype = o;
return new F();
};
var O = Y.Object,
/**
* Extracts the keys, values, or size from an object
*
* @method _extract
* @param o the object
* @param what what to extract (0: keys, 1: values, 2: size)
* @return {boolean|Array} the extracted info
* @private
*/
_extract = function(o, what) {
var count = (what === 2), out = (count) ? 0 : [], i;
for (i in o) {
if (count) {
out++;
} else {
if (o.hasOwnProperty(i)) {
out.push((what) ? o[i] : i);
}
}
}
return out;
};
/**
* Returns an array containing the object's keys
* @TODO use native Object.keys() if available
* @method Object.keys
* @static
* @param o an object
* @return {string[]} the keys
*/
O.keys = function(o) {
return _extract(o);
};
/**
* Returns an array containing the object's values
* @TODO use native Object.values() if available
* @method Object.values
* @static
* @param o an object
* @return {Array} the values
*/
O.values = function(o) {
return _extract(o, 1);
};
/**
* Returns the size of an object
* @TODO use native Object.size() if available
* @method Object.size
* @static
* @param o an object
* @return {int} the size
*/
O.size = function(o) {
return _extract(o, 2);
};
/**
* Returns true if the object contains a given key
* @method Object.hasKey
* @static
* @param o an object
* @param k the key to query
* @return {boolean} true if the object contains the key
*/
O.hasKey = function(o, k) {
// return (o.hasOwnProperty(k));
return (k in o);
};
/**
* Returns true if the object contains a given value
* @method Object.hasValue
* @static
* @param o an object
* @param v the value to query
* @return {boolean} true if the object contains the value
*/
O.hasValue = function(o, v) {
return (Y.Array.indexOf(O.values(o), v) > -1);
};
/**
* Determines whether or not the property was added
* to the object instance. Returns false if the property is not present
* in the object, or was inherited from the prototype.
*
* @deprecated Safari 1.x support has been removed, so this is simply a
* wrapper for the native implementation. Use the native implementation
* directly instead.
*
* @TODO Remove in B1
*
* @method Object.owns
* @static
* @param o {any} The object being testing
* @param p {string} the property to look for
* @return {boolean} true if the object has the property on the instance
*/
O.owns = O.hasKey;
/**
* Executes a function on each item. The function
* receives the value, the key, and the object
* as paramters (in that order).
* @method Object.each
* @static
* @param o the object to iterate
* @param f {function} the function to execute
* @param c the execution context
* @param proto {boolean} include proto
* @return {YUI} the YUI instance
*/
O.each = function (o, f, c, proto) {
var s = c || Y, i;
for (i in o) {
if (proto || o.hasOwnProperty(i)) {
f.call(s, o[i], i, o);
}
}
return Y;
};
/**
* Retrieves the sub value at the provided path,
* from the value object provided.
*
* @method getValue
* @param o The object from which to extract the property value
* @param path {Array} A path array, specifying the object traversal path
* from which to obtain the sub value.
* @return {Any} The value stored in the path, undefined if not found.
* Returns the source object if an empty path is provided.
*/
O.getValue = function (o, path) {
var p=Y.Array(path), l=p.length, i;
for (i=0; o !== undefined && i < l; i=i+1) {
o = o[p[i]];
}
return o;
};
/**
* Sets the sub-attribute value at the provided path on the
* value object. Returns the modified value object, or
* undefined if the path is invalid.
*
* @method setValue
* @param o The object on which to set the sub value.
* @param path {Array} A path array, specifying the object traversal path
* at which to set the sub value.
* @param val {Any} The new value for the sub-attribute.
* @return {Object} The modified object, with the new sub value set, or
* undefined, if the path was invalid.
*/
O.setValue = function(o, path, val) {
var p=Y.Array(path), leafIdx=p.length-1, i, ref=o;
if (leafIdx >= 0) {
for (i=0; ref !== undefined && i < leafIdx; i=i+1) {
ref = ref[p[i]];
}
if (ref !== undefined) {
ref[p[i]] = val;
} else {
return undefined;
}
}
return o;
};
})();
/**
* YUI user agent detection.
* Do not fork for a browser if it can be avoided. Use feature detection when
* you can. Use the user agent as a last resort. UA stores a version
* number for the browser engine, 0 otherwise. This value may or may not map
* to the version number of the browser using the engine. The value is
* presented as a float so that it can easily be used for boolean evaluation
* as well as for looking for a particular range of versions. Because of this,
* some of the granularity of the version info may be lost (e.g., Gecko 1.8.0.9
* reports 1.8).
* @class UA
* @static
*/
Y.UA = function() {
var o={
/**
* Internet Explorer version number or 0. Example: 6
* @property ie
* @type float
* @static
*/
ie:0,
/**
* Opera version number or 0. Example: 9.2
* @property opera
* @type float
* @static
*/
opera:0,
/**
* Gecko engine revision number. Will evaluate to 1 if Gecko
* is detected but the revision could not be found. Other browsers
* will be 0. Example: 1.8
* <pre>
* Firefox 1.0.0.4: 1.7.8 <-- Reports 1.7
* Firefox 1.5.0.9: 1.8.0.9 <-- Reports 1.8
* Firefox 2.0.0.3: 1.8.1.3 <-- Reports 1.8
* Firefox 3 alpha: 1.9a4 <-- Reports 1.9
* </pre>
* @property gecko
* @type float
* @static
*/
gecko:0,
/**
* AppleWebKit version. KHTML browsers that are not WebKit browsers
* will evaluate to 1, other browsers 0. Example: 418.9
* <pre>
* Safari 1.3.2 (312.6): 312.8.1 <-- Reports 312.8 -- currently the
* latest available for Mac OSX 10.3.
* Safari 2.0.2: 416 <-- hasOwnProperty introduced
* Safari 2.0.4: 418 <-- preventDefault fixed
* Safari 2.0.4 (419.3): 418.9.1 <-- One version of Safari may run
* different versions of webkit
* Safari 2.0.4 (419.3): 419 <-- Tiger installations that have been
* updated, but not updated
* to the latest patch.
* Webkit 212 nightly: 522+ <-- Safari 3.0 precursor (with native SVG
* and many major issues fixed).
* Safari 3.0.4 (523.12) 523.12 <-- First Tiger release - automatic update
* from 2.x via the 10.4.11 OS patch
*
* </pre>
* http://en.wikipedia.org/wiki/Safari_(web_browser)#Version_history
* @property webkit
* @type float
* @static
*/
webkit:0,
/**
* The mobile property will be set to a string containing any relevant
* user agent information when a modern mobile browser is detected.
* Currently limited to Safari on the iPhone/iPod Touch, Nokia N-series
* devices with the WebKit-based browser, and Opera Mini.
* @property mobile
* @type string
* @static
*/
mobile: null
},
ua = navigator.userAgent, m;
// Modern KHTML browsers should qualify as Safari X-Grade
if ((/KHTML/).test(ua)) {
o.webkit=1;
}
// Modern WebKit browsers are at least X-Grade
m=ua.match(/AppleWebKit\/([^\s]*)/);
if (m&&m[1]) {
o.webkit=parseFloat(m[1]);
// Mobile browser check
if (/ Mobile\//.test(ua)) {
o.mobile = "Apple"; // iPhone or iPod Touch
} else {
m=ua.match(/NokiaN[^\/]*/);
if (m) {
o.mobile = m[0]; // Nokia N-series, ex: NokiaN95
}
}
}
if (!o.webkit) { // not webkit
// @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr)
m=ua.match(/Opera[\s\/]([^\s]*)/);
if (m&&m[1]) {
o.opera=parseFloat(m[1]);
m=ua.match(/Opera Mini[^;]*/);
if (m) {
o.mobile = m[0]; // ex: Opera Mini/2.0.4509/1316
}
} else { // not opera or webkit
m=ua.match(/MSIE\s([^;]*)/);
if (m&&m[1]) {
o.ie=parseFloat(m[1]);
} else { // not opera, webkit, or ie
m=ua.match(/Gecko\/([^\s]*)/);
if (m) {
o.gecko=1; // Gecko detected, look for revision
m=ua.match(/rv:([^\s\)]*)/);
if (m&&m[1]) {
o.gecko=parseFloat(m[1]);
}
}
}
}
}
return o;
}();
(function() {
var L = Y.Lang,
/**
* Executes the supplied function in the context of the supplied
* object 'when' milliseconds later. Executes the function a
* single time unless periodic is set to true.
* @method later
* @for YUI
* @param when {int} the number of milliseconds to wait until the fn
* is executed.
* @param o the context object.
* @param fn {Function|String} the function to execute or the name of
* the method in the 'o' object to execute.
* @param data [Array] data that is provided to the function. This accepts
* either a single item or an array. If an array is provided, the
* function is executed with one parameter for each array item. If
* you need to pass a single array parameter, it needs to be wrapped in
* an array [myarray].
* @param periodic {boolean} if true, executes continuously at supplied
* interval until canceled.
* @return {object} a timer object. Call the cancel() method on this object to
* stop the timer.
*/
later = function(when, o, fn, data, periodic) {
when = when || 0;
o = o || {};
var m=fn, d=data, f, r;
if (L.isString(fn)) {
m = o[fn];
}
if (!m) {
Y.error("method undefined");
}
if (!L.isArray(d)) {
d = [data];
}
f = function() {
m.apply(o, d);
};
r = (periodic) ? setInterval(f, when) : setTimeout(f, when);
return {
interval: periodic,
cancel: function() {
if (this.interval) {
clearInterval(r);
} else {
clearTimeout(r);
}
}
};
};
Y.later = later;
L.later = later;
})();
(function() {
// var min = ['yui-base', 'log', 'lang', 'array', 'core'], core, C = Y.config;
var min = ['yui-base'], core, C = Y.config;
// apply the minimal required functionality
Y.use.apply(Y, min);
if (C.core) {
core = C.core;
} else {
// core = ["object", "ua", "later"];
// core.push("get", "loader");
core = ["get", "loader"];
}
Y.use.apply(Y, core);
})();
}, '@VERSION@' );