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.

loader-base.js 77KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462
  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('loader-base', function(Y) {
  9. /**
  10. * The YUI loader core
  11. * @module loader
  12. * @submodule loader-base
  13. */
  14. if (!YUI.Env[Y.version]) {
  15. (function() {
  16. var VERSION = Y.version,
  17. BUILD = '/build/',
  18. ROOT = VERSION + BUILD,
  19. CDN_BASE = Y.Env.base,
  20. GALLERY_VERSION = 'gallery-2011.09.14-20-40',
  21. TNT = '2in3',
  22. TNT_VERSION = '4',
  23. YUI2_VERSION = '2.9.0',
  24. COMBO_BASE = CDN_BASE + 'combo?',
  25. META = { version: VERSION,
  26. root: ROOT,
  27. base: Y.Env.base,
  28. comboBase: COMBO_BASE,
  29. skin: { defaultSkin: 'sam',
  30. base: 'assets/skins/',
  31. path: 'skin.css',
  32. after: ['cssreset',
  33. 'cssfonts',
  34. 'cssgrids',
  35. 'cssbase',
  36. 'cssreset-context',
  37. 'cssfonts-context']},
  38. groups: {},
  39. patterns: {} },
  40. groups = META.groups,
  41. yui2Update = function(tnt, yui2) {
  42. var root = TNT + '.' +
  43. (tnt || TNT_VERSION) + '/' +
  44. (yui2 || YUI2_VERSION) + BUILD;
  45. groups.yui2.base = CDN_BASE + root;
  46. groups.yui2.root = root;
  47. },
  48. galleryUpdate = function(tag) {
  49. var root = (tag || GALLERY_VERSION) + BUILD;
  50. groups.gallery.base = CDN_BASE + root;
  51. groups.gallery.root = root;
  52. };
  53. groups[VERSION] = {};
  54. groups.gallery = {
  55. ext: false,
  56. combine: true,
  57. comboBase: COMBO_BASE,
  58. update: galleryUpdate,
  59. patterns: { 'gallery-': { },
  60. 'lang/gallery-': {},
  61. 'gallerycss-': { type: 'css' } }
  62. };
  63. groups.yui2 = {
  64. combine: true,
  65. ext: false,
  66. comboBase: COMBO_BASE,
  67. update: yui2Update,
  68. patterns: {
  69. 'yui2-': {
  70. configFn: function(me) {
  71. if (/-skin|reset|fonts|grids|base/.test(me.name)) {
  72. me.type = 'css';
  73. me.path = me.path.replace(/\.js/, '.css');
  74. // this makes skins in builds earlier than
  75. // 2.6.0 work as long as combine is false
  76. me.path = me.path.replace(/\/yui2-skin/,
  77. '/assets/skins/sam/yui2-skin');
  78. }
  79. }
  80. }
  81. }
  82. };
  83. galleryUpdate();
  84. yui2Update();
  85. YUI.Env[VERSION] = META;
  86. }());
  87. }
  88. /**
  89. * Loader dynamically loads script and css files. It includes the dependency
  90. * info for the version of the library in use, and will automatically pull in
  91. * dependencies for the modules requested. It supports rollup files and will
  92. * automatically use these when appropriate in order to minimize the number of
  93. * http connections required to load all of the dependencies. It can load the
  94. * files from the Yahoo! CDN, and it can utilize the combo service provided on
  95. * this network to reduce the number of http connections required To Download
  96. * YUI files.
  97. *
  98. * @module loader
  99. * @main loader
  100. * @submodule loader-base
  101. */
  102. var NOT_FOUND = {},
  103. NO_REQUIREMENTS = [],
  104. MAX_URL_LENGTH = 2048,
  105. GLOBAL_ENV = YUI.Env,
  106. GLOBAL_LOADED = GLOBAL_ENV._loaded,
  107. CSS = 'css',
  108. JS = 'js',
  109. INTL = 'intl',
  110. VERSION = Y.version,
  111. ROOT_LANG = '',
  112. YObject = Y.Object,
  113. oeach = YObject.each,
  114. YArray = Y.Array,
  115. _queue = GLOBAL_ENV._loaderQueue,
  116. META = GLOBAL_ENV[VERSION],
  117. SKIN_PREFIX = 'skin-',
  118. L = Y.Lang,
  119. ON_PAGE = GLOBAL_ENV.mods,
  120. modulekey,
  121. cache,
  122. _path = function(dir, file, type, nomin) {
  123. var path = dir + '/' + file;
  124. if (!nomin) {
  125. path += '-min';
  126. }
  127. path += '.' + (type || CSS);
  128. return path;
  129. };
  130. if (YUI.Env.aliases) {
  131. YUI.Env.aliases = {}; //Don't need aliases if Loader is present
  132. }
  133. /**
  134. * The component metadata is stored in Y.Env.meta.
  135. * Part of the loader module.
  136. * @property meta
  137. * @for YUI
  138. */
  139. Y.Env.meta = META;
  140. /**
  141. * Loader dynamically loads script and css files. It includes the dependency
  142. * info for the version of the library in use, and will automatically pull in
  143. * dependencies for the modules requested. It supports rollup files and will
  144. * automatically use these when appropriate in order to minimize the number of
  145. * http connections required to load all of the dependencies. It can load the
  146. * files from the Yahoo! CDN, and it can utilize the combo service provided on
  147. * this network to reduce the number of http connections required To Download
  148. * YUI files.
  149. *
  150. * While the loader can be instantiated by the end user, it normally is not.
  151. * @see YUI.use for the normal use case. The use function automatically will
  152. * pull in missing dependencies.
  153. *
  154. * @constructor
  155. * @class Loader
  156. * @param {object} o an optional set of configuration options. Valid options:
  157. * <ul>
  158. * <li>base:
  159. * The base dir</li>
  160. * <li>comboBase:
  161. * The YUI combo service base dir. Ex: http://yui.yahooapis.com/combo?</li>
  162. * <li>root:
  163. * The root path to prepend to module names for the combo service.
  164. * Ex: 2.5.2/build/</li>
  165. * <li>filter:.
  166. *
  167. * A filter to apply to result urls. This filter will modify the default
  168. * path for all modules. The default path for the YUI library is the
  169. * minified version of the files (e.g., event-min.js). The filter property
  170. * can be a predefined filter or a custom filter. The valid predefined
  171. * filters are:
  172. * <dl>
  173. * <dt>DEBUG</dt>
  174. * <dd>Selects the debug versions of the library (e.g., event-debug.js).
  175. * This option will automatically include the Logger widget</dd>
  176. * <dt>RAW</dt>
  177. * <dd>Selects the non-minified version of the library (e.g., event.js).
  178. * </dd>
  179. * </dl>
  180. * You can also define a custom filter, which must be an object literal
  181. * containing a search expression and a replace string:
  182. * <pre>
  183. * myFilter: &#123;
  184. * 'searchExp': "-min\\.js",
  185. * 'replaceStr': "-debug.js"
  186. * &#125;
  187. * </pre>
  188. *
  189. * </li>
  190. * <li>filters: per-component filter specification. If specified
  191. * for a given component, this overrides the filter config. _Note:_ This does not work on combo urls, use the filter property instead.</li>
  192. * <li>combine:
  193. * Use the YUI combo service to reduce the number of http connections
  194. * required to load your dependencies</li>
  195. * <li>ignore:
  196. * A list of modules that should never be dynamically loaded</li>
  197. * <li>force:
  198. * A list of modules that should always be loaded when required, even if
  199. * already present on the page</li>
  200. * <li>insertBefore:
  201. * Node or id for a node that should be used as the insertion point for
  202. * new nodes</li>
  203. * <li>charset:
  204. * charset for dynamic nodes (deprecated, use jsAttributes or cssAttributes)
  205. * </li>
  206. * <li>jsAttributes: object literal containing attributes to add to script
  207. * nodes</li>
  208. * <li>cssAttributes: object literal containing attributes to add to link
  209. * nodes</li>
  210. * <li>timeout:
  211. * The number of milliseconds before a timeout occurs when dynamically
  212. * loading nodes. If not set, there is no timeout</li>
  213. * <li>context:
  214. * execution context for all callbacks</li>
  215. * <li>onSuccess:
  216. * callback for the 'success' event</li>
  217. * <li>onFailure: callback for the 'failure' event</li>
  218. * <li>onCSS: callback for the 'CSSComplete' event. When loading YUI
  219. * components with CSS the CSS is loaded first, then the script. This
  220. * provides a moment you can tie into to improve
  221. * the presentation of the page while the script is loading.</li>
  222. * <li>onTimeout:
  223. * callback for the 'timeout' event</li>
  224. * <li>onProgress:
  225. * callback executed each time a script or css file is loaded</li>
  226. * <li>modules:
  227. * A list of module definitions. See Loader.addModule for the supported
  228. * module metadata</li>
  229. * <li>groups:
  230. * A list of group definitions. Each group can contain specific definitions
  231. * for base, comboBase, combine, and accepts a list of modules. See above
  232. * for the description of these properties.</li>
  233. * <li>2in3: the version of the YUI 2 in 3 wrapper to use. The intrinsic
  234. * support for YUI 2 modules in YUI 3 relies on versions of the YUI 2
  235. * components inside YUI 3 module wrappers. These wrappers
  236. * change over time to accomodate the issues that arise from running YUI 2
  237. * in a YUI 3 sandbox.</li>
  238. * <li>yui2: when using the 2in3 project, you can select the version of
  239. * YUI 2 to use. Valid values * are 2.2.2, 2.3.1, 2.4.1, 2.5.2, 2.6.0,
  240. * 2.7.0, 2.8.0, and 2.8.1 [default] -- plus all versions of YUI 2
  241. * going forward.</li>
  242. * </ul>
  243. */
  244. Y.Loader = function(o) {
  245. var defaults = META.modules,
  246. self = this;
  247. modulekey = META.md5;
  248. /**
  249. * Internal callback to handle multiple internal insert() calls
  250. * so that css is inserted prior to js
  251. * @property _internalCallback
  252. * @private
  253. */
  254. // self._internalCallback = null;
  255. /**
  256. * Callback that will be executed when the loader is finished
  257. * with an insert
  258. * @method onSuccess
  259. * @type function
  260. */
  261. // self.onSuccess = null;
  262. /**
  263. * Callback that will be executed if there is a failure
  264. * @method onFailure
  265. * @type function
  266. */
  267. // self.onFailure = null;
  268. /**
  269. * Callback for the 'CSSComplete' event. When loading YUI components
  270. * with CSS the CSS is loaded first, then the script. This provides
  271. * a moment you can tie into to improve the presentation of the page
  272. * while the script is loading.
  273. * @method onCSS
  274. * @type function
  275. */
  276. // self.onCSS = null;
  277. /**
  278. * Callback executed each time a script or css file is loaded
  279. * @method onProgress
  280. * @type function
  281. */
  282. // self.onProgress = null;
  283. /**
  284. * Callback that will be executed if a timeout occurs
  285. * @method onTimeout
  286. * @type function
  287. */
  288. // self.onTimeout = null;
  289. /**
  290. * The execution context for all callbacks
  291. * @property context
  292. * @default {YUI} the YUI instance
  293. */
  294. self.context = Y;
  295. /**
  296. * Data that is passed to all callbacks
  297. * @property data
  298. */
  299. // self.data = null;
  300. /**
  301. * Node reference or id where new nodes should be inserted before
  302. * @property insertBefore
  303. * @type string|HTMLElement
  304. */
  305. // self.insertBefore = null;
  306. /**
  307. * The charset attribute for inserted nodes
  308. * @property charset
  309. * @type string
  310. * @deprecated , use cssAttributes or jsAttributes.
  311. */
  312. // self.charset = null;
  313. /**
  314. * An object literal containing attributes to add to link nodes
  315. * @property cssAttributes
  316. * @type object
  317. */
  318. // self.cssAttributes = null;
  319. /**
  320. * An object literal containing attributes to add to script nodes
  321. * @property jsAttributes
  322. * @type object
  323. */
  324. // self.jsAttributes = null;
  325. /**
  326. * The base directory.
  327. * @property base
  328. * @type string
  329. * @default http://yui.yahooapis.com/[YUI VERSION]/build/
  330. */
  331. self.base = Y.Env.meta.base + Y.Env.meta.root;
  332. /**
  333. * Base path for the combo service
  334. * @property comboBase
  335. * @type string
  336. * @default http://yui.yahooapis.com/combo?
  337. */
  338. self.comboBase = Y.Env.meta.comboBase;
  339. /*
  340. * Base path for language packs.
  341. */
  342. // self.langBase = Y.Env.meta.langBase;
  343. // self.lang = "";
  344. /**
  345. * If configured, the loader will attempt to use the combo
  346. * service for YUI resources and configured external resources.
  347. * @property combine
  348. * @type boolean
  349. * @default true if a base dir isn't in the config
  350. */
  351. self.combine = o.base &&
  352. (o.base.indexOf(self.comboBase.substr(0, 20)) > -1);
  353. /**
  354. * The default seperator to use between files in a combo URL
  355. * @property comboSep
  356. * @type {String}
  357. * @default Ampersand
  358. */
  359. self.comboSep = '&';
  360. /**
  361. * Max url length for combo urls. The default is 2048. This is the URL
  362. * limit for the Yahoo! hosted combo servers. If consuming
  363. * a different combo service that has a different URL limit
  364. * it is possible to override this default by supplying
  365. * the maxURLLength config option. The config option will
  366. * only take effect if lower than the default.
  367. *
  368. * @property maxURLLength
  369. * @type int
  370. */
  371. self.maxURLLength = MAX_URL_LENGTH;
  372. /**
  373. * Ignore modules registered on the YUI global
  374. * @property ignoreRegistered
  375. * @default false
  376. */
  377. // self.ignoreRegistered = false;
  378. /**
  379. * Root path to prepend to module path for the combo
  380. * service
  381. * @property root
  382. * @type string
  383. * @default [YUI VERSION]/build/
  384. */
  385. self.root = Y.Env.meta.root;
  386. /**
  387. * Timeout value in milliseconds. If set, self value will be used by
  388. * the get utility. the timeout event will fire if
  389. * a timeout occurs.
  390. * @property timeout
  391. * @type int
  392. */
  393. self.timeout = 0;
  394. /**
  395. * A list of modules that should not be loaded, even if
  396. * they turn up in the dependency tree
  397. * @property ignore
  398. * @type string[]
  399. */
  400. // self.ignore = null;
  401. /**
  402. * A list of modules that should always be loaded, even
  403. * if they have already been inserted into the page.
  404. * @property force
  405. * @type string[]
  406. */
  407. // self.force = null;
  408. self.forceMap = {};
  409. /**
  410. * Should we allow rollups
  411. * @property allowRollup
  412. * @type boolean
  413. * @default false
  414. */
  415. self.allowRollup = false;
  416. /**
  417. * A filter to apply to result urls. This filter will modify the default
  418. * path for all modules. The default path for the YUI library is the
  419. * minified version of the files (e.g., event-min.js). The filter property
  420. * can be a predefined filter or a custom filter. The valid predefined
  421. * filters are:
  422. * <dl>
  423. * <dt>DEBUG</dt>
  424. * <dd>Selects the debug versions of the library (e.g., event-debug.js).
  425. * This option will automatically include the Logger widget</dd>
  426. * <dt>RAW</dt>
  427. * <dd>Selects the non-minified version of the library (e.g., event.js).
  428. * </dd>
  429. * </dl>
  430. * You can also define a custom filter, which must be an object literal
  431. * containing a search expression and a replace string:
  432. * <pre>
  433. * myFilter: &#123;
  434. * 'searchExp': "-min\\.js",
  435. * 'replaceStr': "-debug.js"
  436. * &#125;
  437. * </pre>
  438. * @property filter
  439. * @type string| {searchExp: string, replaceStr: string}
  440. */
  441. // self.filter = null;
  442. /**
  443. * per-component filter specification. If specified for a given
  444. * component, this overrides the filter config.
  445. * @property filters
  446. * @type object
  447. */
  448. self.filters = {};
  449. /**
  450. * The list of requested modules
  451. * @property required
  452. * @type {string: boolean}
  453. */
  454. self.required = {};
  455. /**
  456. * If a module name is predefined when requested, it is checked againsts
  457. * the patterns provided in this property. If there is a match, the
  458. * module is added with the default configuration.
  459. *
  460. * At the moment only supporting module prefixes, but anticipate
  461. * supporting at least regular expressions.
  462. * @property patterns
  463. * @type Object
  464. */
  465. // self.patterns = Y.merge(Y.Env.meta.patterns);
  466. self.patterns = {};
  467. /**
  468. * The library metadata
  469. * @property moduleInfo
  470. */
  471. // self.moduleInfo = Y.merge(Y.Env.meta.moduleInfo);
  472. self.moduleInfo = {};
  473. self.groups = Y.merge(Y.Env.meta.groups);
  474. /**
  475. * Provides the information used to skin the skinnable components.
  476. * The following skin definition would result in 'skin1' and 'skin2'
  477. * being loaded for calendar (if calendar was requested), and
  478. * 'sam' for all other skinnable components:
  479. *
  480. * <code>
  481. * skin: {
  482. *
  483. * // The default skin, which is automatically applied if not
  484. * // overriden by a component-specific skin definition.
  485. * // Change this in to apply a different skin globally
  486. * defaultSkin: 'sam',
  487. *
  488. * // This is combined with the loader base property to get
  489. * // the default root directory for a skin. ex:
  490. * // http://yui.yahooapis.com/2.3.0/build/assets/skins/sam/
  491. * base: 'assets/skins/',
  492. *
  493. * // Any component-specific overrides can be specified here,
  494. * // making it possible to load different skins for different
  495. * // components. It is possible to load more than one skin
  496. * // for a given component as well.
  497. * overrides: {
  498. * calendar: ['skin1', 'skin2']
  499. * }
  500. * }
  501. * </code>
  502. * @property skin
  503. */
  504. self.skin = Y.merge(Y.Env.meta.skin);
  505. /*
  506. * Map of conditional modules
  507. * @since 3.2.0
  508. */
  509. self.conditions = {};
  510. // map of modules with a hash of modules that meet the requirement
  511. // self.provides = {};
  512. self.config = o;
  513. self._internal = true;
  514. cache = GLOBAL_ENV._renderedMods;
  515. if (cache) {
  516. oeach(cache, function modCache(v, k) {
  517. //self.moduleInfo[k] = Y.merge(v);
  518. self.moduleInfo[k] = v;
  519. });
  520. cache = GLOBAL_ENV._conditions;
  521. oeach(cache, function condCache(v, k) {
  522. //self.conditions[k] = Y.merge(v);
  523. self.conditions[k] = v;
  524. });
  525. } else {
  526. oeach(defaults, self.addModule, self);
  527. }
  528. if (!GLOBAL_ENV._renderedMods) {
  529. //GLOBAL_ENV._renderedMods = Y.merge(self.moduleInfo);
  530. //GLOBAL_ENV._conditions = Y.merge(self.conditions);
  531. GLOBAL_ENV._renderedMods = self.moduleInfo;
  532. GLOBAL_ENV._conditions = self.conditions;
  533. }
  534. self._inspectPage();
  535. self._internal = false;
  536. self._config(o);
  537. self.testresults = null;
  538. if (Y.config.tests) {
  539. self.testresults = Y.config.tests;
  540. }
  541. /**
  542. * List of rollup files found in the library metadata
  543. * @property rollups
  544. */
  545. // self.rollups = null;
  546. /**
  547. * Whether or not to load optional dependencies for
  548. * the requested modules
  549. * @property loadOptional
  550. * @type boolean
  551. * @default false
  552. */
  553. // self.loadOptional = false;
  554. /**
  555. * All of the derived dependencies in sorted order, which
  556. * will be populated when either calculate() or insert()
  557. * is called
  558. * @property sorted
  559. * @type string[]
  560. */
  561. self.sorted = [];
  562. /**
  563. * Set when beginning to compute the dependency tree.
  564. * Composed of what YUI reports to be loaded combined
  565. * with what has been loaded by any instance on the page
  566. * with the version number specified in the metadata.
  567. * @property loaded
  568. * @type {string: boolean}
  569. */
  570. self.loaded = GLOBAL_LOADED[VERSION];
  571. /*
  572. * A list of modules to attach to the YUI instance when complete.
  573. * If not supplied, the sorted list of dependencies are applied.
  574. * @property attaching
  575. */
  576. // self.attaching = null;
  577. /**
  578. * Flag to indicate the dependency tree needs to be recomputed
  579. * if insert is called again.
  580. * @property dirty
  581. * @type boolean
  582. * @default true
  583. */
  584. self.dirty = true;
  585. /**
  586. * List of modules inserted by the utility
  587. * @property inserted
  588. * @type {string: boolean}
  589. */
  590. self.inserted = {};
  591. /**
  592. * List of skipped modules during insert() because the module
  593. * was not defined
  594. * @property skipped
  595. */
  596. self.skipped = {};
  597. // Y.on('yui:load', self.loadNext, self);
  598. self.tested = {};
  599. /*
  600. * Cached sorted calculate results
  601. * @property results
  602. * @since 3.2.0
  603. */
  604. //self.results = {};
  605. };
  606. Y.Loader.prototype = {
  607. FILTER_DEFS: {
  608. RAW: {
  609. 'searchExp': '-min\\.js',
  610. 'replaceStr': '.js'
  611. },
  612. DEBUG: {
  613. 'searchExp': '-min\\.js',
  614. 'replaceStr': '-debug.js'
  615. }
  616. },
  617. /*
  618. * Check the pages meta-data and cache the result.
  619. * @method _inspectPage
  620. * @private
  621. */
  622. _inspectPage: function() {
  623. oeach(ON_PAGE, function(v, k) {
  624. if (v.details) {
  625. var m = this.moduleInfo[k],
  626. req = v.details.requires,
  627. mr = m && m.requires;
  628. if (m) {
  629. if (!m._inspected && req && mr.length != req.length) {
  630. // console.log('deleting ' + m.name);
  631. // m.requres = YObject.keys(Y.merge(YArray.hash(req), YArray.hash(mr)));
  632. delete m.expanded;
  633. // delete m.expanded_map;
  634. }
  635. } else {
  636. m = this.addModule(v.details, k);
  637. }
  638. m._inspected = true;
  639. }
  640. }, this);
  641. },
  642. /*
  643. * returns true if b is not loaded, and is required directly or by means of modules it supersedes.
  644. * @private
  645. * @method _requires
  646. * @param {String} mod1 The first module to compare
  647. * @param {String} mod2 The second module to compare
  648. */
  649. _requires: function(mod1, mod2) {
  650. var i, rm, after_map, s,
  651. info = this.moduleInfo,
  652. m = info[mod1],
  653. other = info[mod2];
  654. if (!m || !other) {
  655. return false;
  656. }
  657. rm = m.expanded_map;
  658. after_map = m.after_map;
  659. // check if this module should be sorted after the other
  660. // do this first to short circut circular deps
  661. if (after_map && (mod2 in after_map)) {
  662. return true;
  663. }
  664. after_map = other.after_map;
  665. // and vis-versa
  666. if (after_map && (mod1 in after_map)) {
  667. return false;
  668. }
  669. // check if this module requires one the other supersedes
  670. s = info[mod2] && info[mod2].supersedes;
  671. if (s) {
  672. for (i = 0; i < s.length; i++) {
  673. if (this._requires(mod1, s[i])) {
  674. return true;
  675. }
  676. }
  677. }
  678. s = info[mod1] && info[mod1].supersedes;
  679. if (s) {
  680. for (i = 0; i < s.length; i++) {
  681. if (this._requires(mod2, s[i])) {
  682. return false;
  683. }
  684. }
  685. }
  686. // check if this module requires the other directly
  687. // if (r && YArray.indexOf(r, mod2) > -1) {
  688. if (rm && (mod2 in rm)) {
  689. return true;
  690. }
  691. // external css files should be sorted below yui css
  692. if (m.ext && m.type == CSS && !other.ext && other.type == CSS) {
  693. return true;
  694. }
  695. return false;
  696. },
  697. /**
  698. * Apply a new config to the Loader instance
  699. * @method _config
  700. * @param {Object} o The new configuration
  701. */
  702. _config: function(o) {
  703. var i, j, val, f, group, groupName, self = this;
  704. // apply config values
  705. if (o) {
  706. for (i in o) {
  707. if (o.hasOwnProperty(i)) {
  708. val = o[i];
  709. if (i == 'require') {
  710. self.require(val);
  711. } else if (i == 'skin') {
  712. Y.mix(self.skin, o[i], true);
  713. } else if (i == 'groups') {
  714. for (j in val) {
  715. if (val.hasOwnProperty(j)) {
  716. groupName = j;
  717. group = val[j];
  718. self.addGroup(group, groupName);
  719. }
  720. }
  721. } else if (i == 'modules') {
  722. // add a hash of module definitions
  723. oeach(val, self.addModule, self);
  724. } else if (i == 'gallery') {
  725. this.groups.gallery.update(val);
  726. } else if (i == 'yui2' || i == '2in3') {
  727. this.groups.yui2.update(o['2in3'], o.yui2);
  728. } else if (i == 'maxURLLength') {
  729. self[i] = Math.min(MAX_URL_LENGTH, val);
  730. } else {
  731. self[i] = val;
  732. }
  733. }
  734. }
  735. }
  736. // fix filter
  737. f = self.filter;
  738. if (L.isString(f)) {
  739. f = f.toUpperCase();
  740. self.filterName = f;
  741. self.filter = self.FILTER_DEFS[f];
  742. if (f == 'DEBUG') {
  743. self.require('yui-log', 'dump');
  744. }
  745. }
  746. if (self.lang) {
  747. self.require('intl-base', 'intl');
  748. }
  749. },
  750. /**
  751. * Returns the skin module name for the specified skin name. If a
  752. * module name is supplied, the returned skin module name is
  753. * specific to the module passed in.
  754. * @method formatSkin
  755. * @param {string} skin the name of the skin.
  756. * @param {string} mod optional: the name of a module to skin.
  757. * @return {string} the full skin module name.
  758. */
  759. formatSkin: function(skin, mod) {
  760. var s = SKIN_PREFIX + skin;
  761. if (mod) {
  762. s = s + '-' + mod;
  763. }
  764. return s;
  765. },
  766. /**
  767. * Adds the skin def to the module info
  768. * @method _addSkin
  769. * @param {string} skin the name of the skin.
  770. * @param {string} mod the name of the module.
  771. * @param {string} parent parent module if this is a skin of a
  772. * submodule or plugin.
  773. * @return {string} the module name for the skin.
  774. * @private
  775. */
  776. _addSkin: function(skin, mod, parent) {
  777. var mdef, pkg, name, nmod,
  778. info = this.moduleInfo,
  779. sinf = this.skin,
  780. ext = info[mod] && info[mod].ext;
  781. // Add a module definition for the module-specific skin css
  782. if (mod) {
  783. name = this.formatSkin(skin, mod);
  784. if (!info[name]) {
  785. mdef = info[mod];
  786. pkg = mdef.pkg || mod;
  787. nmod = {
  788. name: name,
  789. group: mdef.group,
  790. type: 'css',
  791. after: sinf.after,
  792. path: (parent || pkg) + '/' + sinf.base + skin +
  793. '/' + mod + '.css',
  794. ext: ext
  795. };
  796. if (mdef.base) {
  797. nmod.base = mdef.base;
  798. }
  799. if (mdef.configFn) {
  800. nmod.configFn = mdef.configFn;
  801. }
  802. this.addModule(nmod, name);
  803. }
  804. }
  805. return name;
  806. },
  807. /**
  808. * Add a new module group
  809. * <dl>
  810. * <dt>name:</dt> <dd>required, the group name</dd>
  811. * <dt>base:</dt> <dd>The base dir for this module group</dd>
  812. * <dt>root:</dt> <dd>The root path to add to each combo
  813. * resource path</dd>
  814. * <dt>combine:</dt> <dd>combo handle</dd>
  815. * <dt>comboBase:</dt> <dd>combo service base path</dd>
  816. * <dt>modules:</dt> <dd>the group of modules</dd>
  817. * </dl>
  818. * @method addGroup
  819. * @param {object} o An object containing the module data.
  820. * @param {string} name the group name.
  821. */
  822. addGroup: function(o, name) {
  823. var mods = o.modules,
  824. self = this;
  825. name = name || o.name;
  826. o.name = name;
  827. self.groups[name] = o;
  828. if (o.patterns) {
  829. oeach(o.patterns, function(v, k) {
  830. v.group = name;
  831. self.patterns[k] = v;
  832. });
  833. }
  834. if (mods) {
  835. oeach(mods, function(v, k) {
  836. v.group = name;
  837. self.addModule(v, k);
  838. }, self);
  839. }
  840. },
  841. /**
  842. * Add a new module to the component metadata.
  843. * <dl>
  844. * <dt>name:</dt> <dd>required, the component name</dd>
  845. * <dt>type:</dt> <dd>required, the component type (js or css)
  846. * </dd>
  847. * <dt>path:</dt> <dd>required, the path to the script from
  848. * "base"</dd>
  849. * <dt>requires:</dt> <dd>array of modules required by this
  850. * component</dd>
  851. * <dt>optional:</dt> <dd>array of optional modules for this
  852. * component</dd>
  853. * <dt>supersedes:</dt> <dd>array of the modules this component
  854. * replaces</dd>
  855. * <dt>after:</dt> <dd>array of modules the components which, if
  856. * present, should be sorted above this one</dd>
  857. * <dt>after_map:</dt> <dd>faster alternative to 'after' -- supply
  858. * a hash instead of an array</dd>
  859. * <dt>rollup:</dt> <dd>the number of superseded modules required
  860. * for automatic rollup</dd>
  861. * <dt>fullpath:</dt> <dd>If fullpath is specified, this is used
  862. * instead of the configured base + path</dd>
  863. * <dt>skinnable:</dt> <dd>flag to determine if skin assets should
  864. * automatically be pulled in</dd>
  865. * <dt>submodules:</dt> <dd>a hash of submodules</dd>
  866. * <dt>group:</dt> <dd>The group the module belongs to -- this
  867. * is set automatically when it is added as part of a group
  868. * configuration.</dd>
  869. * <dt>lang:</dt>
  870. * <dd>array of BCP 47 language tags of languages for which this
  871. * module has localized resource bundles,
  872. * e.g., ["en-GB","zh-Hans-CN"]</dd>
  873. * <dt>condition:</dt>
  874. * <dd>Specifies that the module should be loaded automatically if
  875. * a condition is met. This is an object with up to three fields:
  876. * [trigger] - the name of a module that can trigger the auto-load
  877. * [test] - a function that returns true when the module is to be
  878. * loaded.
  879. * [when] - specifies the load order of the conditional module
  880. * with regard to the position of the trigger module.
  881. * This should be one of three values: 'before', 'after', or
  882. * 'instead'. The default is 'after'.
  883. * </dd>
  884. * <dt>testresults:</dt><dd>a hash of test results from Y.Features.all()</dd>
  885. * </dl>
  886. * @method addModule
  887. * @param {object} o An object containing the module data.
  888. * @param {string} name the module name (optional), required if not
  889. * in the module data.
  890. * @return {object} the module definition or null if
  891. * the object passed in did not provide all required attributes.
  892. */
  893. addModule: function(o, name) {
  894. name = name || o.name;
  895. //Only merge this data if the temp flag is set
  896. //from an earlier pass from a pattern or else
  897. //an override module (YUI_config) can not be used to
  898. //replace a default module.
  899. if (this.moduleInfo[name] && this.moduleInfo[name].temp) {
  900. //This catches temp modules loaded via a pattern
  901. // The module will be added twice, once from the pattern and
  902. // Once from the actual add call, this ensures that properties
  903. // that were added to the module the first time around (group: gallery)
  904. // are also added the second time around too.
  905. o = Y.merge(this.moduleInfo[name], o);
  906. }
  907. o.name = name;
  908. if (!o || !o.name) {
  909. return null;
  910. }
  911. if (!o.type) {
  912. o.type = JS;
  913. }
  914. if (!o.path && !o.fullpath) {
  915. o.path = _path(name, name, o.type);
  916. }
  917. o.supersedes = o.supersedes || o.use;
  918. o.ext = ('ext' in o) ? o.ext : (this._internal) ? false : true;
  919. o.requires = this.filterRequires(o.requires) || [];
  920. // Handle submodule logic
  921. var subs = o.submodules, i, l, t, sup, s, smod, plugins, plug,
  922. j, langs, packName, supName, flatSup, flatLang, lang, ret,
  923. overrides, skinname, when,
  924. conditions = this.conditions, trigger;
  925. // , existing = this.moduleInfo[name], newr;
  926. this.moduleInfo[name] = o;
  927. if (!o.langPack && o.lang) {
  928. langs = YArray(o.lang);
  929. for (j = 0; j < langs.length; j++) {
  930. lang = langs[j];
  931. packName = this.getLangPackName(lang, name);
  932. smod = this.moduleInfo[packName];
  933. if (!smod) {
  934. smod = this._addLangPack(lang, o, packName);
  935. }
  936. }
  937. }
  938. if (subs) {
  939. sup = o.supersedes || [];
  940. l = 0;
  941. for (i in subs) {
  942. if (subs.hasOwnProperty(i)) {
  943. s = subs[i];
  944. s.path = s.path || _path(name, i, o.type);
  945. s.pkg = name;
  946. s.group = o.group;
  947. if (s.supersedes) {
  948. sup = sup.concat(s.supersedes);
  949. }
  950. smod = this.addModule(s, i);
  951. sup.push(i);
  952. if (smod.skinnable) {
  953. o.skinnable = true;
  954. overrides = this.skin.overrides;
  955. if (overrides && overrides[i]) {
  956. for (j = 0; j < overrides[i].length; j++) {
  957. skinname = this._addSkin(overrides[i][j],
  958. i, name);
  959. sup.push(skinname);
  960. }
  961. }
  962. skinname = this._addSkin(this.skin.defaultSkin,
  963. i, name);
  964. sup.push(skinname);
  965. }
  966. // looks like we are expected to work out the metadata
  967. // for the parent module language packs from what is
  968. // specified in the child modules.
  969. if (s.lang && s.lang.length) {
  970. langs = YArray(s.lang);
  971. for (j = 0; j < langs.length; j++) {
  972. lang = langs[j];
  973. packName = this.getLangPackName(lang, name);
  974. supName = this.getLangPackName(lang, i);
  975. smod = this.moduleInfo[packName];
  976. if (!smod) {
  977. smod = this._addLangPack(lang, o, packName);
  978. }
  979. flatSup = flatSup || YArray.hash(smod.supersedes);
  980. if (!(supName in flatSup)) {
  981. smod.supersedes.push(supName);
  982. }
  983. o.lang = o.lang || [];
  984. flatLang = flatLang || YArray.hash(o.lang);
  985. if (!(lang in flatLang)) {
  986. o.lang.push(lang);
  987. }
  988. // Add rollup file, need to add to supersedes list too
  989. // default packages
  990. packName = this.getLangPackName(ROOT_LANG, name);
  991. supName = this.getLangPackName(ROOT_LANG, i);
  992. smod = this.moduleInfo[packName];
  993. if (!smod) {
  994. smod = this._addLangPack(lang, o, packName);
  995. }
  996. if (!(supName in flatSup)) {
  997. smod.supersedes.push(supName);
  998. }
  999. // Add rollup file, need to add to supersedes list too
  1000. }
  1001. }
  1002. l++;
  1003. }
  1004. }
  1005. //o.supersedes = YObject.keys(YArray.hash(sup));
  1006. o.supersedes = YArray.dedupe(sup);
  1007. if (this.allowRollup) {
  1008. o.rollup = (l < 4) ? l : Math.min(l - 1, 4);
  1009. }
  1010. }
  1011. plugins = o.plugins;
  1012. if (plugins) {
  1013. for (i in plugins) {
  1014. if (plugins.hasOwnProperty(i)) {
  1015. plug = plugins[i];
  1016. plug.pkg = name;
  1017. plug.path = plug.path || _path(name, i, o.type);
  1018. plug.requires = plug.requires || [];
  1019. plug.group = o.group;
  1020. this.addModule(plug, i);
  1021. if (o.skinnable) {
  1022. this._addSkin(this.skin.defaultSkin, i, name);
  1023. }
  1024. }
  1025. }
  1026. }
  1027. if (o.condition) {
  1028. t = o.condition.trigger;
  1029. if (YUI.Env.aliases[t]) {
  1030. t = YUI.Env.aliases[t];
  1031. }
  1032. if (!Y.Lang.isArray(t)) {
  1033. t = [t];
  1034. }
  1035. for (i = 0; i < t.length; i++) {
  1036. trigger = t[i];
  1037. when = o.condition.when;
  1038. conditions[trigger] = conditions[trigger] || {};
  1039. conditions[trigger][name] = o.condition;
  1040. // the 'when' attribute can be 'before', 'after', or 'instead'
  1041. // the default is after.
  1042. if (when && when != 'after') {
  1043. if (when == 'instead') { // replace the trigger
  1044. o.supersedes = o.supersedes || [];
  1045. o.supersedes.push(trigger);
  1046. } else { // before the trigger
  1047. // the trigger requires the conditional mod,
  1048. // so it should appear before the conditional
  1049. // mod if we do not intersede.
  1050. }
  1051. } else { // after the trigger
  1052. o.after = o.after || [];
  1053. o.after.push(trigger);
  1054. }
  1055. }
  1056. }
  1057. if (o.after) {
  1058. o.after_map = YArray.hash(o.after);
  1059. }
  1060. // this.dirty = true;
  1061. if (o.configFn) {
  1062. ret = o.configFn(o);
  1063. if (ret === false) {
  1064. delete this.moduleInfo[name];
  1065. o = null;
  1066. }
  1067. }
  1068. return o;
  1069. },
  1070. /**
  1071. * Add a requirement for one or more module
  1072. * @method require
  1073. * @param {string[] | string*} what the modules to load.
  1074. */
  1075. require: function(what) {
  1076. var a = (typeof what === 'string') ? YArray(arguments) : what;
  1077. this.dirty = true;
  1078. this.required = Y.merge(this.required, YArray.hash(this.filterRequires(a)));
  1079. this._explodeRollups();
  1080. },
  1081. /**
  1082. * Grab all the items that were asked for, check to see if the Loader
  1083. * meta-data contains a "use" array. If it doesm remove the asked item and replace it with
  1084. * the content of the "use".
  1085. * This will make asking for: "dd"
  1086. * Actually ask for: "dd-ddm-base,dd-ddm,dd-ddm-drop,dd-drag,dd-proxy,dd-constrain,dd-drop,dd-scroll,dd-drop-plugin"
  1087. * @private
  1088. * @method _explodeRollups
  1089. */
  1090. _explodeRollups: function() {
  1091. var self = this, m,
  1092. r = self.required;
  1093. if (!self.allowRollup) {
  1094. oeach(r, function(v, name) {
  1095. m = self.getModule(name);
  1096. if (m && m.use) {
  1097. //delete r[name];
  1098. YArray.each(m.use, function(v) {
  1099. m = self.getModule(v);
  1100. if (m && m.use) {
  1101. //delete r[v];
  1102. YArray.each(m.use, function(v) {
  1103. r[v] = true;
  1104. });
  1105. } else {
  1106. r[v] = true;
  1107. }
  1108. });
  1109. }
  1110. });
  1111. self.required = r;
  1112. }
  1113. },
  1114. /**
  1115. * Explodes the required array to remove aliases and replace them with real modules
  1116. * @method filterRequires
  1117. * @param {Array} r The original requires array
  1118. * @return {Array} The new array of exploded requirements
  1119. */
  1120. filterRequires: function(r) {
  1121. if (r) {
  1122. if (!Y.Lang.isArray(r)) {
  1123. r = [r];
  1124. }
  1125. r = Y.Array(r);
  1126. var c = [], i, mod, o, m;
  1127. for (i = 0; i < r.length; i++) {
  1128. mod = this.getModule(r[i]);
  1129. if (mod && mod.use) {
  1130. for (o = 0; o < mod.use.length; o++) {
  1131. //Must walk the other modules in case a module is a rollup of rollups (datatype)
  1132. m = this.getModule(mod.use[o]);
  1133. if (m && m.use) {
  1134. c = Y.Array.dedupe([].concat(c, this.filterRequires(m.use)));
  1135. } else {
  1136. c.push(mod.use[o]);
  1137. }
  1138. }
  1139. } else {
  1140. c.push(r[i]);
  1141. }
  1142. }
  1143. r = c;
  1144. }
  1145. return r;
  1146. },
  1147. /**
  1148. * Returns an object containing properties for all modules required
  1149. * in order to load the requested module
  1150. * @method getRequires
  1151. * @param {object} mod The module definition from moduleInfo.
  1152. * @return {array} the expanded requirement list.
  1153. */
  1154. getRequires: function(mod) {
  1155. if (!mod || mod._parsed) {
  1156. return NO_REQUIREMENTS;
  1157. }
  1158. var i, m, j, add, packName, lang, testresults = this.testresults,
  1159. name = mod.name, cond, go,
  1160. adddef = ON_PAGE[name] && ON_PAGE[name].details,
  1161. d, k, m1,
  1162. r, old_mod,
  1163. o, skinmod, skindef, skinpar, skinname,
  1164. intl = mod.lang || mod.intl,
  1165. info = this.moduleInfo,
  1166. ftests = Y.Features && Y.Features.tests.load,
  1167. hash;
  1168. // console.log(name);
  1169. // pattern match leaves module stub that needs to be filled out
  1170. if (mod.temp && adddef) {
  1171. old_mod = mod;
  1172. mod = this.addModule(adddef, name);
  1173. mod.group = old_mod.group;
  1174. mod.pkg = old_mod.pkg;
  1175. delete mod.expanded;
  1176. }
  1177. // console.log('cache: ' + mod.langCache + ' == ' + this.lang);
  1178. // if (mod.expanded && (!mod.langCache || mod.langCache == this.lang)) {
  1179. if (mod.expanded && (!this.lang || mod.langCache === this.lang)) {
  1180. return mod.expanded;
  1181. }
  1182. d = [];
  1183. hash = {};
  1184. r = this.filterRequires(mod.requires);
  1185. if (mod.lang) {
  1186. //If a module has a lang attribute, auto add the intl requirement.
  1187. d.unshift('intl');
  1188. r.unshift('intl');
  1189. intl = true;
  1190. }
  1191. o = this.filterRequires(mod.optional);
  1192. mod._parsed = true;
  1193. mod.langCache = this.lang;
  1194. for (i = 0; i < r.length; i++) {
  1195. if (!hash[r[i]]) {
  1196. d.push(r[i]);
  1197. hash[r[i]] = true;
  1198. m = this.getModule(r[i]);
  1199. if (m) {
  1200. add = this.getRequires(m);
  1201. intl = intl || (m.expanded_map &&
  1202. (INTL in m.expanded_map));
  1203. for (j = 0; j < add.length; j++) {
  1204. d.push(add[j]);
  1205. }
  1206. }
  1207. }
  1208. }
  1209. // get the requirements from superseded modules, if any
  1210. r = this.filterRequires(mod.supersedes);
  1211. if (r) {
  1212. for (i = 0; i < r.length; i++) {
  1213. if (!hash[r[i]]) {
  1214. // if this module has submodules, the requirements list is
  1215. // expanded to include the submodules. This is so we can
  1216. // prevent dups when a submodule is already loaded and the
  1217. // parent is requested.
  1218. if (mod.submodules) {
  1219. d.push(r[i]);
  1220. }
  1221. hash[r[i]] = true;
  1222. m = this.getModule(r[i]);
  1223. if (m) {
  1224. add = this.getRequires(m);
  1225. intl = intl || (m.expanded_map &&
  1226. (INTL in m.expanded_map));
  1227. for (j = 0; j < add.length; j++) {
  1228. d.push(add[j]);
  1229. }
  1230. }
  1231. }
  1232. }
  1233. }
  1234. if (o && this.loadOptional) {
  1235. for (i = 0; i < o.length; i++) {
  1236. if (!hash[o[i]]) {
  1237. d.push(o[i]);
  1238. hash[o[i]] = true;
  1239. m = info[o[i]];
  1240. if (m) {
  1241. add = this.getRequires(m);
  1242. intl = intl || (m.expanded_map &&
  1243. (INTL in m.expanded_map));
  1244. for (j = 0; j < add.length; j++) {
  1245. d.push(add[j]);
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. cond = this.conditions[name];
  1252. if (cond) {
  1253. if (testresults && ftests) {
  1254. oeach(testresults, function(result, id) {
  1255. var condmod = ftests[id].name;
  1256. if (!hash[condmod] && ftests[id].trigger == name) {
  1257. if (result && ftests[id]) {
  1258. hash[condmod] = true;
  1259. d.push(condmod);
  1260. }
  1261. }
  1262. });
  1263. } else {
  1264. oeach(cond, function(def, condmod) {
  1265. if (!hash[condmod]) {
  1266. go = def && ((def.ua && Y.UA[def.ua]) ||
  1267. (def.test && def.test(Y, r)));
  1268. if (go) {
  1269. hash[condmod] = true;
  1270. d.push(condmod);
  1271. m = this.getModule(condmod);
  1272. if (m) {
  1273. add = this.getRequires(m);
  1274. for (j = 0; j < add.length; j++) {
  1275. d.push(add[j]);
  1276. }
  1277. }
  1278. }
  1279. }
  1280. }, this);
  1281. }
  1282. }
  1283. // Create skin modules
  1284. if (mod.skinnable) {
  1285. skindef = this.skin.overrides;
  1286. oeach(YUI.Env.aliases, function(o, n) {
  1287. if (Y.Array.indexOf(o, name) > -1) {
  1288. skinpar = n;
  1289. }
  1290. });
  1291. if (skindef && (skindef[name] || (skinpar && skindef[skinpar]))) {
  1292. skinname = name;
  1293. if (skindef[skinpar]) {
  1294. skinname = skinpar;
  1295. }
  1296. for (i = 0; i < skindef[skinname].length; i++) {
  1297. skinmod = this._addSkin(skindef[skinname][i], name);
  1298. d.push(skinmod);
  1299. }
  1300. } else {
  1301. skinmod = this._addSkin(this.skin.defaultSkin, name);
  1302. d.push(skinmod);
  1303. }
  1304. }
  1305. mod._parsed = false;
  1306. if (intl) {
  1307. if (mod.lang && !mod.langPack && Y.Intl) {
  1308. lang = Y.Intl.lookupBestLang(this.lang || ROOT_LANG, mod.lang);
  1309. packName = this.getLangPackName(lang, name);
  1310. if (packName) {
  1311. d.unshift(packName);
  1312. }
  1313. }
  1314. d.unshift(INTL);
  1315. }
  1316. mod.expanded_map = YArray.hash(d);
  1317. mod.expanded = YObject.keys(mod.expanded_map);
  1318. return mod.expanded;
  1319. },
  1320. /**
  1321. * Returns a hash of module names the supplied module satisfies.
  1322. * @method getProvides
  1323. * @param {string} name The name of the module.
  1324. * @return {object} what this module provides.
  1325. */
  1326. getProvides: function(name) {
  1327. var m = this.getModule(name), o, s;
  1328. // supmap = this.provides;
  1329. if (!m) {
  1330. return NOT_FOUND;
  1331. }
  1332. if (m && !m.provides) {
  1333. o = {};
  1334. s = m.supersedes;
  1335. if (s) {
  1336. YArray.each(s, function(v) {
  1337. Y.mix(o, this.getProvides(v));
  1338. }, this);
  1339. }
  1340. o[name] = true;
  1341. m.provides = o;
  1342. }
  1343. return m.provides;
  1344. },
  1345. /**
  1346. * Calculates the dependency tree, the result is stored in the sorted
  1347. * property.
  1348. * @method calculate
  1349. * @param {object} o optional options object.
  1350. * @param {string} type optional argument to prune modules.
  1351. */
  1352. calculate: function(o, type) {
  1353. if (o || type || this.dirty) {
  1354. if (o) {
  1355. this._config(o);
  1356. }
  1357. if (!this._init) {
  1358. this._setup();
  1359. }
  1360. this._explode();
  1361. if (this.allowRollup) {
  1362. this._rollup();
  1363. } else {
  1364. this._explodeRollups();
  1365. }
  1366. this._reduce();
  1367. this._sort();
  1368. }
  1369. },
  1370. /**
  1371. * Creates a "psuedo" package for languages provided in the lang array
  1372. * @method _addLangPack
  1373. * @param {String} lang The language to create
  1374. * @param {Object} m The module definition to create the language pack around
  1375. * @param {String} packName The name of the package (e.g: lang/datatype-date-en-US)
  1376. * @return {Object} The module definition
  1377. */
  1378. _addLangPack: function(lang, m, packName) {
  1379. var name = m.name,
  1380. packPath,
  1381. existing = this.moduleInfo[packName];
  1382. if (!existing) {
  1383. packPath = _path((m.pkg || name), packName, JS, true);
  1384. this.addModule({ path: packPath,
  1385. intl: true,
  1386. langPack: true,
  1387. ext: m.ext,
  1388. group: m.group,
  1389. supersedes: [] }, packName);
  1390. if (lang) {
  1391. Y.Env.lang = Y.Env.lang || {};
  1392. Y.Env.lang[lang] = Y.Env.lang[lang] || {};
  1393. Y.Env.lang[lang][name] = true;
  1394. }
  1395. }
  1396. return this.moduleInfo[packName];
  1397. },
  1398. /**
  1399. * Investigates the current YUI configuration on the page. By default,
  1400. * modules already detected will not be loaded again unless a force
  1401. * option is encountered. Called by calculate()
  1402. * @method _setup
  1403. * @private
  1404. */
  1405. _setup: function() {
  1406. var info = this.moduleInfo, name, i, j, m, l,
  1407. packName;
  1408. for (name in info) {
  1409. if (info.hasOwnProperty(name)) {
  1410. m = info[name];
  1411. if (m) {
  1412. // remove dups
  1413. //m.requires = YObject.keys(YArray.hash(m.requires));
  1414. m.requires = YArray.dedupe(m.requires);
  1415. // Create lang pack modules
  1416. if (m.lang && m.lang.length) {
  1417. // Setup root package if the module has lang defined,
  1418. // it needs to provide a root language pack
  1419. packName = this.getLangPackName(ROOT_LANG, name);
  1420. this._addLangPack(null, m, packName);
  1421. }
  1422. }
  1423. }
  1424. }
  1425. //l = Y.merge(this.inserted);
  1426. l = {};
  1427. // available modules
  1428. if (!this.ignoreRegistered) {
  1429. Y.mix(l, GLOBAL_ENV.mods);
  1430. }
  1431. // add the ignore list to the list of loaded packages
  1432. if (this.ignore) {
  1433. Y.mix(l, YArray.hash(this.ignore));
  1434. }
  1435. // expand the list to include superseded modules
  1436. for (j in l) {
  1437. if (l.hasOwnProperty(j)) {
  1438. Y.mix(l, this.getProvides(j));
  1439. }
  1440. }
  1441. // remove modules on the force list from the loaded list
  1442. if (this.force) {
  1443. for (i = 0; i < this.force.length; i++) {
  1444. if (this.force[i] in l) {
  1445. delete l[this.force[i]];
  1446. }
  1447. }
  1448. }
  1449. Y.mix(this.loaded, l);
  1450. this._init = true;
  1451. },
  1452. /**
  1453. * Builds a module name for a language pack
  1454. * @method getLangPackName
  1455. * @param {string} lang the language code.
  1456. * @param {string} mname the module to build it for.
  1457. * @return {string} the language pack module name.
  1458. */
  1459. getLangPackName: function(lang, mname) {
  1460. return ('lang/' + mname + ((lang) ? '_' + lang : ''));
  1461. },
  1462. /**
  1463. * Inspects the required modules list looking for additional
  1464. * dependencies. Expands the required list to include all
  1465. * required modules. Called by calculate()
  1466. * @method _explode
  1467. * @private
  1468. */
  1469. _explode: function() {
  1470. var r = this.required, m, reqs, done = {},
  1471. self = this;
  1472. // the setup phase is over, all modules have been created
  1473. self.dirty = false;
  1474. self._explodeRollups();
  1475. r = self.required;
  1476. oeach(r, function(v, name) {
  1477. if (!done[name]) {
  1478. done[name] = true;
  1479. m = self.getModule(name);
  1480. if (m) {
  1481. var expound = m.expound;
  1482. if (expound) {
  1483. r[expound] = self.getModule(expound);
  1484. reqs = self.getRequires(r[expound]);
  1485. Y.mix(r, YArray.hash(reqs));
  1486. }
  1487. reqs = self.getRequires(m);
  1488. Y.mix(r, YArray.hash(reqs));
  1489. }
  1490. }
  1491. });
  1492. },
  1493. /**
  1494. * Get's the loader meta data for the requested module
  1495. * @method getModule
  1496. * @param {String} mname The module name to get
  1497. * @return {Object} The module metadata
  1498. */
  1499. getModule: function(mname) {
  1500. //TODO: Remove name check - it's a quick hack to fix pattern WIP
  1501. if (!mname) {
  1502. return null;
  1503. }
  1504. var p, found, pname,
  1505. m = this.moduleInfo[mname],
  1506. patterns = this.patterns;
  1507. // check the patterns library to see if we should automatically add
  1508. // the module with defaults
  1509. if (!m) {
  1510. for (pname in patterns) {
  1511. if (patterns.hasOwnProperty(pname)) {
  1512. p = patterns[pname];
  1513. // use the metadata supplied for the pattern
  1514. // as the module definition.
  1515. if (mname.indexOf(pname) > -1) {
  1516. found = p;
  1517. break;
  1518. }
  1519. }
  1520. }
  1521. if (found) {
  1522. if (p.action) {
  1523. p.action.call(this, mname, pname);
  1524. } else {
  1525. // ext true or false?
  1526. m = this.addModule(Y.merge(found), mname);
  1527. m.temp = true;
  1528. }
  1529. }
  1530. }
  1531. return m;
  1532. },
  1533. // impl in rollup submodule
  1534. _rollup: function() { },
  1535. /**
  1536. * Remove superceded modules and loaded modules. Called by
  1537. * calculate() after we have the mega list of all dependencies
  1538. * @method _reduce
  1539. * @return {object} the reduced dependency hash.
  1540. * @private
  1541. */
  1542. _reduce: function(r) {
  1543. r = r || this.required;
  1544. var i, j, s, m, type = this.loadType,
  1545. ignore = this.ignore ? YArray.hash(this.ignore) : false;
  1546. for (i in r) {
  1547. if (r.hasOwnProperty(i)) {
  1548. m = this.getModule(i);
  1549. // remove if already loaded
  1550. if (((this.loaded[i] || ON_PAGE[i]) &&
  1551. !this.forceMap[i] && !this.ignoreRegistered) ||
  1552. (type && m && m.type != type)) {
  1553. delete r[i];
  1554. }
  1555. if (ignore && ignore[i]) {
  1556. delete r[i];
  1557. }
  1558. // remove anything this module supersedes
  1559. s = m && m.supersedes;
  1560. if (s) {
  1561. for (j = 0; j < s.length; j++) {
  1562. if (s[j] in r) {
  1563. delete r[s[j]];
  1564. }
  1565. }
  1566. }
  1567. }
  1568. }
  1569. return r;
  1570. },
  1571. /**
  1572. * Handles the queue when a module has been loaded for all cases
  1573. * @method _finish
  1574. * @private
  1575. * @param {String} msg The message from Loader
  1576. * @param {Boolean} success A boolean denoting success or failure
  1577. */
  1578. _finish: function(msg, success) {
  1579. _queue.running = false;
  1580. var onEnd = this.onEnd;
  1581. if (onEnd) {
  1582. onEnd.call(this.context, {
  1583. msg: msg,
  1584. data: this.data,
  1585. success: success
  1586. });
  1587. }
  1588. this._continue();
  1589. },
  1590. /**
  1591. * The default Loader onSuccess handler, calls this.onSuccess with a payload
  1592. * @method _onSuccess
  1593. * @private
  1594. */
  1595. _onSuccess: function() {
  1596. var self = this, skipped = Y.merge(self.skipped), fn,
  1597. failed = [], rreg = self.requireRegistration,
  1598. success, msg;
  1599. oeach(skipped, function(k) {
  1600. delete self.inserted[k];
  1601. });
  1602. self.skipped = {};
  1603. oeach(self.inserted, function(v, k) {
  1604. var mod = self.getModule(k);
  1605. if (mod && rreg && mod.type == JS && !(k in YUI.Env.mods)) {
  1606. failed.push(k);
  1607. } else {
  1608. Y.mix(self.loaded, self.getProvides(k));
  1609. }
  1610. });
  1611. fn = self.onSuccess;
  1612. msg = (failed.length) ? 'notregistered' : 'success';
  1613. success = !(failed.length);
  1614. if (fn) {
  1615. fn.call(self.context, {
  1616. msg: msg,
  1617. data: self.data,
  1618. success: success,
  1619. failed: failed,
  1620. skipped: skipped
  1621. });
  1622. }
  1623. self._finish(msg, success);
  1624. },
  1625. /**
  1626. * The default Loader onFailure handler, calls this.onFailure with a payload
  1627. * @method _onFailure
  1628. * @private
  1629. */
  1630. _onFailure: function(o) {
  1631. var f = this.onFailure, msg = 'failure: ' + o.msg;
  1632. if (f) {
  1633. f.call(this.context, {
  1634. msg: msg,
  1635. data: this.data,
  1636. success: false
  1637. });
  1638. }
  1639. this._finish(msg, false);
  1640. },
  1641. /**
  1642. * The default Loader onTimeout handler, calls this.onTimeout with a payload
  1643. * @method _onTimeout
  1644. * @private
  1645. */
  1646. _onTimeout: function() {
  1647. var f = this.onTimeout;
  1648. if (f) {
  1649. f.call(this.context, {
  1650. msg: 'timeout',
  1651. data: this.data,
  1652. success: false
  1653. });
  1654. }
  1655. this._finish('timeout', false);
  1656. },
  1657. /**
  1658. * Sorts the dependency tree. The last step of calculate()
  1659. * @method _sort
  1660. * @private
  1661. */
  1662. _sort: function() {
  1663. // create an indexed list
  1664. var s = YObject.keys(this.required),
  1665. // loaded = this.loaded,
  1666. done = {},
  1667. p = 0, l, a, b, j, k, moved, doneKey;
  1668. // keep going until we make a pass without moving anything
  1669. for (;;) {
  1670. l = s.length;
  1671. moved = false;
  1672. // start the loop after items that are already sorted
  1673. for (j = p; j < l; j++) {
  1674. // check the next module on the list to see if its
  1675. // dependencies have been met
  1676. a = s[j];
  1677. // check everything below current item and move if we
  1678. // find a requirement for the current item
  1679. for (k = j + 1; k < l; k++) {
  1680. doneKey = a + s[k];
  1681. if (!done[doneKey] && this._requires(a, s[k])) {
  1682. // extract the dependency so we can move it up
  1683. b = s.splice(k, 1);
  1684. // insert the dependency above the item that
  1685. // requires it
  1686. s.splice(j, 0, b[0]);
  1687. // only swap two dependencies once to short circut
  1688. // circular dependencies
  1689. done[doneKey] = true;
  1690. // keep working
  1691. moved = true;
  1692. break;
  1693. }
  1694. }
  1695. // jump out of loop if we moved something
  1696. if (moved) {
  1697. break;
  1698. // this item is sorted, move our pointer and keep going
  1699. } else {
  1700. p++;
  1701. }
  1702. }
  1703. // when we make it here and moved is false, we are
  1704. // finished sorting
  1705. if (!moved) {
  1706. break;
  1707. }
  1708. }
  1709. this.sorted = s;
  1710. },
  1711. /**
  1712. * (Unimplemented)
  1713. * @method partial
  1714. * @unimplemented
  1715. */
  1716. partial: function(partial, o, type) {
  1717. this.sorted = partial;
  1718. this.insert(o, type, true);
  1719. },
  1720. /**
  1721. * Handles the actual insertion of script/link tags
  1722. * @method _insert
  1723. * @param {Object} source The YUI instance the request came from
  1724. * @param {Object} o The metadata to include
  1725. * @param {String} type JS or CSS
  1726. * @param {Boolean} [skipcalc=false] Do a Loader.calculate on the meta
  1727. */
  1728. _insert: function(source, o, type, skipcalc) {
  1729. // restore the state at the time of the request
  1730. if (source) {
  1731. this._config(source);
  1732. }
  1733. // build the dependency list
  1734. // don't include type so we can process CSS and script in
  1735. // one pass when the type is not specified.
  1736. if (!skipcalc) {
  1737. this.calculate(o);
  1738. }
  1739. this.loadType = type;
  1740. if (!type) {
  1741. var self = this;
  1742. this._internalCallback = function() {
  1743. var f = self.onCSS, n, p, sib;
  1744. // IE hack for style overrides that are not being applied
  1745. if (this.insertBefore && Y.UA.ie) {
  1746. n = Y.config.doc.getElementById(this.insertBefore);
  1747. p = n.parentNode;
  1748. sib = n.nextSibling;
  1749. p.removeChild(n);
  1750. if (sib) {
  1751. p.insertBefore(n, sib);
  1752. } else {
  1753. p.appendChild(n);
  1754. }
  1755. }
  1756. if (f) {
  1757. f.call(self.context, Y);
  1758. }
  1759. self._internalCallback = null;
  1760. self._insert(null, null, JS);
  1761. };
  1762. this._insert(null, null, CSS);
  1763. return;
  1764. }
  1765. // set a flag to indicate the load has started
  1766. this._loading = true;
  1767. // flag to indicate we are done with the combo service
  1768. // and any additional files will need to be loaded
  1769. // individually
  1770. this._combineComplete = {};
  1771. // start the load
  1772. this.loadNext();
  1773. },
  1774. /**
  1775. * Once a loader operation is completely finished, process any additional queued items.
  1776. * @method _continue
  1777. * @private
  1778. */
  1779. _continue: function() {
  1780. if (!(_queue.running) && _queue.size() > 0) {
  1781. _queue.running = true;
  1782. _queue.next()();
  1783. }
  1784. },
  1785. /**
  1786. * inserts the requested modules and their dependencies.
  1787. * <code>type</code> can be "js" or "css". Both script and
  1788. * css are inserted if type is not provided.
  1789. * @method insert
  1790. * @param {object} o optional options object.
  1791. * @param {string} type the type of dependency to insert.
  1792. */
  1793. insert: function(o, type, skipsort) {
  1794. var self = this, copy = Y.merge(this);
  1795. delete copy.require;
  1796. delete copy.dirty;
  1797. _queue.add(function() {
  1798. self._insert(copy, o, type, skipsort);
  1799. });
  1800. this._continue();
  1801. },
  1802. /**
  1803. * Executed every time a module is loaded, and if we are in a load
  1804. * cycle, we attempt to load the next script. Public so that it
  1805. * is possible to call this if using a method other than
  1806. * Y.register to determine when scripts are fully loaded
  1807. * @method loadNext
  1808. * @param {string} mname optional the name of the module that has
  1809. * been loaded (which is usually why it is time to load the next
  1810. * one).
  1811. */
  1812. loadNext: function(mname) {
  1813. // It is possible that this function is executed due to something
  1814. // else on the page loading a YUI module. Only react when we
  1815. // are actively loading something
  1816. if (!this._loading) {
  1817. return;
  1818. }
  1819. var s, len, i, m, url, fn, msg, attr, group, groupName, j, frag,
  1820. comboSource, comboSources, mods, combining, urls, comboBase,
  1821. self = this,
  1822. type = self.loadType,
  1823. handleSuccess = function(o) {
  1824. self.loadNext(o.data);
  1825. },
  1826. handleCombo = function(o) {
  1827. self._combineComplete[type] = true;
  1828. var i, len = combining.length;
  1829. for (i = 0; i < len; i++) {
  1830. self.inserted[combining[i]] = true;
  1831. }
  1832. handleSuccess(o);
  1833. };
  1834. if (self.combine && (!self._combineComplete[type])) {
  1835. combining = [];
  1836. self._combining = combining;
  1837. s = self.sorted;
  1838. len = s.length;
  1839. // the default combo base
  1840. comboBase = self.comboBase;
  1841. url = comboBase;
  1842. urls = [];
  1843. comboSources = {};
  1844. for (i = 0; i < len; i++) {
  1845. comboSource = comboBase;
  1846. m = self.getModule(s[i]);
  1847. groupName = m && m.group;
  1848. if (groupName) {
  1849. group = self.groups[groupName];
  1850. if (!group.combine) {
  1851. m.combine = false;
  1852. continue;
  1853. }
  1854. m.combine = true;
  1855. if (group.comboBase) {
  1856. comboSource = group.comboBase;
  1857. }
  1858. if ("root" in group && L.isValue(group.root)) {
  1859. m.root = group.root;
  1860. }
  1861. }
  1862. comboSources[comboSource] = comboSources[comboSource] || [];
  1863. comboSources[comboSource].push(m);
  1864. }
  1865. for (j in comboSources) {
  1866. if (comboSources.hasOwnProperty(j)) {
  1867. url = j;
  1868. mods = comboSources[j];
  1869. len = mods.length;
  1870. for (i = 0; i < len; i++) {
  1871. // m = self.getModule(s[i]);
  1872. m = mods[i];
  1873. // Do not try to combine non-yui JS unless combo def
  1874. // is found
  1875. if (m && (m.type === type) && (m.combine || !m.ext)) {
  1876. frag = ((L.isValue(m.root)) ? m.root : self.root) + m.path;
  1877. frag = self._filter(frag, m.name);
  1878. if ((url !== j) && (i <= (len - 1)) &&
  1879. ((frag.length + url.length) > self.maxURLLength)) {
  1880. //Hack until this is rewritten to use an array and not string concat:
  1881. if (url.substr(url.length - 1, 1) === self.comboSep) {
  1882. url = url.substr(0, (url.length - 1));
  1883. }
  1884. urls.push(self._filter(url));
  1885. url = j;
  1886. }
  1887. url += frag;
  1888. if (i < (len - 1)) {
  1889. url += self.comboSep;
  1890. }
  1891. combining.push(m.name);
  1892. }
  1893. }
  1894. if (combining.length && (url != j)) {
  1895. //Hack until this is rewritten to use an array and not string concat:
  1896. if (url.substr(url.length - 1, 1) === self.comboSep) {
  1897. url = url.substr(0, (url.length - 1));
  1898. }
  1899. urls.push(self._filter(url));
  1900. }
  1901. }
  1902. }
  1903. if (combining.length) {
  1904. // if (m.type === CSS) {
  1905. if (type === CSS) {
  1906. fn = Y.Get.css;
  1907. attr = self.cssAttributes;
  1908. } else {
  1909. fn = Y.Get.script;
  1910. attr = self.jsAttributes;
  1911. }
  1912. fn(urls, {
  1913. data: self._loading,
  1914. onSuccess: handleCombo,
  1915. onFailure: self._onFailure,
  1916. onTimeout: self._onTimeout,
  1917. insertBefore: self.insertBefore,
  1918. charset: self.charset,
  1919. attributes: attr,
  1920. timeout: self.timeout,
  1921. autopurge: false,
  1922. context: self
  1923. });
  1924. return;
  1925. } else {
  1926. self._combineComplete[type] = true;
  1927. }
  1928. }
  1929. if (mname) {
  1930. // if the module that was just loaded isn't what we were expecting,
  1931. // continue to wait
  1932. if (mname !== self._loading) {
  1933. return;
  1934. }
  1935. // The global handler that is called when each module is loaded
  1936. // will pass that module name to this function. Storing this
  1937. // data to avoid loading the same module multiple times
  1938. // centralize this in the callback
  1939. self.inserted[mname] = true;
  1940. // self.loaded[mname] = true;
  1941. // provided = self.getProvides(mname);
  1942. // Y.mix(self.loaded, provided);
  1943. // Y.mix(self.inserted, provided);
  1944. if (self.onProgress) {
  1945. self.onProgress.call(self.context, {
  1946. name: mname,
  1947. data: self.data
  1948. });
  1949. }
  1950. }
  1951. s = self.sorted;
  1952. len = s.length;
  1953. for (i = 0; i < len; i = i + 1) {
  1954. // this.inserted keeps track of what the loader has loaded.
  1955. // move on if this item is done.
  1956. if (s[i] in self.inserted) {
  1957. continue;
  1958. }
  1959. // Because rollups will cause multiple load notifications
  1960. // from Y, loadNext may be called multiple times for
  1961. // the same module when loading a rollup. We can safely
  1962. // skip the subsequent requests
  1963. if (s[i] === self._loading) {
  1964. return;
  1965. }
  1966. // log("inserting " + s[i]);
  1967. m = self.getModule(s[i]);
  1968. if (!m) {
  1969. if (!self.skipped[s[i]]) {
  1970. msg = 'Undefined module ' + s[i] + ' skipped';
  1971. // self.inserted[s[i]] = true;
  1972. self.skipped[s[i]] = true;
  1973. }
  1974. continue;
  1975. }
  1976. group = (m.group && self.groups[m.group]) || NOT_FOUND;
  1977. // The load type is stored to offer the possibility to load
  1978. // the css separately from the script.
  1979. if (!type || type === m.type) {
  1980. self._loading = s[i];
  1981. if (m.type === CSS) {
  1982. fn = Y.Get.css;
  1983. attr = self.cssAttributes;
  1984. } else {
  1985. fn = Y.Get.script;
  1986. attr = self.jsAttributes;
  1987. }
  1988. url = (m.fullpath) ? self._filter(m.fullpath, s[i]) :
  1989. self._url(m.path, s[i], group.base || m.base);
  1990. fn(url, {
  1991. data: s[i],
  1992. onSuccess: handleSuccess,
  1993. insertBefore: self.insertBefore,
  1994. charset: self.charset,
  1995. attributes: attr,
  1996. onFailure: self._onFailure,
  1997. onTimeout: self._onTimeout,
  1998. timeout: self.timeout,
  1999. autopurge: false,
  2000. context: self
  2001. });
  2002. return;
  2003. }
  2004. }
  2005. // we are finished
  2006. self._loading = null;
  2007. fn = self._internalCallback;
  2008. // internal callback for loading css first
  2009. if (fn) {
  2010. self._internalCallback = null;
  2011. fn.call(self);
  2012. } else {
  2013. self._onSuccess();
  2014. }
  2015. },
  2016. /**
  2017. * Apply filter defined for this instance to a url/path
  2018. * @method _filter
  2019. * @param {string} u the string to filter.
  2020. * @param {string} name the name of the module, if we are processing
  2021. * a single module as opposed to a combined url.
  2022. * @return {string} the filtered string.
  2023. * @private
  2024. */
  2025. _filter: function(u, name) {
  2026. var f = this.filter,
  2027. hasFilter = name && (name in this.filters),
  2028. modFilter = hasFilter && this.filters[name],
  2029. groupName = this.moduleInfo[name] ? this.moduleInfo[name].group:null;
  2030. if (groupName && this.groups[groupName] && this.groups[groupName].filter) {
  2031. modFilter = this.groups[groupName].filter;
  2032. hasFilter = true;
  2033. };
  2034. if (u) {
  2035. if (hasFilter) {
  2036. f = (L.isString(modFilter)) ?
  2037. this.FILTER_DEFS[modFilter.toUpperCase()] || null :
  2038. modFilter;
  2039. }
  2040. if (f) {
  2041. u = u.replace(new RegExp(f.searchExp, 'g'), f.replaceStr);
  2042. }
  2043. }
  2044. return u;
  2045. },
  2046. /**
  2047. * Generates the full url for a module
  2048. * @method _url
  2049. * @param {string} path the path fragment.
  2050. * @param {String} name The name of the module
  2051. * @pamra {String} [base=self.base] The base url to use
  2052. * @return {string} the full url.
  2053. * @private
  2054. */
  2055. _url: function(path, name, base) {
  2056. return this._filter((base || this.base || '') + path, name);
  2057. },
  2058. /**
  2059. * Returns an Object hash of file arrays built from `loader.sorted` or from an arbitrary list of sorted modules.
  2060. * @method resolve
  2061. * @param {Boolean} [calc=false] Perform a loader.calculate() before anything else
  2062. * @param {Array} [s=loader.sorted] An override for the loader.sorted array
  2063. * @return {Object} Object hash (js and css) of two arrays of file lists
  2064. * @example This method can be used as an off-line dep calculator
  2065. *
  2066. * var Y = YUI();
  2067. * var loader = new Y.Loader({
  2068. * filter: 'debug',
  2069. * base: '../../',
  2070. * root: 'build/',
  2071. * combine: true,
  2072. * require: ['node', 'dd', 'console']
  2073. * });
  2074. * var out = loader.resolve(true);
  2075. *
  2076. */
  2077. resolve: function(calc, s) {
  2078. var self = this, i, m, url, out = { js: [], css: [] };
  2079. if (calc) {
  2080. self.calculate();
  2081. }
  2082. s = s || self.sorted;
  2083. for (i = 0; i < s.length; i++) {
  2084. m = self.getModule(s[i]);
  2085. if (m) {
  2086. if (self.combine) {
  2087. url = self._filter((self.root + m.path), m.name, self.root);
  2088. } else {
  2089. url = self._filter(m.fullpath, m.name, '') || self._url(m.path, m.name);
  2090. }
  2091. out[m.type].push(url);
  2092. }
  2093. }
  2094. if (self.combine) {
  2095. out.js = [self.comboBase + out.js.join(self.comboSep)];
  2096. out.css = [self.comboBase + out.css.join(self.comboSep)];
  2097. }
  2098. return out;
  2099. },
  2100. /**
  2101. * Returns an Object hash of hashes built from `loader.sorted` or from an arbitrary list of sorted modules.
  2102. * @method hash
  2103. * @private
  2104. * @param {Boolean} [calc=false] Perform a loader.calculate() before anything else
  2105. * @param {Array} [s=loader.sorted] An override for the loader.sorted array
  2106. * @return {Object} Object hash (js and css) of two object hashes of file lists, with the module name as the key
  2107. * @example This method can be used as an off-line dep calculator
  2108. *
  2109. * var Y = YUI();
  2110. * var loader = new Y.Loader({
  2111. * filter: 'debug',
  2112. * base: '../../',
  2113. * root: 'build/',
  2114. * combine: true,
  2115. * require: ['node', 'dd', 'console']
  2116. * });
  2117. * var out = loader.hash(true);
  2118. *
  2119. */
  2120. hash: function(calc, s) {
  2121. var self = this, i, m, url, out = { js: {}, css: {} };
  2122. if (calc) {
  2123. self.calculate();
  2124. }
  2125. s = s || self.sorted;
  2126. for (i = 0; i < s.length; i++) {
  2127. m = self.getModule(s[i]);
  2128. if (m) {
  2129. url = self._filter(m.fullpath, m.name, '') || self._url(m.path, m.name);
  2130. out[m.type][m.name] = url;
  2131. }
  2132. }
  2133. return out;
  2134. }
  2135. };
  2136. }, '3.4.0' ,{requires:['get']});