cesiumWorkerBootstrapper.js 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141
  1. if (typeof self === 'undefined') {
  2. self = {}; //define self so that the Dojo build can evaluate this file without crashing.
  3. }
  4. self.onmessage = function(event) {
  5. var data = event.data;
  6. require(data.loaderConfig, [data.workerModule], function(workerModule) {
  7. //replace onmessage with the required-in workerModule
  8. self.onmessage = workerModule;
  9. CESIUM_BASE_URL = data.loaderConfig.baseUrl;
  10. });
  11. };
  12. // replace setTimeout with a function that executes immediately synchronously, which
  13. // will make the above require synchronous like it used to be, to ensure that we we
  14. // have the real worker module loaded and installed before receiving any more messages.
  15. function setTimeout(fn) {
  16. fn();
  17. }
  18. //below is RequireJS, verbatim
  19. /** vim: et:ts=4:sw=4:sts=4
  20. * @license RequireJS 2.1.20 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved.
  21. * Available via the MIT or new BSD license.
  22. * see: http://github.com/jrburke/requirejs for details
  23. */
  24. //Not using strict: uneven strict support in browsers, #392, and causes
  25. //problems with requirejs.exec()/transpiler plugins that may not be strict.
  26. /*jslint regexp: true, nomen: true, sloppy: true */
  27. /*global window, navigator, document, importScripts, setTimeout, opera */
  28. var requirejs, require, define;
  29. (function (global) {
  30. var req, s, head, baseElement, dataMain, src,
  31. interactiveScript, currentlyAddingScript, mainScript, subPath,
  32. version = '2.1.20',
  33. commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
  34. cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
  35. jsSuffixRegExp = /\.js$/,
  36. currDirRegExp = /^\.\//,
  37. op = Object.prototype,
  38. ostring = op.toString,
  39. hasOwn = op.hasOwnProperty,
  40. ap = Array.prototype,
  41. isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document),
  42. isWebWorker = !isBrowser && typeof importScripts !== 'undefined',
  43. //PS3 indicates loaded and complete, but need to wait for complete
  44. //specifically. Sequence is 'loading', 'loaded', execution,
  45. // then 'complete'. The UA check is unfortunate, but not sure how
  46. //to feature test w/o causing perf issues.
  47. readyRegExp = isBrowser && navigator.platform === 'PLAYSTATION 3' ?
  48. /^complete$/ : /^(complete|loaded)$/,
  49. defContextName = '_',
  50. //Oh the tragedy, detecting opera. See the usage of isOpera for reason.
  51. isOpera = typeof opera !== 'undefined' && opera.toString() === '[object Opera]',
  52. contexts = {},
  53. cfg = {},
  54. globalDefQueue = [],
  55. useInteractive = false;
  56. function isFunction(it) {
  57. return ostring.call(it) === '[object Function]';
  58. }
  59. function isArray(it) {
  60. return ostring.call(it) === '[object Array]';
  61. }
  62. /**
  63. * @private
  64. * Helper function for iterating over an array. If the func returns
  65. * a true value, it will break out of the loop.
  66. */
  67. function each(ary, func) {
  68. if (ary) {
  69. var i;
  70. for (i = 0; i < ary.length; i += 1) {
  71. if (ary[i] && func(ary[i], i, ary)) {
  72. break;
  73. }
  74. }
  75. }
  76. }
  77. /**
  78. * @private
  79. * Helper function for iterating over an array backwards. If the func
  80. * returns a true value, it will break out of the loop.
  81. */
  82. function eachReverse(ary, func) {
  83. if (ary) {
  84. var i;
  85. for (i = ary.length - 1; i > -1; i -= 1) {
  86. if (ary[i] && func(ary[i], i, ary)) {
  87. break;
  88. }
  89. }
  90. }
  91. }
  92. function hasProp(obj, prop) {
  93. return hasOwn.call(obj, prop);
  94. }
  95. function getOwn(obj, prop) {
  96. return hasProp(obj, prop) && obj[prop];
  97. }
  98. /**
  99. * @private
  100. * Cycles over properties in an object and calls a function for each
  101. * property value. If the function returns a truthy value, then the
  102. * iteration is stopped.
  103. */
  104. function eachProp(obj, func) {
  105. var prop;
  106. for (prop in obj) {
  107. if (hasProp(obj, prop)) {
  108. if (func(obj[prop], prop)) {
  109. break;
  110. }
  111. }
  112. }
  113. }
  114. /**
  115. * @private
  116. * Simple function to mix in properties from source into target,
  117. * but only if target does not already have a property of the same name.
  118. */
  119. function mixin(target, source, force, deepStringMixin) {
  120. if (source) {
  121. eachProp(source, function (value, prop) {
  122. if (force || !hasProp(target, prop)) {
  123. if (deepStringMixin && typeof value === 'object' && value &&
  124. !isArray(value) && !isFunction(value) &&
  125. !(value instanceof RegExp)) {
  126. if (!target[prop]) {
  127. target[prop] = {};
  128. }
  129. mixin(target[prop], value, force, deepStringMixin);
  130. } else {
  131. target[prop] = value;
  132. }
  133. }
  134. });
  135. }
  136. return target;
  137. }
  138. //Similar to Function.prototype.bind, but the 'this' object is specified
  139. //first, since it is easier to read/figure out what 'this' will be.
  140. function bind(obj, fn) {
  141. return function () {
  142. return fn.apply(obj, arguments);
  143. };
  144. }
  145. function scripts() {
  146. return document.getElementsByTagName('script');
  147. }
  148. function defaultOnError(err) {
  149. throw err;
  150. }
  151. //Allow getting a global that is expressed in
  152. //dot notation, like 'a.b.c'.
  153. function getGlobal(value) {
  154. if (!value) {
  155. return value;
  156. }
  157. var g = global;
  158. each(value.split('.'), function (part) {
  159. g = g[part];
  160. });
  161. return g;
  162. }
  163. /**
  164. * Constructs an error with a pointer to an URL with more information.
  165. * @param {String} id the error ID that maps to an ID on a web page.
  166. * @param {String} msg human readable error.
  167. * @param {Error} [err] the original error, if there is one.
  168. * @param {RequireModules} requireModules The modules required but not found.
  169. * @private
  170. * @returns {Error}
  171. */
  172. function makeError(id, msg, err, requireModules) {
  173. var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id);
  174. e.requireType = id;
  175. e.requireModules = requireModules;
  176. if (err) {
  177. e.originalError = err;
  178. }
  179. return e;
  180. }
  181. if (typeof define !== 'undefined') {
  182. //If a define is already in play via another AMD loader,
  183. //do not overwrite.
  184. return;
  185. }
  186. if (typeof requirejs !== 'undefined') {
  187. if (isFunction(requirejs)) {
  188. //Do not overwrite an existing requirejs instance.
  189. return;
  190. }
  191. cfg = requirejs;
  192. requirejs = undefined;
  193. }
  194. //Allow for a require config object
  195. if (typeof require !== 'undefined' && !isFunction(require)) {
  196. //assume it is a config object.
  197. cfg = require;
  198. require = undefined;
  199. }
  200. function newContext(contextName) {
  201. var inCheckLoaded, Module, context, handlers,
  202. checkLoadedTimeoutId,
  203. config = {
  204. //Defaults. Do not set a default for map
  205. //config to speed up normalize(), which
  206. //will run faster if there is no default.
  207. waitSeconds: 7,
  208. baseUrl: './',
  209. paths: {},
  210. bundles: {},
  211. pkgs: {},
  212. shim: {},
  213. config: {}
  214. },
  215. registry = {},
  216. //registry of just enabled modules, to speed
  217. //cycle breaking code when lots of modules
  218. //are registered, but not activated.
  219. enabledRegistry = {},
  220. undefEvents = {},
  221. defQueue = [],
  222. defined = {},
  223. urlFetched = {},
  224. bundlesMap = {},
  225. requireCounter = 1,
  226. unnormalizedCounter = 1;
  227. /**
  228. * @private
  229. * Trims the . and .. from an array of path segments.
  230. * It will keep a leading path segment if a .. will become
  231. * the first path segment, to help with module name lookups,
  232. * which act like paths, but can be remapped. But the end result,
  233. * all paths that use this function should look normalized.
  234. * NOTE: this method MODIFIES the input array.
  235. * @param {Array} ary the array of path segments.
  236. */
  237. function trimDots(ary) {
  238. var i, part;
  239. for (i = 0; i < ary.length; i++) {
  240. part = ary[i];
  241. if (part === '.') {
  242. ary.splice(i, 1);
  243. i -= 1;
  244. } else if (part === '..') {
  245. // If at the start, or previous value is still ..,
  246. // keep them so that when converted to a path it may
  247. // still work when converted to a path, even though
  248. // as an ID it is less than ideal. In larger point
  249. // releases, may be better to just kick out an error.
  250. if (i === 0 || (i === 1 && ary[2] === '..') || ary[i - 1] === '..') {
  251. continue;
  252. } else if (i > 0) {
  253. ary.splice(i - 1, 2);
  254. i -= 2;
  255. }
  256. }
  257. }
  258. }
  259. /**
  260. * @private
  261. * Given a relative module name, like ./something, normalize it to
  262. * a real name that can be mapped to a path.
  263. * @param {String} name the relative name
  264. * @param {String} baseName a real name that the name arg is relative
  265. * to.
  266. * @param {Boolean} applyMap apply the map config to the value. Should
  267. * only be done if this normalization is for a dependency ID.
  268. * @returns {String} normalized name
  269. */
  270. function normalize(name, baseName, applyMap) {
  271. var pkgMain, mapValue, nameParts, i, j, nameSegment, lastIndex,
  272. foundMap, foundI, foundStarMap, starI, normalizedBaseParts,
  273. baseParts = (baseName && baseName.split('/')),
  274. map = config.map,
  275. starMap = map && map['*'];
  276. //Adjust any relative paths.
  277. if (name) {
  278. name = name.split('/');
  279. lastIndex = name.length - 1;
  280. // If wanting node ID compatibility, strip .js from end
  281. // of IDs. Have to do this here, and not in nameToUrl
  282. // because node allows either .js or non .js to map
  283. // to same file.
  284. if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
  285. name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
  286. }
  287. // Starts with a '.' so need the baseName
  288. if (name[0].charAt(0) === '.' && baseParts) {
  289. //Convert baseName to array, and lop off the last part,
  290. //so that . matches that 'directory' and not name of the baseName's
  291. //module. For instance, baseName of 'one/two/three', maps to
  292. //'one/two/three.js', but we want the directory, 'one/two' for
  293. //this normalization.
  294. normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
  295. name = normalizedBaseParts.concat(name);
  296. }
  297. trimDots(name);
  298. name = name.join('/');
  299. }
  300. //Apply map config if available.
  301. if (applyMap && map && (baseParts || starMap)) {
  302. nameParts = name.split('/');
  303. outerLoop: for (i = nameParts.length; i > 0; i -= 1) {
  304. nameSegment = nameParts.slice(0, i).join('/');
  305. if (baseParts) {
  306. //Find the longest baseName segment match in the config.
  307. //So, do joins on the biggest to smallest lengths of baseParts.
  308. for (j = baseParts.length; j > 0; j -= 1) {
  309. mapValue = getOwn(map, baseParts.slice(0, j).join('/'));
  310. //baseName segment has config, find if it has one for
  311. //this name.
  312. if (mapValue) {
  313. mapValue = getOwn(mapValue, nameSegment);
  314. if (mapValue) {
  315. //Match, update name to the new value.
  316. foundMap = mapValue;
  317. foundI = i;
  318. break outerLoop;
  319. }
  320. }
  321. }
  322. }
  323. //Check for a star map match, but just hold on to it,
  324. //if there is a shorter segment match later in a matching
  325. //config, then favor over this star map.
  326. if (!foundStarMap && starMap && getOwn(starMap, nameSegment)) {
  327. foundStarMap = getOwn(starMap, nameSegment);
  328. starI = i;
  329. }
  330. }
  331. if (!foundMap && foundStarMap) {
  332. foundMap = foundStarMap;
  333. foundI = starI;
  334. }
  335. if (foundMap) {
  336. nameParts.splice(0, foundI, foundMap);
  337. name = nameParts.join('/');
  338. }
  339. }
  340. // If the name points to a package's name, use
  341. // the package main instead.
  342. pkgMain = getOwn(config.pkgs, name);
  343. return pkgMain ? pkgMain : name;
  344. }
  345. function removeScript(name) {
  346. if (isBrowser) {
  347. each(scripts(), function (scriptNode) {
  348. if (scriptNode.getAttribute('data-requiremodule') === name &&
  349. scriptNode.getAttribute('data-requirecontext') === context.contextName) {
  350. scriptNode.parentNode.removeChild(scriptNode);
  351. return true;
  352. }
  353. });
  354. }
  355. }
  356. function hasPathFallback(id) {
  357. var pathConfig = getOwn(config.paths, id);
  358. if (pathConfig && isArray(pathConfig) && pathConfig.length > 1) {
  359. //Pop off the first array value, since it failed, and
  360. //retry
  361. pathConfig.shift();
  362. context.require.undef(id);
  363. //Custom require that does not do map translation, since
  364. //ID is "absolute", already mapped/resolved.
  365. context.makeRequire(null, {
  366. skipMap: true
  367. })([id]);
  368. return true;
  369. }
  370. }
  371. //Turns a plugin!resource to [plugin, resource]
  372. //with the plugin being undefined if the name
  373. //did not have a plugin prefix.
  374. function splitPrefix(name) {
  375. var prefix,
  376. index = name ? name.indexOf('!') : -1;
  377. if (index > -1) {
  378. prefix = name.substring(0, index);
  379. name = name.substring(index + 1, name.length);
  380. }
  381. return [prefix, name];
  382. }
  383. /**
  384. * Creates a module mapping that includes plugin prefix, module
  385. * name, and path. If parentModuleMap is provided it will
  386. * also normalize the name via require.normalize()
  387. *
  388. * @param {String} name the module name
  389. * @param {String} [parentModuleMap] parent module map
  390. * for the module name, used to resolve relative names.
  391. * @param {Boolean} isNormalized: is the ID already normalized.
  392. * This is true if this call is done for a define() module ID.
  393. * @param {Boolean} applyMap: apply the map config to the ID.
  394. * Should only be true if this map is for a dependency.
  395. * @private
  396. * @returns {Object}
  397. */
  398. function makeModuleMap(name, parentModuleMap, isNormalized, applyMap) {
  399. var url, pluginModule, suffix, nameParts,
  400. prefix = null,
  401. parentName = parentModuleMap ? parentModuleMap.name : null,
  402. originalName = name,
  403. isDefine = true,
  404. normalizedName = '';
  405. //If no name, then it means it is a require call, generate an
  406. //internal name.
  407. if (!name) {
  408. isDefine = false;
  409. name = '_@r' + (requireCounter += 1);
  410. }
  411. nameParts = splitPrefix(name);
  412. prefix = nameParts[0];
  413. name = nameParts[1];
  414. if (prefix) {
  415. prefix = normalize(prefix, parentName, applyMap);
  416. pluginModule = getOwn(defined, prefix);
  417. }
  418. //Account for relative paths if there is a base name.
  419. if (name) {
  420. if (prefix) {
  421. if (pluginModule && pluginModule.normalize) {
  422. //Plugin is loaded, use its normalize method.
  423. normalizedName = pluginModule.normalize(name, function (name) {
  424. return normalize(name, parentName, applyMap);
  425. });
  426. } else {
  427. // If nested plugin references, then do not try to
  428. // normalize, as it will not normalize correctly. This
  429. // places a restriction on resourceIds, and the longer
  430. // term solution is not to normalize until plugins are
  431. // loaded and all normalizations to allow for async
  432. // loading of a loader plugin. But for now, fixes the
  433. // common uses. Details in #1131
  434. normalizedName = name.indexOf('!') === -1 ?
  435. normalize(name, parentName, applyMap) :
  436. name;
  437. }
  438. } else {
  439. //A regular module.
  440. normalizedName = normalize(name, parentName, applyMap);
  441. //Normalized name may be a plugin ID due to map config
  442. //application in normalize. The map config values must
  443. //already be normalized, so do not need to redo that part.
  444. nameParts = splitPrefix(normalizedName);
  445. prefix = nameParts[0];
  446. normalizedName = nameParts[1];
  447. isNormalized = true;
  448. url = context.nameToUrl(normalizedName);
  449. }
  450. }
  451. //If the id is a plugin id that cannot be determined if it needs
  452. //normalization, stamp it with a unique ID so two matching relative
  453. //ids that may conflict can be separate.
  454. suffix = prefix && !pluginModule && !isNormalized ?
  455. '_unnormalized' + (unnormalizedCounter += 1) :
  456. '';
  457. return {
  458. prefix: prefix,
  459. name: normalizedName,
  460. parentMap: parentModuleMap,
  461. unnormalized: !!suffix,
  462. url: url,
  463. originalName: originalName,
  464. isDefine: isDefine,
  465. id: (prefix ?
  466. prefix + '!' + normalizedName :
  467. normalizedName) + suffix
  468. };
  469. }
  470. function getModule(depMap) {
  471. var id = depMap.id,
  472. mod = getOwn(registry, id);
  473. if (!mod) {
  474. mod = registry[id] = new context.Module(depMap);
  475. }
  476. return mod;
  477. }
  478. function on(depMap, name, fn) {
  479. var id = depMap.id,
  480. mod = getOwn(registry, id);
  481. if (hasProp(defined, id) &&
  482. (!mod || mod.defineEmitComplete)) {
  483. if (name === 'defined') {
  484. fn(defined[id]);
  485. }
  486. } else {
  487. mod = getModule(depMap);
  488. if (mod.error && name === 'error') {
  489. fn(mod.error);
  490. } else {
  491. mod.on(name, fn);
  492. }
  493. }
  494. }
  495. function onError(err, errback) {
  496. var ids = err.requireModules,
  497. notified = false;
  498. if (errback) {
  499. errback(err);
  500. } else {
  501. each(ids, function (id) {
  502. var mod = getOwn(registry, id);
  503. if (mod) {
  504. //Set error on module, so it skips timeout checks.
  505. mod.error = err;
  506. if (mod.events.error) {
  507. notified = true;
  508. mod.emit('error', err);
  509. }
  510. }
  511. });
  512. if (!notified) {
  513. req.onError(err);
  514. }
  515. }
  516. }
  517. /**
  518. * @private
  519. * Internal method to transfer globalQueue items to this context's
  520. * defQueue.
  521. */
  522. function takeGlobalQueue() {
  523. //Push all the globalDefQueue items into the context's defQueue
  524. if (globalDefQueue.length) {
  525. each(globalDefQueue, function(queueItem) {
  526. var id = queueItem[0];
  527. if (typeof id === 'string') {
  528. context.defQueueMap[id] = true;
  529. }
  530. defQueue.push(queueItem);
  531. });
  532. globalDefQueue = [];
  533. }
  534. }
  535. handlers = {
  536. 'require': function (mod) {
  537. if (mod.require) {
  538. return mod.require;
  539. } else {
  540. return (mod.require = context.makeRequire(mod.map));
  541. }
  542. },
  543. 'exports': function (mod) {
  544. mod.usingExports = true;
  545. if (mod.map.isDefine) {
  546. if (mod.exports) {
  547. return (defined[mod.map.id] = mod.exports);
  548. } else {
  549. return (mod.exports = defined[mod.map.id] = {});
  550. }
  551. }
  552. },
  553. 'module': function (mod) {
  554. if (mod.module) {
  555. return mod.module;
  556. } else {
  557. return (mod.module = {
  558. id: mod.map.id,
  559. uri: mod.map.url,
  560. config: function () {
  561. return getOwn(config.config, mod.map.id) || {};
  562. },
  563. exports: mod.exports || (mod.exports = {})
  564. });
  565. }
  566. }
  567. };
  568. function cleanRegistry(id) {
  569. //Clean up machinery used for waiting modules.
  570. delete registry[id];
  571. delete enabledRegistry[id];
  572. }
  573. function breakCycle(mod, traced, processed) {
  574. var id = mod.map.id;
  575. if (mod.error) {
  576. mod.emit('error', mod.error);
  577. } else {
  578. traced[id] = true;
  579. each(mod.depMaps, function (depMap, i) {
  580. var depId = depMap.id,
  581. dep = getOwn(registry, depId);
  582. //Only force things that have not completed
  583. //being defined, so still in the registry,
  584. //and only if it has not been matched up
  585. //in the module already.
  586. if (dep && !mod.depMatched[i] && !processed[depId]) {
  587. if (getOwn(traced, depId)) {
  588. mod.defineDep(i, defined[depId]);
  589. mod.check(); //pass false?
  590. } else {
  591. breakCycle(dep, traced, processed);
  592. }
  593. }
  594. });
  595. processed[id] = true;
  596. }
  597. }
  598. function checkLoaded() {
  599. var err, usingPathFallback,
  600. waitInterval = config.waitSeconds * 1000,
  601. //It is possible to disable the wait interval by using waitSeconds of 0.
  602. expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
  603. noLoads = [],
  604. reqCalls = [],
  605. stillLoading = false,
  606. needCycleCheck = true;
  607. //Do not bother if this call was a result of a cycle break.
  608. if (inCheckLoaded) {
  609. return;
  610. }
  611. inCheckLoaded = true;
  612. //Figure out the state of all the modules.
  613. eachProp(enabledRegistry, function (mod) {
  614. var map = mod.map,
  615. modId = map.id;
  616. //Skip things that are not enabled or in error state.
  617. if (!mod.enabled) {
  618. return;
  619. }
  620. if (!map.isDefine) {
  621. reqCalls.push(mod);
  622. }
  623. if (!mod.error) {
  624. //If the module should be executed, and it has not
  625. //been inited and time is up, remember it.
  626. if (!mod.inited && expired) {
  627. if (hasPathFallback(modId)) {
  628. usingPathFallback = true;
  629. stillLoading = true;
  630. } else {
  631. noLoads.push(modId);
  632. removeScript(modId);
  633. }
  634. } else if (!mod.inited && mod.fetched && map.isDefine) {
  635. stillLoading = true;
  636. if (!map.prefix) {
  637. //No reason to keep looking for unfinished
  638. //loading. If the only stillLoading is a
  639. //plugin resource though, keep going,
  640. //because it may be that a plugin resource
  641. //is waiting on a non-plugin cycle.
  642. return (needCycleCheck = false);
  643. }
  644. }
  645. }
  646. });
  647. if (expired && noLoads.length) {
  648. //If wait time expired, throw error of unloaded modules.
  649. err = makeError('timeout', 'Load timeout for modules: ' + noLoads, null, noLoads);
  650. err.contextName = context.contextName;
  651. return onError(err);
  652. }
  653. //Not expired, check for a cycle.
  654. if (needCycleCheck) {
  655. each(reqCalls, function (mod) {
  656. breakCycle(mod, {}, {});
  657. });
  658. }
  659. //If still waiting on loads, and the waiting load is something
  660. //other than a plugin resource, or there are still outstanding
  661. //scripts, then just try back later.
  662. if ((!expired || usingPathFallback) && stillLoading) {
  663. //Something is still waiting to load. Wait for it, but only
  664. //if a timeout is not already in effect.
  665. if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) {
  666. checkLoadedTimeoutId = setTimeout(function () {
  667. checkLoadedTimeoutId = 0;
  668. checkLoaded();
  669. }, 50);
  670. }
  671. }
  672. inCheckLoaded = false;
  673. }
  674. Module = function (map) {
  675. this.events = getOwn(undefEvents, map.id) || {};
  676. this.map = map;
  677. this.shim = getOwn(config.shim, map.id);
  678. this.depExports = [];
  679. this.depMaps = [];
  680. this.depMatched = [];
  681. this.pluginMaps = {};
  682. this.depCount = 0;
  683. /* this.exports this.factory
  684. this.depMaps = [],
  685. this.enabled, this.fetched
  686. */
  687. };
  688. Module.prototype = {
  689. init: function (depMaps, factory, errback, options) {
  690. options = options || {};
  691. //Do not do more inits if already done. Can happen if there
  692. //are multiple define calls for the same module. That is not
  693. //a normal, common case, but it is also not unexpected.
  694. if (this.inited) {
  695. return;
  696. }
  697. this.factory = factory;
  698. if (errback) {
  699. //Register for errors on this module.
  700. this.on('error', errback);
  701. } else if (this.events.error) {
  702. //If no errback already, but there are error listeners
  703. //on this module, set up an errback to pass to the deps.
  704. errback = bind(this, function (err) {
  705. this.emit('error', err);
  706. });
  707. }
  708. //Do a copy of the dependency array, so that
  709. //source inputs are not modified. For example
  710. //"shim" deps are passed in here directly, and
  711. //doing a direct modification of the depMaps array
  712. //would affect that config.
  713. this.depMaps = depMaps && depMaps.slice(0);
  714. this.errback = errback;
  715. //Indicate this module has be initialized
  716. this.inited = true;
  717. this.ignore = options.ignore;
  718. //Could have option to init this module in enabled mode,
  719. //or could have been previously marked as enabled. However,
  720. //the dependencies are not known until init is called. So
  721. //if enabled previously, now trigger dependencies as enabled.
  722. if (options.enabled || this.enabled) {
  723. //Enable this module and dependencies.
  724. //Will call this.check()
  725. this.enable();
  726. } else {
  727. this.check();
  728. }
  729. },
  730. defineDep: function (i, depExports) {
  731. //Because of cycles, defined callback for a given
  732. //export can be called more than once.
  733. if (!this.depMatched[i]) {
  734. this.depMatched[i] = true;
  735. this.depCount -= 1;
  736. this.depExports[i] = depExports;
  737. }
  738. },
  739. fetch: function () {
  740. if (this.fetched) {
  741. return;
  742. }
  743. this.fetched = true;
  744. context.startTime = (new Date()).getTime();
  745. var map = this.map;
  746. //If the manager is for a plugin managed resource,
  747. //ask the plugin to load it now.
  748. if (this.shim) {
  749. context.makeRequire(this.map, {
  750. enableBuildCallback: true
  751. })(this.shim.deps || [], bind(this, function () {
  752. return map.prefix ? this.callPlugin() : this.load();
  753. }));
  754. } else {
  755. //Regular dependency.
  756. return map.prefix ? this.callPlugin() : this.load();
  757. }
  758. },
  759. load: function () {
  760. var url = this.map.url;
  761. //Regular dependency.
  762. if (!urlFetched[url]) {
  763. urlFetched[url] = true;
  764. context.load(this.map.id, url);
  765. }
  766. },
  767. /**
  768. * Checks if the module is ready to define itself, and if so,
  769. * define it.
  770. * @private
  771. */
  772. check: function () {
  773. if (!this.enabled || this.enabling) {
  774. return;
  775. }
  776. var err, cjsModule,
  777. id = this.map.id,
  778. depExports = this.depExports,
  779. exports = this.exports,
  780. factory = this.factory;
  781. if (!this.inited) {
  782. // Only fetch if not already in the defQueue.
  783. if (!hasProp(context.defQueueMap, id)) {
  784. this.fetch();
  785. }
  786. } else if (this.error) {
  787. this.emit('error', this.error);
  788. } else if (!this.defining) {
  789. //The factory could trigger another require call
  790. //that would result in checking this module to
  791. //define itself again. If already in the process
  792. //of doing that, skip this work.
  793. this.defining = true;
  794. if (this.depCount < 1 && !this.defined) {
  795. if (isFunction(factory)) {
  796. //If there is an error listener, favor passing
  797. //to that instead of throwing an error. However,
  798. //only do it for define()'d modules. require
  799. //errbacks should not be called for failures in
  800. //their callbacks (#699). However if a global
  801. //onError is set, use that.
  802. if ((this.events.error && this.map.isDefine) ||
  803. req.onError !== defaultOnError) {
  804. try {
  805. exports = context.execCb(id, factory, depExports, exports);
  806. } catch (e) {
  807. err = e;
  808. }
  809. } else {
  810. exports = context.execCb(id, factory, depExports, exports);
  811. }
  812. // Favor return value over exports. If node/cjs in play,
  813. // then will not have a return value anyway. Favor
  814. // module.exports assignment over exports object.
  815. if (this.map.isDefine && exports === undefined) {
  816. cjsModule = this.module;
  817. if (cjsModule) {
  818. exports = cjsModule.exports;
  819. } else if (this.usingExports) {
  820. //exports already set the defined value.
  821. exports = this.exports;
  822. }
  823. }
  824. if (err) {
  825. err.requireMap = this.map;
  826. err.requireModules = this.map.isDefine ? [this.map.id] : null;
  827. err.requireType = this.map.isDefine ? 'define' : 'require';
  828. return onError((this.error = err));
  829. }
  830. } else {
  831. //Just a literal value
  832. exports = factory;
  833. }
  834. this.exports = exports;
  835. if (this.map.isDefine && !this.ignore) {
  836. defined[id] = exports;
  837. if (req.onResourceLoad) {
  838. req.onResourceLoad(context, this.map, this.depMaps);
  839. }
  840. }
  841. //Clean up
  842. cleanRegistry(id);
  843. this.defined = true;
  844. }
  845. //Finished the define stage. Allow calling check again
  846. //to allow define notifications below in the case of a
  847. //cycle.
  848. this.defining = false;
  849. if (this.defined && !this.defineEmitted) {
  850. this.defineEmitted = true;
  851. this.emit('defined', this.exports);
  852. this.defineEmitComplete = true;
  853. }
  854. }
  855. },
  856. callPlugin: function () {
  857. var map = this.map,
  858. id = map.id,
  859. //Map already normalized the prefix.
  860. pluginMap = makeModuleMap(map.prefix);
  861. //Mark this as a dependency for this plugin, so it
  862. //can be traced for cycles.
  863. this.depMaps.push(pluginMap);
  864. on(pluginMap, 'defined', bind(this, function (plugin) {
  865. var load, normalizedMap, normalizedMod,
  866. bundleId = getOwn(bundlesMap, this.map.id),
  867. name = this.map.name,
  868. parentName = this.map.parentMap ? this.map.parentMap.name : null,
  869. localRequire = context.makeRequire(map.parentMap, {
  870. enableBuildCallback: true
  871. });
  872. //If current map is not normalized, wait for that
  873. //normalized name to load instead of continuing.
  874. if (this.map.unnormalized) {
  875. //Normalize the ID if the plugin allows it.
  876. if (plugin.normalize) {
  877. name = plugin.normalize(name, function (name) {
  878. return normalize(name, parentName, true);
  879. }) || '';
  880. }
  881. //prefix and name should already be normalized, no need
  882. //for applying map config again either.
  883. normalizedMap = makeModuleMap(map.prefix + '!' + name,
  884. this.map.parentMap);
  885. on(normalizedMap,
  886. 'defined', bind(this, function (value) {
  887. this.init([], function () { return value; }, null, {
  888. enabled: true,
  889. ignore: true
  890. });
  891. }));
  892. normalizedMod = getOwn(registry, normalizedMap.id);
  893. if (normalizedMod) {
  894. //Mark this as a dependency for this plugin, so it
  895. //can be traced for cycles.
  896. this.depMaps.push(normalizedMap);
  897. if (this.events.error) {
  898. normalizedMod.on('error', bind(this, function (err) {
  899. this.emit('error', err);
  900. }));
  901. }
  902. normalizedMod.enable();
  903. }
  904. return;
  905. }
  906. //If a paths config, then just load that file instead to
  907. //resolve the plugin, as it is built into that paths layer.
  908. if (bundleId) {
  909. this.map.url = context.nameToUrl(bundleId);
  910. this.load();
  911. return;
  912. }
  913. load = bind(this, function (value) {
  914. this.init([], function () { return value; }, null, {
  915. enabled: true
  916. });
  917. });
  918. load.error = bind(this, function (err) {
  919. this.inited = true;
  920. this.error = err;
  921. err.requireModules = [id];
  922. //Remove temp unnormalized modules for this module,
  923. //since they will never be resolved otherwise now.
  924. eachProp(registry, function (mod) {
  925. if (mod.map.id.indexOf(id + '_unnormalized') === 0) {
  926. cleanRegistry(mod.map.id);
  927. }
  928. });
  929. onError(err);
  930. });
  931. //Allow plugins to load other code without having to know the
  932. //context or how to 'complete' the load.
  933. load.fromText = bind(this, function (text, textAlt) {
  934. /*jslint evil: true */
  935. var moduleName = map.name,
  936. moduleMap = makeModuleMap(moduleName),
  937. hasInteractive = useInteractive;
  938. //As of 2.1.0, support just passing the text, to reinforce
  939. //fromText only being called once per resource. Still
  940. //support old style of passing moduleName but discard
  941. //that moduleName in favor of the internal ref.
  942. if (textAlt) {
  943. text = textAlt;
  944. }
  945. //Turn off interactive script matching for IE for any define
  946. //calls in the text, then turn it back on at the end.
  947. if (hasInteractive) {
  948. useInteractive = false;
  949. }
  950. //Prime the system by creating a module instance for
  951. //it.
  952. getModule(moduleMap);
  953. //Transfer any config to this other module.
  954. if (hasProp(config.config, id)) {
  955. config.config[moduleName] = config.config[id];
  956. }
  957. try {
  958. req.exec(text);
  959. } catch (e) {
  960. return onError(makeError('fromtexteval',
  961. 'fromText eval for ' + id +
  962. ' failed: ' + e,
  963. e,
  964. [id]));
  965. }
  966. if (hasInteractive) {
  967. useInteractive = true;
  968. }
  969. //Mark this as a dependency for the plugin
  970. //resource
  971. this.depMaps.push(moduleMap);
  972. //Support anonymous modules.
  973. context.completeLoad(moduleName);
  974. //Bind the value of that module to the value for this
  975. //resource ID.
  976. localRequire([moduleName], load);
  977. });
  978. //Use parentName here since the plugin's name is not reliable,
  979. //could be some weird string with no path that actually wants to
  980. //reference the parentName's path.
  981. plugin.load(map.name, localRequire, load, config);
  982. }));
  983. context.enable(pluginMap, this);
  984. this.pluginMaps[pluginMap.id] = pluginMap;
  985. },
  986. enable: function () {
  987. enabledRegistry[this.map.id] = this;
  988. this.enabled = true;
  989. //Set flag mentioning that the module is enabling,
  990. //so that immediate calls to the defined callbacks
  991. //for dependencies do not trigger inadvertent load
  992. //with the depCount still being zero.
  993. this.enabling = true;
  994. //Enable each dependency
  995. each(this.depMaps, bind(this, function (depMap, i) {
  996. var id, mod, handler;
  997. if (typeof depMap === 'string') {
  998. //Dependency needs to be converted to a depMap
  999. //and wired up to this module.
  1000. depMap = makeModuleMap(depMap,
  1001. (this.map.isDefine ? this.map : this.map.parentMap),
  1002. false,
  1003. !this.skipMap);
  1004. this.depMaps[i] = depMap;
  1005. handler = getOwn(handlers, depMap.id);
  1006. if (handler) {
  1007. this.depExports[i] = handler(this);
  1008. return;
  1009. }
  1010. this.depCount += 1;
  1011. on(depMap, 'defined', bind(this, function (depExports) {
  1012. if (this.undefed) {
  1013. return;
  1014. }
  1015. this.defineDep(i, depExports);
  1016. this.check();
  1017. }));
  1018. if (this.errback) {
  1019. on(depMap, 'error', bind(this, this.errback));
  1020. } else if (this.events.error) {
  1021. // No direct errback on this module, but something
  1022. // else is listening for errors, so be sure to
  1023. // propagate the error correctly.
  1024. on(depMap, 'error', bind(this, function(err) {
  1025. this.emit('error', err);
  1026. }));
  1027. }
  1028. }
  1029. id = depMap.id;
  1030. mod = registry[id];
  1031. //Skip special modules like 'require', 'exports', 'module'
  1032. //Also, don't call enable if it is already enabled,
  1033. //important in circular dependency cases.
  1034. if (!hasProp(handlers, id) && mod && !mod.enabled) {
  1035. context.enable(depMap, this);
  1036. }
  1037. }));
  1038. //Enable each plugin that is used in
  1039. //a dependency
  1040. eachProp(this.pluginMaps, bind(this, function (pluginMap) {
  1041. var mod = getOwn(registry, pluginMap.id);
  1042. if (mod && !mod.enabled) {
  1043. context.enable(pluginMap, this);
  1044. }
  1045. }));
  1046. this.enabling = false;
  1047. this.check();
  1048. },
  1049. on: function (name, cb) {
  1050. var cbs = this.events[name];
  1051. if (!cbs) {
  1052. cbs = this.events[name] = [];
  1053. }
  1054. cbs.push(cb);
  1055. },
  1056. emit: function (name, evt) {
  1057. each(this.events[name], function (cb) {
  1058. cb(evt);
  1059. });
  1060. if (name === 'error') {
  1061. //Now that the error handler was triggered, remove
  1062. //the listeners, since this broken Module instance
  1063. //can stay around for a while in the registry.
  1064. delete this.events[name];
  1065. }
  1066. }
  1067. };
  1068. function callGetModule(args) {
  1069. //Skip modules already defined.
  1070. if (!hasProp(defined, args[0])) {
  1071. getModule(makeModuleMap(args[0], null, true)).init(args[1], args[2]);
  1072. }
  1073. }
  1074. function removeListener(node, func, name, ieName) {
  1075. //Favor detachEvent because of IE9
  1076. //issue, see attachEvent/addEventListener comment elsewhere
  1077. //in this file.
  1078. if (node.detachEvent && !isOpera) {
  1079. //Probably IE. If not it will throw an error, which will be
  1080. //useful to know.
  1081. if (ieName) {
  1082. node.detachEvent(ieName, func);
  1083. }
  1084. } else {
  1085. node.removeEventListener(name, func, false);
  1086. }
  1087. }
  1088. /**
  1089. * Given an event from a script node, get the requirejs info from it,
  1090. * and then removes the event listeners on the node.
  1091. * @param {Event} evt
  1092. * @private
  1093. * @returns {Object}
  1094. */
  1095. function getScriptData(evt) {
  1096. //Using currentTarget instead of target for Firefox 2.0's sake. Not
  1097. //all old browsers will be supported, but this one was easy enough
  1098. //to support and still makes sense.
  1099. var node = evt.currentTarget || evt.srcElement;
  1100. //Remove the listeners once here.
  1101. removeListener(node, context.onScriptLoad, 'load', 'onreadystatechange');
  1102. removeListener(node, context.onScriptError, 'error');
  1103. return {
  1104. node: node,
  1105. id: node && node.getAttribute('data-requiremodule')
  1106. };
  1107. }
  1108. function intakeDefines() {
  1109. var args;
  1110. //Any defined modules in the global queue, intake them now.
  1111. takeGlobalQueue();
  1112. //Make sure any remaining defQueue items get properly processed.
  1113. while (defQueue.length) {
  1114. args = defQueue.shift();
  1115. if (args[0] === null) {
  1116. return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' +
  1117. args[args.length - 1]));
  1118. } else {
  1119. //args are id, deps, factory. Should be normalized by the
  1120. //define() function.
  1121. callGetModule(args);
  1122. }
  1123. }
  1124. context.defQueueMap = {};
  1125. }
  1126. context = {
  1127. config: config,
  1128. contextName: contextName,
  1129. registry: registry,
  1130. defined: defined,
  1131. urlFetched: urlFetched,
  1132. defQueue: defQueue,
  1133. defQueueMap: {},
  1134. Module: Module,
  1135. makeModuleMap: makeModuleMap,
  1136. nextTick: req.nextTick,
  1137. onError: onError,
  1138. /**
  1139. * @private
  1140. * Set a configuration for the context.
  1141. * @param {Object} cfg config object to integrate.
  1142. */
  1143. configure: function (cfg) {
  1144. //Make sure the baseUrl ends in a slash.
  1145. if (cfg.baseUrl) {
  1146. if (cfg.baseUrl.charAt(cfg.baseUrl.length - 1) !== '/') {
  1147. cfg.baseUrl += '/';
  1148. }
  1149. }
  1150. //Save off the paths since they require special processing,
  1151. //they are additive.
  1152. var shim = config.shim,
  1153. objs = {
  1154. paths: true,
  1155. bundles: true,
  1156. config: true,
  1157. map: true
  1158. };
  1159. eachProp(cfg, function (value, prop) {
  1160. if (objs[prop]) {
  1161. if (!config[prop]) {
  1162. config[prop] = {};
  1163. }
  1164. mixin(config[prop], value, true, true);
  1165. } else {
  1166. config[prop] = value;
  1167. }
  1168. });
  1169. //Reverse map the bundles
  1170. if (cfg.bundles) {
  1171. eachProp(cfg.bundles, function (value, prop) {
  1172. each(value, function (v) {
  1173. if (v !== prop) {
  1174. bundlesMap[v] = prop;
  1175. }
  1176. });
  1177. });
  1178. }
  1179. //Merge shim
  1180. if (cfg.shim) {
  1181. eachProp(cfg.shim, function (value, id) {
  1182. //Normalize the structure
  1183. if (isArray(value)) {
  1184. value = {
  1185. deps: value
  1186. };
  1187. }
  1188. if ((value.exports || value.init) && !value.exportsFn) {
  1189. value.exportsFn = context.makeShimExports(value);
  1190. }
  1191. shim[id] = value;
  1192. });
  1193. config.shim = shim;
  1194. }
  1195. //Adjust packages if necessary.
  1196. if (cfg.packages) {
  1197. each(cfg.packages, function (pkgObj) {
  1198. var location, name;
  1199. pkgObj = typeof pkgObj === 'string' ? {name: pkgObj} : pkgObj;
  1200. name = pkgObj.name;
  1201. location = pkgObj.location;
  1202. if (location) {
  1203. config.paths[name] = pkgObj.location;
  1204. }
  1205. //Save pointer to main module ID for pkg name.
  1206. //Remove leading dot in main, so main paths are normalized,
  1207. //and remove any trailing .js, since different package
  1208. //envs have different conventions: some use a module name,
  1209. //some use a file name.
  1210. config.pkgs[name] = pkgObj.name + '/' + (pkgObj.main || 'main')
  1211. .replace(currDirRegExp, '')
  1212. .replace(jsSuffixRegExp, '');
  1213. });
  1214. }
  1215. //If there are any "waiting to execute" modules in the registry,
  1216. //update the maps for them, since their info, like URLs to load,
  1217. //may have changed.
  1218. eachProp(registry, function (mod, id) {
  1219. //If module already has init called, since it is too
  1220. //late to modify them, and ignore unnormalized ones
  1221. //since they are transient.
  1222. if (!mod.inited && !mod.map.unnormalized) {
  1223. mod.map = makeModuleMap(id, null, true);
  1224. }
  1225. });
  1226. //If a deps array or a config callback is specified, then call
  1227. //require with those args. This is useful when require is defined as a
  1228. //config object before require.js is loaded.
  1229. if (cfg.deps || cfg.callback) {
  1230. context.require(cfg.deps || [], cfg.callback);
  1231. }
  1232. },
  1233. makeShimExports: function (value) {
  1234. function fn() {
  1235. var ret;
  1236. if (value.init) {
  1237. ret = value.init.apply(global, arguments);
  1238. }
  1239. return ret || (value.exports && getGlobal(value.exports));
  1240. }
  1241. return fn;
  1242. },
  1243. makeRequire: function (relMap, options) {
  1244. options = options || {};
  1245. function localRequire(deps, callback, errback) {
  1246. var id, map, requireMod;
  1247. if (options.enableBuildCallback && callback && isFunction(callback)) {
  1248. callback.__requireJsBuild = true;
  1249. }
  1250. if (typeof deps === 'string') {
  1251. if (isFunction(callback)) {
  1252. //Invalid call
  1253. return onError(makeError('requireargs', 'Invalid require call'), errback);
  1254. }
  1255. //If require|exports|module are requested, get the
  1256. //value for them from the special handlers. Caveat:
  1257. //this only works while module is being defined.
  1258. if (relMap && hasProp(handlers, deps)) {
  1259. return handlers[deps](registry[relMap.id]);
  1260. }
  1261. //Synchronous access to one module. If require.get is
  1262. //available (as in the Node adapter), prefer that.
  1263. if (req.get) {
  1264. return req.get(context, deps, relMap, localRequire);
  1265. }
  1266. //Normalize module name, if it contains . or ..
  1267. map = makeModuleMap(deps, relMap, false, true);
  1268. id = map.id;
  1269. if (!hasProp(defined, id)) {
  1270. return onError(makeError('notloaded', 'Module name "' +
  1271. id +
  1272. '" has not been loaded yet for context: ' +
  1273. contextName +
  1274. (relMap ? '' : '. Use require([])')));
  1275. }
  1276. return defined[id];
  1277. }
  1278. //Grab defines waiting in the global queue.
  1279. intakeDefines();
  1280. //Mark all the dependencies as needing to be loaded.
  1281. context.nextTick(function () {
  1282. //Some defines could have been added since the
  1283. //require call, collect them.
  1284. intakeDefines();
  1285. requireMod = getModule(makeModuleMap(null, relMap));
  1286. //Store if map config should be applied to this require
  1287. //call for dependencies.
  1288. requireMod.skipMap = options.skipMap;
  1289. requireMod.init(deps, callback, errback, {
  1290. enabled: true
  1291. });
  1292. checkLoaded();
  1293. });
  1294. return localRequire;
  1295. }
  1296. mixin(localRequire, {
  1297. isBrowser: isBrowser,
  1298. /**
  1299. * Converts a module name + .extension into an URL path.
  1300. * *Requires* the use of a module name. It does not support using
  1301. * plain URLs like nameToUrl.
  1302. */
  1303. toUrl: function (moduleNamePlusExt) {
  1304. var ext,
  1305. index = moduleNamePlusExt.lastIndexOf('.'),
  1306. segment = moduleNamePlusExt.split('/')[0],
  1307. isRelative = segment === '.' || segment === '..';
  1308. //Have a file extension alias, and it is not the
  1309. //dots from a relative path.
  1310. if (index !== -1 && (!isRelative || index > 1)) {
  1311. ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length);
  1312. moduleNamePlusExt = moduleNamePlusExt.substring(0, index);
  1313. }
  1314. return context.nameToUrl(normalize(moduleNamePlusExt,
  1315. relMap && relMap.id, true), ext, true);
  1316. },
  1317. defined: function (id) {
  1318. return hasProp(defined, makeModuleMap(id, relMap, false, true).id);
  1319. },
  1320. specified: function (id) {
  1321. id = makeModuleMap(id, relMap, false, true).id;
  1322. return hasProp(defined, id) || hasProp(registry, id);
  1323. }
  1324. });
  1325. //Only allow undef on top level require calls
  1326. if (!relMap) {
  1327. localRequire.undef = function (id) {
  1328. //Bind any waiting define() calls to this context,
  1329. //fix for #408
  1330. takeGlobalQueue();
  1331. var map = makeModuleMap(id, relMap, true),
  1332. mod = getOwn(registry, id);
  1333. mod.undefed = true;
  1334. removeScript(id);
  1335. delete defined[id];
  1336. delete urlFetched[map.url];
  1337. delete undefEvents[id];
  1338. //Clean queued defines too. Go backwards
  1339. //in array so that the splices do not
  1340. //mess up the iteration.
  1341. eachReverse(defQueue, function(args, i) {
  1342. if (args[0] === id) {
  1343. defQueue.splice(i, 1);
  1344. }
  1345. });
  1346. delete context.defQueueMap[id];
  1347. if (mod) {
  1348. //Hold on to listeners in case the
  1349. //module will be attempted to be reloaded
  1350. //using a different config.
  1351. if (mod.events.defined) {
  1352. undefEvents[id] = mod.events;
  1353. }
  1354. cleanRegistry(id);
  1355. }
  1356. };
  1357. }
  1358. return localRequire;
  1359. },
  1360. /**
  1361. * @private
  1362. * Called to enable a module if it is still in the registry
  1363. * awaiting enablement. A second arg, parent, the parent module,
  1364. * is passed in for context, when this method is overridden by
  1365. * the optimizer. Not shown here to keep code compact.
  1366. */
  1367. enable: function (depMap) {
  1368. var mod = getOwn(registry, depMap.id);
  1369. if (mod) {
  1370. getModule(depMap).enable();
  1371. }
  1372. },
  1373. /**
  1374. * Internal method used by environment adapters to complete a load event.
  1375. * A load event could be a script load or just a load pass from a synchronous
  1376. * load call.
  1377. * @param {String} moduleName the name of the module to potentially complete.
  1378. * @private
  1379. */
  1380. completeLoad: function (moduleName) {
  1381. var found, args, mod,
  1382. shim = getOwn(config.shim, moduleName) || {},
  1383. shExports = shim.exports;
  1384. takeGlobalQueue();
  1385. while (defQueue.length) {
  1386. args = defQueue.shift();
  1387. if (args[0] === null) {
  1388. args[0] = moduleName;
  1389. //If already found an anonymous module and bound it
  1390. //to this name, then this is some other anon module
  1391. //waiting for its completeLoad to fire.
  1392. if (found) {
  1393. break;
  1394. }
  1395. found = true;
  1396. } else if (args[0] === moduleName) {
  1397. //Found matching define call for this script!
  1398. found = true;
  1399. }
  1400. callGetModule(args);
  1401. }
  1402. context.defQueueMap = {};
  1403. //Do this after the cycle of callGetModule in case the result
  1404. //of those calls/init calls changes the registry.
  1405. mod = getOwn(registry, moduleName);
  1406. if (!found && !hasProp(defined, moduleName) && mod && !mod.inited) {
  1407. if (config.enforceDefine && (!shExports || !getGlobal(shExports))) {
  1408. if (hasPathFallback(moduleName)) {
  1409. return;
  1410. } else {
  1411. return onError(makeError('nodefine',
  1412. 'No define call for ' + moduleName,
  1413. null,
  1414. [moduleName]));
  1415. }
  1416. } else {
  1417. //A script that does not call define(), so just simulate
  1418. //the call for it.
  1419. callGetModule([moduleName, (shim.deps || []), shim.exportsFn]);
  1420. }
  1421. }
  1422. checkLoaded();
  1423. },
  1424. /**
  1425. * @private
  1426. * Converts a module name to a file path. Supports cases where
  1427. * moduleName may actually be just an URL.
  1428. * Note that it **does not** call normalize on the moduleName,
  1429. * it is assumed to have already been normalized. This is an
  1430. * internal API, not a public one. Use toUrl for the public API.
  1431. */
  1432. nameToUrl: function (moduleName, ext, skipExt) {
  1433. var paths, syms, i, parentModule, url,
  1434. parentPath, bundleId,
  1435. pkgMain = getOwn(config.pkgs, moduleName);
  1436. if (pkgMain) {
  1437. moduleName = pkgMain;
  1438. }
  1439. bundleId = getOwn(bundlesMap, moduleName);
  1440. if (bundleId) {
  1441. return context.nameToUrl(bundleId, ext, skipExt);
  1442. }
  1443. //If a colon is in the URL, it indicates a protocol is used and it is just
  1444. //an URL to a file, or if it starts with a slash, contains a query arg (i.e. ?)
  1445. //or ends with .js, then assume the user meant to use an url and not a module id.
  1446. //The slash is important for protocol-less URLs as well as full paths.
  1447. if (req.jsExtRegExp.test(moduleName)) {
  1448. //Just a plain path, not module name lookup, so just return it.
  1449. //Add extension if it is included. This is a bit wonky, only non-.js things pass
  1450. //an extension, this method probably needs to be reworked.
  1451. url = moduleName + (ext || '');
  1452. } else {
  1453. //A module that needs to be converted to a path.
  1454. paths = config.paths;
  1455. syms = moduleName.split('/');
  1456. //For each module name segment, see if there is a path
  1457. //registered for it. Start with most specific name
  1458. //and work up from it.
  1459. for (i = syms.length; i > 0; i -= 1) {
  1460. parentModule = syms.slice(0, i).join('/');
  1461. parentPath = getOwn(paths, parentModule);
  1462. if (parentPath) {
  1463. //If an array, it means there are a few choices,
  1464. //Choose the one that is desired
  1465. if (isArray(parentPath)) {
  1466. parentPath = parentPath[0];
  1467. }
  1468. syms.splice(0, i, parentPath);
  1469. break;
  1470. }
  1471. }
  1472. //Join the path parts together, then figure out if baseUrl is needed.
  1473. url = syms.join('/');
  1474. url += (ext || (/^data\:|\?/.test(url) || skipExt ? '' : '.js'));
  1475. url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url;
  1476. }
  1477. return config.urlArgs ? url +
  1478. ((url.indexOf('?') === -1 ? '?' : '&') +
  1479. config.urlArgs) : url;
  1480. },
  1481. //Delegates to req.load. Broken out as a separate function to
  1482. //allow overriding in the optimizer.
  1483. load: function (id, url) {
  1484. req.load(context, id, url);
  1485. },
  1486. /**
  1487. * Executes a module callback function. Broken out as a separate function
  1488. * solely to allow the build system to sequence the files in the built
  1489. * layer in the right sequence.
  1490. *
  1491. * @private
  1492. */
  1493. execCb: function (name, callback, args, exports) {
  1494. return callback.apply(exports, args);
  1495. },
  1496. /**
  1497. * callback for script loads, used to check status of loading.
  1498. * @private
  1499. * @param {Event} evt the event from the browser for the script
  1500. * that was loaded.
  1501. */
  1502. onScriptLoad: function (evt) {
  1503. //Using currentTarget instead of target for Firefox 2.0's sake. Not
  1504. //all old browsers will be supported, but this one was easy enough
  1505. //to support and still makes sense.
  1506. if (evt.type === 'load' ||
  1507. (readyRegExp.test((evt.currentTarget || evt.srcElement).readyState))) {
  1508. //Reset interactive script so a script node is not held onto for
  1509. //to long.
  1510. interactiveScript = null;
  1511. //Pull out the name of the module and the context.
  1512. var data = getScriptData(evt);
  1513. context.completeLoad(data.id);
  1514. }
  1515. },
  1516. /**
  1517. * @private
  1518. * Callback for script errors.
  1519. */
  1520. onScriptError: function (evt) {
  1521. var data = getScriptData(evt);
  1522. if (!hasPathFallback(data.id)) {
  1523. return onError(makeError('scripterror', 'Script error for: ' + data.id, evt, [data.id]));
  1524. }
  1525. }
  1526. };
  1527. context.require = context.makeRequire();
  1528. return context;
  1529. }
  1530. /**
  1531. * Main entry point.
  1532. *
  1533. * If the only argument to require is a string, then the module that
  1534. * is represented by that string is fetched for the appropriate context.
  1535. *
  1536. * If the first argument is an array, then it will be treated as an array
  1537. * of dependency string names to fetch. An optional function callback can
  1538. * be specified to execute when all of those dependencies are available.
  1539. *
  1540. * Make a local req variable to help Caja compliance (it assumes things
  1541. * on a require that are not standardized), and to give a short
  1542. * name for minification/local scope use.
  1543. * @namespace
  1544. */
  1545. req = requirejs = function (deps, callback, errback, optional) {
  1546. //Find the right context, use default
  1547. var context, config,
  1548. contextName = defContextName;
  1549. // Determine if have config object in the call.
  1550. if (!isArray(deps) && typeof deps !== 'string') {
  1551. // deps is a config object
  1552. config = deps;
  1553. if (isArray(callback)) {
  1554. // Adjust args if there are dependencies
  1555. deps = callback;
  1556. callback = errback;
  1557. errback = optional;
  1558. } else {
  1559. deps = [];
  1560. }
  1561. }
  1562. if (config && config.context) {
  1563. contextName = config.context;
  1564. }
  1565. context = getOwn(contexts, contextName);
  1566. if (!context) {
  1567. context = contexts[contextName] = req.s.newContext(contextName);
  1568. }
  1569. if (config) {
  1570. context.configure(config);
  1571. }
  1572. return context.require(deps, callback, errback);
  1573. };
  1574. /**
  1575. * Support require.config() to make it easier to cooperate with other
  1576. * AMD loaders on globally agreed names.
  1577. */
  1578. req.config = function (config) {
  1579. return req(config);
  1580. };
  1581. /**
  1582. * Execute something after the current tick
  1583. * of the event loop. Override for other envs
  1584. * that have a better solution than setTimeout.
  1585. * @param {Function} fn function to execute later.
  1586. */
  1587. req.nextTick = typeof setTimeout !== 'undefined' ? function (fn) {
  1588. setTimeout(fn, 4);
  1589. } : function (fn) { fn(); };
  1590. /**
  1591. * Export require as a global, but only if it does not already exist.
  1592. */
  1593. if (!require) {
  1594. require = req;
  1595. }
  1596. req.version = version;
  1597. //Used to filter out dependencies that are already paths.
  1598. req.jsExtRegExp = /^\/|:|\?|\.js$/;
  1599. req.isBrowser = isBrowser;
  1600. s = req.s = {
  1601. contexts: contexts,
  1602. newContext: newContext
  1603. };
  1604. //Create default context.
  1605. req({});
  1606. //Exports some context-sensitive methods on global require.
  1607. each([
  1608. 'toUrl',
  1609. 'undef',
  1610. 'defined',
  1611. 'specified'
  1612. ], function (prop) {
  1613. //Reference from contexts instead of early binding to default context,
  1614. //so that during builds, the latest instance of the default context
  1615. //with its config gets used.
  1616. req[prop] = function () {
  1617. var ctx = contexts[defContextName];
  1618. return ctx.require[prop].apply(ctx, arguments);
  1619. };
  1620. });
  1621. if (isBrowser) {
  1622. head = s.head = document.getElementsByTagName('head')[0];
  1623. //If BASE tag is in play, using appendChild is a problem for IE6.
  1624. //When that browser dies, this can be removed. Details in this jQuery bug:
  1625. //http://dev.jquery.com/ticket/2709
  1626. baseElement = document.getElementsByTagName('base')[0];
  1627. if (baseElement) {
  1628. head = s.head = baseElement.parentNode;
  1629. }
  1630. }
  1631. /**
  1632. * Any errors that require explicitly generates will be passed to this
  1633. * function. Intercept/override it if you want custom error handling.
  1634. * @param {Error} err the error object.
  1635. */
  1636. req.onError = defaultOnError;
  1637. /**
  1638. * Creates the node for the load command. Only used in browser envs.
  1639. */
  1640. req.createNode = function (config, moduleName, url) {
  1641. var node = config.xhtml ?
  1642. document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') :
  1643. document.createElement('script');
  1644. node.type = config.scriptType || 'text/javascript';
  1645. node.charset = 'utf-8';
  1646. node.async = true;
  1647. return node;
  1648. };
  1649. /**
  1650. * Does the request to load a module for the browser case.
  1651. * Make this a separate function to allow other environments
  1652. * to override it.
  1653. *
  1654. * @param {Object} context the require context to find state.
  1655. * @param {String} moduleName the name of the module.
  1656. * @param {Object} url the URL to the module.
  1657. */
  1658. req.load = function (context, moduleName, url) {
  1659. var config = (context && context.config) || {},
  1660. node;
  1661. if (isBrowser) {
  1662. //In the browser so use a script tag
  1663. node = req.createNode(config, moduleName, url);
  1664. if (config.onNodeCreated) {
  1665. config.onNodeCreated(node, config, moduleName, url);
  1666. }
  1667. node.setAttribute('data-requirecontext', context.contextName);
  1668. node.setAttribute('data-requiremodule', moduleName);
  1669. //Set up load listener. Test attachEvent first because IE9 has
  1670. //a subtle issue in its addEventListener and script onload firings
  1671. //that do not match the behavior of all other browsers with
  1672. //addEventListener support, which fire the onload event for a
  1673. //script right after the script execution. See:
  1674. //https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution
  1675. //UNFORTUNATELY Opera implements attachEvent but does not follow the script
  1676. //script execution mode.
  1677. if (node.attachEvent &&
  1678. //Check if node.attachEvent is artificially added by custom script or
  1679. //natively supported by browser
  1680. //read https://github.com/jrburke/requirejs/issues/187
  1681. //if we can NOT find [native code] then it must NOT natively supported.
  1682. //in IE8, node.attachEvent does not have toString()
  1683. //Note the test for "[native code" with no closing brace, see:
  1684. //https://github.com/jrburke/requirejs/issues/273
  1685. !(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) &&
  1686. !isOpera) {
  1687. //Probably IE. IE (at least 6-8) do not fire
  1688. //script onload right after executing the script, so
  1689. //we cannot tie the anonymous define call to a name.
  1690. //However, IE reports the script as being in 'interactive'
  1691. //readyState at the time of the define call.
  1692. useInteractive = true;
  1693. node.attachEvent('onreadystatechange', context.onScriptLoad);
  1694. //It would be great to add an error handler here to catch
  1695. //404s in IE9+. However, onreadystatechange will fire before
  1696. //the error handler, so that does not help. If addEventListener
  1697. //is used, then IE will fire error before load, but we cannot
  1698. //use that pathway given the connect.microsoft.com issue
  1699. //mentioned above about not doing the 'script execute,
  1700. //then fire the script load event listener before execute
  1701. //next script' that other browsers do.
  1702. //Best hope: IE10 fixes the issues,
  1703. //and then destroys all installs of IE 6-9.
  1704. //node.attachEvent('onerror', context.onScriptError);
  1705. } else {
  1706. node.addEventListener('load', context.onScriptLoad, false);
  1707. node.addEventListener('error', context.onScriptError, false);
  1708. }
  1709. node.src = url;
  1710. //For some cache cases in IE 6-8, the script executes before the end
  1711. //of the appendChild execution, so to tie an anonymous define
  1712. //call to the module name (which is stored on the node), hold on
  1713. //to a reference to this node, but clear after the DOM insertion.
  1714. currentlyAddingScript = node;
  1715. if (baseElement) {
  1716. head.insertBefore(node, baseElement);
  1717. } else {
  1718. head.appendChild(node);
  1719. }
  1720. currentlyAddingScript = null;
  1721. return node;
  1722. } else if (isWebWorker) {
  1723. try {
  1724. //In a web worker, use importScripts. This is not a very
  1725. //efficient use of importScripts, importScripts will block until
  1726. //its script is downloaded and evaluated. However, if web workers
  1727. //are in play, the expectation that a build has been done so that
  1728. //only one script needs to be loaded anyway. This may need to be
  1729. //reevaluated if other use cases become common.
  1730. importScripts(url);
  1731. //Account for anonymous modules
  1732. context.completeLoad(moduleName);
  1733. } catch (e) {
  1734. context.onError(makeError('importscripts',
  1735. 'importScripts failed for ' +
  1736. moduleName + ' at ' + url,
  1737. e,
  1738. [moduleName]));
  1739. }
  1740. }
  1741. };
  1742. function getInteractiveScript() {
  1743. if (interactiveScript && interactiveScript.readyState === 'interactive') {
  1744. return interactiveScript;
  1745. }
  1746. eachReverse(scripts(), function (script) {
  1747. if (script.readyState === 'interactive') {
  1748. return (interactiveScript = script);
  1749. }
  1750. });
  1751. return interactiveScript;
  1752. }
  1753. //Look for a data-main script attribute, which could also adjust the baseUrl.
  1754. if (isBrowser && !cfg.skipDataMain) {
  1755. //Figure out baseUrl. Get it from the script tag with require.js in it.
  1756. eachReverse(scripts(), function (script) {
  1757. //Set the 'head' where we can append children by
  1758. //using the script's parent.
  1759. if (!head) {
  1760. head = script.parentNode;
  1761. }
  1762. //Look for a data-main attribute to set main script for the page
  1763. //to load. If it is there, the path to data main becomes the
  1764. //baseUrl, if it is not already set.
  1765. dataMain = script.getAttribute('data-main');
  1766. if (dataMain) {
  1767. //Preserve dataMain in case it is a path (i.e. contains '?')
  1768. mainScript = dataMain;
  1769. //Set final baseUrl if there is not already an explicit one.
  1770. if (!cfg.baseUrl) {
  1771. //Pull off the directory of data-main for use as the
  1772. //baseUrl.
  1773. src = mainScript.split('/');
  1774. mainScript = src.pop();
  1775. subPath = src.length ? src.join('/') + '/' : './';
  1776. cfg.baseUrl = subPath;
  1777. }
  1778. //Strip off any trailing .js since mainScript is now
  1779. //like a module name.
  1780. mainScript = mainScript.replace(jsSuffixRegExp, '');
  1781. //If mainScript is still a path, fall back to dataMain
  1782. if (req.jsExtRegExp.test(mainScript)) {
  1783. mainScript = dataMain;
  1784. }
  1785. //Put the data-main script in the files to load.
  1786. cfg.deps = cfg.deps ? cfg.deps.concat(mainScript) : [mainScript];
  1787. return true;
  1788. }
  1789. });
  1790. }
  1791. /**
  1792. * The function that handles definitions of modules. Differs from
  1793. * require() in that a string for the module should be the first argument,
  1794. * and the function to execute after dependencies are loaded should
  1795. * return a value to define the module corresponding to the first argument's
  1796. * name.
  1797. */
  1798. define = function (name, deps, callback) {
  1799. var node, context;
  1800. //Allow for anonymous modules
  1801. if (typeof name !== 'string') {
  1802. //Adjust args appropriately
  1803. callback = deps;
  1804. deps = name;
  1805. name = null;
  1806. }
  1807. //This module may not have dependencies
  1808. if (!isArray(deps)) {
  1809. callback = deps;
  1810. deps = null;
  1811. }
  1812. //If no name, and callback is a function, then figure out if it a
  1813. //CommonJS thing with dependencies.
  1814. if (!deps && isFunction(callback)) {
  1815. deps = [];
  1816. //Remove comments from the callback string,
  1817. //look for require calls, and pull them into the dependencies,
  1818. //but only if there are function args.
  1819. if (callback.length) {
  1820. callback
  1821. .toString()
  1822. .replace(commentRegExp, '')
  1823. .replace(cjsRequireRegExp, function (match, dep) {
  1824. deps.push(dep);
  1825. });
  1826. //May be a CommonJS thing even without require calls, but still
  1827. //could use exports, and module. Avoid doing exports and module
  1828. //work though if it just needs require.
  1829. //REQUIRES the function to expect the CommonJS variables in the
  1830. //order listed below.
  1831. deps = (callback.length === 1 ? ['require'] : ['require', 'exports', 'module']).concat(deps);
  1832. }
  1833. }
  1834. //If in IE 6-8 and hit an anonymous define() call, do the interactive
  1835. //work.
  1836. if (useInteractive) {
  1837. node = currentlyAddingScript || getInteractiveScript();
  1838. if (node) {
  1839. if (!name) {
  1840. name = node.getAttribute('data-requiremodule');
  1841. }
  1842. context = contexts[node.getAttribute('data-requirecontext')];
  1843. }
  1844. }
  1845. //Always save off evaluating the def call until the script onload handler.
  1846. //This allows multiple modules to be in a file without prematurely
  1847. //tracing dependencies, and allows for anonymous module support,
  1848. //where the module name is not known until the script onload event
  1849. //occurs. If no context, use the global queue, and get it processed
  1850. //in the onscript load callback.
  1851. if (context) {
  1852. context.defQueue.push([name, deps, callback]);
  1853. context.defQueueMap[name] = true;
  1854. } else {
  1855. globalDefQueue.push([name, deps, callback]);
  1856. }
  1857. };
  1858. define.amd = {
  1859. jQuery: true
  1860. };
  1861. /**
  1862. * Executes the text. Normally just uses eval, but can be modified
  1863. * to use a better, environment-specific call. Only used for transpiling
  1864. * loader plugins, not for plain JS modules.
  1865. * @param {String} text the text to execute/evaluate.
  1866. */
  1867. req.exec = function (text) {
  1868. /*jslint evil: true */
  1869. return eval(text);
  1870. };
  1871. //Set up with config info.
  1872. req(cfg);
  1873. }(this));