| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- /*
- Copyright (c) 2010, Yahoo! Inc. All rights reserved.
- Code licensed under the BSD License:
- http://developer.yahoo.com/yui/license.html
- version: 3.4.0
- build: nightly
- */
- YUI.add('rls', function(Y) {
-
- /**
- * RLS (Remote Loader Service) Support
- * @module yui
- * @submodule rls
- * @class rls
- */
-
-
- Y.rls_handleTimeout = function(o) {
- Y.Get.abort(o.tId);
- o.purge();
- o.message = 'RLS request timed out, fetching loader';
- Y.rls_failure(o);
- };
-
- Y.rls_handleFailure = function(o) {
- o.message = 'RLS request failed, fetching loader';
- Y.rls_failure(o);
- };
-
- Y.rls_failure = function(o) {
- YUI.Env.rls_disabled = true;
- Y.config.use_rls = false;
- if (o.data) {
- o.data.unshift('loader');
- Y._use(o.data, function(Y, response) {
- Y._notify(Y.rls_callback, response, o.data);
- //Call the RLS done method, so it can progress the queue
- Y.rls_advance();
- });
- }
- };
-
- /**
- * Checks the environment for local modules and deals with them before firing off an RLS request.
- * This needs to make sure that all dependencies are calculated before it can make an RLS request in
- * order to make sure all remote dependencies are evaluated and their requirements are met.
- * @method rls_locals
- * @private
- * @param {YUI} instance The YUI Instance we are working with.
- * @param {Array} argz The requested modules.
- * @param {Callback} cb The callback to be executed when we are done
- * @param {YUI} cb.instance The instance is passed back to the callback
- * @param {Array} cb.argz The modified list or modules needed to require
- */
- Y.rls_locals = function(instance, argz, cb) {
- if (YUI.Env.rls_disabled) {
- var data = {
- message: 'RLS is disabled, moving to loader',
- data: argz
- };
- Y.rls_failure(data);
- return;
- }
- if (instance.config.modules) {
- var files = [], asked = Y.Array.hash(argz),
- PATH = 'fullpath', f,
- mods = instance.config.modules;
-
- for (f in mods) {
- if (mods[f][PATH]) {
- if (asked[f]) {
- files.push(mods[f][PATH]);
- if (mods[f].requires) {
- Y.Array.each(mods[f].requires, function(f) {
- if (!YUI.Env.mods[f]) {
- if (mods[f]) {
- if (mods[f][PATH]) {
- files.push(mods[f][PATH]);
- argz.push(f);
- }
- }
- }
- });
- }
- }
- }
- }
- if (files.length) {
- Y.Get.script(files, {
- onEnd: function(o) {
- cb(instance, argz);
- },
- data: argz
- });
- } else {
- cb(instance, argz);
- }
- } else {
- cb(instance, argz);
- }
- };
-
-
- /**
- * Check the environment and the local config to determine if a module has already been registered.
- * @method rls_needs
- * @private
- * @param {String} mod The module to check
- * @param {YUI} instance The instance to check against.
- */
- Y.rls_needs = function(mod, instance) {
- var self = instance || this,
- config = self.config, i,
- m = YUI.Env.aliases[mod];
-
- if (m) {
- for (i = 0; i < m.length; i++) {
- if (Y.rls_needs(m[i])) {
- return true;
- }
- }
- return false;
- }
-
- if (!YUI.Env.mods[mod] && !(config.modules && config.modules[mod])) {
- return true;
- }
- return false;
- };
-
- /**
- * Implentation for building the remote loader service url.
- * @method _rls
- * @private
- * @param {Array} what the requested modules.
- * @since 3.2.0
- * @return {string} the url for the remote loader service call, returns false if no modules are required to be fetched (they are in the ENV already).
- */
- Y._rls = function(what) {
- //what.push('intl');
- var config = Y.config,
- mods = config.modules,
- YArray = Y.Array,
- YObject = Y.Object,
-
- // the configuration
- rls = config.rls || {
- m: 1, // required in the template
- v: Y.version,
- gv: config.gallery,
- env: 1, // required in the template
- lang: config.lang,
- '2in3v': config['2in3'],
- '2v': config.yui2,
- filt: config.filter,
- filts: config.filters,
- ignore: config.ignore,
- tests: 1 // required in the template
- },
- // The rls base path
- rls_base = config.rls_base || 'http://loader.yahooapis.com/v1/load?',
-
- // the template
- rls_tmpl = config.rls_tmpl || function() {
- var s = [], param;
- for (param in rls) {
- if (param in rls && rls[param]) {
- s.push(param + '={' + param + '}');
- }
- }
- return s.join('&');
- }(),
- m = [], asked = {}, o, d, mod, a, j,
- w = [],
- i, len = what.length,
- url;
-
- //Explode our aliases..
- for (i = 0; i < len; i++) {
- a = YUI.Env.aliases[what[i]];
- if (a) {
- for (j = 0; j < a.length; j++) {
- w.push(a[j]);
- }
- } else {
- w.push(what[i]);
- }
-
- }
- what = w;
- len = what.length;
-
-
- for (i = 0; i < len; i++) {
- asked[what[i]] = 1;
- if (Y.rls_needs(what[i])) {
- m.push(what[i]);
- } else {
- }
- }
-
- if (mods) {
- for (i in mods) {
- if (asked[i] && mods[i].requires && !mods[i].noop) {
- len = mods[i].requires.length;
- for (o = 0; o < len; o++) {
- mod = mods[i].requires[o];
- if (Y.rls_needs(mod)) {
- m.push(mod);
- } else {
- d = YUI.Env.mods[mod] || mods[mod];
- if (d) {
- d = d.details || d;
- if (!d.noop) {
- if (d.requires) {
- YArray.each(d.requires, function(o) {
- if (Y.rls_needs(o)) {
- m.push(o);
- }
- });
- }
- }
- }
- }
- }
- }
- }
- }
-
- YObject.each(YUI.Env.mods, function(i) {
- if (asked[i.name]) {
- if (i.details && i.details.requires) {
- if (!i.noop) {
- YArray.each(i.details.requires, function(o) {
- if (Y.rls_needs(o)) {
- m.push(o);
- }
- });
- }
- }
- }
- });
-
- function addIfNeeded(module) {
- if (Y.rls_needs(module)) {
- m.unshift(module);
- }
- }
-
- //Add in the debug modules
- if (rls.filt === 'debug') {
- YArray.each(['dump', 'yui-log'], addIfNeeded);
- }
- //If they have a groups config, add the loader-base module
- if (Y.config.groups) {
- addIfNeeded('loader-base');
- }
-
- m = YArray.dedupe(m);
-
- //Strip Duplicates
- m = YArray.dedupe(m);
- what = YArray.dedupe(what);
-
- if (!m.length) {
- //Return here if there no modules to load.
- return false;
- }
- // update the request
- rls.m = m.sort(); // cache proxy optimization
- rls.env = [].concat(YObject.keys(YUI.Env.mods), YArray.dedupe(YUI._rls_skins)).sort();
- rls.tests = Y.Features.all('load', [Y]);
-
- url = Y.Lang.sub(rls_base + rls_tmpl, rls);
-
- config.rls = rls;
- config.rls_tmpl = rls_tmpl;
-
- YUI._rls_active = {
- asked: what,
- attach: m,
- inst: Y,
- url: url
- };
- return url;
- };
-
- /**
- *
- * @method rls_oncomplete
- * @param {Callback} cb The callback to execute when the RLS request is complete
- */
- Y.rls_oncomplete = function(cb) {
- YUI._rls_active.cb = cb;
- };
-
- Y.rls_advance = function() {
- var G_ENV = YUI.Env;
-
- G_ENV._rls_in_progress = false;
- if (G_ENV._rls_queue.size()) {
- G_ENV._rls_queue.next()();
- }
- };
-
- /**
- * Calls the callback registered with Y.rls_oncomplete when the RLS request (and it's dependency requests) is done.
- * @method rls_done
- * @param {Array} data The modules loaded
- */
- Y.rls_done = function(data) {
- data.success = true;
- YUI._rls_active.cb(data);
- };
-
- /**
- * Hash to hang on to the calling RLS instance so we can deal with the return from the server.
- * @property _rls_active
- * @private
- * @type Object
- * @static
- */
- if (!YUI._rls_active) {
- YUI._rls_active = {};
- }
-
- /**
- * An array of skins loaded via RLS to populate the ENV with when making future requests.
- * @property _rls_skins
- * @private
- * @type Array
- * @static
- */
- if (!YUI._rls_skins) {
- YUI._rls_skins = [];
- }
-
- /**
- *
- * @method $rls
- * @private
- * @static
- * @param {Object} req The data returned from the RLS server
- * @param {String} req.css Does this request need CSS? If so, load the same RLS url with &css=1 attached
- * @param {Array} req.module The sorted list of modules to attach to the page.
- */
- if (!YUI.$rls) {
- YUI.$rls = function(req) {
- var rls_active = YUI._rls_active,
- Y = rls_active.inst;
- if (Y) {
- if (req.error) {
- if (!req.missing) {
- req.missing = [];
- }
- Y.rls_failure({
- message: req.error,
- data: [].concat(req.modules, req.missing)
- });
- }
- if (YUI.Env && YUI.Env.rls_disabled) {
- return;
- }
- if (req.css && Y.config.fetchCSS) {
- Y.Get.css(rls_active.url + '&css=1');
- }
- if (req.modules && !req.css) {
- if (req.modules.length) {
- var loadInt = Y.Array.some(req.modules, function(v) {
- return (v.indexOf('lang') === 0);
- });
- if (loadInt) {
- req.modules.unshift('intl');
- }
- }
-
- Y.Env.bootstrapped = true;
- Y.Array.each(req.modules, function(v) {
- if (v.indexOf('skin-') > -1) {
- YUI._rls_skins.push(v);
- }
- });
-
- Y._attach([].concat(req.modules, rls_active.asked));
-
- var additional = req.missing;
-
- if (Y.config.groups) {
- if (!additional) {
- additional = [];
- }
- additional = [].concat(additional, rls_active.what);
- }
-
- if (additional && Y.Loader) {
- var loader = new Y.Loader(rls_active.inst.config);
- loader.onEnd = Y.rls_done;
- loader.context = Y;
- loader.data = additional;
- loader.ignoreRegistered = false;
- loader.require(additional);
- loader.insert(null, (Y.config.fetchCSS) ? null : 'js');
- } else {
- Y.rls_done({ data: req.modules });
- }
- }
- }
- };
- }
-
-
- }, '3.4.0' ,{requires:['get','features']});
|