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-debug.js 79KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495
  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. // Y.log('group: ' + j);
  717. groupName = j;
  718. group = val[j];
  719. self.addGroup(group, groupName);
  720. }
  721. }
  722. } else if (i == 'modules') {
  723. // add a hash of module definitions
  724. oeach(val, self.addModule, self);
  725. } else if (i == 'gallery') {
  726. this.groups.gallery.update(val);
  727. } else if (i == 'yui2' || i == '2in3') {
  728. this.groups.yui2.update(o['2in3'], o.yui2);
  729. } else if (i == 'maxURLLength') {
  730. self[i] = Math.min(MAX_URL_LENGTH, val);
  731. } else {
  732. self[i] = val;
  733. }
  734. }
  735. }
  736. }
  737. // fix filter
  738. f = self.filter;
  739. if (L.isString(f)) {
  740. f = f.toUpperCase();
  741. self.filterName = f;
  742. self.filter = self.FILTER_DEFS[f];
  743. if (f == 'DEBUG') {
  744. self.require('yui-log', 'dump');
  745. }
  746. }
  747. if (self.lang) {
  748. self.require('intl-base', 'intl');
  749. }
  750. },
  751. /**
  752. * Returns the skin module name for the specified skin name. If a
  753. * module name is supplied, the returned skin module name is
  754. * specific to the module passed in.
  755. * @method formatSkin
  756. * @param {string} skin the name of the skin.
  757. * @param {string} mod optional: the name of a module to skin.
  758. * @return {string} the full skin module name.
  759. */
  760. formatSkin: function(skin, mod) {
  761. var s = SKIN_PREFIX + skin;
  762. if (mod) {
  763. s = s + '-' + mod;
  764. }
  765. return s;
  766. },
  767. /**
  768. * Adds the skin def to the module info
  769. * @method _addSkin
  770. * @param {string} skin the name of the skin.
  771. * @param {string} mod the name of the module.
  772. * @param {string} parent parent module if this is a skin of a
  773. * submodule or plugin.
  774. * @return {string} the module name for the skin.
  775. * @private
  776. */
  777. _addSkin: function(skin, mod, parent) {
  778. var mdef, pkg, name, nmod,
  779. info = this.moduleInfo,
  780. sinf = this.skin,
  781. ext = info[mod] && info[mod].ext;
  782. // Add a module definition for the module-specific skin css
  783. if (mod) {
  784. name = this.formatSkin(skin, mod);
  785. if (!info[name]) {
  786. mdef = info[mod];
  787. pkg = mdef.pkg || mod;
  788. nmod = {
  789. name: name,
  790. group: mdef.group,
  791. type: 'css',
  792. after: sinf.after,
  793. path: (parent || pkg) + '/' + sinf.base + skin +
  794. '/' + mod + '.css',
  795. ext: ext
  796. };
  797. if (mdef.base) {
  798. nmod.base = mdef.base;
  799. }
  800. if (mdef.configFn) {
  801. nmod.configFn = mdef.configFn;
  802. }
  803. this.addModule(nmod, name);
  804. Y.log('adding skin ' + name + ', ' + parent + ', ' + pkg + ', ' + info[name].path);
  805. }
  806. }
  807. return name;
  808. },
  809. /**
  810. * Add a new module group
  811. * <dl>
  812. * <dt>name:</dt> <dd>required, the group name</dd>
  813. * <dt>base:</dt> <dd>The base dir for this module group</dd>
  814. * <dt>root:</dt> <dd>The root path to add to each combo
  815. * resource path</dd>
  816. * <dt>combine:</dt> <dd>combo handle</dd>
  817. * <dt>comboBase:</dt> <dd>combo service base path</dd>
  818. * <dt>modules:</dt> <dd>the group of modules</dd>
  819. * </dl>
  820. * @method addGroup
  821. * @param {object} o An object containing the module data.
  822. * @param {string} name the group name.
  823. */
  824. addGroup: function(o, name) {
  825. var mods = o.modules,
  826. self = this;
  827. name = name || o.name;
  828. o.name = name;
  829. self.groups[name] = o;
  830. if (o.patterns) {
  831. oeach(o.patterns, function(v, k) {
  832. v.group = name;
  833. self.patterns[k] = v;
  834. });
  835. }
  836. if (mods) {
  837. oeach(mods, function(v, k) {
  838. v.group = name;
  839. self.addModule(v, k);
  840. }, self);
  841. }
  842. },
  843. /**
  844. * Add a new module to the component metadata.
  845. * <dl>
  846. * <dt>name:</dt> <dd>required, the component name</dd>
  847. * <dt>type:</dt> <dd>required, the component type (js or css)
  848. * </dd>
  849. * <dt>path:</dt> <dd>required, the path to the script from
  850. * "base"</dd>
  851. * <dt>requires:</dt> <dd>array of modules required by this
  852. * component</dd>
  853. * <dt>optional:</dt> <dd>array of optional modules for this
  854. * component</dd>
  855. * <dt>supersedes:</dt> <dd>array of the modules this component
  856. * replaces</dd>
  857. * <dt>after:</dt> <dd>array of modules the components which, if
  858. * present, should be sorted above this one</dd>
  859. * <dt>after_map:</dt> <dd>faster alternative to 'after' -- supply
  860. * a hash instead of an array</dd>
  861. * <dt>rollup:</dt> <dd>the number of superseded modules required
  862. * for automatic rollup</dd>
  863. * <dt>fullpath:</dt> <dd>If fullpath is specified, this is used
  864. * instead of the configured base + path</dd>
  865. * <dt>skinnable:</dt> <dd>flag to determine if skin assets should
  866. * automatically be pulled in</dd>
  867. * <dt>submodules:</dt> <dd>a hash of submodules</dd>
  868. * <dt>group:</dt> <dd>The group the module belongs to -- this
  869. * is set automatically when it is added as part of a group
  870. * configuration.</dd>
  871. * <dt>lang:</dt>
  872. * <dd>array of BCP 47 language tags of languages for which this
  873. * module has localized resource bundles,
  874. * e.g., ["en-GB","zh-Hans-CN"]</dd>
  875. * <dt>condition:</dt>
  876. * <dd>Specifies that the module should be loaded automatically if
  877. * a condition is met. This is an object with up to three fields:
  878. * [trigger] - the name of a module that can trigger the auto-load
  879. * [test] - a function that returns true when the module is to be
  880. * loaded.
  881. * [when] - specifies the load order of the conditional module
  882. * with regard to the position of the trigger module.
  883. * This should be one of three values: 'before', 'after', or
  884. * 'instead'. The default is 'after'.
  885. * </dd>
  886. * <dt>testresults:</dt><dd>a hash of test results from Y.Features.all()</dd>
  887. * </dl>
  888. * @method addModule
  889. * @param {object} o An object containing the module data.
  890. * @param {string} name the module name (optional), required if not
  891. * in the module data.
  892. * @return {object} the module definition or null if
  893. * the object passed in did not provide all required attributes.
  894. */
  895. addModule: function(o, name) {
  896. name = name || o.name;
  897. //Only merge this data if the temp flag is set
  898. //from an earlier pass from a pattern or else
  899. //an override module (YUI_config) can not be used to
  900. //replace a default module.
  901. if (this.moduleInfo[name] && this.moduleInfo[name].temp) {
  902. //This catches temp modules loaded via a pattern
  903. // The module will be added twice, once from the pattern and
  904. // Once from the actual add call, this ensures that properties
  905. // that were added to the module the first time around (group: gallery)
  906. // are also added the second time around too.
  907. o = Y.merge(this.moduleInfo[name], o);
  908. }
  909. o.name = name;
  910. if (!o || !o.name) {
  911. return null;
  912. }
  913. if (!o.type) {
  914. o.type = JS;
  915. }
  916. if (!o.path && !o.fullpath) {
  917. o.path = _path(name, name, o.type);
  918. }
  919. o.supersedes = o.supersedes || o.use;
  920. o.ext = ('ext' in o) ? o.ext : (this._internal) ? false : true;
  921. o.requires = this.filterRequires(o.requires) || [];
  922. // Handle submodule logic
  923. var subs = o.submodules, i, l, t, sup, s, smod, plugins, plug,
  924. j, langs, packName, supName, flatSup, flatLang, lang, ret,
  925. overrides, skinname, when,
  926. conditions = this.conditions, trigger;
  927. // , existing = this.moduleInfo[name], newr;
  928. this.moduleInfo[name] = o;
  929. if (!o.langPack && o.lang) {
  930. langs = YArray(o.lang);
  931. for (j = 0; j < langs.length; j++) {
  932. lang = langs[j];
  933. packName = this.getLangPackName(lang, name);
  934. smod = this.moduleInfo[packName];
  935. if (!smod) {
  936. smod = this._addLangPack(lang, o, packName);
  937. }
  938. }
  939. }
  940. if (subs) {
  941. sup = o.supersedes || [];
  942. l = 0;
  943. for (i in subs) {
  944. if (subs.hasOwnProperty(i)) {
  945. s = subs[i];
  946. s.path = s.path || _path(name, i, o.type);
  947. s.pkg = name;
  948. s.group = o.group;
  949. if (s.supersedes) {
  950. sup = sup.concat(s.supersedes);
  951. }
  952. smod = this.addModule(s, i);
  953. sup.push(i);
  954. if (smod.skinnable) {
  955. o.skinnable = true;
  956. overrides = this.skin.overrides;
  957. if (overrides && overrides[i]) {
  958. for (j = 0; j < overrides[i].length; j++) {
  959. skinname = this._addSkin(overrides[i][j],
  960. i, name);
  961. sup.push(skinname);
  962. }
  963. }
  964. skinname = this._addSkin(this.skin.defaultSkin,
  965. i, name);
  966. sup.push(skinname);
  967. }
  968. // looks like we are expected to work out the metadata
  969. // for the parent module language packs from what is
  970. // specified in the child modules.
  971. if (s.lang && s.lang.length) {
  972. langs = YArray(s.lang);
  973. for (j = 0; j < langs.length; j++) {
  974. lang = langs[j];
  975. packName = this.getLangPackName(lang, name);
  976. supName = this.getLangPackName(lang, i);
  977. smod = this.moduleInfo[packName];
  978. if (!smod) {
  979. smod = this._addLangPack(lang, o, packName);
  980. }
  981. flatSup = flatSup || YArray.hash(smod.supersedes);
  982. if (!(supName in flatSup)) {
  983. smod.supersedes.push(supName);
  984. }
  985. o.lang = o.lang || [];
  986. flatLang = flatLang || YArray.hash(o.lang);
  987. if (!(lang in flatLang)) {
  988. o.lang.push(lang);
  989. }
  990. // Y.log('pack ' + packName + ' should supersede ' + supName);
  991. // Add rollup file, need to add to supersedes list too
  992. // default packages
  993. packName = this.getLangPackName(ROOT_LANG, name);
  994. supName = this.getLangPackName(ROOT_LANG, i);
  995. smod = this.moduleInfo[packName];
  996. if (!smod) {
  997. smod = this._addLangPack(lang, o, packName);
  998. }
  999. if (!(supName in flatSup)) {
  1000. smod.supersedes.push(supName);
  1001. }
  1002. // Y.log('pack ' + packName + ' should supersede ' + supName);
  1003. // Add rollup file, need to add to supersedes list too
  1004. }
  1005. }
  1006. l++;
  1007. }
  1008. }
  1009. //o.supersedes = YObject.keys(YArray.hash(sup));
  1010. o.supersedes = YArray.dedupe(sup);
  1011. if (this.allowRollup) {
  1012. o.rollup = (l < 4) ? l : Math.min(l - 1, 4);
  1013. }
  1014. }
  1015. plugins = o.plugins;
  1016. if (plugins) {
  1017. for (i in plugins) {
  1018. if (plugins.hasOwnProperty(i)) {
  1019. plug = plugins[i];
  1020. plug.pkg = name;
  1021. plug.path = plug.path || _path(name, i, o.type);
  1022. plug.requires = plug.requires || [];
  1023. plug.group = o.group;
  1024. this.addModule(plug, i);
  1025. if (o.skinnable) {
  1026. this._addSkin(this.skin.defaultSkin, i, name);
  1027. }
  1028. }
  1029. }
  1030. }
  1031. if (o.condition) {
  1032. t = o.condition.trigger;
  1033. if (YUI.Env.aliases[t]) {
  1034. t = YUI.Env.aliases[t];
  1035. }
  1036. if (!Y.Lang.isArray(t)) {
  1037. t = [t];
  1038. }
  1039. for (i = 0; i < t.length; i++) {
  1040. trigger = t[i];
  1041. when = o.condition.when;
  1042. conditions[trigger] = conditions[trigger] || {};
  1043. conditions[trigger][name] = o.condition;
  1044. // the 'when' attribute can be 'before', 'after', or 'instead'
  1045. // the default is after.
  1046. if (when && when != 'after') {
  1047. if (when == 'instead') { // replace the trigger
  1048. o.supersedes = o.supersedes || [];
  1049. o.supersedes.push(trigger);
  1050. } else { // before the trigger
  1051. // the trigger requires the conditional mod,
  1052. // so it should appear before the conditional
  1053. // mod if we do not intersede.
  1054. }
  1055. } else { // after the trigger
  1056. o.after = o.after || [];
  1057. o.after.push(trigger);
  1058. }
  1059. }
  1060. }
  1061. if (o.after) {
  1062. o.after_map = YArray.hash(o.after);
  1063. }
  1064. // this.dirty = true;
  1065. if (o.configFn) {
  1066. ret = o.configFn(o);
  1067. if (ret === false) {
  1068. delete this.moduleInfo[name];
  1069. o = null;
  1070. }
  1071. }
  1072. return o;
  1073. },
  1074. /**
  1075. * Add a requirement for one or more module
  1076. * @method require
  1077. * @param {string[] | string*} what the modules to load.
  1078. */
  1079. require: function(what) {
  1080. var a = (typeof what === 'string') ? YArray(arguments) : what;
  1081. this.dirty = true;
  1082. this.required = Y.merge(this.required, YArray.hash(this.filterRequires(a)));
  1083. this._explodeRollups();
  1084. },
  1085. /**
  1086. * Grab all the items that were asked for, check to see if the Loader
  1087. * meta-data contains a "use" array. If it doesm remove the asked item and replace it with
  1088. * the content of the "use".
  1089. * This will make asking for: "dd"
  1090. * Actually ask for: "dd-ddm-base,dd-ddm,dd-ddm-drop,dd-drag,dd-proxy,dd-constrain,dd-drop,dd-scroll,dd-drop-plugin"
  1091. * @private
  1092. * @method _explodeRollups
  1093. */
  1094. _explodeRollups: function() {
  1095. var self = this, m,
  1096. r = self.required;
  1097. if (!self.allowRollup) {
  1098. oeach(r, function(v, name) {
  1099. m = self.getModule(name);
  1100. if (m && m.use) {
  1101. //delete r[name];
  1102. YArray.each(m.use, function(v) {
  1103. m = self.getModule(v);
  1104. if (m && m.use) {
  1105. //delete r[v];
  1106. YArray.each(m.use, function(v) {
  1107. r[v] = true;
  1108. });
  1109. } else {
  1110. r[v] = true;
  1111. }
  1112. });
  1113. }
  1114. });
  1115. self.required = r;
  1116. }
  1117. },
  1118. /**
  1119. * Explodes the required array to remove aliases and replace them with real modules
  1120. * @method filterRequires
  1121. * @param {Array} r The original requires array
  1122. * @return {Array} The new array of exploded requirements
  1123. */
  1124. filterRequires: function(r) {
  1125. if (r) {
  1126. if (!Y.Lang.isArray(r)) {
  1127. r = [r];
  1128. }
  1129. r = Y.Array(r);
  1130. var c = [], i, mod, o, m;
  1131. for (i = 0; i < r.length; i++) {
  1132. mod = this.getModule(r[i]);
  1133. if (mod && mod.use) {
  1134. for (o = 0; o < mod.use.length; o++) {
  1135. //Must walk the other modules in case a module is a rollup of rollups (datatype)
  1136. m = this.getModule(mod.use[o]);
  1137. if (m && m.use) {
  1138. c = Y.Array.dedupe([].concat(c, this.filterRequires(m.use)));
  1139. } else {
  1140. c.push(mod.use[o]);
  1141. }
  1142. }
  1143. } else {
  1144. c.push(r[i]);
  1145. }
  1146. }
  1147. r = c;
  1148. }
  1149. return r;
  1150. },
  1151. /**
  1152. * Returns an object containing properties for all modules required
  1153. * in order to load the requested module
  1154. * @method getRequires
  1155. * @param {object} mod The module definition from moduleInfo.
  1156. * @return {array} the expanded requirement list.
  1157. */
  1158. getRequires: function(mod) {
  1159. if (!mod || mod._parsed) {
  1160. // Y.log('returning no reqs for ' + mod.name);
  1161. return NO_REQUIREMENTS;
  1162. }
  1163. var i, m, j, add, packName, lang, testresults = this.testresults,
  1164. name = mod.name, cond, go,
  1165. adddef = ON_PAGE[name] && ON_PAGE[name].details,
  1166. d, k, m1,
  1167. r, old_mod,
  1168. o, skinmod, skindef, skinpar, skinname,
  1169. intl = mod.lang || mod.intl,
  1170. info = this.moduleInfo,
  1171. ftests = Y.Features && Y.Features.tests.load,
  1172. hash;
  1173. // console.log(name);
  1174. // pattern match leaves module stub that needs to be filled out
  1175. if (mod.temp && adddef) {
  1176. old_mod = mod;
  1177. mod = this.addModule(adddef, name);
  1178. mod.group = old_mod.group;
  1179. mod.pkg = old_mod.pkg;
  1180. delete mod.expanded;
  1181. }
  1182. // console.log('cache: ' + mod.langCache + ' == ' + this.lang);
  1183. // if (mod.expanded && (!mod.langCache || mod.langCache == this.lang)) {
  1184. if (mod.expanded && (!this.lang || mod.langCache === this.lang)) {
  1185. //Y.log('Already expanded ' + name + ', ' + mod.expanded);
  1186. return mod.expanded;
  1187. }
  1188. d = [];
  1189. hash = {};
  1190. r = this.filterRequires(mod.requires);
  1191. if (mod.lang) {
  1192. //If a module has a lang attribute, auto add the intl requirement.
  1193. d.unshift('intl');
  1194. r.unshift('intl');
  1195. intl = true;
  1196. }
  1197. o = this.filterRequires(mod.optional);
  1198. // Y.log("getRequires: " + name + " (dirty:" + this.dirty +
  1199. // ", expanded:" + mod.expanded + ")");
  1200. mod._parsed = true;
  1201. mod.langCache = this.lang;
  1202. for (i = 0; i < r.length; i++) {
  1203. //Y.log(name + ' requiring ' + r[i], 'info', 'loader');
  1204. if (!hash[r[i]]) {
  1205. d.push(r[i]);
  1206. hash[r[i]] = true;
  1207. m = this.getModule(r[i]);
  1208. if (m) {
  1209. add = this.getRequires(m);
  1210. intl = intl || (m.expanded_map &&
  1211. (INTL in m.expanded_map));
  1212. for (j = 0; j < add.length; j++) {
  1213. d.push(add[j]);
  1214. }
  1215. }
  1216. }
  1217. }
  1218. // get the requirements from superseded modules, if any
  1219. r = this.filterRequires(mod.supersedes);
  1220. if (r) {
  1221. for (i = 0; i < r.length; i++) {
  1222. if (!hash[r[i]]) {
  1223. // if this module has submodules, the requirements list is
  1224. // expanded to include the submodules. This is so we can
  1225. // prevent dups when a submodule is already loaded and the
  1226. // parent is requested.
  1227. if (mod.submodules) {
  1228. d.push(r[i]);
  1229. }
  1230. hash[r[i]] = true;
  1231. m = this.getModule(r[i]);
  1232. if (m) {
  1233. add = this.getRequires(m);
  1234. intl = intl || (m.expanded_map &&
  1235. (INTL in m.expanded_map));
  1236. for (j = 0; j < add.length; j++) {
  1237. d.push(add[j]);
  1238. }
  1239. }
  1240. }
  1241. }
  1242. }
  1243. if (o && this.loadOptional) {
  1244. for (i = 0; i < o.length; i++) {
  1245. if (!hash[o[i]]) {
  1246. d.push(o[i]);
  1247. hash[o[i]] = true;
  1248. m = info[o[i]];
  1249. if (m) {
  1250. add = this.getRequires(m);
  1251. intl = intl || (m.expanded_map &&
  1252. (INTL in m.expanded_map));
  1253. for (j = 0; j < add.length; j++) {
  1254. d.push(add[j]);
  1255. }
  1256. }
  1257. }
  1258. }
  1259. }
  1260. cond = this.conditions[name];
  1261. if (cond) {
  1262. if (testresults && ftests) {
  1263. oeach(testresults, function(result, id) {
  1264. var condmod = ftests[id].name;
  1265. if (!hash[condmod] && ftests[id].trigger == name) {
  1266. if (result && ftests[id]) {
  1267. hash[condmod] = true;
  1268. d.push(condmod);
  1269. }
  1270. }
  1271. });
  1272. } else {
  1273. oeach(cond, function(def, condmod) {
  1274. if (!hash[condmod]) {
  1275. go = def && ((def.ua && Y.UA[def.ua]) ||
  1276. (def.test && def.test(Y, r)));
  1277. if (go) {
  1278. hash[condmod] = true;
  1279. d.push(condmod);
  1280. m = this.getModule(condmod);
  1281. // Y.log('conditional', m);
  1282. if (m) {
  1283. add = this.getRequires(m);
  1284. for (j = 0; j < add.length; j++) {
  1285. d.push(add[j]);
  1286. }
  1287. }
  1288. }
  1289. }
  1290. }, this);
  1291. }
  1292. }
  1293. // Create skin modules
  1294. if (mod.skinnable) {
  1295. skindef = this.skin.overrides;
  1296. oeach(YUI.Env.aliases, function(o, n) {
  1297. if (Y.Array.indexOf(o, name) > -1) {
  1298. skinpar = n;
  1299. }
  1300. });
  1301. if (skindef && (skindef[name] || (skinpar && skindef[skinpar]))) {
  1302. skinname = name;
  1303. if (skindef[skinpar]) {
  1304. skinname = skinpar;
  1305. }
  1306. for (i = 0; i < skindef[skinname].length; i++) {
  1307. skinmod = this._addSkin(skindef[skinname][i], name);
  1308. d.push(skinmod);
  1309. }
  1310. } else {
  1311. skinmod = this._addSkin(this.skin.defaultSkin, name);
  1312. d.push(skinmod);
  1313. }
  1314. }
  1315. mod._parsed = false;
  1316. if (intl) {
  1317. if (mod.lang && !mod.langPack && Y.Intl) {
  1318. lang = Y.Intl.lookupBestLang(this.lang || ROOT_LANG, mod.lang);
  1319. //Y.log('Best lang: ' + lang + ', this.lang: ' + this.lang + ', mod.lang: ' + mod.lang);
  1320. packName = this.getLangPackName(lang, name);
  1321. if (packName) {
  1322. d.unshift(packName);
  1323. }
  1324. }
  1325. d.unshift(INTL);
  1326. }
  1327. mod.expanded_map = YArray.hash(d);
  1328. mod.expanded = YObject.keys(mod.expanded_map);
  1329. return mod.expanded;
  1330. },
  1331. /**
  1332. * Returns a hash of module names the supplied module satisfies.
  1333. * @method getProvides
  1334. * @param {string} name The name of the module.
  1335. * @return {object} what this module provides.
  1336. */
  1337. getProvides: function(name) {
  1338. var m = this.getModule(name), o, s;
  1339. // supmap = this.provides;
  1340. if (!m) {
  1341. return NOT_FOUND;
  1342. }
  1343. if (m && !m.provides) {
  1344. o = {};
  1345. s = m.supersedes;
  1346. if (s) {
  1347. YArray.each(s, function(v) {
  1348. Y.mix(o, this.getProvides(v));
  1349. }, this);
  1350. }
  1351. o[name] = true;
  1352. m.provides = o;
  1353. }
  1354. return m.provides;
  1355. },
  1356. /**
  1357. * Calculates the dependency tree, the result is stored in the sorted
  1358. * property.
  1359. * @method calculate
  1360. * @param {object} o optional options object.
  1361. * @param {string} type optional argument to prune modules.
  1362. */
  1363. calculate: function(o, type) {
  1364. if (o || type || this.dirty) {
  1365. if (o) {
  1366. this._config(o);
  1367. }
  1368. if (!this._init) {
  1369. this._setup();
  1370. }
  1371. this._explode();
  1372. if (this.allowRollup) {
  1373. this._rollup();
  1374. } else {
  1375. this._explodeRollups();
  1376. }
  1377. this._reduce();
  1378. this._sort();
  1379. }
  1380. },
  1381. /**
  1382. * Creates a "psuedo" package for languages provided in the lang array
  1383. * @method _addLangPack
  1384. * @param {String} lang The language to create
  1385. * @param {Object} m The module definition to create the language pack around
  1386. * @param {String} packName The name of the package (e.g: lang/datatype-date-en-US)
  1387. * @return {Object} The module definition
  1388. */
  1389. _addLangPack: function(lang, m, packName) {
  1390. var name = m.name,
  1391. packPath,
  1392. existing = this.moduleInfo[packName];
  1393. if (!existing) {
  1394. packPath = _path((m.pkg || name), packName, JS, true);
  1395. this.addModule({ path: packPath,
  1396. intl: true,
  1397. langPack: true,
  1398. ext: m.ext,
  1399. group: m.group,
  1400. supersedes: [] }, packName);
  1401. if (lang) {
  1402. Y.Env.lang = Y.Env.lang || {};
  1403. Y.Env.lang[lang] = Y.Env.lang[lang] || {};
  1404. Y.Env.lang[lang][name] = true;
  1405. }
  1406. }
  1407. return this.moduleInfo[packName];
  1408. },
  1409. /**
  1410. * Investigates the current YUI configuration on the page. By default,
  1411. * modules already detected will not be loaded again unless a force
  1412. * option is encountered. Called by calculate()
  1413. * @method _setup
  1414. * @private
  1415. */
  1416. _setup: function() {
  1417. var info = this.moduleInfo, name, i, j, m, l,
  1418. packName;
  1419. for (name in info) {
  1420. if (info.hasOwnProperty(name)) {
  1421. m = info[name];
  1422. if (m) {
  1423. // remove dups
  1424. //m.requires = YObject.keys(YArray.hash(m.requires));
  1425. m.requires = YArray.dedupe(m.requires);
  1426. // Create lang pack modules
  1427. if (m.lang && m.lang.length) {
  1428. // Setup root package if the module has lang defined,
  1429. // it needs to provide a root language pack
  1430. packName = this.getLangPackName(ROOT_LANG, name);
  1431. this._addLangPack(null, m, packName);
  1432. }
  1433. }
  1434. }
  1435. }
  1436. //l = Y.merge(this.inserted);
  1437. l = {};
  1438. // available modules
  1439. if (!this.ignoreRegistered) {
  1440. Y.mix(l, GLOBAL_ENV.mods);
  1441. }
  1442. // add the ignore list to the list of loaded packages
  1443. if (this.ignore) {
  1444. Y.mix(l, YArray.hash(this.ignore));
  1445. }
  1446. // expand the list to include superseded modules
  1447. for (j in l) {
  1448. if (l.hasOwnProperty(j)) {
  1449. Y.mix(l, this.getProvides(j));
  1450. }
  1451. }
  1452. // remove modules on the force list from the loaded list
  1453. if (this.force) {
  1454. for (i = 0; i < this.force.length; i++) {
  1455. if (this.force[i] in l) {
  1456. delete l[this.force[i]];
  1457. }
  1458. }
  1459. }
  1460. Y.mix(this.loaded, l);
  1461. this._init = true;
  1462. },
  1463. /**
  1464. * Builds a module name for a language pack
  1465. * @method getLangPackName
  1466. * @param {string} lang the language code.
  1467. * @param {string} mname the module to build it for.
  1468. * @return {string} the language pack module name.
  1469. */
  1470. getLangPackName: function(lang, mname) {
  1471. return ('lang/' + mname + ((lang) ? '_' + lang : ''));
  1472. },
  1473. /**
  1474. * Inspects the required modules list looking for additional
  1475. * dependencies. Expands the required list to include all
  1476. * required modules. Called by calculate()
  1477. * @method _explode
  1478. * @private
  1479. */
  1480. _explode: function() {
  1481. var r = this.required, m, reqs, done = {},
  1482. self = this;
  1483. // the setup phase is over, all modules have been created
  1484. self.dirty = false;
  1485. self._explodeRollups();
  1486. r = self.required;
  1487. oeach(r, function(v, name) {
  1488. if (!done[name]) {
  1489. done[name] = true;
  1490. m = self.getModule(name);
  1491. if (m) {
  1492. var expound = m.expound;
  1493. if (expound) {
  1494. r[expound] = self.getModule(expound);
  1495. reqs = self.getRequires(r[expound]);
  1496. Y.mix(r, YArray.hash(reqs));
  1497. }
  1498. reqs = self.getRequires(m);
  1499. Y.mix(r, YArray.hash(reqs));
  1500. }
  1501. }
  1502. });
  1503. // Y.log('After explode: ' + YObject.keys(r));
  1504. },
  1505. /**
  1506. * Get's the loader meta data for the requested module
  1507. * @method getModule
  1508. * @param {String} mname The module name to get
  1509. * @return {Object} The module metadata
  1510. */
  1511. getModule: function(mname) {
  1512. //TODO: Remove name check - it's a quick hack to fix pattern WIP
  1513. if (!mname) {
  1514. return null;
  1515. }
  1516. var p, found, pname,
  1517. m = this.moduleInfo[mname],
  1518. patterns = this.patterns;
  1519. // check the patterns library to see if we should automatically add
  1520. // the module with defaults
  1521. if (!m) {
  1522. // Y.log('testing patterns ' + YObject.keys(patterns));
  1523. for (pname in patterns) {
  1524. if (patterns.hasOwnProperty(pname)) {
  1525. // Y.log('testing pattern ' + i);
  1526. p = patterns[pname];
  1527. // use the metadata supplied for the pattern
  1528. // as the module definition.
  1529. if (mname.indexOf(pname) > -1) {
  1530. found = p;
  1531. break;
  1532. }
  1533. }
  1534. }
  1535. if (found) {
  1536. if (p.action) {
  1537. // Y.log('executing pattern action: ' + pname);
  1538. p.action.call(this, mname, pname);
  1539. } else {
  1540. Y.log('Undefined module: ' + mname + ', matched a pattern: ' +
  1541. pname, 'info', 'loader');
  1542. // ext true or false?
  1543. m = this.addModule(Y.merge(found), mname);
  1544. m.temp = true;
  1545. }
  1546. }
  1547. }
  1548. return m;
  1549. },
  1550. // impl in rollup submodule
  1551. _rollup: function() { },
  1552. /**
  1553. * Remove superceded modules and loaded modules. Called by
  1554. * calculate() after we have the mega list of all dependencies
  1555. * @method _reduce
  1556. * @return {object} the reduced dependency hash.
  1557. * @private
  1558. */
  1559. _reduce: function(r) {
  1560. r = r || this.required;
  1561. var i, j, s, m, type = this.loadType,
  1562. ignore = this.ignore ? YArray.hash(this.ignore) : false;
  1563. for (i in r) {
  1564. if (r.hasOwnProperty(i)) {
  1565. m = this.getModule(i);
  1566. // remove if already loaded
  1567. if (((this.loaded[i] || ON_PAGE[i]) &&
  1568. !this.forceMap[i] && !this.ignoreRegistered) ||
  1569. (type && m && m.type != type)) {
  1570. delete r[i];
  1571. }
  1572. if (ignore && ignore[i]) {
  1573. delete r[i];
  1574. }
  1575. // remove anything this module supersedes
  1576. s = m && m.supersedes;
  1577. if (s) {
  1578. for (j = 0; j < s.length; j++) {
  1579. if (s[j] in r) {
  1580. delete r[s[j]];
  1581. }
  1582. }
  1583. }
  1584. }
  1585. }
  1586. return r;
  1587. },
  1588. /**
  1589. * Handles the queue when a module has been loaded for all cases
  1590. * @method _finish
  1591. * @private
  1592. * @param {String} msg The message from Loader
  1593. * @param {Boolean} success A boolean denoting success or failure
  1594. */
  1595. _finish: function(msg, success) {
  1596. Y.log('loader finishing: ' + msg + ', ' + Y.id + ', ' +
  1597. this.data, 'info', 'loader');
  1598. _queue.running = false;
  1599. var onEnd = this.onEnd;
  1600. if (onEnd) {
  1601. onEnd.call(this.context, {
  1602. msg: msg,
  1603. data: this.data,
  1604. success: success
  1605. });
  1606. }
  1607. this._continue();
  1608. },
  1609. /**
  1610. * The default Loader onSuccess handler, calls this.onSuccess with a payload
  1611. * @method _onSuccess
  1612. * @private
  1613. */
  1614. _onSuccess: function() {
  1615. var self = this, skipped = Y.merge(self.skipped), fn,
  1616. failed = [], rreg = self.requireRegistration,
  1617. success, msg;
  1618. oeach(skipped, function(k) {
  1619. delete self.inserted[k];
  1620. });
  1621. self.skipped = {};
  1622. oeach(self.inserted, function(v, k) {
  1623. var mod = self.getModule(k);
  1624. if (mod && rreg && mod.type == JS && !(k in YUI.Env.mods)) {
  1625. failed.push(k);
  1626. } else {
  1627. Y.mix(self.loaded, self.getProvides(k));
  1628. }
  1629. });
  1630. fn = self.onSuccess;
  1631. msg = (failed.length) ? 'notregistered' : 'success';
  1632. success = !(failed.length);
  1633. if (fn) {
  1634. fn.call(self.context, {
  1635. msg: msg,
  1636. data: self.data,
  1637. success: success,
  1638. failed: failed,
  1639. skipped: skipped
  1640. });
  1641. }
  1642. self._finish(msg, success);
  1643. },
  1644. /**
  1645. * The default Loader onFailure handler, calls this.onFailure with a payload
  1646. * @method _onFailure
  1647. * @private
  1648. */
  1649. _onFailure: function(o) {
  1650. Y.log('load error: ' + o.msg + ', ' + Y.id, 'error', 'loader');
  1651. var f = this.onFailure, msg = 'failure: ' + o.msg;
  1652. if (f) {
  1653. f.call(this.context, {
  1654. msg: msg,
  1655. data: this.data,
  1656. success: false
  1657. });
  1658. }
  1659. this._finish(msg, false);
  1660. },
  1661. /**
  1662. * The default Loader onTimeout handler, calls this.onTimeout with a payload
  1663. * @method _onTimeout
  1664. * @private
  1665. */
  1666. _onTimeout: function() {
  1667. Y.log('loader timeout: ' + Y.id, 'error', 'loader');
  1668. var f = this.onTimeout;
  1669. if (f) {
  1670. f.call(this.context, {
  1671. msg: 'timeout',
  1672. data: this.data,
  1673. success: false
  1674. });
  1675. }
  1676. this._finish('timeout', false);
  1677. },
  1678. /**
  1679. * Sorts the dependency tree. The last step of calculate()
  1680. * @method _sort
  1681. * @private
  1682. */
  1683. _sort: function() {
  1684. // create an indexed list
  1685. var s = YObject.keys(this.required),
  1686. // loaded = this.loaded,
  1687. done = {},
  1688. p = 0, l, a, b, j, k, moved, doneKey;
  1689. // keep going until we make a pass without moving anything
  1690. for (;;) {
  1691. l = s.length;
  1692. moved = false;
  1693. // start the loop after items that are already sorted
  1694. for (j = p; j < l; j++) {
  1695. // check the next module on the list to see if its
  1696. // dependencies have been met
  1697. a = s[j];
  1698. // check everything below current item and move if we
  1699. // find a requirement for the current item
  1700. for (k = j + 1; k < l; k++) {
  1701. doneKey = a + s[k];
  1702. if (!done[doneKey] && this._requires(a, s[k])) {
  1703. // extract the dependency so we can move it up
  1704. b = s.splice(k, 1);
  1705. // insert the dependency above the item that
  1706. // requires it
  1707. s.splice(j, 0, b[0]);
  1708. // only swap two dependencies once to short circut
  1709. // circular dependencies
  1710. done[doneKey] = true;
  1711. // keep working
  1712. moved = true;
  1713. break;
  1714. }
  1715. }
  1716. // jump out of loop if we moved something
  1717. if (moved) {
  1718. break;
  1719. // this item is sorted, move our pointer and keep going
  1720. } else {
  1721. p++;
  1722. }
  1723. }
  1724. // when we make it here and moved is false, we are
  1725. // finished sorting
  1726. if (!moved) {
  1727. break;
  1728. }
  1729. }
  1730. this.sorted = s;
  1731. },
  1732. /**
  1733. * (Unimplemented)
  1734. * @method partial
  1735. * @unimplemented
  1736. */
  1737. partial: function(partial, o, type) {
  1738. this.sorted = partial;
  1739. this.insert(o, type, true);
  1740. },
  1741. /**
  1742. * Handles the actual insertion of script/link tags
  1743. * @method _insert
  1744. * @param {Object} source The YUI instance the request came from
  1745. * @param {Object} o The metadata to include
  1746. * @param {String} type JS or CSS
  1747. * @param {Boolean} [skipcalc=false] Do a Loader.calculate on the meta
  1748. */
  1749. _insert: function(source, o, type, skipcalc) {
  1750. // Y.log('private _insert() ' + (type || '') + ', ' + Y.id, "info", "loader");
  1751. // restore the state at the time of the request
  1752. if (source) {
  1753. this._config(source);
  1754. }
  1755. // build the dependency list
  1756. // don't include type so we can process CSS and script in
  1757. // one pass when the type is not specified.
  1758. if (!skipcalc) {
  1759. this.calculate(o);
  1760. }
  1761. this.loadType = type;
  1762. if (!type) {
  1763. var self = this;
  1764. // Y.log("trying to load css first");
  1765. this._internalCallback = function() {
  1766. var f = self.onCSS, n, p, sib;
  1767. // IE hack for style overrides that are not being applied
  1768. if (this.insertBefore && Y.UA.ie) {
  1769. n = Y.config.doc.getElementById(this.insertBefore);
  1770. p = n.parentNode;
  1771. sib = n.nextSibling;
  1772. p.removeChild(n);
  1773. if (sib) {
  1774. p.insertBefore(n, sib);
  1775. } else {
  1776. p.appendChild(n);
  1777. }
  1778. }
  1779. if (f) {
  1780. f.call(self.context, Y);
  1781. }
  1782. self._internalCallback = null;
  1783. self._insert(null, null, JS);
  1784. };
  1785. this._insert(null, null, CSS);
  1786. return;
  1787. }
  1788. // set a flag to indicate the load has started
  1789. this._loading = true;
  1790. // flag to indicate we are done with the combo service
  1791. // and any additional files will need to be loaded
  1792. // individually
  1793. this._combineComplete = {};
  1794. // start the load
  1795. this.loadNext();
  1796. },
  1797. /**
  1798. * Once a loader operation is completely finished, process any additional queued items.
  1799. * @method _continue
  1800. * @private
  1801. */
  1802. _continue: function() {
  1803. if (!(_queue.running) && _queue.size() > 0) {
  1804. _queue.running = true;
  1805. _queue.next()();
  1806. }
  1807. },
  1808. /**
  1809. * inserts the requested modules and their dependencies.
  1810. * <code>type</code> can be "js" or "css". Both script and
  1811. * css are inserted if type is not provided.
  1812. * @method insert
  1813. * @param {object} o optional options object.
  1814. * @param {string} type the type of dependency to insert.
  1815. */
  1816. insert: function(o, type, skipsort) {
  1817. // Y.log('public insert() ' + (type || '') + ', ' +
  1818. // Y.Object.keys(this.required), "info", "loader");
  1819. var self = this, copy = Y.merge(this);
  1820. delete copy.require;
  1821. delete copy.dirty;
  1822. _queue.add(function() {
  1823. self._insert(copy, o, type, skipsort);
  1824. });
  1825. this._continue();
  1826. },
  1827. /**
  1828. * Executed every time a module is loaded, and if we are in a load
  1829. * cycle, we attempt to load the next script. Public so that it
  1830. * is possible to call this if using a method other than
  1831. * Y.register to determine when scripts are fully loaded
  1832. * @method loadNext
  1833. * @param {string} mname optional the name of the module that has
  1834. * been loaded (which is usually why it is time to load the next
  1835. * one).
  1836. */
  1837. loadNext: function(mname) {
  1838. // It is possible that this function is executed due to something
  1839. // else on the page loading a YUI module. Only react when we
  1840. // are actively loading something
  1841. if (!this._loading) {
  1842. return;
  1843. }
  1844. var s, len, i, m, url, fn, msg, attr, group, groupName, j, frag,
  1845. comboSource, comboSources, mods, combining, urls, comboBase,
  1846. self = this,
  1847. type = self.loadType,
  1848. handleSuccess = function(o) {
  1849. self.loadNext(o.data);
  1850. },
  1851. handleCombo = function(o) {
  1852. self._combineComplete[type] = true;
  1853. var i, len = combining.length;
  1854. for (i = 0; i < len; i++) {
  1855. self.inserted[combining[i]] = true;
  1856. }
  1857. handleSuccess(o);
  1858. };
  1859. if (self.combine && (!self._combineComplete[type])) {
  1860. combining = [];
  1861. self._combining = combining;
  1862. s = self.sorted;
  1863. len = s.length;
  1864. // the default combo base
  1865. comboBase = self.comboBase;
  1866. url = comboBase;
  1867. urls = [];
  1868. comboSources = {};
  1869. for (i = 0; i < len; i++) {
  1870. comboSource = comboBase;
  1871. m = self.getModule(s[i]);
  1872. groupName = m && m.group;
  1873. if (groupName) {
  1874. group = self.groups[groupName];
  1875. if (!group.combine) {
  1876. m.combine = false;
  1877. continue;
  1878. }
  1879. m.combine = true;
  1880. if (group.comboBase) {
  1881. comboSource = group.comboBase;
  1882. }
  1883. if ("root" in group && L.isValue(group.root)) {
  1884. m.root = group.root;
  1885. }
  1886. }
  1887. comboSources[comboSource] = comboSources[comboSource] || [];
  1888. comboSources[comboSource].push(m);
  1889. }
  1890. for (j in comboSources) {
  1891. if (comboSources.hasOwnProperty(j)) {
  1892. url = j;
  1893. mods = comboSources[j];
  1894. len = mods.length;
  1895. for (i = 0; i < len; i++) {
  1896. // m = self.getModule(s[i]);
  1897. m = mods[i];
  1898. // Do not try to combine non-yui JS unless combo def
  1899. // is found
  1900. if (m && (m.type === type) && (m.combine || !m.ext)) {
  1901. frag = ((L.isValue(m.root)) ? m.root : self.root) + m.path;
  1902. frag = self._filter(frag, m.name);
  1903. if ((url !== j) && (i <= (len - 1)) &&
  1904. ((frag.length + url.length) > self.maxURLLength)) {
  1905. //Hack until this is rewritten to use an array and not string concat:
  1906. if (url.substr(url.length - 1, 1) === self.comboSep) {
  1907. url = url.substr(0, (url.length - 1));
  1908. }
  1909. urls.push(self._filter(url));
  1910. url = j;
  1911. }
  1912. url += frag;
  1913. if (i < (len - 1)) {
  1914. url += self.comboSep;
  1915. }
  1916. combining.push(m.name);
  1917. }
  1918. }
  1919. if (combining.length && (url != j)) {
  1920. //Hack until this is rewritten to use an array and not string concat:
  1921. if (url.substr(url.length - 1, 1) === self.comboSep) {
  1922. url = url.substr(0, (url.length - 1));
  1923. }
  1924. urls.push(self._filter(url));
  1925. }
  1926. }
  1927. }
  1928. if (combining.length) {
  1929. Y.log('Attempting to use combo: ' + combining, 'info', 'loader');
  1930. // if (m.type === CSS) {
  1931. if (type === CSS) {
  1932. fn = Y.Get.css;
  1933. attr = self.cssAttributes;
  1934. } else {
  1935. fn = Y.Get.script;
  1936. attr = self.jsAttributes;
  1937. }
  1938. fn(urls, {
  1939. data: self._loading,
  1940. onSuccess: handleCombo,
  1941. onFailure: self._onFailure,
  1942. onTimeout: self._onTimeout,
  1943. insertBefore: self.insertBefore,
  1944. charset: self.charset,
  1945. attributes: attr,
  1946. timeout: self.timeout,
  1947. autopurge: false,
  1948. context: self
  1949. });
  1950. return;
  1951. } else {
  1952. self._combineComplete[type] = true;
  1953. }
  1954. }
  1955. if (mname) {
  1956. // if the module that was just loaded isn't what we were expecting,
  1957. // continue to wait
  1958. if (mname !== self._loading) {
  1959. return;
  1960. }
  1961. // Y.log("loadNext executing, just loaded " + mname + ", " +
  1962. // Y.id, "info", "loader");
  1963. // The global handler that is called when each module is loaded
  1964. // will pass that module name to this function. Storing this
  1965. // data to avoid loading the same module multiple times
  1966. // centralize this in the callback
  1967. self.inserted[mname] = true;
  1968. // self.loaded[mname] = true;
  1969. // provided = self.getProvides(mname);
  1970. // Y.mix(self.loaded, provided);
  1971. // Y.mix(self.inserted, provided);
  1972. if (self.onProgress) {
  1973. self.onProgress.call(self.context, {
  1974. name: mname,
  1975. data: self.data
  1976. });
  1977. }
  1978. }
  1979. s = self.sorted;
  1980. len = s.length;
  1981. for (i = 0; i < len; i = i + 1) {
  1982. // this.inserted keeps track of what the loader has loaded.
  1983. // move on if this item is done.
  1984. if (s[i] in self.inserted) {
  1985. continue;
  1986. }
  1987. // Because rollups will cause multiple load notifications
  1988. // from Y, loadNext may be called multiple times for
  1989. // the same module when loading a rollup. We can safely
  1990. // skip the subsequent requests
  1991. if (s[i] === self._loading) {
  1992. Y.log('still loading ' + s[i] + ', waiting', 'info', 'loader');
  1993. return;
  1994. }
  1995. // log("inserting " + s[i]);
  1996. m = self.getModule(s[i]);
  1997. if (!m) {
  1998. if (!self.skipped[s[i]]) {
  1999. msg = 'Undefined module ' + s[i] + ' skipped';
  2000. Y.log(msg, 'warn', 'loader');
  2001. // self.inserted[s[i]] = true;
  2002. self.skipped[s[i]] = true;
  2003. }
  2004. continue;
  2005. }
  2006. group = (m.group && self.groups[m.group]) || NOT_FOUND;
  2007. // The load type is stored to offer the possibility to load
  2008. // the css separately from the script.
  2009. if (!type || type === m.type) {
  2010. self._loading = s[i];
  2011. Y.log('attempting to load ' + s[i] + ', ' + self.base, 'info', 'loader');
  2012. if (m.type === CSS) {
  2013. fn = Y.Get.css;
  2014. attr = self.cssAttributes;
  2015. } else {
  2016. fn = Y.Get.script;
  2017. attr = self.jsAttributes;
  2018. }
  2019. url = (m.fullpath) ? self._filter(m.fullpath, s[i]) :
  2020. self._url(m.path, s[i], group.base || m.base);
  2021. fn(url, {
  2022. data: s[i],
  2023. onSuccess: handleSuccess,
  2024. insertBefore: self.insertBefore,
  2025. charset: self.charset,
  2026. attributes: attr,
  2027. onFailure: self._onFailure,
  2028. onTimeout: self._onTimeout,
  2029. timeout: self.timeout,
  2030. autopurge: false,
  2031. context: self
  2032. });
  2033. return;
  2034. }
  2035. }
  2036. // we are finished
  2037. self._loading = null;
  2038. fn = self._internalCallback;
  2039. // internal callback for loading css first
  2040. if (fn) {
  2041. // Y.log('loader internal');
  2042. self._internalCallback = null;
  2043. fn.call(self);
  2044. } else {
  2045. // Y.log('loader complete');
  2046. self._onSuccess();
  2047. }
  2048. },
  2049. /**
  2050. * Apply filter defined for this instance to a url/path
  2051. * @method _filter
  2052. * @param {string} u the string to filter.
  2053. * @param {string} name the name of the module, if we are processing
  2054. * a single module as opposed to a combined url.
  2055. * @return {string} the filtered string.
  2056. * @private
  2057. */
  2058. _filter: function(u, name) {
  2059. var f = this.filter,
  2060. hasFilter = name && (name in this.filters),
  2061. modFilter = hasFilter && this.filters[name],
  2062. groupName = this.moduleInfo[name] ? this.moduleInfo[name].group:null;
  2063. if (groupName && this.groups[groupName] && this.groups[groupName].filter) {
  2064. modFilter = this.groups[groupName].filter;
  2065. hasFilter = true;
  2066. };
  2067. if (u) {
  2068. if (hasFilter) {
  2069. f = (L.isString(modFilter)) ?
  2070. this.FILTER_DEFS[modFilter.toUpperCase()] || null :
  2071. modFilter;
  2072. }
  2073. if (f) {
  2074. u = u.replace(new RegExp(f.searchExp, 'g'), f.replaceStr);
  2075. }
  2076. }
  2077. return u;
  2078. },
  2079. /**
  2080. * Generates the full url for a module
  2081. * @method _url
  2082. * @param {string} path the path fragment.
  2083. * @param {String} name The name of the module
  2084. * @pamra {String} [base=self.base] The base url to use
  2085. * @return {string} the full url.
  2086. * @private
  2087. */
  2088. _url: function(path, name, base) {
  2089. return this._filter((base || this.base || '') + path, name);
  2090. },
  2091. /**
  2092. * Returns an Object hash of file arrays built from `loader.sorted` or from an arbitrary list of sorted modules.
  2093. * @method resolve
  2094. * @param {Boolean} [calc=false] Perform a loader.calculate() before anything else
  2095. * @param {Array} [s=loader.sorted] An override for the loader.sorted array
  2096. * @return {Object} Object hash (js and css) of two arrays of file lists
  2097. * @example This method can be used as an off-line dep calculator
  2098. *
  2099. * var Y = YUI();
  2100. * var loader = new Y.Loader({
  2101. * filter: 'debug',
  2102. * base: '../../',
  2103. * root: 'build/',
  2104. * combine: true,
  2105. * require: ['node', 'dd', 'console']
  2106. * });
  2107. * var out = loader.resolve(true);
  2108. *
  2109. */
  2110. resolve: function(calc, s) {
  2111. var self = this, i, m, url, out = { js: [], css: [] };
  2112. if (calc) {
  2113. self.calculate();
  2114. }
  2115. s = s || self.sorted;
  2116. for (i = 0; i < s.length; i++) {
  2117. m = self.getModule(s[i]);
  2118. if (m) {
  2119. if (self.combine) {
  2120. url = self._filter((self.root + m.path), m.name, self.root);
  2121. } else {
  2122. url = self._filter(m.fullpath, m.name, '') || self._url(m.path, m.name);
  2123. }
  2124. out[m.type].push(url);
  2125. }
  2126. }
  2127. if (self.combine) {
  2128. out.js = [self.comboBase + out.js.join(self.comboSep)];
  2129. out.css = [self.comboBase + out.css.join(self.comboSep)];
  2130. }
  2131. return out;
  2132. },
  2133. /**
  2134. * Returns an Object hash of hashes built from `loader.sorted` or from an arbitrary list of sorted modules.
  2135. * @method hash
  2136. * @private
  2137. * @param {Boolean} [calc=false] Perform a loader.calculate() before anything else
  2138. * @param {Array} [s=loader.sorted] An override for the loader.sorted array
  2139. * @return {Object} Object hash (js and css) of two object hashes of file lists, with the module name as the key
  2140. * @example This method can be used as an off-line dep calculator
  2141. *
  2142. * var Y = YUI();
  2143. * var loader = new Y.Loader({
  2144. * filter: 'debug',
  2145. * base: '../../',
  2146. * root: 'build/',
  2147. * combine: true,
  2148. * require: ['node', 'dd', 'console']
  2149. * });
  2150. * var out = loader.hash(true);
  2151. *
  2152. */
  2153. hash: function(calc, s) {
  2154. var self = this, i, m, url, out = { js: {}, css: {} };
  2155. if (calc) {
  2156. self.calculate();
  2157. }
  2158. s = s || self.sorted;
  2159. for (i = 0; i < s.length; i++) {
  2160. m = self.getModule(s[i]);
  2161. if (m) {
  2162. url = self._filter(m.fullpath, m.name, '') || self._url(m.path, m.name);
  2163. out[m.type][m.name] = url;
  2164. }
  2165. }
  2166. return out;
  2167. }
  2168. };
  2169. }, '3.4.0' ,{requires:['get']});