yui.js revision 82c2b86968ca03bd7f27803809a28f05799ff06f
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp(function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var _instances = {},
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _startTime = new Date().getTime(),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp p,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp i,
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp add = function () {
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (window.addEventListener) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp return function(el, type, fn, capture) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp el.addEventListener(type, fn, (!!capture));
a89ad754cce3cfc8aee71760e10217b54020360dTripp };
a89ad754cce3cfc8aee71760e10217b54020360dTripp } else if (window.attachEvent) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp return function(el, type, fn) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp el.attachEvent("on" + type, fn);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } else {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return function(){};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }(),
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp remove = function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (window.removeEventListener) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return function (el, type, fn, capture) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp el.removeEventListener(type, fn, !!capture);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } else if (window.detachEvent) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return function (el, type, fn) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp el.detachEvent("on" + type, fn);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } else {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return function(){};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }(),
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp globalListener = function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp YUI.Env.windowLoaded = true;
a89ad754cce3cfc8aee71760e10217b54020360dTripp YUI.Env.DOMReady = true;
a89ad754cce3cfc8aee71760e10217b54020360dTripp remove(window, 'load', globalListener);
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp// @TODO: this needs to be created at build time from module metadata
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp _APPLY_TO_WHITE_LIST = {
a89ad754cce3cfc8aee71760e10217b54020360dTripp 'io.xdrReady': 1,
a89ad754cce3cfc8aee71760e10217b54020360dTripp 'io.start': 1,
a89ad754cce3cfc8aee71760e10217b54020360dTripp 'io.success': 1,
a89ad754cce3cfc8aee71760e10217b54020360dTripp 'io.failure': 1
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp SLICE = Array.prototype.slice;
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp// reduce to one or the other
a89ad754cce3cfc8aee71760e10217b54020360dTrippif (typeof YUI === 'undefined' || !YUI) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * The YUI global namespace object. If YUI is already defined, the
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * existing YUI object will not be overwritten so that defined
a89ad754cce3cfc8aee71760e10217b54020360dTripp * namespaces are preserved.
a89ad754cce3cfc8aee71760e10217b54020360dTripp *
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * @class YUI
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @constructor
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @global
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @uses EventTarget
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param o Optional configuration object. This object is stored
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * in YUI.config. See config for the list of supported properties.
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /*global YUI*/
a89ad754cce3cfc8aee71760e10217b54020360dTripp // Make a function, disallow direct instantiation
a89ad754cce3cfc8aee71760e10217b54020360dTripp YUI = function(o) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var Y = this;
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp // Allow instantiation without the new operator
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (!(Y instanceof YUI)) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp return new YUI(o);
a89ad754cce3cfc8aee71760e10217b54020360dTripp } else {
a89ad754cce3cfc8aee71760e10217b54020360dTripp // set up the core environment
a89ad754cce3cfc8aee71760e10217b54020360dTripp Y._init(o);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp // bind the specified additional modules for this instance
a89ad754cce3cfc8aee71760e10217b54020360dTripp Y._setup();
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp return Y;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp}
a89ad754cce3cfc8aee71760e10217b54020360dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp// The prototype contains the functions that are required to allow the external
a89ad754cce3cfc8aee71760e10217b54020360dTripp// modules to be registered and for the instance to be initialized.
a89ad754cce3cfc8aee71760e10217b54020360dTrippYUI.prototype = {
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Initialize this YUI instance
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param o config options
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @private
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _init: function(o) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o = o || {};
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp // find targeted window/frame
a89ad754cce3cfc8aee71760e10217b54020360dTripp // @TODO create facades
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var v = '@VERSION@', Y = this;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (v.indexOf('@') > -1) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp v = 'test';
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.version = v;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.Env = {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // @todo expand the new module metadata
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp mods: {},
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp cdn: 'http://yui.yahooapis.com/' + v + '/build/',
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp bootstrapped: false,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _idx: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _used: {},
a4d2446149b07f9e5c32947091dcbcf4d2eee765Tripp _attached: {},
a4d2446149b07f9e5c32947091dcbcf4d2eee765Tripp _yidx: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _uidx: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _loaded: {}
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o.win = o.win || window || {};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o.win = o.win.contentWindow || o.win;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o.doc = o.win.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
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o.base = o.base || function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var b, nodes, i, match;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // get from querystring
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp nodes = document.getElementsByTagName('script');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp for (i=0; i<nodes.length; i=i+1) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp match = nodes[i].src.match(/^(.*)yui\/yui[\.\-].*js(\?.*)?$/);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp b = match && match[1];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (b) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp break;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // use CDN default
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return b || Y.Env.cdn;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o.loaderPath = o.loaderPath || 'loader/loader-min.js';
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // add a reference to o for anything that needs it
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // before _setup is called.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.config = o;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.Env._loaded[v] = {};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (YUI.Env) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.Env._yidx = (++YUI.Env._yidx);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.Env._guidp = ('yui_' + v + '-' + Y.Env._yidx + '-' + _startTime).replace(/\./g, '_');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.id = Y.stamp(Y);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _instances[Y.id] = Y;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.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.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method applyTo
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param id {string} the YUI instance id
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param method {string} the name of the method to exectute.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Ex: 'Object.keys'
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param args {Array} the arguments to apply to the method
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return {object} the return value from the applied method or null
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
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) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp nest = method.split('.');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp m = instance;
a89ad754cce3cfc8aee71760e10217b54020360dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for (i=0; i<nest.length; i=i+1) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp m = m[nest[i]];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (!m) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.error('applyTo not found: ' + method);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return m.apply(instance, args);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return null;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Register a module
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method add
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param name {string} module name
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param fn {Function} entry point into the module that
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * is used to bind module to the YUI instance
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param version {string} version string
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param details optional config data:
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * requires - features that should be present before loading
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * optional - optional features that should be present if load optional defined
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * use - features that should be attached automatically
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * skinnable -
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * rollup
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * omit - features that should not be loaded if this module is present
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return {YUI} the YUI instance
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp add: function(name, fn, version, details) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // this.log('Adding a new component ' + name);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // @todo expand this to include version mapping
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // @todo may want to restore the build property
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // @todo fire moduleAvailable event
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // if (this.Lang.isFunction(fn)) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp YUI.Env.mods[name] = {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp name: name,
a89ad754cce3cfc8aee71760e10217b54020360dTripp fn: fn,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp version: version,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp details: details || {}
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // } else {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp //
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // var c = Y.config;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // c.modules = c.modules || {};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // c.modules[name] = c.modules[name] || fn;
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp // }
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp return this; // chain support
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _attach: function(r, fromLoader) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var mods = YUI.Env.mods,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp attached = this.Env._attached,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp i, l = r.length, name, m, d, req, use;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp for (i=0; i<l; i=i+1) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
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;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (req) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._attach(this.Array(req));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // this.log('attaching ' + name, 'info', 'yui');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (m.fn) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp m.fn(this);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (use) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._attach(this.Array(use));
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Bind a module to a YUI instance
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param modules* {string} 1-n modules to bind (uses arguments array)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param *callback {function} callback function executed when
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * the instance has the required functionality. If included, it
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * must be the last parameter.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @TODO
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Implement versioning? loader can load different versions?
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Should sub-modules/plugins be normal modules, or do
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * we add syntax for specifying these?
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * YUI().use('dragdrop')
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * YUI().use('dragdrop:2.4.0'); // specific version
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * YUI().use('dragdrop:2.4.0-'); // at least this version
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * YUI().use('dragdrop:2.4.0-2.9999.9999'); // version range
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * YUI().use('*'); // use all available modules
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * YUI().use('lang+dump+substitute'); // use lang and some plugins
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * YUI().use('lang+*'); // use lang and all known plugins
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return {YUI} the YUI instance
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp use: function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (this._loading) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._useQueue.add(SLICE.call(arguments, 0));
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var Y = this,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp a=SLICE.call(arguments, 0),
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp mods = YUI.Env.mods,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp used = Y.Env._used,
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp loader,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp firstArg = a[0],
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp dynamic = false,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp callback = a[a.length-1],
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp k, i, l, missing = [],
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp r = [],
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp f = function(name) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // only attach a module once
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (used[name]) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // Y.log(name + ' already used', 'info', 'yui');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var m = mods[name], j, req, use;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (m) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // Y.log('USING ' + name, 'info', 'yui');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp used[name] = true;
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp req = m.details.requires;
a89ad754cce3cfc8aee71760e10217b54020360dTripp use = m.details.use;
a89ad754cce3cfc8aee71760e10217b54020360dTripp } else {
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp // CSS files don't register themselves, see if it has been loaded
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (!YUI.Env._loaded[Y.version][name]) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp Y.log('module not found: ' + name, 'info', 'yui');
a89ad754cce3cfc8aee71760e10217b54020360dTripp missing.push(name);
a89ad754cce3cfc8aee71760e10217b54020360dTripp } else {
a89ad754cce3cfc8aee71760e10217b54020360dTripp // probably css
a89ad754cce3cfc8aee71760e10217b54020360dTripp // Y.log('module not found BUT HAS BEEN LOADED: ' + name, 'info', 'yui');
a89ad754cce3cfc8aee71760e10217b54020360dTripp used[name] = true;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp // make sure requirements are attached
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (req) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (Y.Lang.isString(req)) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp f(req);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp } else {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for (j = 0; j < req.length; j = j + 1) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // Y.log('using module\'s requirements: ' + name, 'info', 'yui');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp f(req[j]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // add this module to full list of things to attach
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // Y.log('adding to requires list: ' + name);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp r.push(name);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp onComplete = function(fromLoader) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // Y.log('Use complete');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp fromLoader = fromLoader || {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp success: true,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp msg: 'not dynamic'
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (Y.Env._callback) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var cb = Y.Env._callback;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.Env._callback = null;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp cb(Y, fromLoader);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (Y.fire) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.fire('yui:load', Y, fromLoader);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // process queued use requests as long until done
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // or dynamic load happens again.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._loading = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp while (this._useQueue && this._useQueue.size() && !this._loading) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.use.apply(Y, this._useQueue.next());
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // Y.log(Y.id + ': use called: ' + a + ' :: ' + callback);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // The last argument supplied to use can be a load complete callback
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (typeof callback === 'function') {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp a.pop();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.Env._callback = callback;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } else {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp callback = null;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // YUI().use('*'); // bind everything available
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (firstArg === "*") {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp a = [];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for (k in mods) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (mods.hasOwnProperty(k)) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp a.push(k);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // Y.log('Use *: ' + a);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return Y.use.apply(Y, a);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // Y.log('loader before: ' + a.join(','));
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // use loader to expand dependencies and sort the
a89ad754cce3cfc8aee71760e10217b54020360dTripp // requirements if it is available.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (Y.Loader) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp dynamic = true;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._useQueue = this._useQueue || new Y.Queue();
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 // Y.log('loader after: ' + a.join(','));
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp l = a.length;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // process each requirement and any additional requirements
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // the module metadata specifies
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for (i=0; i<l; i=i+1) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp f(a[i]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // Y.log('all reqs: ' + r + ' --- missing: ' + missing + ', l: ' + l + ', ' + r[0]);
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // dynamic load
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (Y.Loader && missing.length) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.log('Attempting to dynamically load the missing modules ' + missing, 'info', 'yui');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._loading = true;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader = new Y.Loader(Y.config);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.onSuccess = onComplete;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.onFailure = onComplete;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.onTimeout = onComplete;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.attaching = a;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.require(missing);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loader.insert();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp } else if (Y.Get && missing.length && !Y.Env.bootstrapped) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.log('fetching loader: ' + Y.config.base + Y.config.loaderPath);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp a = Y.Array(arguments, 0, true);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // a.unshift('loader');
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.Get.script(Y.config.base + Y.config.loaderPath, {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp onEnd: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.Env.bootstrapped = true;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y._attach(['loader']);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.use.apply(Y, a);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp });
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return Y;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp } else {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y._attach(r);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp onComplete();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp return Y; // chain support var yui = YUI().use('dragdrop');
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp },
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp /**
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * Returns the namespace specified and creates it if it doesn't exist
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * <pre>
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * YUI.namespace("property.package");
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * YUI.namespace("YAHOO.property.package");
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * </pre>
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * Either of the above would create YUI.property, then
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * YUI.property.package (YAHOO is scrubbed out, this is
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * to remain compatible with YUI2)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
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
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp *
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp * @method namespace
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {string*} arguments 1-n namespaces to create
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return {object} A reference to the last namespace object created
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
9eaaa502227248d304ac9170902697d02158c1d9Tripp namespace: function() {
9eaaa502227248d304ac9170902697d02158c1d9Tripp var a=arguments, o=null, i, j, d;
9eaaa502227248d304ac9170902697d02158c1d9Tripp for (i=0; i<a.length; i=i+1) {
9eaaa502227248d304ac9170902697d02158c1d9Tripp d = ("" + a[i]).split(".");
9eaaa502227248d304ac9170902697d02158c1d9Tripp o = this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for (j=(d[0] == "YAHOO") ? 1 : 0; j<d.length; j=j+1) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp o[d[j]] = o[d[j]] || {};
4ef2f7e4cb7c7d255be077c47d542199f7bf8607Tripp o = o[d[j]];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return o;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // this is replaced if the log module is included
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp log: function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Report an error. The reporting mechanism is controled by
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * the 'throwFail' configuration attribute. If throwFail is
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * not specified, the message is written to the Logger, otherwise
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * a JS error is thrown
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method error
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param msg {string} the error message
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param e {Error} Optional JS error that was caught. If supplied
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * and throwFail is specified, this error will be re-thrown.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return {YUI} this YUI instance
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp error: function(msg, e) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (this.config.throwFail) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp throw (e || new Error(msg));
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } else {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.message(msg, "error"); // don't scrub this one
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Generate an id that is unique among all YUI instances
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method guid
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param pre {string} optional guid prefix
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return {string} the guid
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp guid: function(pre) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var id = this.Env._guidp + (++this.Env._uidx);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return (pre) ? (pre + id) : id;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Returns a guid associated with an object. If the object
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * does not have one, a new one is created unless readOnly
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * is specified.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method stamp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param o The object to stamp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param readOnly {boolean} if true, a valid guid will only
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * be returned if the object has one assigned to it.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return {string} The object's guid or null
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp stamp: function(o, readOnly) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (!o) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return o;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var uid = (typeof o === 'string') ? o : o._yuid;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (!uid) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp uid = this.guid();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (!readOnly) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp try {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp o._yuid = uid;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } catch(e) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp uid = null;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return uid;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp// Give the YUI global the same properties as an instance.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp// This makes it so that the YUI global can be used like the YAHOO
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp// global was used prior to 3.x. More importantly, the YUI global
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp// provides global metadata, so env needs to be configured.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp// @TODO review
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp p = YUI.prototype;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // inheritance utilities are not available yet
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp for (i in p) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // if (1) { // intenionally ignoring hasOwnProperty check
a89ad754cce3cfc8aee71760e10217b54020360dTripp YUI[i] = p[i];
a89ad754cce3cfc8aee71760e10217b54020360dTripp // }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
// set up the environment
YUI._init();
// add a window load event at load time so we can capture
// the case where it fires before dynamic loading is
// complete.
add(window, 'load', globalListener);
YUI.Env.add = add;
YUI.Env.remove = remove;
/*
* Subscribe to an event. The signature differs depending on the
* type of event you are attaching to.
* @method on
* @param type {string|function|object} The type of the event. If
* this is a function, this is dispatched to the aop system. If an
* object, it is parsed for multiple subsription definitions
* @param fn {Function} The callback
* @param elspec {any} DOM element(s), selector string(s), and or
* Node ref(s) to attach DOM related events to (only applies to
* DOM events).
* @param
* @return the event target or a detach handle per 'chain' config
*/
})();
/**
* The config object contains all of the configuration options for
* the YUI instance. This object is supplied by the implementer
* when instantiating a YUI instance. Some properties have default
* values if they are not supplied by the implementer.
*
* @class config
* @static
*/
/**
* Turn debug statements on or off.
*
* @property debug
* @type boolean
* @default true
*/
/**
* Log to the browser console if debug is on and the browser has a
* supported console.
*
* @property useBrowserConsole
* @type boolean
* @default true
*/
/**
* A hash of log sources that should be logged. If specified, only log messages from these sources will be logged.
*
* @property logInclude
* @type object
*/
/**
* A hash of log sources that should be not be logged. If specified, all sources are logged if not on this list.
*
* @property logExclude
* @type object
*/
/**
* Set to true if the yui seed file was dynamically loaded in
* order to bootstrap components relying on the window load event
* and the 'domready' custom event.
*
* @property injected
* @type object
*/
/**
* If throwFail is set, Y.fail will generate or re-throw a JS Error. Otherwise the failure is logged.
*
* @property throwFail
* @type boolean
* @default true
*/
/**
* The window/frame that this instance should operate in.
*
* @property win
* @type Window
* @default the window hosting YUI
*/
/**
* The document associated with the 'win' configuration.
*
* @property doc
* @type Document
* @default the document hosting YUI
*/
/**
* A list of modules that defines the YUI core (overrides the default).
*
* @property core
* @type string[]
*/
/**
* The default date format
*
* @property dateFormat
* @type string
*/
/**
* The default locale
*
* @property locale
* @type string
*/
/**
* The default interval when polling in milliseconds.
*
* @property pollInterval
* @type int
* @default 20
*/
/**
* The number of dynamic nodes to insert by default before
* automatically removing them. This applies to script nodes
* because remove the node will not make the evaluated script
* unavailable. Dynamic CSS is not auto purged, because removing
* a linked style sheet will also remove the style definitions.
*
* @property purgethreshold
* @type int
* @default 20
*/
/**
* The default interval when polling in milliseconds.
*
* @property windowResizeDelay
* @type int
* @default 40
*/
/**
* Base directory for dynamic loading
*
* @property base
* @type string
*/
/**
* The secure base dir (not implemented)
*
* For dynamic loading.
*
* @property secureBase
* @type string
*/
/**
* The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?
*
* For dynamic loading.
*
* @property comboBase
* @type string
*/
/**
* The root path to prepend to module names for the combo service. Ex: 3.0.0b1/build/
*
* For dynamic loading.
*
* @property root
* @type string
*/
/**
* A filter to apply to result urls. This filter will modify the default
* path for all modules. The default path for the YUI library is the
* minified version of the files (e.g., event-min.js). The filter property
* can be a predefined filter or a custom filter. The valid predefined
* filters are:
* <dl>
* <dt>DEBUG</dt>
* <dd>Selects the debug versions of the library (e.g., event-debug.js).
* This option will automatically include the Logger widget</dd>
* <dt>RAW</dt>
* <dd>Selects the non-minified version of the library (e.g., event.js).</dd>
* </dl>
* You can also define a custom filter, which must be an object literal
* containing a search expression and a replace string:
* <pre>
* myFilter: &#123;
* 'searchExp': "-min\\.js",
* 'replaceStr': "-debug.js"
* &#125;
* </pre>
*
* For dynamic loading.
*
* @property filter
* @type string|object
*/
/**
* Hash of per-component filter specification. If specified for a given component,
* this overrides the filter config
*
* For dynamic loading.
*
* @property filters
* @type object
*/
/**
* Use the YUI combo service to reduce the number of http connections
* required to load your dependencies.
*
* For dynamic loading.
*
* @property combine
* @type boolean
* @default true if 'base' is not supplied, false if it is.
*/
/**
* A list of modules that should never be dynamically loaded
*
* @property ignore
* @type string[]
*/
/**
* A list of modules that should always be loaded when required, even if already
* present on the page.
*
* @property force
* @type string[]
*/
/**
* Node or id for a node that should be used as the insertion point for new nodes
* For dynamic loading.
*
* @property insertBefore
* @type string
*/
/**
* charset for dynamic nodes
*
* @property charset
* @type string
* @deprecated use jsAttributes cssAttributes
*/
/**
* Object literal containing attributes to add to dynamically loaded script nodes.
*
* @property jsAttributes
* @type string
*/
/**
* Object literal containing attributes to add to dynamically loaded link nodes.
*
* @property cssAttributes
* @type string
*/
/**
* Number of milliseconds before a timeout occurs when dynamically
* loading nodes. If not set, there is no timeout.
*
* @property timeout
* @type int
*/
/**
* Callback for the 'CSSComplete' event. When dynamically loading YUI
* components with CSS, this property fires when the CSS is finished
* loading but script loading is still ongoing. This provides an
* opportunity to enhance the presentation of a loading page a little
* bit before the entire loading process is done.
*
* @property onCSS
* @type function
*/
/**
* A list of module definitions to add to the list of YUI components.
* These components can then be dynamically loaded side by side with
* YUI via the use() method.See Loader.addModule for the supported
* module metadata.
*
* @property modules
* @type function
*/
/**
* The loader 'path' attribute to the loader itself. This is combined
* with the 'base' attribute to dynamically load the loader component
* when boostrapping with the get utility alone.
*
* @property loaderPath
* @default loader/loader-min.js
*/