cesiumWorkerBootstrapper.js 86 KB

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