Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /*
  2. Copyright (c) 2010, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.com/yui/license.html
  5. version: 3.4.0
  6. build: nightly
  7. */
  8. YUI.add('rls', function(Y) {
  9. /**
  10. * RLS (Remote Loader Service) Support
  11. * @module yui
  12. * @submodule rls
  13. * @class rls
  14. */
  15. Y.rls_handleTimeout = function(o) {
  16. Y.Get.abort(o.tId);
  17. o.purge();
  18. o.message = 'RLS request timed out, fetching loader';
  19. Y.rls_failure(o);
  20. };
  21. Y.rls_handleFailure = function(o) {
  22. o.message = 'RLS request failed, fetching loader';
  23. Y.rls_failure(o);
  24. };
  25. Y.rls_failure = function(o) {
  26. YUI.Env.rls_disabled = true;
  27. Y.config.use_rls = false;
  28. if (o.data) {
  29. o.data.unshift('loader');
  30. Y._use(o.data, function(Y, response) {
  31. Y._notify(Y.rls_callback, response, o.data);
  32. //Call the RLS done method, so it can progress the queue
  33. Y.rls_advance();
  34. });
  35. }
  36. };
  37. /**
  38. * Checks the environment for local modules and deals with them before firing off an RLS request.
  39. * This needs to make sure that all dependencies are calculated before it can make an RLS request in
  40. * order to make sure all remote dependencies are evaluated and their requirements are met.
  41. * @method rls_locals
  42. * @private
  43. * @param {YUI} instance The YUI Instance we are working with.
  44. * @param {Array} argz The requested modules.
  45. * @param {Callback} cb The callback to be executed when we are done
  46. * @param {YUI} cb.instance The instance is passed back to the callback
  47. * @param {Array} cb.argz The modified list or modules needed to require
  48. */
  49. Y.rls_locals = function(instance, argz, cb) {
  50. if (YUI.Env.rls_disabled) {
  51. var data = {
  52. message: 'RLS is disabled, moving to loader',
  53. data: argz
  54. };
  55. Y.rls_failure(data);
  56. return;
  57. }
  58. if (instance.config.modules) {
  59. var files = [], asked = Y.Array.hash(argz),
  60. PATH = 'fullpath', f,
  61. mods = instance.config.modules;
  62. for (f in mods) {
  63. if (mods[f][PATH]) {
  64. if (asked[f]) {
  65. files.push(mods[f][PATH]);
  66. if (mods[f].requires) {
  67. Y.Array.each(mods[f].requires, function(f) {
  68. if (!YUI.Env.mods[f]) {
  69. if (mods[f]) {
  70. if (mods[f][PATH]) {
  71. files.push(mods[f][PATH]);
  72. argz.push(f);
  73. }
  74. }
  75. }
  76. });
  77. }
  78. }
  79. }
  80. }
  81. if (files.length) {
  82. Y.Get.script(files, {
  83. onEnd: function(o) {
  84. cb(instance, argz);
  85. },
  86. data: argz
  87. });
  88. } else {
  89. cb(instance, argz);
  90. }
  91. } else {
  92. cb(instance, argz);
  93. }
  94. };
  95. /**
  96. * Check the environment and the local config to determine if a module has already been registered.
  97. * @method rls_needs
  98. * @private
  99. * @param {String} mod The module to check
  100. * @param {YUI} instance The instance to check against.
  101. */
  102. Y.rls_needs = function(mod, instance) {
  103. var self = instance || this,
  104. config = self.config, i,
  105. m = YUI.Env.aliases[mod];
  106. if (m) {
  107. for (i = 0; i < m.length; i++) {
  108. if (Y.rls_needs(m[i])) {
  109. return true;
  110. }
  111. }
  112. return false;
  113. }
  114. if (!YUI.Env.mods[mod] && !(config.modules && config.modules[mod])) {
  115. return true;
  116. }
  117. return false;
  118. };
  119. /**
  120. * Implentation for building the remote loader service url.
  121. * @method _rls
  122. * @private
  123. * @param {Array} what the requested modules.
  124. * @since 3.2.0
  125. * @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).
  126. */
  127. Y._rls = function(what) {
  128. //what.push('intl');
  129. var config = Y.config,
  130. mods = config.modules,
  131. YArray = Y.Array,
  132. YObject = Y.Object,
  133. // the configuration
  134. rls = config.rls || {
  135. m: 1, // required in the template
  136. v: Y.version,
  137. gv: config.gallery,
  138. env: 1, // required in the template
  139. lang: config.lang,
  140. '2in3v': config['2in3'],
  141. '2v': config.yui2,
  142. filt: config.filter,
  143. filts: config.filters,
  144. ignore: config.ignore,
  145. tests: 1 // required in the template
  146. },
  147. // The rls base path
  148. rls_base = config.rls_base || 'http://loader.yahooapis.com/v1/load?',
  149. // the template
  150. rls_tmpl = config.rls_tmpl || function() {
  151. var s = [], param;
  152. for (param in rls) {
  153. if (param in rls && rls[param]) {
  154. s.push(param + '={' + param + '}');
  155. }
  156. }
  157. return s.join('&');
  158. }(),
  159. m = [], asked = {}, o, d, mod, a, j,
  160. w = [],
  161. i, len = what.length,
  162. url;
  163. //Explode our aliases..
  164. for (i = 0; i < len; i++) {
  165. a = YUI.Env.aliases[what[i]];
  166. if (a) {
  167. for (j = 0; j < a.length; j++) {
  168. w.push(a[j]);
  169. }
  170. } else {
  171. w.push(what[i]);
  172. }
  173. }
  174. what = w;
  175. len = what.length;
  176. for (i = 0; i < len; i++) {
  177. asked[what[i]] = 1;
  178. if (Y.rls_needs(what[i])) {
  179. m.push(what[i]);
  180. } else {
  181. }
  182. }
  183. if (mods) {
  184. for (i in mods) {
  185. if (asked[i] && mods[i].requires && !mods[i].noop) {
  186. len = mods[i].requires.length;
  187. for (o = 0; o < len; o++) {
  188. mod = mods[i].requires[o];
  189. if (Y.rls_needs(mod)) {
  190. m.push(mod);
  191. } else {
  192. d = YUI.Env.mods[mod] || mods[mod];
  193. if (d) {
  194. d = d.details || d;
  195. if (!d.noop) {
  196. if (d.requires) {
  197. YArray.each(d.requires, function(o) {
  198. if (Y.rls_needs(o)) {
  199. m.push(o);
  200. }
  201. });
  202. }
  203. }
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }
  210. YObject.each(YUI.Env.mods, function(i) {
  211. if (asked[i.name]) {
  212. if (i.details && i.details.requires) {
  213. if (!i.noop) {
  214. YArray.each(i.details.requires, function(o) {
  215. if (Y.rls_needs(o)) {
  216. m.push(o);
  217. }
  218. });
  219. }
  220. }
  221. }
  222. });
  223. function addIfNeeded(module) {
  224. if (Y.rls_needs(module)) {
  225. m.unshift(module);
  226. }
  227. }
  228. //Add in the debug modules
  229. if (rls.filt === 'debug') {
  230. YArray.each(['dump', 'yui-log'], addIfNeeded);
  231. }
  232. //If they have a groups config, add the loader-base module
  233. if (Y.config.groups) {
  234. addIfNeeded('loader-base');
  235. }
  236. m = YArray.dedupe(m);
  237. //Strip Duplicates
  238. m = YArray.dedupe(m);
  239. what = YArray.dedupe(what);
  240. if (!m.length) {
  241. //Return here if there no modules to load.
  242. return false;
  243. }
  244. // update the request
  245. rls.m = m.sort(); // cache proxy optimization
  246. rls.env = [].concat(YObject.keys(YUI.Env.mods), YArray.dedupe(YUI._rls_skins)).sort();
  247. rls.tests = Y.Features.all('load', [Y]);
  248. url = Y.Lang.sub(rls_base + rls_tmpl, rls);
  249. config.rls = rls;
  250. config.rls_tmpl = rls_tmpl;
  251. YUI._rls_active = {
  252. asked: what,
  253. attach: m,
  254. inst: Y,
  255. url: url
  256. };
  257. return url;
  258. };
  259. /**
  260. *
  261. * @method rls_oncomplete
  262. * @param {Callback} cb The callback to execute when the RLS request is complete
  263. */
  264. Y.rls_oncomplete = function(cb) {
  265. YUI._rls_active.cb = cb;
  266. };
  267. Y.rls_advance = function() {
  268. var G_ENV = YUI.Env;
  269. G_ENV._rls_in_progress = false;
  270. if (G_ENV._rls_queue.size()) {
  271. G_ENV._rls_queue.next()();
  272. }
  273. };
  274. /**
  275. * Calls the callback registered with Y.rls_oncomplete when the RLS request (and it's dependency requests) is done.
  276. * @method rls_done
  277. * @param {Array} data The modules loaded
  278. */
  279. Y.rls_done = function(data) {
  280. data.success = true;
  281. YUI._rls_active.cb(data);
  282. };
  283. /**
  284. * Hash to hang on to the calling RLS instance so we can deal with the return from the server.
  285. * @property _rls_active
  286. * @private
  287. * @type Object
  288. * @static
  289. */
  290. if (!YUI._rls_active) {
  291. YUI._rls_active = {};
  292. }
  293. /**
  294. * An array of skins loaded via RLS to populate the ENV with when making future requests.
  295. * @property _rls_skins
  296. * @private
  297. * @type Array
  298. * @static
  299. */
  300. if (!YUI._rls_skins) {
  301. YUI._rls_skins = [];
  302. }
  303. /**
  304. *
  305. * @method $rls
  306. * @private
  307. * @static
  308. * @param {Object} req The data returned from the RLS server
  309. * @param {String} req.css Does this request need CSS? If so, load the same RLS url with &css=1 attached
  310. * @param {Array} req.module The sorted list of modules to attach to the page.
  311. */
  312. if (!YUI.$rls) {
  313. YUI.$rls = function(req) {
  314. var rls_active = YUI._rls_active,
  315. Y = rls_active.inst;
  316. if (Y) {
  317. if (req.error) {
  318. if (!req.missing) {
  319. req.missing = [];
  320. }
  321. Y.rls_failure({
  322. message: req.error,
  323. data: [].concat(req.modules, req.missing)
  324. });
  325. }
  326. if (YUI.Env && YUI.Env.rls_disabled) {
  327. return;
  328. }
  329. if (req.css && Y.config.fetchCSS) {
  330. Y.Get.css(rls_active.url + '&css=1');
  331. }
  332. if (req.modules && !req.css) {
  333. if (req.modules.length) {
  334. var loadInt = Y.Array.some(req.modules, function(v) {
  335. return (v.indexOf('lang') === 0);
  336. });
  337. if (loadInt) {
  338. req.modules.unshift('intl');
  339. }
  340. }
  341. Y.Env.bootstrapped = true;
  342. Y.Array.each(req.modules, function(v) {
  343. if (v.indexOf('skin-') > -1) {
  344. YUI._rls_skins.push(v);
  345. }
  346. });
  347. Y._attach([].concat(req.modules, rls_active.asked));
  348. var additional = req.missing;
  349. if (Y.config.groups) {
  350. if (!additional) {
  351. additional = [];
  352. }
  353. additional = [].concat(additional, rls_active.what);
  354. }
  355. if (additional && Y.Loader) {
  356. var loader = new Y.Loader(rls_active.inst.config);
  357. loader.onEnd = Y.rls_done;
  358. loader.context = Y;
  359. loader.data = additional;
  360. loader.ignoreRegistered = false;
  361. loader.require(additional);
  362. loader.insert(null, (Y.config.fetchCSS) ? null : 'js');
  363. } else {
  364. Y.rls_done({ data: req.modules });
  365. }
  366. }
  367. }
  368. };
  369. }
  370. }, '3.4.0' ,{requires:['get','features']});